diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-07-28 22:30:47 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-07-28 22:34:23 +0400 |
commit | 6355e3a45d1dd26b09713ece4c353bc890fd129c (patch) | |
tree | 90fd864d0106ea901e090eb47cc196999b5fd9a3 /source/blender/editors | |
parent | dfccfeb447b4d59f2326a0af9ca5d550e2eb38fc (diff) |
As suggested by Campbell, rather use BVHTree to get len_diff in this morning's fix.
Note than it's using nearest faces, since it showed to be much more performant than
nearest vertex (quite odd, it's about 40% slower for the first element, then 50 times quicker
for all others, as if BVH was cached, and building face was slower than verts one,
but then using it, much quicker!).
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/transform/transform_snap.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 26eb836bdc9..dfb75bb9a35 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -1523,21 +1523,25 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes } else if (do_ray_start_correction) { /* We *need* a reasonably valid len_diff in this case. - * Default to distance from object's center (i.e. point (0,0,0) since we are in local space) - * minus farthest vertex from this center. + * Use BHVTree to find the closest face from ray_start_local. */ - int i = totvert; - MVert *mv = dm->getVertArray(dm); - float max_dist_squared = 0.0f; - - for (; i; i--, mv++) { - const float d = len_squared_v3(mv->co); - if (d > max_dist_squared) { - max_dist_squared = d; + BVHTreeFromMesh treeData; + BVHTreeNearest nearest; + len_diff = 0.0f; /* In case BVHTree would fail for some reason... */ + + treeData.em_evil = em; + bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 2, 6); + if (treeData.tree != NULL) { + nearest.index = -1; + nearest.dist_sq = FLT_MAX; + /* Compute and store result. */ + BLI_bvhtree_find_nearest(treeData.tree, ray_start_local, &nearest, + treeData.nearest_callback, &treeData); + if (nearest.index != -1) { + len_diff = sqrtf(nearest.dist_sq); } } - - len_diff = len_v3(ray_start_local) - sqrtf(max_dist_squared); + free_bvhtree_from_mesh(&treeData); } switch (snap_mode) { |