Blender V4.3
editmesh_extrude_spin.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "DNA_object_types.h"
10
11#include "BLI_math_rotation.h"
12#include "BLI_math_vector.h"
13#include "BLI_string.h"
14
15#include "BKE_context.hh"
16#include "BKE_editmesh.hh"
17#include "BKE_layer.hh"
18#include "BKE_report.hh"
19
20#include "RNA_access.hh"
21#include "RNA_define.hh"
22
23#include "WM_types.hh"
24
25#include "ED_mesh.hh"
26#include "ED_screen.hh"
27#include "ED_view3d.hh"
28
29#include "MEM_guardedalloc.h"
30
31#include "mesh_intern.hh" /* own include */
32
33using blender::Vector;
34
35#define USE_GIZMO
36
37/* -------------------------------------------------------------------- */
42{
43 const Scene *scene = CTX_data_scene(C);
44 ViewLayer *view_layer = CTX_data_view_layer(C);
45 float cent[3], axis[3];
46 const float d[3] = {0.0f, 0.0f, 0.0f};
47
48 RNA_float_get_array(op->ptr, "center", cent);
49 RNA_float_get_array(op->ptr, "axis", axis);
50 const int steps = RNA_int_get(op->ptr, "steps");
51 const float angle = RNA_float_get(op->ptr, "angle");
52 const bool use_normal_flip = RNA_boolean_get(op->ptr, "use_normal_flip");
53 const bool dupli = RNA_boolean_get(op->ptr, "dupli");
54 const bool use_auto_merge = (RNA_boolean_get(op->ptr, "use_auto_merge") && (dupli == false) &&
55 (steps >= 3) && fabsf(fabsf(angle) - float(M_PI * 2)) <= 1e-6f);
56
57 if (is_zero_v3(axis)) {
58 BKE_report(op->reports, RPT_ERROR, "Invalid/unset axis");
59 return OPERATOR_CANCELLED;
60 }
61
63 scene, view_layer, CTX_wm_view3d(C));
64
65 for (Object *obedit : objects) {
67 BMesh *bm = em->bm;
68 BMOperator spinop;
69
70 /* Keep the values in world-space since we're passing the `obmat`. */
71 if (!EDBM_op_init(em,
72 &spinop,
73 op,
74 "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i angle=%f space=%m4 "
75 "use_normal_flip=%b use_duplicate=%b use_merge=%b",
77 cent,
78 axis,
79 d,
80 steps,
81 -angle,
82 obedit->object_to_world().ptr(),
83 use_normal_flip,
84 dupli,
85 use_auto_merge))
86 {
87 continue;
88 }
89 BMO_op_exec(bm, &spinop);
90 if (use_auto_merge == false) {
93 bm, spinop.slots_out, "geom_last.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, true);
94 }
95 if (!EDBM_op_finish(em, &spinop, op, true)) {
96 continue;
97 }
98
100 params.calc_looptris = true;
101 params.calc_normals = false;
102 params.is_destructive = true;
103 EDBM_update(static_cast<Mesh *>(obedit->data), &params);
104 }
105
106 return OPERATOR_FINISHED;
107}
108
109/* get center and axis, in global coords */
110static int edbm_spin_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
111{
112 Scene *scene = CTX_data_scene(C);
113 View3D *v3d = CTX_wm_view3d(C);
115
116 PropertyRNA *prop;
117 prop = RNA_struct_find_property(op->ptr, "center");
118 if (!RNA_property_is_set(op->ptr, prop)) {
119 RNA_property_float_set_array(op->ptr, prop, scene->cursor.location);
120 }
121 if (rv3d) {
122 prop = RNA_struct_find_property(op->ptr, "axis");
123 if (!RNA_property_is_set(op->ptr, prop)) {
124 RNA_property_float_set_array(op->ptr, prop, rv3d->viewinv[2]);
125 }
126 }
127
128#ifdef USE_GIZMO
129 /* Start with zero angle, drag out the value. */
130 prop = RNA_struct_find_property(op->ptr, "angle");
131 if (!RNA_property_is_set(op->ptr, prop)) {
132 RNA_property_float_set(op->ptr, prop, 0.0f);
133 }
134#endif
135
136 int ret = edbm_spin_exec(C, op);
137
138#ifdef USE_GIZMO
139 if (ret & OPERATOR_FINISHED) {
140 /* Setup gizmos */
141 if (v3d && ((v3d->gizmo_flag & V3D_GIZMO_HIDE) == 0)) {
142 wmGizmoGroupType *gzgt = WM_gizmogrouptype_find("MESH_GGT_spin_redo", false);
144 Main *bmain = CTX_data_main(C);
146 }
147 }
148 }
149#endif
150
151 return ret;
152}
153
154static bool edbm_spin_poll_property(const bContext * /*C*/,
155 wmOperator *op,
156 const PropertyRNA *prop)
157{
158 const char *prop_id = RNA_property_identifier(prop);
159 const bool dupli = RNA_boolean_get(op->ptr, "dupli");
160
161 if (dupli) {
162 if (STR_ELEM(prop_id, "use_auto_merge", "use_normal_flip")) {
163 return false;
164 }
165 }
166 return true;
167}
168
170{
171 PropertyRNA *prop;
172
173 /* identifiers */
174 ot->name = "Spin";
175 ot->description =
176 "Extrude selected vertices in a circle around the cursor in indicated viewport";
177 ot->idname = "MESH_OT_spin";
178
179 /* api callbacks */
184
185 /* flags */
187
188 /* props */
189 RNA_def_int(ot->srna, "steps", 12, 0, 1000000, "Steps", "Steps", 0, 1000);
190
191 prop = RNA_def_boolean(ot->srna, "dupli", false, "Use Duplicates", "");
193
194 prop = RNA_def_float(ot->srna,
195 "angle",
196 DEG2RADF(90.0f),
197 -1e12f,
198 1e12f,
199 "Angle",
200 "Rotation for each step",
201 DEG2RADF(-360.0f),
202 DEG2RADF(360.0f));
205 "use_auto_merge",
206 true,
207 "Auto Merge",
208 "Merge first/last when the angle is a full revolution");
209 RNA_def_boolean(ot->srna, "use_normal_flip", false, "Flip Normals", "");
210
212 "center",
213 3,
214 nullptr,
215 -1e12f,
216 1e12f,
217 "Center",
218 "Center in global view space",
219 -1e4f,
220 1e4f);
222 ot->srna, "axis", 3, nullptr, -1.0f, 1.0f, "Axis", "Axis in global view space", -1.0f, 1.0f);
223
225#ifdef USE_GIZMO
227#endif
228}
229
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:63
blender::Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
#define M_PI
#define DEG2RADF(_deg)
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
#define STR_ELEM(...)
Definition BLI_string.h:653
Object is a sort of wrapper for general info.
@ V3D_GIZMO_HIDE
void EDBM_flag_disable_all(BMEditMesh *em, char hflag)
void EDBM_update(Mesh *mesh, const EDBMUpdate_Params *params)
bool ED_operator_editmesh(bContext *C)
RegionView3D * ED_view3d_context_rv3d(bContext *C)
Read Guarded memory(de)allocation.
@ PROP_SKIP_SAVE
Definition RNA_types.hh:245
@ PROP_ANGLE
Definition RNA_types.hh:155
@ OPTYPE_UNDO
Definition WM_types.hh:162
@ OPTYPE_REGISTER
Definition WM_types.hh:160
#define BM_ALL_NOLOOP
@ BM_ELEM_SELECT
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BMO_slot_buffer_hflag_enable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, char hflag, bool do_flush)
BMO_FLAG_BUFFER.
void BMO_op_exec(BMesh *bm, BMOperator *op)
BMESH OPSTACK EXEC OP.
#define fabsf(x)
static int edbm_spin_exec(bContext *C, wmOperator *op)
static int edbm_spin_invoke(bContext *C, wmOperator *op, const wmEvent *)
void MESH_OT_spin(wmOperatorType *ot)
static bool edbm_spin_poll_property(const bContext *, wmOperator *op, const PropertyRNA *prop)
void MESH_GGT_spin_redo(wmGizmoGroupType *gzgt)
void MESH_GGT_spin(wmGizmoGroupType *gzgt)
bool EDBM_op_init(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const char *fmt,...)
bool EDBM_op_finish(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const bool do_report)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
return ret
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
int RNA_int_get(PointerRNA *ptr, const char *name)
float RNA_float_get(PointerRNA *ptr, const char *name)
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
const char * RNA_property_identifier(const PropertyRNA *prop)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
static const int steps
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
float viewinv[4][4]
const char * name
Definition WM_types.hh:990
bool(* poll_property)(const bContext *C, wmOperator *op, const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1048
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1022
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
StructRNA * srna
Definition WM_types.hh:1080
struct ReportList * reports
struct PointerRNA * ptr
wmOperatorType * ot
Definition wm_files.cc:4125
bool WM_gizmo_group_type_ensure_ptr(wmGizmoGroupType *gzgt)
void WM_gizmo_group_type_reinit_ptr(Main *bmain, wmGizmoGroupType *gzgt)
wmGizmoGroupType * WM_gizmogrouptype_append(void(*wtfunc)(wmGizmoGroupType *))
wmGizmoGroupType * WM_gizmogrouptype_find(const char *idname, bool quiet)