bugfix [#20768] Project Snap Broken
authorCampbell Barton <ideasman42@gmail.com>
Mon, 22 Nov 2010 14:16:11 +0000 (14:16 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 22 Nov 2010 14:16:11 +0000 (14:16 +0000)
source/blender/blenkernel/BKE_bvhutils.h
source/blender/blenkernel/intern/bvhutils.c
source/blender/editors/physics/particle_object.c
source/blender/editors/transform/transform_snap.c
source/blender/makesrna/intern/rna_object_api.c

index 5a1db432589e990b6944007a1ce8a499f45a3b4e..975e64929c2603ea8f1a322149ece7c8cd44213f 100644 (file)
@@ -65,6 +65,7 @@ typedef struct BVHTreeFromMesh
 
        /* Private data */
        int cached;
+       void *em_evil;  /* var only for snapping */
 
 } BVHTreeFromMesh;
 
index 671bcb3668038cbb0c297c0fa3a270b1cda69d2a..882295b931cafed89090a015677545c89bbaaadb 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "BKE_DerivedMesh.h"
 #include "BKE_utildefines.h"
+#include "BLI_editVert.h"
 
 #include "BLI_math.h"
 #include "MEM_guardedalloc.h"
@@ -577,16 +578,34 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float
                        tree = BLI_bvhtree_new(numFaces, epsilon, tree_type, axis);
                        if(tree != NULL)
                        {
-                               for(i = 0; i < numFaces; i++)
-                               {
-                                       float co[4][3];
-                                       VECCOPY(co[0], vert[ face[i].v1 ].co);
-                                       VECCOPY(co[1], vert[ face[i].v2 ].co);
-                                       VECCOPY(co[2], vert[ face[i].v3 ].co);
-                                       if(face[i].v4)
-                                               VECCOPY(co[3], vert[ face[i].v4 ].co);
-                       
-                                       BLI_bvhtree_insert(tree, i, co[0], face[i].v4 ? 4 : 3);
+                               /* XXX, for snap only, em & dm are assumed to be aligned, since dm is the em's cage */
+                               EditMesh *em= data->em_evil;
+                               if(em) {
+                                       EditFace *efa= em->faces.first;
+                                       for(i = 0; i < numFaces; i++, efa= efa->next) {
+                                               if(!(efa->f & 1) && efa->h==0 && !((efa->v1->f&1)+(efa->v2->f&1)+(efa->v3->f&1)+(efa->v4?efa->v4->f&1:0))) {
+                                                       float co[4][3];
+                                                       VECCOPY(co[0], vert[ face[i].v1 ].co);
+                                                       VECCOPY(co[1], vert[ face[i].v2 ].co);
+                                                       VECCOPY(co[2], vert[ face[i].v3 ].co);
+                                                       if(face[i].v4)
+                                                               VECCOPY(co[3], vert[ face[i].v4 ].co);
+                                       
+                                                       BLI_bvhtree_insert(tree, i, co[0], face[i].v4 ? 4 : 3);
+                                               }
+                                       }
+                               }
+                               else {
+                                       for(i = 0; i < numFaces; i++) {
+                                               float co[4][3];
+                                               VECCOPY(co[0], vert[ face[i].v1 ].co);
+                                               VECCOPY(co[1], vert[ face[i].v2 ].co);
+                                               VECCOPY(co[2], vert[ face[i].v3 ].co);
+                                               if(face[i].v4)
+                                                       VECCOPY(co[3], vert[ face[i].v4 ].co);
+                               
+                                               BLI_bvhtree_insert(tree, i, co[0], face[i].v4 ? 4 : 3);
+                                       }
                                }
                                BLI_bvhtree_balance(tree);
 
index 428d8ce6b8258d6ed5c370186fd32b185aae383e..9d4880ea2ede1ae221beb0c5f2e21ce75be37c05 100644 (file)
@@ -623,7 +623,7 @@ static void connect_hair(Scene *scene, Object *ob, ParticleSystem *psys)
        PTCacheEditPoint *point;
        PTCacheEditKey *ekey = NULL;
        HairKey *key;
-       BVHTreeFromMesh bvhtree;
+       BVHTreeFromMesh bvhtree= {0};
        BVHTreeNearest nearest;
        MFace *mface;
        DerivedMesh *dm = NULL;
@@ -646,8 +646,6 @@ static void connect_hair(Scene *scene, Object *ob, ParticleSystem *psys)
 
        numverts = dm->getNumVerts (dm);
 
-       memset( &bvhtree, 0, sizeof(bvhtree) );
-
        /* convert to global coordinates */
        for (i=0; i<numverts; i++)
                mul_m4_v3(ob->obmat, CDDM_get_vert(dm, i)->co);
index d5f14f0a47077baae2454ed6dd7bf409c7b24522..750165219e593837dcc6045047c0aadac8ceba66 100644 (file)
@@ -374,7 +374,8 @@ void initSnappingMode(TransInfo *t)
                if (t->tsnap.applySnap != NULL && // A snapping function actually exist
                        (obedit != NULL && ELEM3(obedit->type, OB_MESH, OB_ARMATURE, OB_CURVE)) ) // Temporary limited to edit mode meshes, armature, curves
                {
-                       if ((t->flag & T_PROP_EDIT) || t->tsnap.project) /* also exclude edit for project, for now */
+                       /* editmode meshes now supported */
+                       if ((obedit->type != OB_MESH) && ((t->flag & T_PROP_EDIT) || t->tsnap.project)) /* also exclude edit for project, for now */
                        {
                                t->tsnap.modeSelect = SNAP_NOT_OBEDIT;
                        }
@@ -1266,7 +1267,7 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
        int retval = 0;
        int totvert = dm->getNumVerts(dm);
        int totface = dm->getNumFaces(dm);
-       
+
        if (totvert > 0) {
                float imat[4][4];
                float timat[3][3]; /* transpose inverse matrix for normals */
@@ -1306,6 +1307,7 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
                                        /* local scale in normal direction */
                                        float local_scale = len_v3(ray_normal_local);
 
+                                       treeData.em_evil= em;
                                        bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 6);
 
                                        hit.index = -1;
index 293c837c21f78a232446f5bdb7289d5e5c09e9e7..34e3caad61865f95ec48dcb51dad35617a1dbff0 100644 (file)
@@ -343,7 +343,7 @@ static void rna_Mesh_assign_verts_to_group(Object *ob, bDeformGroup *group, int
 
 void rna_Object_ray_cast(Object *ob, ReportList *reports, float ray_start[3], float ray_end[3], float r_location[3], float r_normal[3], int *index)
 {
-       BVHTreeFromMesh treeData;
+       BVHTreeFromMesh treeData= {0};
        
        if(ob->derivedFinal==NULL) {
                BKE_reportf(reports, RPT_ERROR, "object \"%s\" has no mesh data to be used for ray casting.", ob->id.name+2);