diff options
Diffstat (limited to 'source/blender/editors/mesh/editmesh_tools.c')
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 2009 |
1 files changed, 3 insertions, 2006 deletions
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index f05df06ffa2..5befcd7b5f2 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -37,19 +37,15 @@ #include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" #include "DNA_object_types.h" -#include "DNA_scene_types.h" -#include "BLI_blenlib.h" +#include "BLI_listbase.h" #include "BLI_noise.h" #include "BLI_math.h" #include "BLI_rand.h" -#include "BLF_translation.h" - #include "BKE_material.h" #include "BKE_context.h" #include "BKE_depsgraph.h" -#include "BKE_object.h" #include "BKE_report.h" #include "BKE_texture.h" #include "BKE_main.h" @@ -63,7 +59,6 @@ #include "WM_types.h" #include "ED_mesh.h" -#include "ED_numinput.h" #include "ED_object.h" #include "ED_screen.h" #include "ED_transform.h" @@ -75,24 +70,10 @@ #include "UI_interface.h" #include "UI_resources.h" -#include "mesh_intern.h" +#include "mesh_intern.h" /* own include */ #define USE_FACE_CREATE_SEL_EXTEND -#define MVAL_PIXEL_MARGIN 5.0f - -/* allow accumulated normals to form a new direction but don't - * accept direct opposite directions else they will cancel each other out */ -static void add_normal_aligned(float nor[3], const float add[3]) -{ - if (dot_v3v3(nor, add) < -0.9999f) { - sub_v3_v3(nor, add); - } - else { - add_v3_v3(nor, add); - } -} - static int edbm_subdivide_exec(bContext *C, wmOperator *op) { Object *obedit = CTX_data_edit_object(C); @@ -229,735 +210,6 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em) } -/* individual face extrude */ -/* will use vertex normals for extrusion directions, so *nor is unaffected */ -static short edbm_extrude_discrete_faces(BMEditMesh *em, wmOperator *op, const char hflag, float *UNUSED(nor)) -{ - BMOIter siter; - BMIter liter; - BMFace *f; - BMLoop *l; - BMOperator bmop; - - EDBM_op_init(em, &bmop, op, "extrude_discrete_faces faces=%hf", hflag); - - /* deselect original verts */ - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - - BMO_op_exec(em->bm, &bmop); - - BMO_ITER (f, &siter, bmop.slots_out, "faces.out", BM_FACE) { - BM_face_select_set(em->bm, f, true); - - /* set face vertex normals to face normal */ - BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - copy_v3_v3(l->v->no, f->no); - } - } - - if (!EDBM_op_finish(em, &bmop, op, true)) { - return 0; - } - - return 's'; /* s is shrink/fatten */ -} - -/* extrudes individual edges */ -static short edbm_extrude_edges_indiv(BMEditMesh *em, wmOperator *op, const char hflag, float *UNUSED(nor)) -{ - BMOperator bmop; - - EDBM_op_init(em, &bmop, op, "extrude_edge_only edges=%he", hflag); - - /* deselect original verts */ - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - - BMO_op_exec(em->bm, &bmop); - BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "geom.out", BM_VERT | BM_EDGE, BM_ELEM_SELECT, true); - - if (!EDBM_op_finish(em, &bmop, op, true)) { - return 0; - } - - return 'n'; /* n is normal grab */ -} - -/* extrudes individual vertices */ -static short edbm_extrude_verts_indiv(BMEditMesh *em, wmOperator *op, const char hflag, float *UNUSED(nor)) -{ - BMOperator bmop; - - EDBM_op_init(em, &bmop, op, "extrude_vert_indiv verts=%hv", hflag); - - /* deselect original verts */ - BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_in, "verts", BM_VERT, BM_ELEM_SELECT, true); - - BMO_op_exec(em->bm, &bmop); - BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "verts.out", BM_VERT, BM_ELEM_SELECT, true); - - if (!EDBM_op_finish(em, &bmop, op, true)) { - return 0; - } - - return 'g'; /* g is grab */ -} - -static short edbm_extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, float nor[3]) -{ - BMesh *bm = em->bm; - BMIter iter; - BMOIter siter; - BMOperator extop; - BMEdge *edge; - BMFace *f; - ModifierData *md; - BMElem *ele; - BMOpSlot *slot_edges_exclude; - - BMO_op_init(bm, &extop, BMO_FLAG_DEFAULTS, "extrude_face_region"); - BMO_slot_buffer_from_enabled_hflag(bm, &extop, extop.slots_in, "geom", BM_VERT | BM_EDGE | BM_FACE, hflag); - - slot_edges_exclude = BMO_slot_get(extop.slots_in, "edges_exclude"); - - /* If a mirror modifier with clipping is on, we need to adjust some - * of the cases above to handle edges on the line of symmetry. - */ - md = obedit->modifiers.first; - for (; md; md = md->next) { - if ((md->type == eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) { - MirrorModifierData *mmd = (MirrorModifierData *) md; - - if (mmd->flag & MOD_MIR_CLIPPING) { - float mtx[4][4]; - if (mmd->mirror_ob) { - float imtx[4][4]; - invert_m4_m4(imtx, mmd->mirror_ob->obmat); - mult_m4_m4m4(mtx, imtx, obedit->obmat); - } - - BM_ITER_MESH (edge, &iter, bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(edge, hflag) && - BM_edge_is_boundary(edge) && - BM_elem_flag_test(edge->l->f, hflag)) - { - float co1[3], co2[3]; - - copy_v3_v3(co1, edge->v1->co); - copy_v3_v3(co2, edge->v2->co); - - if (mmd->mirror_ob) { - mul_v3_m4v3(co1, mtx, co1); - mul_v3_m4v3(co2, mtx, co2); - } - - if (mmd->flag & MOD_MIR_AXIS_X) { - if ((fabsf(co1[0]) < mmd->tolerance) && - (fabsf(co2[0]) < mmd->tolerance)) - { - BMO_slot_map_empty_insert(&extop, slot_edges_exclude, edge); - } - } - if (mmd->flag & MOD_MIR_AXIS_Y) { - if ((fabsf(co1[1]) < mmd->tolerance) && - (fabsf(co2[1]) < mmd->tolerance)) - { - BMO_slot_map_empty_insert(&extop, slot_edges_exclude, edge); - } - } - if (mmd->flag & MOD_MIR_AXIS_Z) { - if ((fabsf(co1[2]) < mmd->tolerance) && - (fabsf(co2[2]) < mmd->tolerance)) - { - BMO_slot_map_empty_insert(&extop, slot_edges_exclude, edge); - } - } - } - } - } - } - } - - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - - BMO_op_exec(bm, &extop); - - zero_v3(nor); - - BMO_ITER (ele, &siter, extop.slots_out, "geom.out", BM_ALL) { - BM_elem_select_set(bm, ele, true); - - if (ele->head.htype == BM_FACE) { - f = (BMFace *)ele; - add_normal_aligned(nor, f->no); - } - } - - normalize_v3(nor); - - BMO_op_finish(bm, &extop); - - /* grab / normal constraint */ - return is_zero_v3(nor) ? 'g' : 'n'; -} - -static short edbm_extrude_vert(Object *obedit, BMEditMesh *em, const char hflag, float nor[3]) -{ - BMIter iter; - BMEdge *eed; - - /* ensure vert flags are consistent for edge selections */ - BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(eed, hflag)) { - if (hflag & BM_ELEM_SELECT) { - BM_vert_select_set(em->bm, eed->v1, true); - BM_vert_select_set(em->bm, eed->v2, true); - } - - BM_elem_flag_enable(eed->v1, hflag & ~BM_ELEM_SELECT); - BM_elem_flag_enable(eed->v2, hflag & ~BM_ELEM_SELECT); - } - else { - if (BM_elem_flag_test(eed->v1, hflag) && BM_elem_flag_test(eed->v2, hflag)) { - if (hflag & BM_ELEM_SELECT) { - BM_edge_select_set(em->bm, eed, true); - } - - BM_elem_flag_enable(eed, hflag & ~BM_ELEM_SELECT); - } - } - } - - return edbm_extrude_edge(obedit, em, hflag, nor); -} - -static int edbm_extrude_repeat_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - RegionView3D *rv3d = CTX_wm_region_view3d(C); - - const int steps = RNA_int_get(op->ptr, "steps"); - - const float offs = RNA_float_get(op->ptr, "offset"); - float dvec[3], tmat[3][3], bmat[3][3], nor[3] = {0.0, 0.0, 0.0}; - short a; - - /* dvec */ - normalize_v3_v3(dvec, rv3d->persinv[2]); - mul_v3_fl(dvec, offs); - - /* base correction */ - copy_m3_m4(bmat, obedit->obmat); - invert_m3_m3(tmat, bmat); - mul_m3_v3(tmat, dvec); - - for (a = 0; a < steps; a++) { - edbm_extrude_edge(obedit, em, BM_ELEM_SELECT, nor); - //BMO_op_callf(em->bm, BMO_FLAG_DEFAULTS, "extrude_face_region geom=%hef", BM_ELEM_SELECT); - BMO_op_callf(em->bm, BMO_FLAG_DEFAULTS, - "translate vec=%v verts=%hv", - (float *)dvec, BM_ELEM_SELECT); - //extrudeflag(obedit, em, SELECT, nor); - //translateflag(em, SELECT, dvec); - } - - EDBM_mesh_normals_update(em); - - EDBM_update_generic(em, true, true); - - return OPERATOR_FINISHED; -} - -void MESH_OT_extrude_repeat(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Extrude Repeat Mesh"; - ot->description = "Extrude selected vertices, edges or faces repeatedly"; - ot->idname = "MESH_OT_extrude_repeat"; - - /* api callbacks */ - ot->exec = edbm_extrude_repeat_exec; - ot->poll = ED_operator_editmesh_view3d; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* props */ - RNA_def_float(ot->srna, "offset", 2.0f, 0.0f, FLT_MAX, "Offset", "", 0.0f, 100.0f); - RNA_def_int(ot->srna, "steps", 10, 0, INT_MAX, "Steps", "", 0, 180); -} - -/* generic extern called extruder */ -static int edbm_extrude_mesh(Scene *scene, Object *obedit, BMEditMesh *em, wmOperator *op, float *norin) -{ - short nr, transmode = 0; - float stacknor[3] = {0.0f, 0.0f, 0.0f}; - float *nor = norin ? norin : stacknor; - - zero_v3(nor); - - /* XXX If those popup menus were to be enabled again, please get rid of this "menu string" syntax! */ - if (em->selectmode & SCE_SELECT_VERTEX) { - if (em->bm->totvertsel == 0) nr = 0; - else if (em->bm->totvertsel == 1) nr = 4; - else if (em->bm->totedgesel == 0) nr = 4; - else if (em->bm->totfacesel == 0) - nr = 3; /* pupmenu("Extrude %t|Only Edges %x3|Only Vertices %x4"); */ - else if (em->bm->totfacesel == 1) - nr = 1; /* pupmenu("Extrude %t|Region %x1|Only Edges% x3|Only Vertices %x4"); */ - else - nr = 1; /* pupmenu("Extrude %t|Region %x1|Individual Faces %x2|Only Edges %x3|Only Vertices %x4"); */ - } - else if (em->selectmode & SCE_SELECT_EDGE) { - if (em->bm->totedgesel == 0) nr = 0; - - nr = 1; -#if 0 - else if (em->totedgesel == 1) nr = 3; - else if (em->totfacesel == 0) nr = 3; - else if (em->totfacesel == 1) - nr = 1; /* pupmenu("Extrude %t|Region %x1|Only Edges %x3"); */ - else - nr = 1; /* pupmenu("Extrude %t|Region %x1|Individual Faces %x2|Only Edges %x3"); */ -#endif - } - else { - if (em->bm->totfacesel == 0) nr = 0; - else if (em->bm->totfacesel == 1) nr = 1; - else - nr = 1; /* pupmenu("Extrude %t|Region %x1|Individual Faces %x2"); */ - } - - if (nr < 1) return 'g'; - - if (nr == 1 && (em->selectmode & SCE_SELECT_VERTEX)) - transmode = edbm_extrude_vert(obedit, em, BM_ELEM_SELECT, nor); - else if (nr == 1) transmode = edbm_extrude_edge(obedit, em, BM_ELEM_SELECT, nor); - else if (nr == 4) transmode = edbm_extrude_verts_indiv(em, op, BM_ELEM_SELECT, nor); - else if (nr == 3) transmode = edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, nor); - else transmode = edbm_extrude_discrete_faces(em, op, BM_ELEM_SELECT, nor); - - if (transmode == 0) { - BKE_report(op->reports, RPT_ERROR, "Not a valid selection for extrude"); - } - else { - - /* We need to force immediate calculation here because - * transform may use derived objects (which are now stale). - * - * This shouldn't be necessary, derived queries should be - * automatically building this data if invalid. Or something. - */ -// DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); - BKE_object_handle_update(scene, obedit); - - /* individual faces? */ -// BIF_TransformSetUndo("Extrude"); - if (nr == 2) { -// initTransform(TFM_SHRINKFATTEN, CTX_NO_PET|CTX_NO_MIRROR); -// Transform(); - } - else { -// initTransform(TFM_TRANSLATION, CTX_NO_PET|CTX_NO_MIRROR); - if (transmode == 'n') { - mul_m4_v3(obedit->obmat, nor); - sub_v3_v3v3(nor, nor, obedit->obmat[3]); -// BIF_setSingleAxisConstraint(nor, "along normal"); - } -// Transform(); - } - } - - return transmode; -} - -/* extrude without transform */ -static int edbm_extrude_region_exec(bContext *C, wmOperator *op) -{ - Scene *scene = CTX_data_scene(C); - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - - edbm_extrude_mesh(scene, obedit, em, op, NULL); - - /* This normally happens when pushing undo but modal operators - * like this one don't push undo data until after modal mode is - * done.*/ - EDBM_mesh_normals_update(em); - - EDBM_update_generic(em, true, true); - - return OPERATOR_FINISHED; -} - -void MESH_OT_extrude_region(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Extrude Region"; - ot->idname = "MESH_OT_extrude_region"; - ot->description = "Extrude region of faces"; - - /* api callbacks */ - //ot->invoke = mesh_extrude_region_invoke; - ot->exec = edbm_extrude_region_exec; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); -} - -static int edbm_extrude_verts_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - float nor[3]; - - edbm_extrude_verts_indiv(em, op, BM_ELEM_SELECT, nor); - - EDBM_update_generic(em, true, true); - - return OPERATOR_FINISHED; -} - -void MESH_OT_extrude_verts_indiv(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Extrude Only Vertices"; - ot->idname = "MESH_OT_extrude_verts_indiv"; - ot->description = "Extrude individual vertices only"; - - /* api callbacks */ - ot->exec = edbm_extrude_verts_exec; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* to give to transform */ - RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); -} - -static int edbm_extrude_edges_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - float nor[3]; - - edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, nor); - - EDBM_update_generic(em, true, true); - - return OPERATOR_FINISHED; -} - -void MESH_OT_extrude_edges_indiv(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Extrude Only Edges"; - ot->idname = "MESH_OT_extrude_edges_indiv"; - ot->description = "Extrude individual edges only"; - - /* api callbacks */ - ot->exec = edbm_extrude_edges_exec; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* to give to transform */ - RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); -} - -static int edbm_extrude_faces_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - float nor[3]; - - edbm_extrude_discrete_faces(em, op, BM_ELEM_SELECT, nor); - - EDBM_update_generic(em, true, true); - - return OPERATOR_FINISHED; -} - -void MESH_OT_extrude_faces_indiv(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Extrude Individual Faces"; - ot->idname = "MESH_OT_extrude_faces_indiv"; - ot->description = "Extrude individual faces only"; - - /* api callbacks */ - ot->exec = edbm_extrude_faces_exec; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); -} - -/* ******************** (de)select all operator **************** */ - -static int edbm_select_all_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - const int action = RNA_enum_get(op->ptr, "action"); - - switch (action) { - case SEL_TOGGLE: - EDBM_select_toggle_all(em); - break; - case SEL_SELECT: - EDBM_flag_enable_all(em, BM_ELEM_SELECT); - break; - case SEL_DESELECT: - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - break; - case SEL_INVERT: - EDBM_select_swap(em); - EDBM_selectmode_flush(em); - break; - } - - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); - - return OPERATOR_FINISHED; -} - -void MESH_OT_select_all(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "(De)select All"; - ot->idname = "MESH_OT_select_all"; - ot->description = "(De)select all vertices, edges or faces"; - - /* api callbacks */ - ot->exec = edbm_select_all_exec; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - WM_operator_properties_select_all(ot); -} - -static int edbm_faces_select_interior_exec(bContext *C, wmOperator *UNUSED(op)) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - - if (EDBM_select_interior_faces(em)) { - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); - - return OPERATOR_FINISHED; - } - else { - return OPERATOR_CANCELLED; - } - -} - -void MESH_OT_select_interior_faces(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Select Interior Faces"; - ot->idname = "MESH_OT_select_interior_faces"; - ot->description = "Select faces where all edges have more than 2 face users"; - - /* api callbacks */ - ot->exec = edbm_faces_select_interior_exec; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - -/* *************** add-click-mesh (extrude) operator ************** */ -static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - ViewContext vc; - BMVert *v1; - BMIter iter; - float min[3], max[3]; - bool done = false; - bool use_proj; - - em_setup_viewcontext(C, &vc); - - ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d); - - - use_proj = ((vc.scene->toolsettings->snap_flag & SCE_SNAP) && - (vc.scene->toolsettings->snap_mode == SCE_SNAP_MODE_FACE)); - - INIT_MINMAX(min, max); - - BM_ITER_MESH (v1, &iter, vc.em->bm, BM_VERTS_OF_MESH) { - if (BM_elem_flag_test(v1, BM_ELEM_SELECT)) { - minmax_v3v3_v3(min, max, v1->co); - done = true; - } - } - - /* call extrude? */ - if (done) { - const bool rot_src = RNA_boolean_get(op->ptr, "rotate_source"); - BMEdge *eed; - float vec[3], cent[3], mat[3][3]; - float nor[3] = {0.0, 0.0, 0.0}; - - /* 2D normal calc */ - const float mval_f[2] = {(float)event->mval[0], - (float)event->mval[1]}; - - /* check for edges that are half selected, use for rotation */ - done = false; - BM_ITER_MESH (eed, &iter, vc.em->bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { - float co1[2], co2[2]; - - if ((ED_view3d_project_float_object(vc.ar, eed->v1->co, co1, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) && - (ED_view3d_project_float_object(vc.ar, eed->v2->co, co2, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK)) - { - /* 2D rotate by 90d while adding. - * (x, y) = (y, -x) - * - * accumulate the screenspace normal in 2D, - * with screenspace edge length weighting the result. */ - if (line_point_side_v2(co1, co2, mval_f) >= 0.0f) { - nor[0] += (co1[1] - co2[1]); - nor[1] += -(co1[0] - co2[0]); - } - else { - nor[0] += (co2[1] - co1[1]); - nor[1] += -(co2[0] - co1[0]); - } - done = true; - } - } - } - - if (done) { - float view_vec[3], cross[3]; - - /* convert the 2D nomal into 3D */ - mul_mat3_m4_v3(vc.rv3d->viewinv, nor); /* worldspace */ - mul_mat3_m4_v3(vc.obedit->imat, nor); /* local space */ - - /* correct the normal to be aligned on the view plane */ - copy_v3_v3(view_vec, vc.rv3d->viewinv[2]); - mul_mat3_m4_v3(vc.obedit->imat, view_vec); - cross_v3_v3v3(cross, nor, view_vec); - cross_v3_v3v3(nor, view_vec, cross); - normalize_v3(nor); - } - - /* center */ - mid_v3_v3v3(cent, min, max); - copy_v3_v3(min, cent); - - mul_m4_v3(vc.obedit->obmat, min); /* view space */ - ED_view3d_win_to_3d_int(vc.ar, min, event->mval, min); - mul_m4_v3(vc.obedit->imat, min); // back in object space - - sub_v3_v3(min, cent); - - /* calculate rotation */ - unit_m3(mat); - if (done) { - float angle; - - normalize_v3_v3(vec, min); - - angle = angle_normalized_v3v3(vec, nor); - - if (angle != 0.0f) { - float axis[3]; - - cross_v3_v3v3(axis, nor, vec); - - /* halve the rotation if its applied twice */ - if (rot_src) { - angle *= 0.5f; - } - - axis_angle_to_mat3(mat, axis, angle); - } - } - - if (rot_src) { - EDBM_op_callf(vc.em, op, "rotate verts=%hv cent=%v matrix=%m3", - BM_ELEM_SELECT, cent, mat); - - /* also project the source, for retopo workflow */ - if (use_proj) - EMBM_project_snap_verts(C, vc.ar, vc.em); - } - - edbm_extrude_edge(vc.obedit, vc.em, BM_ELEM_SELECT, nor); - EDBM_op_callf(vc.em, op, "rotate verts=%hv cent=%v matrix=%m3", - BM_ELEM_SELECT, cent, mat); - EDBM_op_callf(vc.em, op, "translate verts=%hv vec=%v", - BM_ELEM_SELECT, min); - } - else { - const float *curs = give_cursor(vc.scene, vc.v3d); - BMOperator bmop; - BMOIter oiter; - - copy_v3_v3(min, curs); - ED_view3d_win_to_3d_int(vc.ar, min, event->mval, min); - - invert_m4_m4(vc.obedit->imat, vc.obedit->obmat); - mul_m4_v3(vc.obedit->imat, min); // back in object space - - EDBM_op_init(vc.em, &bmop, op, "create_vert co=%v", min); - BMO_op_exec(vc.em->bm, &bmop); - - BMO_ITER (v1, &oiter, bmop.slots_out, "vert.out", BM_VERT) { - BM_vert_select_set(vc.em->bm, v1, true); - } - - if (!EDBM_op_finish(vc.em, &bmop, op, true)) { - return OPERATOR_CANCELLED; - } - } - - if (use_proj) - EMBM_project_snap_verts(C, vc.ar, vc.em); - - /* This normally happens when pushing undo but modal operators - * like this one don't push undo data until after modal mode is - * done. */ - EDBM_mesh_normals_update(vc.em); - - EDBM_update_generic(vc.em, true, true); - - return OPERATOR_FINISHED; -} - -void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Duplicate or Extrude at 3D Cursor"; - ot->idname = "MESH_OT_dupli_extrude_cursor"; - ot->description = "Duplicate and extrude selected vertices, edges or faces towards the mouse cursor"; - - /* api callbacks */ - ot->invoke = edbm_dupli_extrude_cursor_invoke; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_boolean(ot->srna, "rotate_source", 1, "Rotate Source", "Rotate initial selection giving better shape"); -} - /* Note, these values must match delete_mesh() event values */ static EnumPropertyItem prop_mesh_delete_types[] = { {0, "VERT", 0, "Vertices", ""}, @@ -2014,7 +1266,6 @@ static int edbm_rotate_uvs_exec(bContext *C, wmOperator *op) EDBM_update_generic(em, false, false); - /* we succeeded */ return OPERATOR_FINISHED; } @@ -2037,7 +1288,6 @@ static int edbm_reverse_uvs_exec(bContext *C, wmOperator *op) EDBM_update_generic(em, false, false); - /* we succeeded */ return OPERATOR_FINISHED; } @@ -2064,7 +1314,6 @@ static int edbm_rotate_colors_exec(bContext *C, wmOperator *op) /* dependencies graph and notification stuff */ EDBM_update_generic(em, false, false); - /* we succeeded */ return OPERATOR_FINISHED; } @@ -2088,7 +1337,6 @@ static int edbm_reverse_colors_exec(bContext *C, wmOperator *op) EDBM_update_generic(em, false, false); - /* we succeeded */ return OPERATOR_FINISHED; } @@ -2110,7 +1358,6 @@ void MESH_OT_uvs_rotate(wmOperatorType *ot) RNA_def_boolean(ot->srna, "use_ccw", false, "Counter Clockwise", ""); } -//void MESH_OT_uvs_mirror(wmOperatorType *ot) void MESH_OT_uvs_reverse(wmOperatorType *ot) { /* identifiers */ @@ -2428,123 +1675,6 @@ void MESH_OT_remove_doubles(wmOperatorType *ot) RNA_def_boolean(ot->srna, "use_unselected", 0, "Unselected", "Merge selected to other unselected vertices"); } -/************************ Vertex Path Operator *************************/ - -typedef struct PathNode { - /* int u; */ /* UNUSED */ - /* int visited; */ /* UNUSED */ - ListBase edges; -} PathNode; - -typedef struct PathEdge { - struct PathEdge *next, *prev; - int v; - float w; -} PathEdge; - - - -static int edbm_select_vertex_path_exec(bContext *C, wmOperator *op) -{ - Object *ob = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(ob); - BMOperator bmop; - BMIter iter; - BMVert *eve = NULL, *svert = NULL, *evert = NULL; - BMEditSelection *sv, *ev; - - /* get the type from RNA */ - const int type = RNA_enum_get(op->ptr, "type"); - - /* first try to find vertices in edit selection */ - sv = em->bm->selected.last; - if (sv != NULL) { - ev = sv->prev; - - if (ev && (sv->htype == BM_VERT) && (ev->htype == BM_VERT)) { - svert = (BMVert *)sv->ele; - evert = (BMVert *)ev->ele; - } - } - - /* if those are not found, because vertices where selected by e.g. - * border or circle select, find two selected vertices */ - if (svert == NULL) { - BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { - if (!BM_elem_flag_test(eve, BM_ELEM_SELECT) || BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) - continue; - - if (svert == NULL) { - svert = eve; - } - else if (evert == NULL) { - evert = eve; - } - else { - /* more than two vertices are selected, - * show warning message and cancel operator */ - svert = evert = NULL; - break; - } - } - } - - if (svert == NULL || evert == NULL) { - BKE_report(op->reports, RPT_WARNING, "Path selection requires two vertices to be selected"); - return OPERATOR_CANCELLED; - } - - /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ - EDBM_op_init(em, &bmop, op, - "shortest_path vert_start=%e vert_end=%e type=%i", - svert, evert, type); - - /* execute the operator */ - BMO_op_exec(em->bm, &bmop); - - /* DO NOT clear the existing selection */ - /* EDBM_flag_disable_all(em, BM_ELEM_SELECT); */ - - /* select the output */ - BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "verts.out", BM_VERT, BM_ELEM_SELECT, true); - - /* finish the operator */ - if (!EDBM_op_finish(em, &bmop, op, true)) { - return OPERATOR_CANCELLED; - } - - EDBM_selectmode_flush(em); - - EDBM_update_generic(em, false, false); - - /* we succeeded */ - return OPERATOR_FINISHED; -} - -void MESH_OT_select_vertex_path(wmOperatorType *ot) -{ - static const EnumPropertyItem type_items[] = { - {VPATH_SELECT_EDGE_LENGTH, "EDGE_LENGTH", 0, "Edge Length", NULL}, - {VPATH_SELECT_TOPOLOGICAL, "TOPOLOGICAL", 0, "Topological", NULL}, - {0, NULL, 0, NULL, NULL} - }; - - /* identifiers */ - ot->name = "Select Vertex Path"; - ot->idname = "MESH_OT_select_vertex_path"; - ot->description = "Selected vertex path between two vertices"; - - /* api callbacks */ - ot->exec = edbm_select_vertex_path_exec; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* properties */ - RNA_def_enum(ot->srna, "type", type_items, VPATH_SELECT_EDGE_LENGTH, "Type", "Method to compute distance"); -} -/********************** Rip Operator *************************/ /************************ Shape Operators *************************/ @@ -2740,89 +1870,6 @@ void MESH_OT_blend_from_shape(wmOperatorType *ot) RNA_def_boolean(ot->srna, "add", 1, "Add", "Add rather than blend between shapes"); } -/* BMESH_TODO - some way to select on an arbitrary axis */ -static int edbm_select_axis_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - BMEditSelection *ese = em->bm->selected.last; - const int axis = RNA_enum_get(op->ptr, "axis"); - const int mode = RNA_enum_get(op->ptr, "mode"); /* -1 == aligned, 0 == neg, 1 == pos */ - - if (ese == NULL || ese->htype != BM_VERT) { - BKE_report(op->reports, RPT_WARNING, "This operator requires an active vertex (last selected)"); - return OPERATOR_CANCELLED; - } - else { - BMVert *ev, *act_vert = (BMVert *)ese->ele; - BMIter iter; - float value = act_vert->co[axis]; - float limit = CTX_data_tool_settings(C)->doublimit; // XXX - - if (mode == 0) - value -= limit; - else if (mode == 1) - value += limit; - - BM_ITER_MESH (ev, &iter, em->bm, BM_VERTS_OF_MESH) { - if (!BM_elem_flag_test(ev, BM_ELEM_HIDDEN)) { - switch (mode) { - case -1: /* aligned */ - if (fabsf(ev->co[axis] - value) < limit) - BM_vert_select_set(em->bm, ev, true); - break; - case 0: /* neg */ - if (ev->co[axis] > value) - BM_vert_select_set(em->bm, ev, true); - break; - case 1: /* pos */ - if (ev->co[axis] < value) - BM_vert_select_set(em->bm, ev, true); - break; - } - } - } - } - - EDBM_selectmode_flush(em); - WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); - - return OPERATOR_FINISHED; -} - -void MESH_OT_select_axis(wmOperatorType *ot) -{ - static EnumPropertyItem axis_mode_items[] = { - {0, "POSITIVE", 0, "Positive Axis", ""}, - {1, "NEGATIVE", 0, "Negative Axis", ""}, - {-1, "ALIGNED", 0, "Aligned Axis", ""}, - {0, NULL, 0, NULL, NULL} - }; - - static EnumPropertyItem axis_items_xyz[] = { - {0, "X_AXIS", 0, "X Axis", ""}, - {1, "Y_AXIS", 0, "Y Axis", ""}, - {2, "Z_AXIS", 0, "Z Axis", ""}, - {0, NULL, 0, NULL, NULL} - }; - - /* identifiers */ - ot->name = "Select Axis"; - ot->description = "Select all data in the mesh on a single axis"; - ot->idname = "MESH_OT_select_axis"; - - /* api callbacks */ - ot->exec = edbm_select_axis_exec; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* properties */ - RNA_def_enum(ot->srna, "mode", axis_mode_items, 0, "Axis Mode", "Axis side to use when selecting"); - RNA_def_enum(ot->srna, "axis", axis_items_xyz, 0, "Axis", "Select the axis to compare each vertex on"); -} - static int edbm_solidify_exec(bContext *C, wmOperator *op) { Object *obedit = CTX_data_edit_object(C); @@ -3197,7 +2244,7 @@ void MESH_OT_knife_cut(wmOperatorType *ot) ot->modal = WM_gesture_lines_modal; ot->exec = edbm_knife_cut_exec; - ot->poll = EM_view3d_poll; + ot->poll = EDBM_view3d_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -3842,366 +2889,6 @@ void MESH_OT_split(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } - -static int edbm_spin_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - BMesh *bm = em->bm; - BMOperator spinop; - float cent[3], axis[3], imat[3][3]; - float d[3] = {0.0f, 0.0f, 0.0f}; - int steps, dupli; - float angle; - - RNA_float_get_array(op->ptr, "center", cent); - RNA_float_get_array(op->ptr, "axis", axis); - steps = RNA_int_get(op->ptr, "steps"); - angle = RNA_float_get(op->ptr, "angle"); - //if (ts->editbutflag & B_CLOCKWISE) - angle = -angle; - dupli = RNA_boolean_get(op->ptr, "dupli"); - - /* undo object transformation */ - copy_m3_m4(imat, obedit->imat); - sub_v3_v3(cent, obedit->obmat[3]); - mul_m3_v3(imat, cent); - mul_m3_v3(imat, axis); - - if (!EDBM_op_init(em, &spinop, op, - "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i angle=%f use_duplicate=%b", - BM_ELEM_SELECT, cent, axis, d, steps, angle, dupli)) - { - return OPERATOR_CANCELLED; - } - BMO_op_exec(bm, &spinop); - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - BMO_slot_buffer_hflag_enable(bm, spinop.slots_out, "geom_last.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, true); - if (!EDBM_op_finish(em, &spinop, op, true)) { - return OPERATOR_CANCELLED; - } - - EDBM_update_generic(em, true, true); - - return OPERATOR_FINISHED; -} - -/* get center and axis, in global coords */ -static int edbm_spin_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) -{ - Scene *scene = CTX_data_scene(C); - View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d = ED_view3d_context_rv3d(C); - - RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d)); - RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[2]); - - return edbm_spin_exec(C, op); -} - -void MESH_OT_spin(wmOperatorType *ot) -{ - PropertyRNA *prop; - - /* identifiers */ - ot->name = "Spin"; - ot->description = "Extrude selected vertices in a circle around the cursor in indicated viewport"; - ot->idname = "MESH_OT_spin"; - - /* api callbacks */ - ot->invoke = edbm_spin_invoke; - ot->exec = edbm_spin_exec; - ot->poll = EM_view3d_poll; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* props */ - RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, INT_MAX); - RNA_def_boolean(ot->srna, "dupli", 0, "Dupli", "Make Duplicates"); - prop = RNA_def_float(ot->srna, "angle", DEG2RADF(90.0f), -FLT_MAX, FLT_MAX, "Angle", "Angle", DEG2RADF(-360.0f), DEG2RADF(360.0f)); - RNA_def_property_subtype(prop, PROP_ANGLE); - - RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX); - RNA_def_float_vector(ot->srna, "axis", 3, NULL, -FLT_MAX, FLT_MAX, "Axis", "Axis in global view space", -1.0f, 1.0f); - -} - -static int edbm_screw_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - BMesh *bm = em->bm; - BMEdge *eed; - BMVert *eve, *v1, *v2; - BMIter iter, eiter; - BMOperator spinop; - float dvec[3], nor[3], cent[3], axis[3]; - float imat[3][3]; - int steps, turns; - int valence; - - - turns = RNA_int_get(op->ptr, "turns"); - steps = RNA_int_get(op->ptr, "steps"); - RNA_float_get_array(op->ptr, "center", cent); - RNA_float_get_array(op->ptr, "axis", axis); - - /* undo object transformation */ - copy_m3_m4(imat, obedit->imat); - sub_v3_v3(cent, obedit->obmat[3]); - mul_m3_v3(imat, cent); - mul_m3_v3(imat, axis); - - - /* find two vertices with valence count == 1, more or less is wrong */ - v1 = NULL; - v2 = NULL; - - BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { - valence = 0; - BM_ITER_ELEM (eed, &eiter, eve, BM_EDGES_OF_VERT) { - if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { - valence++; - } - } - - if (valence == 1) { - if (v1 == NULL) { - v1 = eve; - } - else if (v2 == NULL) { - v2 = eve; - } - else { - v1 = NULL; - break; - } - } - } - - if (v1 == NULL || v2 == NULL) { - BKE_report(op->reports, RPT_ERROR, "You have to select a string of connected vertices too"); - return OPERATOR_CANCELLED; - } - - /* calculate dvec */ - sub_v3_v3v3(dvec, v1->co, v2->co); - mul_v3_fl(dvec, 1.0f / steps); - - if (dot_v3v3(nor, dvec) > 0.000f) - negate_v3(dvec); - - if (!EDBM_op_init(em, &spinop, op, - "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i angle=%f use_duplicate=%b", - BM_ELEM_SELECT, cent, axis, dvec, turns * steps, DEG2RADF(360.0f * turns), false)) - { - return OPERATOR_CANCELLED; - } - BMO_op_exec(bm, &spinop); - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - BMO_slot_buffer_hflag_enable(bm, spinop.slots_out, "geom_last.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, true); - if (!EDBM_op_finish(em, &spinop, op, true)) { - return OPERATOR_CANCELLED; - } - - EDBM_update_generic(em, true, true); - - return OPERATOR_FINISHED; -} - -/* get center and axis, in global coords */ -static int edbm_screw_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) -{ - Scene *scene = CTX_data_scene(C); - View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d = ED_view3d_context_rv3d(C); - - RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d)); - RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[1]); - - return edbm_screw_exec(C, op); -} - -void MESH_OT_screw(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Screw"; - ot->description = "Extrude selected vertices in screw-shaped rotation around the cursor in indicated viewport"; - ot->idname = "MESH_OT_screw"; - - /* api callbacks */ - ot->invoke = edbm_screw_invoke; - ot->exec = edbm_screw_exec; - ot->poll = EM_view3d_poll; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* props */ - RNA_def_int(ot->srna, "steps", 9, 1, INT_MAX, "Steps", "Steps", 3, 256); - RNA_def_int(ot->srna, "turns", 1, 1, INT_MAX, "Turns", "Turns", 1, 256); - - RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, - "Center", "Center in global view space", -FLT_MAX, FLT_MAX); - RNA_def_float_vector(ot->srna, "axis", 3, NULL, -FLT_MAX, FLT_MAX, - "Axis", "Axis in global view space", -1.0f, 1.0f); -} - -static int edbm_select_face_by_sides_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - BMFace *efa; - BMIter iter; - const int numverts = RNA_int_get(op->ptr, "number"); - const int type = RNA_enum_get(op->ptr, "type"); - - if (!RNA_boolean_get(op->ptr, "extend")) - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - - int select; - - switch (type) { - case 0: - select = (efa->len < numverts); - break; - case 1: - select = (efa->len == numverts); - break; - case 2: - select = (efa->len > numverts); - break; - case 3: - select = (efa->len != numverts); - break; - default: - BLI_assert(0); - select = false; - break; - } - - if (select) { - BM_face_select_set(em->bm, efa, true); - } - } - - EDBM_selectmode_flush(em); - - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); - return OPERATOR_FINISHED; -} - -void MESH_OT_select_face_by_sides(wmOperatorType *ot) -{ - static const EnumPropertyItem type_items[] = { - {0, "LESS", 0, "Less Than", ""}, - {1, "EQUAL", 0, "Equal To", ""}, - {2, "GREATER", 0, "Greater Than", ""}, - {3, "NOTEQUAL", 0, "Not Equal To", ""}, - {0, NULL, 0, NULL, NULL} - }; - - /* identifiers */ - ot->name = "Select Faces by Sides"; - ot->description = "Select vertices or faces by the number of polygon sides"; - ot->idname = "MESH_OT_select_face_by_sides"; - - /* api callbacks */ - ot->exec = edbm_select_face_by_sides_exec; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* properties */ - RNA_def_int(ot->srna, "number", 4, 3, INT_MAX, "Number of Vertices", "", 3, INT_MAX); - RNA_def_enum(ot->srna, "type", type_items, 1, "Type", "Type of comparison to make"); - RNA_def_boolean(ot->srna, "extend", true, "Extend", "Extend the selection"); -} - -static int edbm_select_loose_verts_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - BMVert *eve; - BMEdge *eed; - BMIter iter; - - if (!RNA_boolean_get(op->ptr, "extend")) - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - - BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { - if (!eve->e) { - BM_vert_select_set(em->bm, eve, true); - } - } - - BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { - if (!eed->l) { - BM_edge_select_set(em->bm, eed, true); - } - } - - EDBM_selectmode_flush(em); - - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); - return OPERATOR_FINISHED; -} - -void MESH_OT_select_loose_verts(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Select Loose Vertices/Edges"; - ot->description = "Select vertices with no edges nor faces, and edges with no faces"; - ot->idname = "MESH_OT_select_loose_verts"; - - /* api callbacks */ - ot->exec = edbm_select_loose_verts_exec; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* props */ - RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection"); -} - -static int edbm_select_mirror_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - bool extend = RNA_boolean_get(op->ptr, "extend"); - - if (em->bm->totvert && em->bm->totvertsel) { - EDBM_select_mirrored(obedit, em, extend); - EDBM_selectmode_flush(em); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); - } - - return OPERATOR_FINISHED; -} - -void MESH_OT_select_mirror(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Select Mirror"; - ot->description = "Select mesh items at mirrored locations"; - ot->idname = "MESH_OT_select_mirror"; - - /* api callbacks */ - ot->exec = edbm_select_mirror_exec; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* props */ - RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the existing selection"); -} - /****************************************************************************** * qsort routines. * Now unified, for vertices/edges/faces. */ @@ -4854,320 +3541,6 @@ void MESH_OT_noise(wmOperatorType *ot) RNA_def_float(ot->srna, "factor", 0.1f, -FLT_MAX, FLT_MAX, "Factor", "", 0.0f, 1.0f); } -typedef struct { - BMEditMesh *em; - BMBackup mesh_backup; - int mcenter[2]; - float initial_length; - float pixel_size; /* use when mouse input is interpreted as spatial distance */ - int is_modal; - NumInput num_input; - float shift_factor; /* The current factor when shift is pressed. Negative when shift not active. */ -} BevelData; - -#define HEADER_LENGTH 180 - -static void edbm_bevel_update_header(wmOperator *op, bContext *C) -{ - const char *str = IFACE_("Confirm: Enter/LClick, Cancel: (Esc/RMB), Offset: %s, Segments: %d"); - - char msg[HEADER_LENGTH]; - ScrArea *sa = CTX_wm_area(C); - - if (sa) { - char offset_str[NUM_STR_REP_LEN]; - BLI_snprintf(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset")); - BLI_snprintf(msg, HEADER_LENGTH, str, - offset_str, - RNA_int_get(op->ptr, "segments") - ); - - ED_area_headerprint(sa, msg); - } -} - -static int edbm_bevel_init(bContext *C, wmOperator *op, int is_modal) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - BevelData *opdata; - - if (em == NULL) { - return 0; - } - - op->customdata = opdata = MEM_mallocN(sizeof(BevelData), "beveldata_mesh_operator"); - - opdata->em = em; - opdata->is_modal = is_modal; - opdata->shift_factor = -1.0f; - - initNumInput(&opdata->num_input); - opdata->num_input.flag = NUM_NO_NEGATIVE; - - /* avoid the cost of allocating a bm copy */ - if (is_modal) - opdata->mesh_backup = EDBM_redo_state_store(em); - - return 1; -} - -static int edbm_bevel_calc(wmOperator *op) -{ - BevelData *opdata = op->customdata; - BMEditMesh *em = opdata->em; - BMOperator bmop; - const float offset = RNA_float_get(op->ptr, "offset"); - const int segments = RNA_int_get(op->ptr, "segments"); - const bool vertex_only = RNA_boolean_get(op->ptr, "vertex_only"); - - /* revert to original mesh */ - if (opdata->is_modal) { - EDBM_redo_state_restore(opdata->mesh_backup, em, false); - } - - if (!EDBM_op_init(em, &bmop, op, - "bevel geom=%hev offset=%f segments=%i vertex_only=%b", - BM_ELEM_SELECT, offset, segments, vertex_only)) - { - return 0; - } - - BMO_op_exec(em->bm, &bmop); - - if (offset != 0.0f) { - /* not essential, but we may have some loose geometry that - * won't get bevel'd and better not leave it selected */ - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true); - } - - /* no need to de-select existing geometry */ - if (!EDBM_op_finish(em, &bmop, op, true)) - return 0; - - EDBM_mesh_normals_update(opdata->em); - - EDBM_update_generic(opdata->em, true, true); - - return 1; -} - -static void edbm_bevel_exit(bContext *C, wmOperator *op) -{ - BevelData *opdata = op->customdata; - - ScrArea *sa = CTX_wm_area(C); - - if (sa) { - ED_area_headerprint(sa, NULL); - } - - if (opdata->is_modal) { - EDBM_redo_state_free(&opdata->mesh_backup, NULL, false); - } - MEM_freeN(opdata); - op->customdata = NULL; -} - -static int edbm_bevel_cancel(bContext *C, wmOperator *op) -{ - BevelData *opdata = op->customdata; - if (opdata->is_modal) { - EDBM_redo_state_free(&opdata->mesh_backup, opdata->em, true); - EDBM_update_generic(opdata->em, false, true); - } - - edbm_bevel_exit(C, op); - - /* need to force redisplay or we may still view the modified result */ - ED_region_tag_redraw(CTX_wm_region(C)); - return OPERATOR_CANCELLED; -} - -/* bevel! yay!!*/ -static int edbm_bevel_exec(bContext *C, wmOperator *op) -{ - if (!edbm_bevel_init(C, op, false)) { - edbm_bevel_exit(C, op); - return OPERATOR_CANCELLED; - } - - if (!edbm_bevel_calc(op)) { - edbm_bevel_cancel(C, op); - return OPERATOR_CANCELLED; - } - - edbm_bevel_exit(C, op); - - return OPERATOR_FINISHED; -} - -static int edbm_bevel_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - /* TODO make modal keymap (see fly mode) */ - RegionView3D *rv3d = CTX_wm_region_view3d(C); - BevelData *opdata; - float mlen[2]; - float center_3d[3]; - - if (!edbm_bevel_init(C, op, true)) { - return OPERATOR_CANCELLED; - } - - opdata = op->customdata; - - /* initialize mouse values */ - if (!calculateTransformCenter(C, V3D_CENTROID, center_3d, opdata->mcenter)) { - /* in this case the tool will likely do nothing, - * ideally this will never happen and should be checked for above */ - opdata->mcenter[0] = opdata->mcenter[1] = 0; - } - mlen[0] = opdata->mcenter[0] - event->mval[0]; - mlen[1] = opdata->mcenter[1] - event->mval[1]; - opdata->initial_length = len_v2(mlen); - opdata->pixel_size = rv3d ? ED_view3d_pixel_size(rv3d, center_3d) : 1.0f; - - edbm_bevel_update_header(op, C); - - if (!edbm_bevel_calc(op)) { - edbm_bevel_cancel(C, op); - return OPERATOR_CANCELLED; - } - - WM_event_add_modal_handler(C, op); - - return OPERATOR_RUNNING_MODAL; -} - -static float edbm_bevel_mval_factor(wmOperator *op, const wmEvent *event) -{ - BevelData *opdata = op->customdata; - int use_dist = true; - float mdiff[2]; - float factor; - - mdiff[0] = opdata->mcenter[0] - event->mval[0]; - mdiff[1] = opdata->mcenter[1] - event->mval[1]; - - if (use_dist) { - factor = ((len_v2(mdiff) - MVAL_PIXEL_MARGIN) - opdata->initial_length) * opdata->pixel_size; - } - else { - factor = (len_v2(mdiff) - MVAL_PIXEL_MARGIN) / opdata->initial_length; - factor = factor - 1.0f; /* a different kind of buffer where nothing happens */ - } - - /* Fake shift-transform... */ - if (event->shift) { - if (opdata->shift_factor < 0.0f) { - opdata->shift_factor = RNA_float_get(op->ptr, "offset"); - } - factor = (factor - opdata->shift_factor) * 0.1f + opdata->shift_factor; - } - else if (opdata->shift_factor >= 0.0f) - opdata->shift_factor = -1.0f; - - /* clamp differently based on distance/factor */ - if (use_dist) { - if (factor < 0.0f) factor = 0.0f; - } - else { - CLAMP(factor, 0.0f, 1.0f); - } - - return factor; -} - -static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event) -{ - BevelData *opdata = op->customdata; - int segments = RNA_int_get(op->ptr, "segments"); - - if (event->val == KM_PRESS) { - /* Try to handle numeric inputs... */ - - if (handleNumInput(&opdata->num_input, event)) { - float value = RNA_float_get(op->ptr, "offset"); - applyNumInput(&opdata->num_input, &value); - RNA_float_set(op->ptr, "offset", value); - edbm_bevel_calc(op); - edbm_bevel_update_header(op, C); - return OPERATOR_RUNNING_MODAL; - } - } - - switch (event->type) { - case ESCKEY: - case RIGHTMOUSE: - edbm_bevel_cancel(C, op); - return OPERATOR_CANCELLED; - - case MOUSEMOVE: - if (!hasNumInput(&opdata->num_input)) { - const float factor = edbm_bevel_mval_factor(op, event); - RNA_float_set(op->ptr, "offset", factor); - - edbm_bevel_calc(op); - edbm_bevel_update_header(op, C); - } - break; - - case LEFTMOUSE: - case PADENTER: - case RETKEY: - edbm_bevel_calc(op); - edbm_bevel_exit(C, op); - return OPERATOR_FINISHED; - - case WHEELUPMOUSE: /* change number of segments */ - case PAGEUPKEY: - if (event->val == KM_RELEASE) - break; - - segments++; - RNA_int_set(op->ptr, "segments", segments); - edbm_bevel_calc(op); - edbm_bevel_update_header(op, C); - break; - - case WHEELDOWNMOUSE: /* change number of segments */ - case PAGEDOWNKEY: - if (event->val == KM_RELEASE) - break; - - segments = max_ii(segments - 1, 1); - RNA_int_set(op->ptr, "segments", segments); - edbm_bevel_calc(op); - edbm_bevel_update_header(op, C); - break; - } - - return OPERATOR_RUNNING_MODAL; -} - -void MESH_OT_bevel(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Bevel"; - ot->description = "Edge Bevel"; - ot->idname = "MESH_OT_bevel"; - - /* api callbacks */ - ot->exec = edbm_bevel_exec; - ot->invoke = edbm_bevel_invoke; - ot->modal = edbm_bevel_modal; - ot->cancel = edbm_bevel_cancel; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_POINTER | OPTYPE_BLOCKING; - - RNA_def_float(ot->srna, "offset", 0.0f, -FLT_MAX, FLT_MAX, "Offset", "", 0.0f, 1.0f); - RNA_def_int(ot->srna, "segments", 1, 1, 50, "Segments", "Segments for curved edge", 1, 8); - RNA_def_boolean(ot->srna, "vertex_only", false, "Vertex only", "Bevel only vertices"); -} - static int edbm_bridge_edge_loops_exec(bContext *C, wmOperator *op) { BMOperator bmop; @@ -5218,382 +3591,6 @@ void MESH_OT_bridge_edge_loops(wmOperatorType *ot) RNA_def_float(ot->srna, "merge_factor", 0.5f, 0.0f, 1.0f, "Merge Factor", "", 0.0f, 1.0f); } -typedef struct { - float old_thickness; - float old_depth; - int mcenter[2]; - int modify_depth; - float initial_length; - float pixel_size; /* use when mouse input is interpreted as spatial distance */ - int is_modal; - int shift; - float shift_amount; - BMBackup backup; - BMEditMesh *em; - NumInput num_input; -} InsetData; - -static void edbm_inset_update_header(wmOperator *op, bContext *C) -{ - InsetData *opdata = op->customdata; - - const char *str = IFACE_("Confirm: Enter/LClick, Cancel: (Esc/RClick), Thickness: %s, " - "Depth (Ctrl to tweak): %s (%s), Outset (O): (%s), Boundary (B): (%s)"); - - char msg[HEADER_LENGTH]; - ScrArea *sa = CTX_wm_area(C); - - if (sa) { - char flts_str[NUM_STR_REP_LEN * 2]; - if (hasNumInput(&opdata->num_input)) - outputNumInput(&opdata->num_input, flts_str); - else { - BLI_snprintf(flts_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "thickness")); - BLI_snprintf(flts_str + NUM_STR_REP_LEN, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "depth")); - } - BLI_snprintf(msg, HEADER_LENGTH, str, - flts_str, - flts_str + NUM_STR_REP_LEN, - opdata->modify_depth ? IFACE_("On") : IFACE_("Off"), - RNA_boolean_get(op->ptr, "use_outset") ? IFACE_("On") : IFACE_("Off"), - RNA_boolean_get(op->ptr, "use_boundary") ? IFACE_("On") : IFACE_("Off") - ); - - ED_area_headerprint(sa, msg); - } -} - - -static int edbm_inset_init(bContext *C, wmOperator *op, int is_modal) -{ - InsetData *opdata; - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BMEdit_FromObject(obedit); - - op->customdata = opdata = MEM_mallocN(sizeof(InsetData), "inset_operator_data"); - - opdata->old_thickness = 0.01; - opdata->old_depth = 0.0; - opdata->modify_depth = false; - opdata->shift = false; - opdata->shift_amount = 0.0f; - opdata->is_modal = is_modal; - opdata->em = em; - - initNumInput(&opdata->num_input); - opdata->num_input.idx_max = 1; /* Two elements. */ - - if (is_modal) - opdata->backup = EDBM_redo_state_store(em); - - return 1; -} - -static void edbm_inset_exit(bContext *C, wmOperator *op) -{ - InsetData *opdata; - ScrArea *sa = CTX_wm_area(C); - - opdata = op->customdata; - - if (opdata->is_modal) - EDBM_redo_state_free(&opdata->backup, NULL, false); - - if (sa) { - ED_area_headerprint(sa, NULL); - } - MEM_freeN(op->customdata); -} - -static int edbm_inset_cancel(bContext *C, wmOperator *op) -{ - InsetData *opdata; - - opdata = op->customdata; - if (opdata->is_modal) { - EDBM_redo_state_free(&opdata->backup, opdata->em, true); - EDBM_update_generic(opdata->em, false, true); - } - - edbm_inset_exit(C, op); - - /* need to force redisplay or we may still view the modified result */ - ED_region_tag_redraw(CTX_wm_region(C)); - return OPERATOR_CANCELLED; -} - -static int edbm_inset_calc(wmOperator *op) -{ - InsetData *opdata; - BMEditMesh *em; - BMOperator bmop; - - const bool use_boundary = RNA_boolean_get(op->ptr, "use_boundary"); - const bool use_even_offset = RNA_boolean_get(op->ptr, "use_even_offset"); - const bool use_relative_offset = RNA_boolean_get(op->ptr, "use_relative_offset"); - const float thickness = RNA_float_get(op->ptr, "thickness"); - const float depth = RNA_float_get(op->ptr, "depth"); - const bool use_outset = RNA_boolean_get(op->ptr, "use_outset"); - const bool use_select_inset = RNA_boolean_get(op->ptr, "use_select_inset"); /* not passed onto the BMO */ - - opdata = op->customdata; - em = opdata->em; - - if (opdata->is_modal) { - EDBM_redo_state_restore(opdata->backup, em, false); - } - - EDBM_op_init(em, &bmop, op, - "inset faces=%hf use_boundary=%b use_even_offset=%b use_relative_offset=%b " - "thickness=%f depth=%f use_outset=%b", - BM_ELEM_SELECT, use_boundary, use_even_offset, use_relative_offset, - thickness, depth, use_outset); - - BMO_op_exec(em->bm, &bmop); - - if (use_select_inset) { - /* deselect original faces/verts */ - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true); - } - else { - BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE, BM_ELEM_SELECT, false); - BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, false); - /* re-select faces so the verts and edges get selected too */ - BM_mesh_elem_hflag_enable_test(em->bm, BM_FACE, BM_ELEM_SELECT, true, BM_ELEM_SELECT); - } - - if (!EDBM_op_finish(em, &bmop, op, true)) { - return 0; - } - else { - EDBM_update_generic(em, true, true); - return 1; - } -} - -static int edbm_inset_exec(bContext *C, wmOperator *op) -{ - edbm_inset_init(C, op, false); - - if (!edbm_inset_calc(op)) { - edbm_inset_exit(C, op); - return OPERATOR_CANCELLED; - } - - edbm_inset_exit(C, op); - return OPERATOR_FINISHED; -} - -static int edbm_inset_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - RegionView3D *rv3d = CTX_wm_region_view3d(C); - InsetData *opdata; - float mlen[2]; - float center_3d[3]; - - edbm_inset_init(C, op, true); - - opdata = op->customdata; - - /* initialize mouse values */ - if (!calculateTransformCenter(C, V3D_CENTROID, center_3d, opdata->mcenter)) { - /* in this case the tool will likely do nothing, - * ideally this will never happen and should be checked for above */ - opdata->mcenter[0] = opdata->mcenter[1] = 0; - } - mlen[0] = opdata->mcenter[0] - event->mval[0]; - mlen[1] = opdata->mcenter[1] - event->mval[1]; - opdata->initial_length = len_v2(mlen); - opdata->pixel_size = rv3d ? ED_view3d_pixel_size(rv3d, center_3d) : 1.0f; - - edbm_inset_calc(op); - - edbm_inset_update_header(op, C); - - WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; -} - -static int edbm_inset_modal(bContext *C, wmOperator *op, const wmEvent *event) -{ - InsetData *opdata = op->customdata; - - if (event->val == KM_PRESS) { - /* Try to handle numeric inputs... */ - - if (handleNumInput(&opdata->num_input, event)) { - float amounts[2] = {RNA_float_get(op->ptr, "thickness"), - RNA_float_get(op->ptr, "depth")}; - applyNumInput(&opdata->num_input, amounts); - amounts[0] = max_ff(amounts[0], 0.0f); - RNA_float_set(op->ptr, "thickness", amounts[0]); - RNA_float_set(op->ptr, "depth", amounts[1]); - - if (edbm_inset_calc(op)) { - edbm_inset_update_header(op, C); - return OPERATOR_RUNNING_MODAL; - } - else { - edbm_inset_cancel(C, op); - return OPERATOR_CANCELLED; - } - } - } - - switch (event->type) { - case ESCKEY: - case RIGHTMOUSE: - edbm_inset_cancel(C, op); - return OPERATOR_CANCELLED; - - case MOUSEMOVE: - if (!hasNumInput(&opdata->num_input)) { - float mdiff[2]; - float amount; - - mdiff[0] = opdata->mcenter[0] - event->mval[0]; - mdiff[1] = opdata->mcenter[1] - event->mval[1]; - - if (opdata->modify_depth) - amount = opdata->old_depth + ((len_v2(mdiff) - opdata->initial_length) * opdata->pixel_size); - else - amount = opdata->old_thickness - ((len_v2(mdiff) - opdata->initial_length) * opdata->pixel_size); - - /* Fake shift-transform... */ - if (opdata->shift) - amount = (amount - opdata->shift_amount) * 0.1f + opdata->shift_amount; - - if (opdata->modify_depth) - RNA_float_set(op->ptr, "depth", amount); - else { - amount = max_ff(amount, 0.0f); - RNA_float_set(op->ptr, "thickness", amount); - } - - if (edbm_inset_calc(op)) - edbm_inset_update_header(op, C); - else { - edbm_inset_cancel(C, op); - return OPERATOR_CANCELLED; - } - } - break; - - case LEFTMOUSE: - case PADENTER: - case RETKEY: - edbm_inset_calc(op); - edbm_inset_exit(C, op); - return OPERATOR_FINISHED; - - case LEFTSHIFTKEY: - case RIGHTSHIFTKEY: - if (event->val == KM_PRESS) { - if (opdata->modify_depth) - opdata->shift_amount = RNA_float_get(op->ptr, "depth"); - else - opdata->shift_amount = RNA_float_get(op->ptr, "thickness"); - opdata->shift = true; - } - else { - opdata->shift_amount = 0.0f; - opdata->shift = false; - } - break; - - case LEFTCTRLKEY: - case RIGHTCTRLKEY: - { - float mlen[2]; - - mlen[0] = opdata->mcenter[0] - event->mval[0]; - mlen[1] = opdata->mcenter[1] - event->mval[1]; - - if (event->val == KM_PRESS) { - opdata->old_thickness = RNA_float_get(op->ptr, "thickness"); - if (opdata->shift) - opdata->shift_amount = opdata->old_thickness; - opdata->modify_depth = true; - } - else { - opdata->old_depth = RNA_float_get(op->ptr, "depth"); - if (opdata->shift) - opdata->shift_amount = opdata->old_depth; - opdata->modify_depth = false; - } - opdata->initial_length = len_v2(mlen); - - edbm_inset_update_header(op, C); - break; - } - - case OKEY: - if (event->val == KM_PRESS) { - const bool use_outset = RNA_boolean_get(op->ptr, "use_outset"); - RNA_boolean_set(op->ptr, "use_outset", !use_outset); - if (edbm_inset_calc(op)) { - edbm_inset_update_header(op, C); - } - else { - edbm_inset_cancel(C, op); - return OPERATOR_CANCELLED; - } - } - break; - case BKEY: - if (event->val == KM_PRESS) { - const bool use_boundary = RNA_boolean_get(op->ptr, "use_boundary"); - RNA_boolean_set(op->ptr, "use_boundary", !use_boundary); - if (edbm_inset_calc(op)) { - edbm_inset_update_header(op, C); - } - else { - edbm_inset_cancel(C, op); - return OPERATOR_CANCELLED; - } - } - break; - } - - return OPERATOR_RUNNING_MODAL; -} - - -void MESH_OT_inset(wmOperatorType *ot) -{ - PropertyRNA *prop; - - /* identifiers */ - ot->name = "Inset Faces"; - ot->idname = "MESH_OT_inset"; - ot->description = "Inset new faces into selected faces"; - - /* api callbacks */ - ot->invoke = edbm_inset_invoke; - ot->modal = edbm_inset_modal; - ot->exec = edbm_inset_exec; - ot->cancel = edbm_inset_cancel; - ot->poll = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_POINTER | OPTYPE_BLOCKING; - - /* properties */ - RNA_def_boolean(ot->srna, "use_boundary", true, "Boundary", "Inset face boundaries"); - RNA_def_boolean(ot->srna, "use_even_offset", true, "Offset Even", "Scale the offset to give more even thickness"); - RNA_def_boolean(ot->srna, "use_relative_offset", false, "Offset Relative", "Scale the offset by surrounding geometry"); - - prop = RNA_def_float(ot->srna, "thickness", 0.01f, 0.0f, FLT_MAX, "Thickness", "", 0.0f, 10.0f); - /* use 1 rather then 10 for max else dragging the button moves too far */ - RNA_def_property_ui_range(prop, 0.0, 1.0, 0.01, 4); - prop = RNA_def_float(ot->srna, "depth", 0.0f, -FLT_MAX, FLT_MAX, "Depth", "", -10.0f, 10.0f); - RNA_def_property_ui_range(prop, -10.0f, 10.0f, 0.01, 4); - - RNA_def_boolean(ot->srna, "use_outset", false, "Outset", "Outset rather than inset"); - RNA_def_boolean(ot->srna, "use_select_inset", true, "Select Outer", "Select the new inset faces"); -} - static int edbm_wireframe_exec(bContext *C, wmOperator *op) { Object *obedit = CTX_data_edit_object(C); |