diff options
Diffstat (limited to 'source/blender/editors/mesh/meshtools.c')
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 2e75a779fed..87a657c0acd 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -1146,3 +1146,82 @@ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em) return mirrorfaces; } + +/* selection, vertex and face */ +/* returns 0 if not found, otherwise 1 */ + +/** + * Face selection in object mode, + * currently only weight-paint and vertex-paint use this. + * + * \return boolean TRUE == Found + */ +int ED_mesh_pick_face(bContext *C, Mesh *me, Object *ob, const int mval[2], unsigned int *index, short rect) +{ + Scene *scene = CTX_data_scene(C); + ViewContext vc; + view3d_set_viewcontext(C, &vc); + + if (!me || me->totpoly == 0) + return 0; + + makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH, 0); + + // XXX if (v3d->flag & V3D_INVALID_BACKBUF) { +// XXX drawview.c! check_backbuf(); +// XXX persp(PERSP_VIEW); +// XXX } + + if (rect) { + /* sample rect to increase changes of selecting, so that when clicking + * on an edge in the backbuf, we can still select a face */ + + int dist; + *index = view3d_sample_backbuf_rect(&vc, mval, 3, 1, me->totpoly + 1, &dist, 0, NULL, NULL); + } + else { + /* sample only on the exact position */ + *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); + } + + if ((*index) <= 0 || (*index) > (unsigned int)me->totpoly) + return 0; + + (*index)--; + + return 1; +} + +/** + * Vertex selection in object mode, + * currently only weight paint uses this. + * + * \return boolean TRUE == Found + */ +int ED_mesh_pick_vert(bContext *C, Mesh *me, const int mval[2], unsigned int *index, int size) +{ + ViewContext vc; + view3d_set_viewcontext(C, &vc); + + if (!me || me->totvert == 0) + return 0; + + if (size > 0) { + /* sample rect to increase changes of selecting, so that when clicking + * on an face in the backbuf, we can still select a vert */ + + int dist; + *index = view3d_sample_backbuf_rect(&vc, mval, size, 1, me->totvert + 1, &dist, 0, NULL, NULL); + } + else { + /* sample only on the exact position */ + *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); + } + + if ((*index) <= 0 || (*index) > (unsigned int)me->totvert) + return 0; + + (*index)--; + + return 1; +} |