code cleanup: move vertex and face picking functions into meshtools.c

This commit is contained in:
Campbell Barton
2012-09-06 23:50:28 +00:00
parent 0ecbc047e8
commit aca97317af
5 changed files with 90 additions and 70 deletions

View File

@@ -276,6 +276,11 @@ void EDBM_redo_state_restore(struct BMBackup, struct BMEditMesh *em, int recalct
/* delete the backup, optionally flushing it to an editmesh */
void EDBM_redo_state_free(struct BMBackup *, struct BMEditMesh *em, int recalctess);
/* mesh_tools.c */
int ED_mesh_pick_face(struct bContext *C, struct Mesh *me, struct Object *ob, const int mval[2], unsigned int *index, short rect);
int ED_mesh_pick_vert(struct bContext *C, struct Mesh *me, const int mval[2], unsigned int *index, int size);
#ifdef __cplusplus
}
#endif

View File

@@ -123,43 +123,6 @@ void paintface_flush_flags(Object *ob)
}
}
/* returns 0 if not found, otherwise 1 */
static int facesel_face_pick(struct 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;
}
void paintface_hide(Object *ob, const int unselected)
{
Mesh *me;
@@ -331,7 +294,7 @@ void paintface_select_linked(bContext *UNUSED(C), Object *ob, int UNUSED(mval[2]
if (mode == 0 || mode == 1) {
/* XXX - Causes glitches, not sure why */
#if 0
if (!facesel_face_pick(C, me, mval, &index, 1))
if (!ED_mesh_pick_face(C, me, mval, &index, 1))
return;
#endif
}
@@ -518,7 +481,7 @@ int paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], in
/* Get the face under the cursor */
me = BKE_mesh_from_object(ob);
if (!facesel_face_pick(C, me, ob, mval, &index, 1))
if (!ED_mesh_pick_face(C, me, ob, mval, &index, 1))
return 0;
if (index >= me->totpoly)

View File

@@ -749,10 +749,13 @@ static int edbm_vertex_slide_exec_ex(bContext *C, wmOperator *op, const int do_u
return OPERATOR_FINISHED;
}
#if 0
static int edbm_vertex_slide_exec(bContext *C, wmOperator *op)
{
return edbm_vertex_slide_exec_ex(C, op, TRUE);
}
#endif
void MESH_OT_vert_slide(wmOperatorType *ot)
{

View File

@@ -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;
}

View File

@@ -2027,36 +2027,6 @@ void VIEW3D_OT_select_border(wmOperatorType *ot)
WM_operator_properties_gesture_border(ot, TRUE);
}
/* much like facesel_face_pick()*/
/* returns 0 if not found, otherwise 1 */
static int vertsel_vert_pick(struct 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;
}
/* mouse selection in weight paint */
/* gets called via generic mouse select operator */
static int mouse_weight_paint_vertex_select(bContext *C, const int mval[2], short extend, short deselect, short toggle, Object *obact)
@@ -2065,7 +2035,7 @@ static int mouse_weight_paint_vertex_select(bContext *C, const int mval[2], shor
unsigned int index = 0;
MVert *mv;
if (vertsel_vert_pick(C, me, mval, &index, 50)) {
if (ED_mesh_pick_vert(C, me, mval, &index, 50)) {
mv = me->mvert + index;
if (extend) {
mv->flag |= SELECT;