[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53287] trunk/blender/source/blender: use foreachMappedVert for ED_mesh_pick_vert()
Campbell Barton
ideasman42 at gmail.com
Sun Dec 23 03:32:05 CET 2012
Revision: 53287
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53287
Author: campbellbarton
Date: 2012-12-23 02:32:03 +0000 (Sun, 23 Dec 2012)
Log Message:
-----------
use foreachMappedVert for ED_mesh_pick_vert()
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
trunk/blender/source/blender/editors/mesh/meshtools.c
Modified: trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c 2012-12-23 02:04:38 UTC (rev 53286)
+++ trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c 2012-12-23 02:32:03 UTC (rev 53287)
@@ -2310,20 +2310,19 @@
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);
}
}
Modified: trunk/blender/source/blender/editors/mesh/meshtools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/meshtools.c 2012-12-23 02:04:38 UTC (rev 53286)
+++ trunk/blender/source/blender/editors/mesh/meshtools.c 2012-12-23 02:32:03 UTC (rev 53287)
@@ -1261,6 +1261,32 @@
*
* \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 @@
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;
+ /* setup data */
+ data.mvert = me->mvert;
+ data.ar = ar;
+ data.mval_f = mval_f;
+ data.len_best = FLT_MAX;
+ data.v_idx_best = -1;
- /* find the vert closest to 'mval' */
- const float mval_f[2] = {(float)mval[0],
- (float)mval[1]};
- float len_best = FLT_MAX;
+ dm->foreachMappedVert(dm, ed_mesh_pick_vert__mapFunc, &data);
- ED_view3d_init_mats_rv3d(ob, rv3d);
+ dm->release(dm);
- 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--);
+ if (data.v_idx_best == -1) {
+ return 0;
}
- dm->release(dm);
-
- if (v_idx_best != -1) {
- *index = v_idx_best;
- return 1;
- }
+ *index = data.v_idx_best;
}
return 1;
More information about the Bf-blender-cvs
mailing list