bugfix [#20768] Project Snap Broken

This commit is contained in:
2010-11-22 14:16:11 +00:00
parent 69246d9080
commit 4a20c386fd
5 changed files with 36 additions and 16 deletions

View File

@@ -65,6 +65,7 @@ typedef struct BVHTreeFromMesh
/* Private data */
int cached;
void *em_evil; /* var only for snapping */
} BVHTreeFromMesh;

View 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);

View 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);

View 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;

View 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);