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-09-07 03:50:28 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-09-07 03:50:28 +0400
commitaca97317afd7c282d072e927d002fb2571a29a49 (patch)
tree751e4bc81e78512972ccf68c8d558064589ed9fd /source/blender/editors/mesh/meshtools.c
parent0ecbc047e8a540175b00ed967050abb5f7363dbc (diff)
code cleanup: move vertex and face picking functions into meshtools.c
Diffstat (limited to 'source/blender/editors/mesh/meshtools.c')
-rw-r--r--source/blender/editors/mesh/meshtools.c79
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;
+}