svn merge -r41575:41602 ^/trunk/blender
[blender.git] / source / blender / editors / transform / transform_orientations.c
index 5d61d2a1ebb434f089819110ad251ef285b641a9..69753032f42c70a4f400119359283240c25ee3b6 100644 (file)
@@ -41,6 +41,7 @@
 #include "BKE_armature.h"
 #include "BKE_curve.h"
 #include "BKE_context.h"
+#include "BKE_tessmesh.h"
 #include "BKE_report.h"
 
 #include "BLI_math.h"
@@ -572,56 +573,57 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
                if(ob->type==OB_MESH)
                {
                        Mesh *me= ob->data;
-                       EditMesh *em = me->edit_mesh;
-                       EditVert *eve;
-                       EditSelection ese;
+                       BMEditMesh *em = me->edit_btmesh;
+                       BMVert *eve;
+                       BMEditSelection ese;
                        float vec[3]= {0,0,0};
                        
                        /* USE LAST SELECTED WITH ACTIVE */
-                       if (activeOnly && EM_get_actSelection(em, &ese))
+                       if (activeOnly && EDBM_get_actSelection(em, &ese))
                        {
-                               EM_editselection_normal(normal, &ese);
-                               EM_editselection_plane(plane, &ese);
+                               EDBM_editselection_normal(normal, &ese);
+                               EDBM_editselection_plane(em, plane, &ese);
                                
-                               switch (ese.type)
+                               switch (ese.htype)
                                {
-                                       case EDITVERT:
+                                       case BM_VERT:
                                                result = ORIENTATION_VERT;
                                                break;
-                                       case EDITEDGE:
+                                       case BM_EDGE:
                                                result = ORIENTATION_EDGE;
                                                break;
-                                       case EDITFACE:
+                                       case BM_FACE:
                                                result = ORIENTATION_FACE;
                                                break;
                                }
                        }
                        else
                        {
-                               if (em->totfacesel >= 1)
+                               if (em->bm->totfacesel >= 1)
                                {
-                                       EditFace *efa;
-                                       
-                                       for(efa= em->faces.first; efa; efa= efa->next)
-                                       {
-                                               if(efa->f & SELECT)
-                                               {
-                                                       add_v3_v3(normal, efa->n);
-                                                       sub_v3_v3v3(vec, efa->v2->co, efa->v1->co);
+                                       BMFace *efa;
+                                       BMIter iter;
+
+                                       BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
+                                               if(BM_TestHFlag(efa, BM_SELECT)) {
+                                                       add_v3_v3(normal, efa->no);
+                                                       sub_v3_v3v3(vec,
+                                                                   ((BMLoopList*)efa->loops.first)->first->v->co,
+                                                                   (((BMLoopList*)efa->loops.first)->first->next)->v->co);
                                                        add_v3_v3(plane, vec);
                                                }
                                        }
                                        
                                        result = ORIENTATION_FACE;
                                }
-                               else if (em->totvertsel == 3)
+                               else if (em->bm->totvertsel == 3)
                                {
-                                       EditVert *v1 = NULL, *v2 = NULL, *v3 = NULL;
+                                       BMVert *v1 = NULL, *v2 = NULL, *v3 = NULL;
+                                       BMIter iter;
                                        float cotangent[3];
                                        
-                                       for (eve = em->verts.first; eve; eve = eve->next)
-                                       {
-                                               if ( eve->f & SELECT ) {
+                                       BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+                                               if (BM_TestHFlag(eve, BM_SELECT)) {
                                                        if (v1 == NULL) {
                                                                v1 = eve; 
                                                        }
@@ -640,12 +642,13 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
                                        }
 
                                        /* if there's an edge available, use that for the tangent */
-                                       if (em->totedgesel >= 1)
+                                       if (em->bm->totedgesel >= 1)
                                        {
-                                               EditEdge *eed = NULL;
-       
-                                               for(eed= em->edges.first; eed; eed= eed->next) {
-                                                       if(eed->f & SELECT) {
+                                               BMEdge *eed = NULL;
+                                               BMIter iter;
+                                               
+                                               BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) {
+                                                       if(BM_TestHFlag(eed, BM_SELECT)) {
                                                                sub_v3_v3v3(plane, eed->v2->co, eed->v1->co);
                                                                break;
                                                        }
@@ -654,12 +657,13 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
 
                                        result = ORIENTATION_FACE;
                                }
-                               else if (em->totedgesel == 1)
+                               else if (em->bm->totedgesel == 1)
                                {
-                                       EditEdge *eed;
-
-                                       for(eed= em->edges.first; eed; eed= eed->next) {
-                                               if(eed->f & SELECT) {
+                                       BMEdge *eed = NULL;
+                                       BMIter iter;
+                                       
+                                       BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) {
+                                               if(BM_TestHFlag(eed, BM_SELECT)) {
                                                        /* use average vert normals as plane and edge vector as normal */
                                                        copy_v3_v3(plane, eed->v1->no);
                                                        add_v3_v3(plane, eed->v2->no);
@@ -669,13 +673,13 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
                                        }
                                        result = ORIENTATION_EDGE;
                                }
-                               else if (em->totvertsel == 2)
+                               else if (em->bm->totvertsel == 2)
                                {
-                                       EditVert *v1 = NULL, *v2 = NULL;
-               
-                                       for (eve = em->verts.first; eve; eve = eve->next)
-                                       {
-                                               if ( eve->f & SELECT ) {
+                                       BMVert *v1 = NULL, *v2 = NULL;
+                                       BMIter iter;
+
+                                       BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+                                               if (BM_TestHFlag(eve, BM_SELECT)) {
                                                        if (v1 == NULL) {
                                                                v1 = eve; 
                                                        }
@@ -691,24 +695,25 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
                                        }
                                        result = ORIENTATION_EDGE;
                                }
-                               else if (em->totvertsel == 1)
+                               else if (em->bm->totvertsel == 1)
                                {
-                                       for (eve = em->verts.first; eve; eve = eve->next)
-                                       {
-                                               if ( eve->f & SELECT ) {
+                                       BMIter iter;
+
+                                       BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+                                               if (BM_TestHFlag(eve, BM_SELECT)) {
                                                        copy_v3_v3(normal, eve->no);
                                                        break;
                                                }
                                        }
                                        result = ORIENTATION_VERT;
                                }
-                               else if (em->totvertsel > 3)
+                               else if (em->bm->totvertsel > 3)
                                {
-                                       normal[0] = normal[1] = normal[2] = 0;
-                                       
-                                       for (eve = em->verts.first; eve; eve = eve->next)
-                                       {
-                                               if ( eve->f & SELECT ) {
+                                       BMIter iter;
+                                       normal[0] = normal[1] = normal[2] = 0.0f;
+
+                                       BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+                                               if (BM_TestHFlag(eve, BM_SELECT)) {
                                                        add_v3_v3(normal, eve->no);
                                                }
                                        }
@@ -898,6 +903,14 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
                        copy_v3_v3(normal, ob->obmat[2]);
                        copy_v3_v3(plane, ob->obmat[1]);
                }
+               else {
+                       normal[0] = 0.0f;
+                       normal[1] = 0.0f;
+                       normal[2] = 1.0f;
+                       plane[0] = 1.0f;
+                       plane[1] = 0.0f;
+                       plane[2] = 0.0f;
+               }
                result = ORIENTATION_NORMAL;
        }