~ubuntu-branches/ubuntu/saucy/blender/saucy-proposed

« back to all changes in this revision

Viewing changes to source/blender/editors/transform/transform_orientations.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "DNA_armature_types.h"
34
34
#include "DNA_curve_types.h"
35
35
#include "DNA_mesh_types.h"
 
36
#include "DNA_meta_types.h"
36
37
#include "DNA_object_types.h"
37
38
#include "DNA_scene_types.h"
38
39
#include "DNA_screen_types.h"
42
43
#include "BLI_blenlib.h"
43
44
#include "BLI_utildefines.h"
44
45
 
 
46
#include "BKE_action.h"
45
47
#include "BKE_armature.h"
46
48
#include "BKE_curve.h"
47
49
#include "BKE_context.h"
50
52
 
51
53
#include "BLF_translation.h"
52
54
 
53
 
//#include "BIF_editmesh.h"
54
 
//#include "BIF_interface.h"
55
 
//#include "BIF_space.h"
56
 
//#include "BIF_toolbox.h"
57
 
 
58
55
#include "ED_armature.h"
59
56
#include "ED_mesh.h"
60
57
 
75
72
        
76
73
        // Need to loop over all view3d
77
74
        if (v3d && v3d->twmode >= V3D_MANIP_CUSTOM) {
78
 
                v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global   */
 
75
                v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global   */
79
76
        }
80
77
}
81
78
 
82
 
static TransformOrientation* findOrientationName(ListBase *lb, const char *name)
 
79
static TransformOrientation *findOrientationName(ListBase *lb, const char *name)
83
80
{
84
 
        TransformOrientation *ts= NULL;
 
81
        TransformOrientation *ts = NULL;
85
82
 
86
 
        for (ts= lb->first; ts; ts = ts->next) {
87
 
                if (strncmp(ts->name, name, sizeof(ts->name)-1) == 0) {
 
83
        for (ts = lb->first; ts; ts = ts->next) {
 
84
                if (strncmp(ts->name, name, sizeof(ts->name) - 1) == 0) {
88
85
                        return ts;
89
86
                }
90
87
        }
115
112
                        ts = createBoneSpace(C, reports, name, overwrite);
116
113
        }
117
114
        else if (ob && (ob->mode & OB_MODE_POSE)) {
118
 
                        ts = createBoneSpace(C, reports, name, overwrite);
 
115
                ts = createBoneSpace(C, reports, name, overwrite);
119
116
        }
120
117
        else {
121
118
                ts = createObjectSpace(C, reports, name, overwrite);
143
140
 
144
141
        /* use object name if no name is given */
145
142
        if (name[0] == 0) {
146
 
                strncpy(name, ob->id.name+2, MAX_ID_NAME-2);
 
143
                strncpy(name, ob->id.name + 2, MAX_ID_NAME - 2);
147
144
        }
148
145
 
149
 
        return addMatrixSpace(C, mat, name, overwrite); 
 
146
        return addMatrixSpace(C, mat, name, overwrite);
150
147
}
151
148
 
152
149
TransformOrientation *createBoneSpace(bContext *C, ReportList *reports, char *name, int overwrite)
176
173
 
177
174
        type = getTransformOrientation(C, normal, plane, 0);
178
175
        
179
 
        switch (type)
180
 
        {
 
176
        switch (type) {
181
177
                case ORIENTATION_VERT:
182
178
                        if (createSpaceNormal(mat, normal) == 0) {
183
179
                                BKE_reports_prepend(reports, "Cannot use vertex with zero-length normal");
263
259
        return 1;
264
260
}
265
261
 
266
 
TransformOrientation* addMatrixSpace(bContext *C, float mat[3][3], char name[], int overwrite)
 
262
TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], char name[], int overwrite)
267
263
{
268
264
        ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
269
265
        TransformOrientation *ts = NULL;
302
298
                                
303
299
                                // Transform_fix_me NEED TO DO THIS FOR ALL VIEW3D
304
300
                                if (selected_index == i) {
305
 
                                        v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global   */
 
301
                                        v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global   */
306
302
                                }
307
303
                                else if (selected_index > i) {
308
304
                                        v3d->twmode--;
319
315
void BIF_removeTransformOrientationIndex(bContext *C, int index)
320
316
{
321
317
        ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
322
 
        TransformOrientation *ts= BLI_findlink(transform_spaces, index);
 
318
        TransformOrientation *ts = BLI_findlink(transform_spaces, index);
323
319
 
324
320
        if (ts) {
325
321
                View3D *v3d = CTX_wm_view3d(C);
328
324
                        
329
325
                        // Transform_fix_me NEED TO DO THIS FOR ALL VIEW3D
330
326
                        if (selected_index == index) {
331
 
                                v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global   */
 
327
                                v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global   */
332
328
                        }
333
329
                        else if (selected_index > index) {
334
330
                                v3d->twmode--;
366
362
{
367
363
        Scene *scene;
368
364
        ListBase *transform_spaces;
369
 
        TransformOrientation *ts= NULL;
 
365
        TransformOrientation *ts = NULL;
370
366
 
371
 
        EnumPropertyItem global = {V3D_MANIP_GLOBAL, "GLOBAL", 0, "Global", ""};
 
367
        EnumPropertyItem global = {V3D_MANIP_GLOBAL, "GLOBAL", 0, "Global", ""};
372
368
        EnumPropertyItem normal = {V3D_MANIP_NORMAL, "NORMAL", 0, "Normal", ""};
373
369
        EnumPropertyItem local = {V3D_MANIP_LOCAL, "LOCAL", 0, "Local", ""};
374
370
        EnumPropertyItem view = {V3D_MANIP_VIEW, "VIEW", 0, "View", ""};
375
371
        EnumPropertyItem tmp = {0, "", 0, "", ""};
376
 
        EnumPropertyItem *item= NULL;
377
 
        int i = V3D_MANIP_CUSTOM, totitem= 0;
 
372
        EnumPropertyItem *item = NULL;
 
373
        int i = V3D_MANIP_CUSTOM, totitem = 0;
378
374
 
379
375
        RNA_enum_item_add(&item, &totitem, &global);
380
376
        RNA_enum_item_add(&item, &totitem, &normal);
382
378
        RNA_enum_item_add(&item, &totitem, &view);
383
379
 
384
380
        if (C) {
385
 
                scene= CTX_data_scene(C);
 
381
                scene = CTX_data_scene(C);
386
382
 
387
383
                if (scene) {
388
384
                        transform_spaces = &scene->transform_spaces;
395
391
 
396
392
        for (; ts; ts = ts->next) {
397
393
                tmp.identifier = "CUSTOM";
398
 
                tmp.name= ts->name;
 
394
                tmp.name = ts->name;
399
395
                tmp.value = i++;
400
396
                RNA_enum_item_add(&item, &totitem, &tmp);
401
397
        }
405
401
        return item;
406
402
}
407
403
 
408
 
const char * BIF_menustringTransformOrientation(const bContext *C, const char *title)
 
404
const char *BIF_menustringTransformOrientation(const bContext *C, const char *title)
409
405
{
410
 
        const char* menu = IFACE_("%t|Global%x0|Local%x1|Gimbal%x4|Normal%x2|View%x3");
 
406
        const char *menu = IFACE_("%t|Global %x0|Local %x1|Gimbal %x4|Normal %x2|View %x3");
411
407
        ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
412
408
        TransformOrientation *ts;
413
409
        int i = V3D_MANIP_CUSTOM;
416
412
 
417
413
        title = IFACE_(title);
418
414
 
419
 
        str_menu = MEM_callocN(strlen(menu) + strlen(title) + 1 + elem_size * BIF_countTransformOrientation(C), TIP_("UserTransSpace from matrix"));
 
415
        str_menu = MEM_callocN(strlen(menu) + strlen(title) + 1 + elem_size * BIF_countTransformOrientation(C), "UserTransSpace from matrix");
420
416
        p = str_menu;
421
417
        
422
418
        p += sprintf(str_menu, "%s", title);
423
419
        p += sprintf(p, "%s", menu);
424
420
        
425
421
        for (ts = transform_spaces->first; ts; ts = ts->next) {
426
 
                p += sprintf(p, "|%s%%x%d", ts->name, i++);
 
422
                p += sprintf(p, "|%s %%x%d", ts->name, i++);
427
423
        }
428
424
        
429
425
        return str_menu;
442
438
        return count;
443
439
}
444
440
 
445
 
void applyTransformOrientation(const bContext *C, float mat[3][3], char *name)
 
441
void applyTransformOrientation(const bContext *C, float mat[3][3], char name[MAX_NAME])
446
442
{
447
443
        TransformOrientation *ts;
448
444
        View3D *v3d = CTX_wm_view3d(C);
453
449
                for (i = 0, ts = CTX_data_scene(C)->transform_spaces.first; ts; ts = ts->next, i++) {
454
450
                        if (selected_index == i) {
455
451
                                
456
 
                                if (name)
457
 
                                        strcpy(name, ts->name);
 
452
                                if (name) {
 
453
                                        BLI_strncpy(name, ts->name, MAX_NAME);
 
454
                                }
458
455
                                
459
456
                                copy_m3_m3(mat, ts->mat);
460
457
                                break;
461
458
                        }
462
459
                }
463
 
          }
 
460
        }
464
461
}
465
462
 
466
463
static int count_bone_select(bArmature *arm, ListBase *lb, int do_it) 
469
466
        int do_next;
470
467
        int total = 0;
471
468
        
472
 
        for (bone= lb->first; bone; bone= bone->next) {
 
469
        for (bone = lb->first; bone; bone = bone->next) {
473
470
                bone->flag &= ~BONE_TRANSFORM;
474
471
                do_next = do_it;
475
472
                if (do_it) {
477
474
                                if (bone->flag & BONE_SELECTED) {
478
475
                                        bone->flag |= BONE_TRANSFORM;
479
476
                                        total++;
480
 
                                        do_next= 0;     // no transform on children if one parent bone is selected
 
477
                                        do_next = FALSE;    // no transform on children if one parent bone is selected
481
478
                                }
482
479
                        }
483
480
                }
493
490
        Object *ob = CTX_data_active_object(C);
494
491
        Object *obedit = CTX_data_active_object(C);
495
492
 
496
 
        switch(t->current_orientation) {
497
 
        case V3D_MANIP_GLOBAL:
498
 
                unit_m3(t->spacemtx);
499
 
                strcpy(t->spacename, "global");
500
 
                break;
501
 
 
502
 
        case V3D_MANIP_GIMBAL:
503
 
                unit_m3(t->spacemtx);
504
 
                if (gimbal_axis(ob, t->spacemtx)) {
505
 
                        strcpy(t->spacename, "gimbal");
 
493
        switch (t->current_orientation) {
 
494
                case V3D_MANIP_GLOBAL:
 
495
                        unit_m3(t->spacemtx);
 
496
                        strcpy(t->spacename, IFACE_("global"));
506
497
                        break;
507
 
                }
 
498
 
 
499
                case V3D_MANIP_GIMBAL:
 
500
                        unit_m3(t->spacemtx);
 
501
                        if (gimbal_axis(ob, t->spacemtx)) {
 
502
                                strcpy(t->spacename, IFACE_("gimbal"));
 
503
                                break;
 
504
                        }
508
505
                /* no gimbal fallthrough to normal */
509
 
        case V3D_MANIP_NORMAL:
510
 
                if (obedit || (ob && ob->mode & OB_MODE_POSE)) {
511
 
                        strcpy(t->spacename, "normal");
512
 
                        ED_getTransformOrientationMatrix(C, t->spacemtx, (v3d->around == V3D_ACTIVE));
513
 
                        break;
514
 
                }
 
506
                case V3D_MANIP_NORMAL:
 
507
                        if (obedit || (ob && ob->mode & OB_MODE_POSE)) {
 
508
                                strcpy(t->spacename, IFACE_("normal"));
 
509
                                ED_getTransformOrientationMatrix(C, t->spacemtx, (v3d->around == V3D_ACTIVE));
 
510
                                break;
 
511
                        }
515
512
                /* no break we define 'normal' as 'local' in Object mode */
516
 
        case V3D_MANIP_LOCAL:
517
 
                strcpy(t->spacename, "local");
518
 
                
519
 
                if (ob) {
520
 
                        copy_m3_m4(t->spacemtx, ob->obmat);
521
 
                        normalize_m3(t->spacemtx);
522
 
                }
523
 
                else {
524
 
                        unit_m3(t->spacemtx);
525
 
                }
526
 
                
527
 
                break;
528
 
                
529
 
        case V3D_MANIP_VIEW:
530
 
                if (t->ar->regiontype == RGN_TYPE_WINDOW) {
531
 
                        RegionView3D *rv3d = t->ar->regiondata;
532
 
                        float mat[3][3];
 
513
                case V3D_MANIP_LOCAL:
 
514
                        strcpy(t->spacename, IFACE_("local"));
 
515
                
 
516
                        if (ob) {
 
517
                                copy_m3_m4(t->spacemtx, ob->obmat);
 
518
                                normalize_m3(t->spacemtx);
 
519
                        }
 
520
                        else {
 
521
                                unit_m3(t->spacemtx);
 
522
                        }
 
523
                
 
524
                        break;
 
525
                
 
526
                case V3D_MANIP_VIEW:
 
527
                        if (t->ar->regiontype == RGN_TYPE_WINDOW) {
 
528
                                RegionView3D *rv3d = t->ar->regiondata;
 
529
                                float mat[3][3];
533
530
 
534
 
                        strcpy(t->spacename, "view");
535
 
                        copy_m3_m4(mat, rv3d->viewinv);
536
 
                        normalize_m3(mat);
537
 
                        copy_m3_m3(t->spacemtx, mat);
538
 
                }
539
 
                else {
540
 
                        unit_m3(t->spacemtx);
541
 
                }
542
 
                break;
543
 
        default: /* V3D_MANIP_CUSTOM */
544
 
                applyTransformOrientation(C, t->spacemtx, t->spacename);
545
 
                break;
 
531
                                strcpy(t->spacename, IFACE_("view"));
 
532
                                copy_m3_m4(mat, rv3d->viewinv);
 
533
                                normalize_m3(mat);
 
534
                                copy_m3_m3(t->spacemtx, mat);
 
535
                        }
 
536
                        else {
 
537
                                unit_m3(t->spacemtx);
 
538
                        }
 
539
                        break;
 
540
                default: /* V3D_MANIP_CUSTOM */
 
541
                        applyTransformOrientation(C, t->spacemtx, t->spacename);
 
542
                        break;
546
543
        }
547
544
}
548
545
 
550
547
{
551
548
        Scene *scene = CTX_data_scene(C);
552
549
        View3D *v3d = CTX_wm_view3d(C);
553
 
        Object *obedit= CTX_data_edit_object(C);
 
550
        Object *obedit = CTX_data_edit_object(C);
554
551
        Base *base;
555
552
        Object *ob = OBACT;
556
553
        int result = ORIENTATION_NONE;
557
554
 
558
 
        normal[0] = normal[1] = normal[2] = 0;
559
 
        plane[0] = plane[1] = plane[2] = 0;
 
555
        zero_v3(normal);
 
556
        zero_v3(plane);
560
557
 
561
558
        if (obedit) {
562
559
                float imat[3][3], mat[3][3];
567
564
                invert_m3_m3(mat, imat);
568
565
                transpose_m3(mat);
569
566
 
570
 
                ob= obedit;
 
567
                ob = obedit;
571
568
 
572
 
                if (ob->type==OB_MESH) {
573
 
                        Mesh *me= ob->data;
574
 
                        BMEditMesh *em = me->edit_btmesh;
 
569
                if (ob->type == OB_MESH) {
 
570
                        BMEditMesh *em = BMEdit_FromObject(ob);
575
571
                        BMVert *eve;
576
572
                        BMEditSelection ese;
577
 
                        float vec[3]= {0,0,0};
 
573
                        float vec[3] = {0, 0, 0};
578
574
                        
579
575
                        /* USE LAST SELECTED WITH ACTIVE */
580
576
                        if (activeOnly && BM_select_history_active_get(em->bm, &ese)) {
581
577
                                BM_editselection_normal(&ese, normal);
582
578
                                BM_editselection_plane(&ese, plane);
583
579
                                
584
 
                                switch (ese.htype)
585
 
                                {
 
580
                                switch (ese.htype) {
586
581
                                        case BM_VERT:
587
582
                                                result = ORIENTATION_VERT;
588
583
                                                break;
638
633
                                        /* if there's an edge available, use that for the tangent */
639
634
                                        if (em->bm->totedgesel >= 1) {
640
635
                                                BMEdge *eed = NULL;
641
 
                                                BMIter iter;
642
636
                                                
643
637
                                                BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
644
638
                                                        if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
713
707
                        }
714
708
                } /* end editmesh */
715
709
                else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
716
 
                        Curve *cu= obedit->data;
 
710
                        Curve *cu = obedit->data;
717
711
                        Nurb *nu;
718
712
                        BezTriple *bezt;
719
713
                        int a;
720
 
                        ListBase *nurbs= curve_editnurbs(cu);
 
714
                        ListBase *nurbs = BKE_curve_editNurbs_get(cu);
721
715
 
722
716
                        for (nu = nurbs->first; nu; nu = nu->next) {
723
717
                                /* only bezier has a normal */
724
718
                                if (nu->type == CU_BEZIER) {
725
 
                                        bezt= nu->bezt;
726
 
                                        a= nu->pntsu;
727
 
                                        while (a--)
728
 
                                        {
 
719
                                        bezt = nu->bezt;
 
720
                                        a = nu->pntsu;
 
721
                                        while (a--) {
729
722
                                                /* exception */
730
723
                                                if ((bezt->f1 & SELECT) + (bezt->f2 & SELECT) + (bezt->f3 & SELECT) > SELECT) {
731
724
                                                        sub_v3_v3v3(normal, bezt->vec[0], bezt->vec[2]);
746
739
                                }
747
740
                        }
748
741
                        
749
 
                        if (normal[0] != 0 || normal[1] != 0 || normal[2] != 0) {
 
742
                        if (!is_zero_v3(normal)) {
750
743
                                result = ORIENTATION_NORMAL;
751
744
                        }
752
745
                }
753
 
                else if (obedit->type==OB_MBALL) {
754
 
#if 0 // XXX
755
 
                        /* editmball.c */
756
 
                        MetaElem *ml, *ml_sel = NULL;
757
 
        
758
 
                        /* loop and check that only one element is selected */  
759
 
                        for (ml = editelems.first; ml; ml = ml->next) {
760
 
                                if (ml->flag & SELECT) {
761
 
                                        if (ml_sel == NULL) {
762
 
                                                ml_sel = ml;
763
 
                                        }
764
 
                                        else {
765
 
                                                ml_sel = NULL;
766
 
                                                break;
767
 
                                        }
768
 
                                }
769
 
                        }
 
746
                else if (obedit->type == OB_MBALL) {
 
747
                        MetaBall *mb = obedit->data;
770
748
                        
771
 
                        if (ml_sel) {   
772
 
                                float mat[4][4];
 
749
                        if (mb->lastelem) {
 
750
                                float qmat[3][3];
773
751
 
774
752
                                /* Rotation of MetaElem is stored in quat */
775
 
                                quat_to_mat4( mat,ml_sel->quat);
776
 
 
777
 
                                copy_v3_v3(normal, mat[2]);
778
 
 
779
 
                                negate_v3_v3(plane, mat[1]);
 
753
                                quat_to_mat3(qmat, mb->lastelem->quat);
 
754
 
 
755
                                copy_v3_v3(normal, qmat[2]);
 
756
 
 
757
                                negate_v3_v3(plane, qmat[1]);
780
758
                                
781
 
                                result = ORIENTATION_NORMAL;
 
759
                                result = ORIENTATION_FACE;
782
760
                        }
783
 
#endif
784
 
                        
785
761
                }
786
762
                else if (obedit->type == OB_ARMATURE) {
787
763
                        bArmature *arm = obedit->data;
788
764
                        EditBone *ebone;
 
765
                        int ok = FALSE;
789
766
                        
790
 
                        for (ebone = arm->edbo->first; ebone; ebone=ebone->next) {
791
 
                                if (arm->layer & ebone->layer) {
792
 
                                        if (ebone->flag & BONE_SELECTED) {
793
 
                                                float tmat[3][3];
794
 
                                                float vec[3];
795
 
                                                sub_v3_v3v3(vec, ebone->tail, ebone->head);
796
 
                                                normalize_v3(vec);
797
 
                                                add_v3_v3(normal, vec);
798
 
                                                
799
 
                                                vec_roll_to_mat3(vec, ebone->roll, tmat);
800
 
                                                add_v3_v3(plane, tmat[2]);
 
767
                        /* grr. but better then duplicate code */
 
768
#define EBONE_CALC_NORMAL_PLANE  { \
 
769
                        float tmat[3][3]; \
 
770
                        float vec[3]; \
 
771
                        sub_v3_v3v3(vec, ebone->tail, ebone->head); \
 
772
                        normalize_v3(vec); \
 
773
                        add_v3_v3(normal, vec); \
 
774
                        \
 
775
                        vec_roll_to_mat3(vec, ebone->roll, tmat); \
 
776
                        add_v3_v3(plane, tmat[2]); \
 
777
                } (void)0
 
778
 
 
779
 
 
780
                        if (activeOnly && (ebone = arm->act_edbone)) {
 
781
                                EBONE_CALC_NORMAL_PLANE;
 
782
                                ok = TRUE;
 
783
                        }
 
784
                        else {
 
785
                                for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
 
786
                                        if (arm->layer & ebone->layer) {
 
787
                                                if (ebone->flag & BONE_SELECTED) {
 
788
                                                        EBONE_CALC_NORMAL_PLANE;
 
789
                                                        ok = TRUE;
 
790
                                                }
801
791
                                        }
802
792
                                }
803
793
                        }
804
794
                        
805
 
                        normalize_v3(normal);
806
 
                        normalize_v3(plane);
 
795
                        if (ok) {
 
796
                                normalize_v3(normal);
 
797
                                normalize_v3(plane);
807
798
 
808
 
                        if (plane[0] != 0 || plane[1] != 0 || plane[2] != 0) {
809
 
                                result = ORIENTATION_EDGE;
 
799
                                if (!is_zero_v3(plane)) {
 
800
                                        result = ORIENTATION_EDGE;
 
801
                                }
810
802
                        }
811
 
 
 
803
#undef EBONE_CALC_NORMAL_PLANE
812
804
                }
813
805
 
814
806
                /* Vectors from edges don't need the special transpose inverse multiplication */
822
814
                }
823
815
        }
824
816
        else if (ob && (ob->mode & OB_MODE_POSE)) {
825
 
                bArmature *arm= ob->data;
 
817
                bArmature *arm = ob->data;
826
818
                bPoseChannel *pchan;
827
 
                int totsel;
828
 
                
829
 
                totsel = count_bone_select(arm, &arm->bonebase, 1);
830
 
                if (totsel) {
831
 
                        float imat[3][3], mat[3][3];
832
 
 
833
 
                        /* use channels to get stats */
834
 
                        for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
835
 
                                if (pchan->bone && pchan->bone->flag & BONE_TRANSFORM) {
836
 
                                        add_v3_v3(normal, pchan->pose_mat[2]);
837
 
                                        add_v3_v3(plane, pchan->pose_mat[1]);
 
819
                float imat[3][3], mat[3][3];
 
820
                int ok = FALSE;
 
821
 
 
822
                if (activeOnly && (pchan = BKE_pose_channel_active(ob))) {
 
823
                        add_v3_v3(normal, pchan->pose_mat[2]);
 
824
                        add_v3_v3(plane, pchan->pose_mat[1]);
 
825
                        ok = TRUE;
 
826
                }
 
827
                else {
 
828
                        int totsel;
 
829
 
 
830
                        totsel = count_bone_select(arm, &arm->bonebase, 1);
 
831
                        if (totsel) {
 
832
                                /* use channels to get stats */
 
833
                                for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
 
834
                                        if (pchan->bone && pchan->bone->flag & BONE_TRANSFORM) {
 
835
                                                add_v3_v3(normal, pchan->pose_mat[2]);
 
836
                                                add_v3_v3(plane, pchan->pose_mat[1]);
 
837
                                        }
838
838
                                }
 
839
                                ok = TRUE;
839
840
                        }
 
841
                }
 
842
 
 
843
                /* use for both active & all */
 
844
                if (ok) {
840
845
                        negate_v3(plane);
841
846
                        
842
847
                        /* we need the transpose of the inverse for a normal... */
850
855
                        result = ORIENTATION_EDGE;
851
856
                }
852
857
        }
853
 
        else if (ob && (ob->mode & (OB_MODE_ALL_PAINT|OB_MODE_PARTICLE_EDIT))) {
 
858
        else if (ob && (ob->mode & (OB_MODE_ALL_PAINT | OB_MODE_PARTICLE_EDIT))) {
854
859
                /* pass */
855
860
        }
856
861
        else {
858
863
                ob = OBACT;
859
864
                if (ob && !(ob->flag & SELECT)) ob = NULL;
860
865
                
861
 
                for (base= scene->base.first; base; base= base->next) {
 
866
                for (base = scene->base.first; base; base = base->next) {
862
867
                        if (TESTBASELIB(v3d, base)) {
863
868
                                if (ob == NULL) {
864
 
                                        ob= base->object;
 
869
                                        ob = base->object;
865
870
                                        break;
866
871
                                }
867
872
                        }
877
882
        return result;
878
883
}
879
884
 
880
 
void ED_getTransformOrientationMatrix(const bContext *C, float orientation_mat[][3], int activeOnly)
 
885
void ED_getTransformOrientationMatrix(const bContext *C, float orientation_mat[3][3], int activeOnly)
881
886
{
882
 
        float normal[3]={0.0, 0.0, 0.0};
883
 
        float plane[3]={0.0, 0.0, 0.0};
 
887
        float normal[3] = {0.0, 0.0, 0.0};
 
888
        float plane[3] = {0.0, 0.0, 0.0};
884
889
 
885
890
        int type;
886
891
 
887
892
        type = getTransformOrientation(C, normal, plane, activeOnly);
888
893
 
889
 
        switch (type)
890
 
        {
 
894
        switch (type) {
891
895
                case ORIENTATION_NORMAL:
892
896
                        if (createSpaceNormalTangent(orientation_mat, normal, plane) == 0) {
893
897
                                type = ORIENTATION_NONE;