diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-29 14:44:00 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-29 14:44:00 +0400 |
commit | 41a5e731a2e13a18110f3f1919c340425f32f452 (patch) | |
tree | d01fb6155d5cdebd114eb5a06a3b3f5c884cb50a /source/blender/editors | |
parent | 3d1349609c955cd2e326904dbc48c7277e7d99ff (diff) |
bmesh: new wireframe tool
- makes wireframe from faces.
- options similar to inset (even offset, relative scale)
- copies face settings and loops (uvs, vcolors)
- optionally replaces the existing geometry.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 67 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_ops.c | 1 |
3 files changed, 69 insertions, 0 deletions
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 7eae8b4d67e..a5053978186 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -4266,3 +4266,70 @@ void MESH_OT_inset(wmOperatorType *ot) 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); + BMEditMesh *em = BMEdit_FromObject(obedit); + BMOperator bmop; + const int use_boundary = RNA_boolean_get(op->ptr, "use_boundary"); + const int use_even_offset = RNA_boolean_get(op->ptr, "use_even_offset"); + const int use_replace = RNA_boolean_get(op->ptr, "use_replace"); + const int use_relative_offset = RNA_boolean_get(op->ptr, "use_relative_offset"); + const float thickness = RNA_float_get(op->ptr, "thickness"); + + EDBM_op_init(em, &bmop, op, + "wireframe faces=%hf use_boundary=%b use_even_offset=%b use_relative_offset=%b " + "thickness=%f", + BM_ELEM_SELECT, use_boundary, use_even_offset, use_relative_offset, + thickness); + + BMO_op_exec(em->bm, &bmop); + + if (use_replace) { + BM_mesh_elem_hflag_disable_all(em->bm, BM_FACE, BM_ELEM_TAG, FALSE); + BMO_slot_buffer_hflag_enable(em->bm, &bmop, "faces", BM_FACE, BM_ELEM_TAG, FALSE); + + BMO_op_callf(em->bm, "del geom=%hvef context=%i", BM_ELEM_TAG, DEL_FACES); + } + + BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, FALSE); + BMO_slot_buffer_hflag_enable(em->bm, &bmop, "faceout", BM_FACE, BM_ELEM_SELECT, TRUE); + + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { + return OPERATOR_CANCELLED; + } + else { + EDBM_update_generic(C, em, TRUE); + return OPERATOR_FINISHED; + } +} + +void MESH_OT_wireframe(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name = "Wire Frame"; + ot->idname = "MESH_OT_wireframe"; + ot->description = "Inset new faces into selected faces"; + + /* api callbacks */ + ot->exec = edbm_wireframe_exec; + ot->poll = ED_operator_editmesh; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* 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); + + + RNA_def_boolean(ot->srna, "use_replace", TRUE, "Replace", "Remove original faces"); +} + diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index b6403f33bc9..ca989a25ccd 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -211,6 +211,7 @@ void MESH_OT_bevel(struct wmOperatorType *ot); void MESH_OT_bridge_edge_loops(struct wmOperatorType *ot); void MESH_OT_inset(struct wmOperatorType *ot); +void MESH_OT_wireframe(struct wmOperatorType *ot); void MESH_OT_vert_slide(struct wmOperatorType *ot); /* ******************* mesh_navmesh.c */ diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index 4b4fef53275..0b2a6d2bd66 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -164,6 +164,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_wireframe); WM_operatortype_append(MESH_OT_edge_split); #ifdef WITH_GAMEENGINE |