diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-04-06 06:45:43 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-04-06 06:45:43 +0400 |
commit | 1d5f988778ef0e4779e708db9f1921e5713e373c (patch) | |
tree | d65eece982f7e72bf73b30f0b2f3a693fb36d3a5 /source/blender/editors/mesh | |
parent | cf3ec257a2b6913c41db93069b0ec7ce4dc6e2ad (diff) |
patch [#34890] BMesh Poke Face.
by Francisco De La Cruz (xercesblue), with some of my own changes/improvements.
Converts faces to triangle-fans (useful to run on ngons).
To access select a group of faces and press "Alt+P" or alternatively select the operator from the Faces menu (Ctrl+F)
Diffstat (limited to 'source/blender/editors/mesh')
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 57 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_ops.c | 3 |
3 files changed, 60 insertions, 1 deletions
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index a7264d3b006..2dbe2852303 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -2631,6 +2631,37 @@ void MESH_OT_beautify_fill(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } + +/********************** Poke Face **********************/ + +static int edbm_poke_face_exec(bContext *C, wmOperator *op) +{ + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = BMEdit_FromObject(obedit); + BMOperator bmop; + + const float offset = RNA_float_get(op->ptr, "offset"); + const int center_mode = RNA_enum_get(op->ptr, "center_mode"); + + EDBM_op_init(em, &bmop, op, "poke faces=%hf offset=%f center_mode=%i", BM_ELEM_SELECT, offset, center_mode); + BMO_op_exec(em->bm, &bmop); + + EDBM_flag_disable_all(em, BM_ELEM_SELECT); + + BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "verts.out", BM_VERT, BM_ELEM_SELECT, true); + BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true); + + if (!EDBM_op_finish(em, &bmop, op, true)) { + return OPERATOR_CANCELLED; + } + + EDBM_mesh_normals_update(em); + + EDBM_update_generic(em, true, true); + + return OPERATOR_FINISHED; + +} /********************** Quad/Tri Operators *************************/ static int edbm_quads_convert_to_tris_exec(bContext *C, wmOperator *op) @@ -2659,6 +2690,32 @@ static int edbm_quads_convert_to_tris_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +void MESH_OT_poke(wmOperatorType *ot) +{ + + static EnumPropertyItem poke_center_modes[] = { + {BMOP_POKE_MEAN_WEIGHTED, "MEAN_WEIGHTED", 0, "Weighted Mean", "Weighted Mean Face Center"}, + {BMOP_POKE_MEAN, "MEAN", 0, "Mean", "Mean Face Center"}, + {BMOP_POKE_BOUNDS, "BOUNDS", 0, "Bounds", "Face Bounds Center"}, + {0, NULL, 0, NULL, NULL}}; + + + /* identifiers */ + ot->name = "Poke Faces"; + ot->idname = "MESH_OT_poke"; + ot->description = "Splits a face into a fan"; + + /* api callbacks */ + ot->exec = edbm_poke_face_exec; + ot->poll = ED_operator_editmesh; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_float(ot->srna, "offset", 0.0f, -FLT_MAX, FLT_MAX, "Poke Offset", "Poke Offset", -1.0f, 1.0f); + RNA_def_enum(ot->srna, "center_mode", poke_center_modes, BMOP_POKE_MEAN_WEIGHTED, "Poke Center", "Poke Face Center Calculation"); +} + void MESH_OT_quads_convert_to_tris(wmOperatorType *ot) { /* identifiers */ diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index 996ee9fc549..937fbf8146b 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -202,6 +202,7 @@ void MESH_OT_edge_face_add(struct wmOperatorType *ot); void MESH_OT_duplicate(struct wmOperatorType *ot); void MESH_OT_merge(struct wmOperatorType *ot); void MESH_OT_remove_doubles(struct wmOperatorType *ot); +void MESH_OT_poke(struct wmOperatorType *ot); /* *** mesh_data.c *** */ diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index a79923a4fdb..db6f6e3aeb5 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -152,6 +152,7 @@ void ED_operatortypes_mesh(void) WM_operatortype_append(MESH_OT_bridge_edge_loops); WM_operatortype_append(MESH_OT_inset); + WM_operatortype_append(MESH_OT_poke); WM_operatortype_append(MESH_OT_wireframe); WM_operatortype_append(MESH_OT_edge_split); @@ -260,7 +261,7 @@ void ED_keymap_mesh(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "MESH_OT_loopcut_slide", RKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "MESH_OT_inset", IKEY, KM_PRESS, 0, 0); - + WM_keymap_add_item(keymap, "MESH_OT_poke", PKEY, KM_PRESS, KM_ALT, 0); kmi = WM_keymap_add_item(keymap, "MESH_OT_bevel", BKEY, KM_PRESS, KM_CTRL, 0); RNA_boolean_set(kmi->ptr, "vertex_only", false); kmi = WM_keymap_add_item(keymap, "MESH_OT_bevel", BKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0); |