diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-23 06:32:03 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-23 06:32:03 +0400 |
commit | 45681464e7d0ce2b040b4f835a3a40c78d55b7ae (patch) | |
tree | 5f5e28401075bf38d78092f943335e22eeeeb606 | |
parent | b3128cf4068490848834b286df4cc5ca338529c0 (diff) |
use foreachMappedVert for ED_mesh_pick_vert()
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 15 | ||||
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 73 |
2 files changed, 52 insertions, 36 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 2dc01513149..4ccec3893e8 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -2310,20 +2310,19 @@ DerivedMesh *editbmesh_get_derived_base(Object *obedit, BMEditMesh *em) static void make_vertexcosnos__mapFunc(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]) { - float *vec = userData; - - vec += 6 * index; + DMCoNo *co_no = &((DMCoNo *)userData)[index]; /* check if we've been here before (normal should not be 0) */ - if (vec[3] || vec[4] || vec[5]) return; + if (!is_zero_v3(co_no->no)) { + return; + } - copy_v3_v3(vec, co); - vec += 3; + copy_v3_v3(co_no->co, co); if (no_f) { - copy_v3_v3(vec, no_f); + copy_v3_v3(co_no->no, no_f); } else { - normal_short_to_float_v3(vec, no_s); + normal_short_to_float_v3(co_no->no, no_s); } } diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 22f7eb707ab..96b8f1080b9 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -1261,6 +1261,32 @@ int ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned * * \return boolean TRUE == Found */ +typedef struct VertPickData { + const MVert *mvert; + const float *mval_f; /* [2] */ + ARegion *ar; + + /* runtime */ + float len_best; + int v_idx_best; +} VertPickData; + +static void ed_mesh_pick_vert__mapFunc(void *userData, int index, const float co[3], + const float UNUSED(no_f[3]), const short UNUSED(no_s[3])) +{ + VertPickData *data = userData; + if ((data->mvert[index].flag & ME_HIDE) == 0) { + float sco[2]; + + if (ED_view3d_project_float_object(data->ar, co, sco, V3D_PROJ_TEST_CLIP_DEFAULT) == V3D_PROJ_RET_OK) { + const float len = len_manhattan_v2v2(data->mval_f, sco); + if (len < data->len_best) { + data->len_best = len; + data->v_idx_best = index; + } + } + } +} int ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size, int use_zbuf) { ViewContext vc; @@ -1294,46 +1320,37 @@ int ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int * else { /* derived mesh to find deformed locations */ DerivedMesh *dm = mesh_get_derived_final(vc.scene, ob, CD_MASK_BAREMESH); - struct ARegion *ar = vc.ar; + ARegion *ar = vc.ar; + RegionView3D *rv3d = ar->regiondata; - int v_idx_best = -1; - int v_idx; + /* find the vert closest to 'mval' */ + const float mval_f[2] = {(float)mval[0], + (float)mval[1]}; + VertPickData data = {0}; + + ED_view3d_init_mats_rv3d(ob, rv3d); if (dm == NULL) { return 0; } - if (dm->getVertCo) { - RegionView3D *rv3d = ar->regiondata; - - /* find the vert closest to 'mval' */ - const float mval_f[2] = {(float)mval[0], - (float)mval[1]}; - float len_best = FLT_MAX; - - ED_view3d_init_mats_rv3d(ob, rv3d); + /* setup data */ + data.mvert = me->mvert; + data.ar = ar; + data.mval_f = mval_f; + data.len_best = FLT_MAX; + data.v_idx_best = -1; - v_idx = me->totvert - 1; - do { - float co[3], sco[2], len; - dm->getVertCo(dm, v_idx, co); - if (ED_view3d_project_float_object(ar, co, sco, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { - len = len_manhattan_v2v2(mval_f, sco); - if (len < len_best) { - len_best = len; - v_idx_best = v_idx; - } - } - } while (v_idx--); - } + dm->foreachMappedVert(dm, ed_mesh_pick_vert__mapFunc, &data); dm->release(dm); - if (v_idx_best != -1) { - *index = v_idx_best; - return 1; + if (data.v_idx_best == -1) { + return 0; } + + *index = data.v_idx_best; } return 1; |