svn merge -r37500:37600 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / editors / transform / transform_snap.c
index c4d6eb020288ea765b274776b6e832d1db8d72ca..5bf97fd947a88a7adc6ce04f0f724af8dc9ea98a 100644 (file)
@@ -70,6 +70,8 @@
 #include "BKE_object.h"
 #include "BKE_anim.h" /* for duplis */
 #include "BKE_context.h"
+#include "BKE_tessmesh.h"
+#include "BKE_mesh.h"
 
 #include "ED_armature.h"
 #include "ED_image.h"
@@ -1280,11 +1282,14 @@ static int snapArmature(short snap_mode, ARegion *ar, Object *ob, bArmature *arm
        return retval;
 }
 
-static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, EditMesh *em, float obmat[][4], float ray_start[3], float ray_normal[3], float mval[2], float *loc, float *no, int *dist, float *depth)
+static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, 
+                                                  DerivedMesh *dm, BMEditMesh *em, float obmat[][4], 
+                                                  float ray_start[3], float ray_normal[3], float mval[2],
+                                                  float *loc, float *no, int *dist, float *depth)
 {
        int retval = 0;
        int totvert = dm->getNumVerts(dm);
-       int totface = dm->getNumFaces(dm);
+       int totface = dm->getNumTessFaces(dm);
 
        if (totvert > 0) {
                float imat[4][4];
@@ -1352,19 +1357,19 @@ static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh
 
 #else
                                        MVert *verts = dm->getVertArray(dm);
-                                       MFace *faces = dm->getFaceArray(dm);
+                                       MFace *faces = dm->getTessFaceArray(dm);
                                        int *index_array = NULL;
                                        int index = 0;
                                        int i;
                                        
                                        if (em != NULL)
                                        {
-                                               index_array = dm->getFaceDataArray(dm, CD_ORIGINDEX);
-                                               EM_init_index_arrays(em, 0, 0, 1);
+                                               index_array = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
+                                               EDBM_init_index_arrays(em, 0, 0, 1);
                                        }
                                        
                                        for( i = 0; i < totface; i++) {
-                                               EditFace *efa = NULL;
+                                               BMFace *efa = NULL;
                                                MFace *f = faces + i;
                                                
                                                test = 1; /* reset for every face */
@@ -1386,11 +1391,22 @@ static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh
                                                        }
                                                        else
                                                        {
-                                                               efa = EM_get_face_for_index(index);
+                                                               efa = EDBM_get_face_for_index(em, index);
                                                                
-                                                               if (efa && (efa->h || (efa->v1->f & SELECT) || (efa->v2->f & SELECT) || (efa->v3->f & SELECT) || (efa->v4 && efa->v4->f & SELECT)))
+                                                               if (efa && BM_TestHFlag(efa, BM_HIDDEN))
                                                                {
                                                                        test = 0;
+                                                               } else if (efa) {
+                                                                       BMIter iter;
+                                                                       BMLoop *l;
+                                                                       
+                                                                       l = BMIter_New(&iter, em->bm, BM_LOOPS_OF_FACE, efa);
+                                                                       for ( ; l; l=BMIter_Step(&iter)) {
+                                                                               if (BM_TestHFlag(l->v, BM_SELECT)) {
+                                                                                       test = 0;
+                                                                                       break;
+                                                                               }
+                                                                       }
                                                                }
                                                        }
                                                }
@@ -1418,7 +1434,7 @@ static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh
                                        
                                        if (em != NULL)
                                        {
-                                               EM_free_index_arrays();
+                                               EDBM_free_index_arrays(em);
                                        }
 #endif
                                        break;
@@ -1433,11 +1449,11 @@ static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh
                                        if (em != NULL)
                                        {
                                                index_array = dm->getVertDataArray(dm, CD_ORIGINDEX);
-                                               EM_init_index_arrays(em, 1, 0, 0);
+                                               EDBM_init_index_arrays(em, 1, 0, 0);
                                        }
                                        
                                        for( i = 0; i < totvert; i++) {
-                                               EditVert *eve = NULL;
+                                               BMVert *eve = NULL;
                                                MVert *v = verts + i;
                                                
                                                test = 1; /* reset for every vert */
@@ -1459,9 +1475,9 @@ static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh
                                                        }
                                                        else
                                                        {
-                                                               eve = EM_get_vert_for_index(index);
+                                                               eve = EDBM_get_vert_for_index(em, index);
                                                                
-                                                               if (eve && (eve->h || (eve->f & SELECT)))
+                                                               if (eve && (BM_TestHFlag(eve, BM_HIDDEN) || BM_TestHFlag(eve, BM_SELECT)))
                                                                {
                                                                        test = 0;
                                                                }
@@ -1477,7 +1493,7 @@ static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh
 
                                        if (em != NULL)
                                        {
-                                               EM_free_index_arrays();
+                                               EDBM_free_index_arrays(em);
                                        }
                                        break;
                                }
@@ -1493,11 +1509,11 @@ static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh
                                        if (em != NULL)
                                        {
                                                index_array = dm->getEdgeDataArray(dm, CD_ORIGINDEX);
-                                               EM_init_index_arrays(em, 0, 1, 0);
+                                               EDBM_init_index_arrays(em, 0, 1, 0);
                                        }
                                        
                                        for( i = 0; i < totedge; i++) {
-                                               EditEdge *eed = NULL;
+                                               BMEdge *eed = NULL;
                                                MEdge *e = edges + i;
                                                
                                                test = 1; /* reset for every vert */
@@ -1519,9 +1535,11 @@ static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh
                                                        }
                                                        else
                                                        {
-                                                               eed = EM_get_edge_for_index(index);
+                                                               eed = EDBM_get_edge_for_index(em, index);
                                                                
-                                                               if (eed && (eed->h || (eed->v1->f & SELECT) || (eed->v2->f & SELECT)))
+                                                               if (eed && (BM_TestHFlag(eed, BM_HIDDEN) ||
+                                                                       BM_TestHFlag(eed->v1, BM_SELECT) || 
+                                                                       BM_TestHFlag(eed->v2, BM_SELECT)))
                                                                {
                                                                        test = 0;
                                                                }
@@ -1537,7 +1555,7 @@ static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh
 
                                        if (em != NULL)
                                        {
-                                               EM_free_index_arrays();
+                                               EDBM_free_index_arrays(em);
                                        }
                                        break;
                                }
@@ -1554,14 +1572,14 @@ static int snapObject(Scene *scene, ARegion *ar, Object *ob, int editobject, flo
        int retval = 0;
        
        if (ob->type == OB_MESH) {
-               EditMesh *em;
+               BMEditMesh *em;
                DerivedMesh *dm;
                
                if (editobject)
                {
-                       em = ((Mesh *)ob->data)->edit_mesh;
-                       /* dm = editmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH); */
-                       dm = editmesh_get_derived_base(ob, em); /* limitation, em & dm MUST have the same number of faces */
+                       em = ((Mesh *)ob->data)->edit_btmesh;
+                       /* dm = editbmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH); */
+                       dm = editbmesh_get_derived_base(ob, em); /* limitation, em & dm MUST have the same number of faces */
                }
                else
                {
@@ -1708,7 +1726,7 @@ static int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float
 {
        int retval = 0;
        int totvert = dm->getNumVerts(dm);
-       int totface = dm->getNumFaces(dm);
+       int totface = dm->getNumTessFaces(dm);
        
        if (totvert > 0) {
                float imat[4][4];
@@ -1738,7 +1756,7 @@ static int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float
                
                if (test == 1) {
                        MVert *verts = dm->getVertArray(dm);
-                       MFace *faces = dm->getFaceArray(dm);
+                       MFace *faces = dm->getTessFaceArray(dm);
                        int i;
                        
                        for( i = 0; i < totface; i++) {
@@ -1834,6 +1852,7 @@ static int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, L
                                        Object *dob = dupli_ob->ob;
                                        
                                        if (dob->type == OB_MESH) {
+#if 0 //BMESH_TODO
                                                EditMesh *em;
                                                DerivedMesh *dm = NULL;
                                                int val;
@@ -1855,6 +1874,7 @@ static int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, L
                                                retval = retval || val;
                                                
                                                dm->release(dm);
+#endif
                                        }
                                }
                                
@@ -1862,7 +1882,7 @@ static int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, L
                        }
                        
                        if (ob->type == OB_MESH) {
-                               EditMesh *em;
+                               BMEditMesh *em;
                                DerivedMesh *dm = NULL;
                                int val;
 
@@ -1874,8 +1894,8 @@ static int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, L
                                }
                                else
                                {
-                                       em = ((Mesh *)ob->data)->edit_mesh;
-                                       dm = editmesh_get_derived_cage(scene, obedit, em, CD_MASK_BAREMESH);
+                                       em = ((Mesh *)ob->data)->edit_btmesh;
+                                       dm = editbmesh_get_derived_cage(scene, obedit, em, CD_MASK_BAREMESH);
                                        
                                        val = peelDerivedMesh(ob, dm, ob->obmat, ray_start, ray_normal, mval, depth_peels);
                                }