void paintface_reveal(bContext *C, Object *ob, const bool select) { Mesh *me; MPoly *mpoly; int a; me = BKE_mesh_from_object(ob); if (me == NULL || me->totpoly == 0) { return; } mpoly = me->mpoly; a = me->totpoly; while (a--) { if (mpoly->flag & ME_HIDE) { SET_FLAG_FROM_TEST(mpoly->flag, select, ME_FACE_SEL); mpoly->flag &= ~ME_HIDE; } mpoly++; } BKE_mesh_flush_hidden_from_polys(me); paintface_flush_flags(C, ob, SELECT | ME_HIDE); }
bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool flush_flags) { Mesh *me; MPoly *mpoly; int a; me = BKE_mesh_from_object(ob); if (me == NULL) { return false; } if (action == SEL_TOGGLE) { action = SEL_SELECT; mpoly = me->mpoly; a = me->totpoly; while (a--) { if ((mpoly->flag & ME_HIDE) == 0 && mpoly->flag & ME_FACE_SEL) { action = SEL_DESELECT; break; } mpoly++; } } bool changed = false; mpoly = me->mpoly; a = me->totpoly; while (a--) { if ((mpoly->flag & ME_HIDE) == 0) { switch (action) { case SEL_SELECT: if ((mpoly->flag & ME_FACE_SEL) == 0) { mpoly->flag |= ME_FACE_SEL; changed = true; } break; case SEL_DESELECT: if ((mpoly->flag & ME_FACE_SEL) != 0) { mpoly->flag &= ~ME_FACE_SEL; changed = true; } break; case SEL_INVERT: mpoly->flag ^= ME_FACE_SEL; changed = true; break; } } mpoly++; } if (changed) { if (flush_flags) { paintface_flush_flags(C, ob, SELECT); } } return changed; }
void paintface_hide(bContext *C, Object *ob, const bool unselected) { Mesh *me; MPoly *mpoly; int a; me = BKE_mesh_from_object(ob); if (me == NULL || me->totpoly == 0) { return; } mpoly = me->mpoly; a = me->totpoly; while (a--) { if ((mpoly->flag & ME_HIDE) == 0) { if (((mpoly->flag & ME_FACE_SEL) == 0) == unselected) { mpoly->flag |= ME_HIDE; } } if (mpoly->flag & ME_HIDE) { mpoly->flag &= ~ME_FACE_SEL; } mpoly++; } BKE_mesh_flush_hidden_from_polys(me); paintface_flush_flags(C, ob, SELECT | ME_HIDE); }
bool paintface_mouse_select( struct bContext *C, Object *ob, const int mval[2], bool extend, bool deselect, bool toggle) { Mesh *me; MPoly *mpoly_sel; uint index; /* Get the face under the cursor */ me = BKE_mesh_from_object(ob); if (!ED_mesh_pick_face(C, ob, mval, ED_MESH_PICK_DEFAULT_FACE_DIST, &index)) { return false; } if (index >= me->totpoly) { return false; } mpoly_sel = me->mpoly + index; if (mpoly_sel->flag & ME_HIDE) { return false; } /* clear flags */ if (!extend && !deselect && !toggle) { paintface_deselect_all_visible(C, ob, SEL_DESELECT, false); } me->act_face = (int)index; if (extend) { mpoly_sel->flag |= ME_FACE_SEL; } else if (deselect) { mpoly_sel->flag &= ~ME_FACE_SEL; } else if (toggle) { if (mpoly_sel->flag & ME_FACE_SEL) { mpoly_sel->flag &= ~ME_FACE_SEL; } else { mpoly_sel->flag |= ME_FACE_SEL; } } else { mpoly_sel->flag |= ME_FACE_SEL; } /* image window redraw */ paintface_flush_flags(C, ob, SELECT); ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views return true; }
bool paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], bool extend, bool deselect, bool toggle) { Mesh *me; MPoly *mpoly, *mpoly_sel; unsigned int a, index; /* Get the face under the cursor */ me = BKE_mesh_from_object(ob); if (!ED_mesh_pick_face(C, ob, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) return false; if (index >= me->totpoly) return false; mpoly_sel = me->mpoly + index; if (mpoly_sel->flag & ME_HIDE) return false; /* clear flags */ mpoly = me->mpoly; a = me->totpoly; if (!extend && !deselect && !toggle) { while (a--) { mpoly->flag &= ~ME_FACE_SEL; mpoly++; } } me->act_face = (int)index; if (extend) { mpoly_sel->flag |= ME_FACE_SEL; } else if (deselect) { mpoly_sel->flag &= ~ME_FACE_SEL; } else if (toggle) { if (mpoly_sel->flag & ME_FACE_SEL) mpoly_sel->flag &= ~ME_FACE_SEL; else mpoly_sel->flag |= ME_FACE_SEL; } else { mpoly_sel->flag |= ME_FACE_SEL; } /* image window redraw */ paintface_flush_flags(ob, SELECT); WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data); ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views return true; }
void paintface_deselect_all_visible(Object *ob, int action, bool flush_flags) { Mesh *me; MPoly *mpoly; int a; me = BKE_mesh_from_object(ob); if (me == NULL) return; if (action == SEL_TOGGLE) { action = SEL_SELECT; mpoly = me->mpoly; a = me->totpoly; while (a--) { if ((mpoly->flag & ME_HIDE) == 0 && mpoly->flag & ME_FACE_SEL) { action = SEL_DESELECT; break; } mpoly++; } } mpoly = me->mpoly; a = me->totpoly; while (a--) { if ((mpoly->flag & ME_HIDE) == 0) { switch (action) { case SEL_SELECT: mpoly->flag |= ME_FACE_SEL; break; case SEL_DESELECT: mpoly->flag &= ~ME_FACE_SEL; break; case SEL_INVERT: mpoly->flag ^= ME_FACE_SEL; break; } } mpoly++; } if (flush_flags) { paintface_flush_flags(ob, SELECT); } }
void paintface_select_linked(bContext *C, Object *ob, const int mval[2], const bool select) { Mesh *me; unsigned int index = (unsigned int)-1; me = BKE_mesh_from_object(ob); if (me == NULL || me->totpoly == 0) return; if (mval) { if (!ED_mesh_pick_face(C, ob, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) { return; } } select_linked_tfaces_with_seams(me, index, select); paintface_flush_flags(ob, SELECT); }
int do_paintface_box_select(ViewContext *vc, rcti *rect, bool select, bool extend) { Object *ob = vc->obact; Mesh *me; MPoly *mpoly; struct ImBuf *ibuf; unsigned int *rt; char *selar; int a, index; const int size[2] = { BLI_rcti_size_x(rect) + 1, BLI_rcti_size_y(rect) + 1}; me = BKE_mesh_from_object(ob); if ((me == NULL) || (me->totpoly == 0) || (size[0] * size[1] <= 0)) { return OPERATOR_CANCELLED; } selar = MEM_callocN(me->totpoly + 1, "selar"); if (extend == false && select) { paintface_deselect_all_visible(vc->obact, SEL_DESELECT, false); mpoly = me->mpoly; for (a = 1; a <= me->totpoly; a++, mpoly++) { if ((mpoly->flag & ME_HIDE) == 0) mpoly->flag &= ~ME_FACE_SEL; } } ED_view3d_backbuf_validate(vc); ibuf = IMB_allocImBuf(size[0], size[1], 32, IB_rect); rt = ibuf->rect; view3d_opengl_read_pixels(vc->ar, rect->xmin, rect->ymin, size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); if (ENDIAN_ORDER == B_ENDIAN) { IMB_convert_rgba_to_abgr(ibuf); } GPU_select_to_index_array(ibuf->rect, size[0] * size[1]); a = size[0] * size[1]; while (a--) { if (*rt) { index = *rt; if (index <= me->totpoly) { selar[index] = 1; } } rt++; } mpoly = me->mpoly; for (a = 1; a <= me->totpoly; a++, mpoly++) { if (selar[a]) { if (mpoly->flag & ME_HIDE) { /* pass */ } else { if (select) mpoly->flag |= ME_FACE_SEL; else mpoly->flag &= ~ME_FACE_SEL; } } } IMB_freeImBuf(ibuf); MEM_freeN(selar); #ifdef __APPLE__ glReadBuffer(GL_BACK); #endif paintface_flush_flags(vc->obact, SELECT); return OPERATOR_FINISHED; }