diff options
Diffstat (limited to 'source/blender/editors/transform/transform_snap.c')
-rw-r--r-- | source/blender/editors/transform/transform_snap.c | 58 |
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; } |