diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index fe4bdb8994d..9ce70ee2ee7 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -433,7 +433,9 @@ int isect_ray_tri_v3(float p1[3], float d[3], float v0[3], float v1[3], float v2 cross_v3_v3v3(p, d, e2); a = dot_v3v3(e1, p); - if ((a > -0.000001) && (a < 0.000001)) return 0; + /* note: these values were 0.000001 in 2.4x but for projection snapping on + * a human head (1BU==1m), subsurf level 2, this gave many errors */ + if ((a > -0.00000001) && (a < 0.00000001)) return 0; f = 1.0f/a; sub_v3_v3v3(s, p1, v0); diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 1cbfcc55911..062452d9e42 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -1224,6 +1224,35 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E { case SCE_SNAP_MODE_FACE: { +#if 1 // Added for durian + BVHTreeRayHit hit; + BVHTreeFromMesh treeData; + + bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 6); + + hit.index = -1; + hit.dist = *depth; + + if(treeData.tree && BLI_bvhtree_ray_cast(treeData.tree, ray_start_local, ray_normal_local, 0.0f, &hit, treeData.raycast_callback, &treeData) != -1) + { + if(hit.dist<=*depth) { + *depth= hit.dist; + copy_v3_v3(loc, hit.co); + copy_v3_v3(no, hit.no); + + /* back to worldspace */ + mul_m4_v3(obmat, loc); + copy_v3_v3(no, hit.no); + + mul_m3_v3(timat, no); + normalize_v3(no); + + retval |= 1; + } + } + break; + +#else MVert *verts = dm->getVertArray(dm); MFace *faces = dm->getFaceArray(dm); int *index_array = NULL; @@ -1293,6 +1322,7 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E { EM_free_index_arrays(); } +#endif break; } case SCE_SNAP_MODE_VERTEX: