Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano Cavalcante <germano.costa@ig.com.br>2016-01-25 10:18:42 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-01-25 11:01:54 +0300
commit34076a79e381626e66f97cf5507257dba3cb519d (patch)
tree3ab9e4c3c20f6aa322364fd9ab500453d4a42e18 /source/blender/editors/transform/transform_snap.c
parent33a7c7408da50456d7f3ca6e65241b9651e8834f (diff)
Transform: optimize vertex snap w/ nearest-to-ray
Use BLI_bvhtree_find_nearest_to_ray for vertex snapping, avoids doing screen-space lookup on each vertex.
Diffstat (limited to 'source/blender/editors/transform/transform_snap.c')
-rw-r--r--source/blender/editors/transform/transform_snap.c58
1 files changed, 17 insertions, 41 deletions
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index ed48478246f..8e02a402bf8 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -1660,50 +1660,26 @@ static bool snapDerivedMesh(
}
case SCE_SNAP_MODE_VERTEX:
{
- MVert *verts = dm->getVertArray(dm);
- const int *index_array = NULL;
- int index = 0;
- int i;
-
- if (em != NULL) {
- index_array = dm->getVertDataArray(dm, CD_ORIGINDEX);
- BM_mesh_elem_table_ensure(em->bm, BM_VERT);
- }
-
- for (i = 0; i < totvert; i++) {
- BMVert *eve = NULL;
- MVert *v = verts + i;
- bool test = true;
+ BVHTreeNearest nearest;
+ BVHTreeFromMesh treeData;
- if (em != NULL) {
- if (index_array) {
- index = index_array[i];
- }
- else {
- index = i;
- }
-
- if (index == ORIGINDEX_NONE) {
- test = false;
- }
- else {
- eve = BM_vert_at_index(em->bm, index);
-
- if (BM_elem_flag_test(eve, BM_ELEM_HIDDEN) ||
- BM_elem_flag_test(eve, BM_ELEM_SELECT))
- {
- test = false;
- }
- }
- }
+ treeData.em_evil = em;
+ bvhtree_from_mesh_verts(&treeData, dm, 0.0f, 2, 6);
- if (test) {
- retval |= snapVertex(
- ar, v->co, v->no, obmat, timat, mval,
- ray_start, ray_start_local, ray_normal_local, ray_depth,
- r_loc, r_no, r_dist_px);
- }
+ nearest.index = -1;
+ nearest.dist_sq = FLT_MAX;
+ if (treeData.tree &&
+ BLI_bvhtree_find_nearest_to_ray(
+ treeData.tree, ray_start_local, ray_normal_local, 0.0f,
+ &nearest, NULL, &treeData) != -1)
+ {
+ MVert v = treeData.vert[nearest.index];
+ retval = snapVertex(
+ ar, v.co, v.no, obmat, timat, mval,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, r_no, r_dist_px);
}
+ free_bvhtree_from_mesh(&treeData);
break;
}