diff options
-rw-r--r-- | source/blender/editors/mesh/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_extrude.c | 238 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_extrude_screw.c | 186 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_extrude_spin.c | 152 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_intern.h | 5 |
5 files changed, 344 insertions, 239 deletions
diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt index 725d31a64ba..f1f0de3777e 100644 --- a/source/blender/editors/mesh/CMakeLists.txt +++ b/source/blender/editors/mesh/CMakeLists.txt @@ -45,6 +45,8 @@ set(SRC editmesh_bevel.c editmesh_bisect.c editmesh_extrude.c + editmesh_extrude_screw.c + editmesh_extrude_spin.c editmesh_inset.c editmesh_intersect.c editmesh_knife.c diff --git a/source/blender/editors/mesh/editmesh_extrude.c b/source/blender/editors/mesh/editmesh_extrude.c index 78bc361b222..9467c545bbf 100644 --- a/source/blender/editors/mesh/editmesh_extrude.c +++ b/source/blender/editors/mesh/editmesh_extrude.c @@ -36,7 +36,6 @@ #include "BLI_listbase.h" #include "BKE_context.h" -#include "BKE_object.h" #include "BKE_report.h" #include "BKE_editmesh.h" @@ -725,240 +724,3 @@ void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot) /** \} */ -/* -------------------------------------------------------------------- */ -/** \name Spin Operator - * \{ */ - -static int edbm_spin_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); - BMesh *bm = em->bm; - BMOperator spinop; - float cent[3], axis[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"); - - if (is_zero_v3(axis)) { - BKE_report(op->reports, RPT_ERROR, "Invalid/unset axis"); - return OPERATOR_CANCELLED; - } - - /* keep the values in worldspace since we're passing the obmat */ - if (!EDBM_op_init(em, &spinop, op, - "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i angle=%f space=%m4 use_duplicate=%b", - BM_ELEM_SELECT, cent, axis, d, steps, angle, obedit->obmat, 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); - - PropertyRNA *prop; - prop = RNA_struct_find_property(op->ptr, "center"); - if (!RNA_property_is_set(op->ptr, prop)) { - RNA_property_float_set_array(op->ptr, prop, ED_view3d_cursor3d_get(scene, v3d)); - } - if (rv3d) { - prop = RNA_struct_find_property(op->ptr, "axis"); - if (!RNA_property_is_set(op->ptr, prop)) { - RNA_property_float_set_array(op->ptr, prop, 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 = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* props */ - RNA_def_int(ot->srna, "steps", 9, 0, 1000000, "Steps", "Steps", 0, 1000); - RNA_def_boolean(ot->srna, "dupli", 0, "Dupli", "Make Duplicates"); - prop = RNA_def_float(ot->srna, "angle", DEG2RADF(90.0f), -1e12f, 1e12f, "Angle", "Rotation for each step", - DEG2RADF(-360.0f), DEG2RADF(360.0f)); - RNA_def_property_subtype(prop, PROP_ANGLE); - - RNA_def_float_vector(ot->srna, "center", 3, NULL, -1e12f, 1e12f, - "Center", "Center in global view space", -1e4f, 1e4f); - RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -1.0f, 1.0f); - -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Screw Operator - * \{ */ - -static int edbm_screw_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(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], v1_co_global[3], v2_co_global[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); - - if (is_zero_v3(axis)) { - BKE_report(op->reports, RPT_ERROR, "Invalid/unset axis"); - return OPERATOR_CANCELLED; - } - - /* 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; - } - - copy_v3_v3(nor, obedit->obmat[2]); - - /* calculate dvec */ - mul_v3_m4v3(v1_co_global, obedit->obmat, v1->co); - mul_v3_m4v3(v2_co_global, obedit->obmat, v2->co); - sub_v3_v3v3(dvec, v1_co_global, v2_co_global); - mul_v3_fl(dvec, 1.0f / steps); - - if (dot_v3v3(nor, dvec) > 0.0f) - negate_v3(dvec); - - if (!EDBM_op_init(em, &spinop, op, - "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i angle=%f space=%m4 use_duplicate=%b", - BM_ELEM_SELECT, cent, axis, dvec, turns * steps, DEG2RADF(360.0f * turns), obedit->obmat, 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); - - PropertyRNA *prop; - prop = RNA_struct_find_property(op->ptr, "center"); - if (!RNA_property_is_set(op->ptr, prop)) { - RNA_property_float_set_array(op->ptr, prop, ED_view3d_cursor3d_get(scene, v3d)); - } - if (rv3d) { - prop = RNA_struct_find_property(op->ptr, "axis"); - if (!RNA_property_is_set(op->ptr, prop)) { - RNA_property_float_set_array(op->ptr, prop, 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 = ED_operator_editmesh; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* props */ - RNA_def_int(ot->srna, "steps", 9, 1, 100000, "Steps", "Steps", 3, 256); - RNA_def_int(ot->srna, "turns", 1, 1, 100000, "Turns", "Turns", 1, 256); - - RNA_def_float_vector(ot->srna, "center", 3, NULL, -1e12f, 1e12f, - "Center", "Center in global view space", -1e4f, 1e4f); - RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, - "Axis", "Axis in global view space", -1.0f, 1.0f); -} - -/** \} */ diff --git a/source/blender/editors/mesh/editmesh_extrude_screw.c b/source/blender/editors/mesh/editmesh_extrude_screw.c new file mode 100644 index 00000000000..ffbbae60949 --- /dev/null +++ b/source/blender/editors/mesh/editmesh_extrude_screw.c @@ -0,0 +1,186 @@ +/* + * ***** 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. + * + * The Original Code is Copyright (C) 2004 by Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Joseph Eagar + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/mesh/editmesh_extrude_spin.c + * \ingroup edmesh + */ + +#include "DNA_object_types.h" + +#include "BLI_math.h" + +#include "BKE_context.h" +#include "BKE_report.h" +#include "BKE_editmesh.h" + +#include "RNA_define.h" +#include "RNA_access.h" + +#include "WM_types.h" + +#include "ED_mesh.h" +#include "ED_screen.h" +#include "ED_view3d.h" + +#include "mesh_intern.h" /* own include */ + +/* -------------------------------------------------------------------- */ +/** \name Screw Operator + * \{ */ + +static int edbm_screw_exec(bContext *C, wmOperator *op) +{ + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = BKE_editmesh_from_object(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], v1_co_global[3], v2_co_global[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); + + if (is_zero_v3(axis)) { + BKE_report(op->reports, RPT_ERROR, "Invalid/unset axis"); + return OPERATOR_CANCELLED; + } + + /* 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; + } + + copy_v3_v3(nor, obedit->obmat[2]); + + /* calculate dvec */ + mul_v3_m4v3(v1_co_global, obedit->obmat, v1->co); + mul_v3_m4v3(v2_co_global, obedit->obmat, v2->co); + sub_v3_v3v3(dvec, v1_co_global, v2_co_global); + mul_v3_fl(dvec, 1.0f / steps); + + if (dot_v3v3(nor, dvec) > 0.0f) + negate_v3(dvec); + + if (!EDBM_op_init(em, &spinop, op, + "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i angle=%f space=%m4 use_duplicate=%b", + BM_ELEM_SELECT, cent, axis, dvec, turns * steps, DEG2RADF(360.0f * turns), obedit->obmat, 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); + + PropertyRNA *prop; + prop = RNA_struct_find_property(op->ptr, "center"); + if (!RNA_property_is_set(op->ptr, prop)) { + RNA_property_float_set_array(op->ptr, prop, ED_view3d_cursor3d_get(scene, v3d)); + } + if (rv3d) { + prop = RNA_struct_find_property(op->ptr, "axis"); + if (!RNA_property_is_set(op->ptr, prop)) { + RNA_property_float_set_array(op->ptr, prop, 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 = ED_operator_editmesh; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* props */ + RNA_def_int(ot->srna, "steps", 9, 1, 100000, "Steps", "Steps", 3, 256); + RNA_def_int(ot->srna, "turns", 1, 1, 100000, "Turns", "Turns", 1, 256); + + RNA_def_float_vector(ot->srna, "center", 3, NULL, -1e12f, 1e12f, + "Center", "Center in global view space", -1e4f, 1e4f); + RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, + "Axis", "Axis in global view space", -1.0f, 1.0f); +} + +/** \} */ diff --git a/source/blender/editors/mesh/editmesh_extrude_spin.c b/source/blender/editors/mesh/editmesh_extrude_spin.c new file mode 100644 index 00000000000..4cd3b033ca7 --- /dev/null +++ b/source/blender/editors/mesh/editmesh_extrude_spin.c @@ -0,0 +1,152 @@ +/* + * ***** 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. + * + * The Original Code is Copyright (C) 2004 by Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Joseph Eagar + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/mesh/editmesh_extrude_spin.c + * \ingroup edmesh + */ + +#include "DNA_object_types.h" + +#include "BLI_math.h" + +#include "BKE_context.h" +#include "BKE_report.h" +#include "BKE_editmesh.h" + +#include "RNA_define.h" +#include "RNA_access.h" + +#include "WM_types.h" + +#include "ED_mesh.h" +#include "ED_screen.h" +#include "ED_view3d.h" + +#include "mesh_intern.h" /* own include */ + + +/* -------------------------------------------------------------------- */ +/** \name Spin Operator + * \{ */ + +static int edbm_spin_exec(bContext *C, wmOperator *op) +{ + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMesh *bm = em->bm; + BMOperator spinop; + float cent[3], axis[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"); + + if (is_zero_v3(axis)) { + BKE_report(op->reports, RPT_ERROR, "Invalid/unset axis"); + return OPERATOR_CANCELLED; + } + + /* keep the values in worldspace since we're passing the obmat */ + if (!EDBM_op_init(em, &spinop, op, + "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i angle=%f space=%m4 use_duplicate=%b", + BM_ELEM_SELECT, cent, axis, d, steps, angle, obedit->obmat, 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); + + PropertyRNA *prop; + prop = RNA_struct_find_property(op->ptr, "center"); + if (!RNA_property_is_set(op->ptr, prop)) { + RNA_property_float_set_array(op->ptr, prop, ED_view3d_cursor3d_get(scene, v3d)); + } + if (rv3d) { + prop = RNA_struct_find_property(op->ptr, "axis"); + if (!RNA_property_is_set(op->ptr, prop)) { + RNA_property_float_set_array(op->ptr, prop, 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 = ED_operator_editmesh; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* props */ + RNA_def_int(ot->srna, "steps", 9, 0, 1000000, "Steps", "Steps", 0, 1000); + RNA_def_boolean(ot->srna, "dupli", 0, "Dupli", "Make Duplicates"); + prop = RNA_def_float(ot->srna, "angle", DEG2RADF(90.0f), -1e12f, 1e12f, "Angle", "Rotation for each step", + DEG2RADF(-360.0f), DEG2RADF(360.0f)); + RNA_def_property_subtype(prop, PROP_ANGLE); + + RNA_def_float_vector(ot->srna, "center", 3, NULL, -1e12f, 1e12f, + "Center", "Center in global view space", -1e4f, 1e4f); + RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -1.0f, 1.0f); + +} + +/** \} */ + diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index 300b21a052d..71e283ea043 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -106,9 +106,12 @@ void MESH_OT_extrude_verts_indiv(struct wmOperatorType *ot); void MESH_OT_extrude_edges_indiv(struct wmOperatorType *ot); void MESH_OT_extrude_faces_indiv(struct wmOperatorType *ot); void MESH_OT_dupli_extrude_cursor(struct wmOperatorType *ot); -void MESH_OT_spin(struct wmOperatorType *ot); + +/* *** editmesh_extrude_screw.c *** */ void MESH_OT_screw(struct wmOperatorType *ot); +/* *** editmesh_extrude_spin.c *** */ +void MESH_OT_spin(struct wmOperatorType *ot); /* *** editmesh_inset.c *** */ void MESH_OT_inset(struct wmOperatorType *ot); |