merge with trunk at r31523
[blender.git] / source / blender / editors / transform / transform_snap.c
index 5ad7e1fa061e98436f3b91b6900fbba6ecc151d3..3dbd83bfa52b4913639efcc1c7eca8bbe441734e 100644 (file)
 //#include "editmesh.h"
 //#include "BIF_editsima.h"
 #include "BIF_gl.h"
-#include "BIF_glutil.h"
 //#include "BIF_mywindow.h"
 //#include "BIF_screen.h"
 //#include "BIF_editsima.h"
 //#include "BIF_drawimage.h"
 //#include "BIF_editmesh.h"
 
-#include "BKE_global.h"
-#include "BKE_utildefines.h"
 #include "BKE_DerivedMesh.h"
 #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"
@@ -443,9 +442,9 @@ void initSnapping(TransInfo *t, wmOperator *op)
                                normalize_v3(t->tsnap.snapNormal);
                        }
 
-                       if (RNA_struct_find_property(op->ptr, "snap_project"))
+                       if (RNA_struct_find_property(op->ptr, "use_snap_project"))
                        {
-                               t->tsnap.project = RNA_boolean_get(op->ptr, "snap_project");
+                               t->tsnap.project = RNA_boolean_get(op->ptr, "use_snap_project");
                        }
                }
        }
@@ -796,8 +795,8 @@ void CalcSnapGeometry(TransInfo *t, float *vec)
                else
                {
                        found = snapObjectsTransform(t, mval, &dist, loc, no, t->tsnap.modeSelect);
-               }
-               
+                       }
+                               
                if (found == 1)
                {
                        float tangent[3];
@@ -1259,11 +1258,11 @@ int snapArmature(short snap_mode, ARegion *ar, Object *ob, bArmature *arm, float
        return retval;
 }
 
-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)
+int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, BMEditMesh *em, float obmat[][4], float ray_start[3], float ray_normal[3], short 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];
@@ -1327,19 +1326,19 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
 
 #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 */
@@ -1361,11 +1360,22 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
                                                        }
                                                        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;
+                                                                               }
+                                                                       }
                                                                }
                                                        }
                                                }
@@ -1393,7 +1403,7 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
                                        
                                        if (em != NULL)
                                        {
-                                               EM_free_index_arrays();
+                                               EDBM_free_index_arrays(em);
                                        }
 #endif
                                        break;
@@ -1408,11 +1418,11 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
                                        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 */
@@ -1434,9 +1444,9 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
                                                        }
                                                        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;
                                                                }
@@ -1452,7 +1462,7 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
 
                                        if (em != NULL)
                                        {
-                                               EM_free_index_arrays();
+                                               EDBM_free_index_arrays(em);
                                        }
                                        break;
                                }
@@ -1468,11 +1478,11 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
                                        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 */
@@ -1494,9 +1504,11 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
                                                        }
                                                        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;
                                                                }
@@ -1512,7 +1524,7 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
 
                                        if (em != NULL)
                                        {
-                                               EM_free_index_arrays();
+                                               EDBM_free_index_arrays(em);
                                        }
                                        break;
                                }
@@ -1529,13 +1541,13 @@ int snapObject(Scene *scene, ARegion *ar, Object *ob, int editobject, float obma
        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);
+                       em = ((Mesh *)ob->data)->edit_btmesh;
+                       dm = editbmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH);
                }
                else
                {
@@ -1683,7 +1695,7 @@ int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_sta
 {
        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];
@@ -1713,7 +1725,7 @@ int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_sta
                
                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++) {
@@ -1809,6 +1821,7 @@ int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, ListBase
                                        Object *ob = dupli_ob->ob;
                                        
                                        if (ob->type == OB_MESH) {
+#if 0 //BMESH_TODO
                                                EditMesh *em;
                                                DerivedMesh *dm = NULL;
                                                int val;
@@ -1830,6 +1843,7 @@ int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, ListBase
                                                retval = retval || val;
                                                
                                                dm->release(dm);
+#endif
                                        }
                                }
                                
@@ -1837,7 +1851,7 @@ int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, ListBase
                        }
                        
                        if (ob->type == OB_MESH) {
-                               EditMesh *em;
+                               BMEditMesh *em;
                                DerivedMesh *dm = NULL;
                                int val;
 
@@ -1849,8 +1863,8 @@ int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, ListBase
                                }
                                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);
                                }