Index: release/scripts/startup/bl_ui/space_view3d.py =================================================================== --- release/scripts/startup/bl_ui/space_view3d.py (revision 55827) +++ release/scripts/startup/bl_ui/space_view3d.py (working copy) @@ -1945,7 +1945,8 @@ layout.operator("mesh.sort_elements", text="Sort Faces").elements = {'FACE'} layout.separator() - + + layout.operator("mesh.poke") layout.operator("mesh.quads_convert_to_tris") layout.operator("mesh.tris_convert_to_quads") Index: source/blender/bmesh/CMakeLists.txt =================================================================== --- source/blender/bmesh/CMakeLists.txt (revision 55827) +++ source/blender/bmesh/CMakeLists.txt (working copy) @@ -54,6 +54,7 @@ operators/bmo_join_triangles.c operators/bmo_mesh_conv.c operators/bmo_mirror.c + operators/bmo_poke.c operators/bmo_primitive.c operators/bmo_removedoubles.c operators/bmo_similar.c Index: source/blender/bmesh/intern/bmesh_opdefines.c =================================================================== --- source/blender/bmesh/intern/bmesh_opdefines.c (revision 55827) +++ source/blender/bmesh/intern/bmesh_opdefines.c (working copy) @@ -1549,6 +1549,27 @@ 0 }; +/* + * Pokes a face. + * + * Splits a face into a triangle fan. + */ +static BMOpDefine bmo_poke_def = { + "poke", + /* slots_in */ + {{"faces", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}}, /* input faces */ + {"offset", BMO_OP_SLOT_FLT}, /* center vertex offset along normal */ + {"center_mode", BMO_OP_SLOT_INT}, /* calculation mode for center vertex */ + {{'\0'}}, + }, + /* slots_out */ + {{"faces.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}}, /* output faces */ + {{'\0'}}, + }, + bmo_poke_exec, + 0 +}; + #ifdef WITH_BULLET /* * Convex Hull @@ -1654,6 +1675,7 @@ &bmo_object_load_bmesh_def, &bmo_pointmerge_def, &bmo_pointmerge_facedata_def, + &bmo_poke_def, &bmo_recalc_face_normals_def, &bmo_region_extend_def, &bmo_remove_doubles_def, Index: source/blender/bmesh/intern/bmesh_operators.h =================================================================== --- source/blender/bmesh/intern/bmesh_operators.h (revision 55827) +++ source/blender/bmesh/intern/bmesh_operators.h (working copy) @@ -89,6 +89,13 @@ VPATH_SELECT_TOPOLOGICAL }; +/* Poke face center calculation */ +enum { + PF_MEAN_WEIGHTED = 0, + PF_BOUNDS, + PF_MEAN +}; + extern const BMOpDefine *bmo_opdefines[]; extern const int bmo_opdefines_total; Index: source/blender/bmesh/intern/bmesh_operators_private.h =================================================================== --- source/blender/bmesh/intern/bmesh_operators_private.h (revision 55827) +++ source/blender/bmesh/intern/bmesh_operators_private.h (working copy) @@ -73,6 +73,7 @@ void bmo_pointmerge_exec(BMesh *bm, BMOperator *op); void bmo_pointmerge_facedata_exec(BMesh *bm, BMOperator *op); void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op); +void bmo_poke_exec(BMesh *bm, BMOperator *op); void bmo_region_extend_exec(BMesh *bm, BMOperator *op); void bmo_remove_doubles_exec(BMesh *bm, BMOperator *op); void bmo_reverse_colors_exec(BMesh *bm, BMOperator *op); Index: source/blender/bmesh/operators/bmo_poke.c =================================================================== --- source/blender/bmesh/operators/bmo_poke.c (revision 0) +++ source/blender/bmesh/operators/bmo_poke.c (working copy) @@ -0,0 +1,129 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Francisco De La Cruz + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/bmesh/operators/bmo_poke.c + * \ingroup bmesh + * + * Pokes a face. + * + * Splits a face into a triangle fan. + */ + +#include "MEM_guardedalloc.h" + +#include "BLI_math.h" +#include "BLI_array.h" + +#include "bmesh.h" + +#include "intern/bmesh_operators_private.h" /* own include */ + +#define ELE_NEW 1 + +/* Pokes a face + * + * Splits a face into a triangle fan. + * Iterate over all selected faces, create a new center vertex and + * create triangles between original face edges and new center vertex. + */ +void bmo_poke_exec(BMesh *bm, BMOperator *op) +{ + BMVert *centerVert = NULL; + BMVert *v = NULL, *v1 = NULL, *v2 = NULL, *v3 = NULL, *vstart = NULL; + BMLoop *l = NULL; + BMFace *f = NULL, *newFace = NULL; + BMIter fiter, liter; + + int i = 0; + int vertcount = 0; + float fcenter[3] = {0}; + + const float offset = BMO_slot_float_get(op->slots_in, "offset"); + const int center_mode = BMO_slot_int_get(op->slots_in, "center_mode"); + + /* Remove tagged flag from all faces */ + BM_mesh_elem_hflag_disable_all(bm, BM_FACE, BM_ELEM_TAG, false); + + /* Retag only slot faces */ + BMO_slot_buffer_hflag_enable(bm, op->slots_in, "faces", BM_FACE, BM_ELEM_TAG, false); + + BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) { + if (BM_elem_flag_test(f, BM_ELEM_TAG)) { + vertcount = 0; + + BM_elem_flag_disable(f, BM_ELEM_TAG); + + switch (center_mode) { + case PF_MEAN_WEIGHTED: + BM_face_calc_center_mean_weighted(f, fcenter); + break; + case PF_BOUNDS: + BM_face_calc_center_bounds(f, fcenter); + break; + case PF_MEAN: + BM_face_calc_center_mean(f, fcenter); + break; + } + + centerVert = BM_vert_create(bm, fcenter, NULL, false); + + BMO_elem_flag_enable(bm, centerVert, ELE_NEW); + + BM_vert_interp_from_face(bm, centerVert, f); + + vertcount = f->len; + BM_ITER_ELEM_INDEX(l, &liter, f,BM_LOOPS_OF_FACE, i) { + BMLoop *floop; + + v1 = l->v; + if (i == 1) vstart = v1; + if (i == vertcount) v2 = vstart; + else v2 = l->next->v; + + newFace = BM_face_create_quad_tri(bm, v1, v2, centerVert, NULL, f, false); + + /* Copy Loop Data */ + floop = BM_FACE_FIRST_LOOP(newFace); + BM_elem_attrs_copy(bm, bm, l, floop); + BM_elem_attrs_copy(bm, bm, l->next, floop->next); + BM_elem_attrs_copy(bm, bm, l, floop->prev); + + BMO_elem_flag_enable(bm, newFace, ELE_NEW); + + l = l->next; + } + + copy_v3_v3(centerVert->co, fcenter); + + copy_v3_v3(centerVert->no, f->no); + madd_v3_v3fl(centerVert->co, centerVert->no, offset); + + /* Untag face (to prevent reprocessing) and mark for deletion */ + BM_elem_flag_disable(f, BM_ELEM_TAG); + + /* Kill Face */ + BM_face_kill(bm, f); + } + } + + BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "faces.out", BM_FACE, ELE_NEW); +} \ No newline at end of file Index: source/blender/editors/mesh/editmesh_tools.c =================================================================== --- source/blender/editors/mesh/editmesh_tools.c (revision 55827) +++ source/blender/editors/mesh/editmesh_tools.c (working copy) @@ -2631,6 +2631,36 @@ 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, "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 +2689,32 @@ return OPERATOR_FINISHED; } +void MESH_OT_poke(wmOperatorType *ot) +{ + + static EnumPropertyItem poke_center_modes[] = { + {PF_MEAN_WEIGHTED, "PF_MEAN_WEIGHTED", 0, "Weighted Mean", "Weighted Mean Face Center"}, + {PF_BOUNDS, "PF_BOUNDS", 0, "Bounds", "Face Bounds Center"}, + {PF_MEAN, "PF_MEAN", 0, "Mean", "Mean Face Center"}, + {0, NULL, 0, NULL, NULL}}; + + + /* identifiers */ + ot->name = "Poke Faces"; + ot->idname = "MESH_OT_poke"; + ot->description = "Poke Faces"; + + /* 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, PF_MEAN_WEIGHTED, "Poke Center", "Poke Face Center Calculation"); +} + void MESH_OT_quads_convert_to_tris(wmOperatorType *ot) { /* identifiers */ Index: source/blender/editors/mesh/mesh_intern.h =================================================================== --- source/blender/editors/mesh/mesh_intern.h (revision 55827) +++ source/blender/editors/mesh/mesh_intern.h (working copy) @@ -202,6 +202,7 @@ 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 *** */ Index: source/blender/editors/mesh/mesh_ops.c =================================================================== --- source/blender/editors/mesh/mesh_ops.c (revision 55827) +++ source/blender/editors/mesh/mesh_ops.c (working copy) @@ -152,6 +152,7 @@ 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 @@ 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);