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:
authorCampbell Barton <ideasman42@gmail.com>2012-12-23 06:32:03 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-12-23 06:32:03 +0400
commit45681464e7d0ce2b040b4f835a3a40c78d55b7ae (patch)
tree5f5e28401075bf38d78092f943335e22eeeeb606 /source/blender/editors/mesh/meshtools.c
parentb3128cf4068490848834b286df4cc5ca338529c0 (diff)
use foreachMappedVert for ED_mesh_pick_vert()
Diffstat (limited to 'source/blender/editors/mesh/meshtools.c')
-rw-r--r--source/blender/editors/mesh/meshtools.c73
1 files changed, 45 insertions, 28 deletions
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;