Blender V5.3
editmesh_extrude_screw.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
8
9#include "DNA_mesh_types.h"
10#include "DNA_object_types.h"
11
12#include "BKE_context.hh"
13#include "BKE_editmesh.hh"
14#include "BKE_layer.hh"
15#include "BKE_report.hh"
16
17#include "BLI_math_matrix_c.hh"
19#include "BLI_math_vector_c.hh"
20
21#include "RNA_access.hh"
22#include "RNA_define.hh"
23
24#include "WM_types.hh"
25
26#include "ED_mesh.hh"
27#include "ED_screen.hh"
28#include "ED_view3d.hh"
29
30#include "mesh_intern.hh" /* own include */
31
32namespace blender {
33
34/* -------------------------------------------------------------------- */
37
39{
40 BMEdge *eed;
41 BMVert *eve, *v1, *v2;
42 BMIter iter, eiter;
43 float dvec[3], nor[3], cent[3], axis[3], v1_co_global[3], v2_co_global[3];
44 int steps, turns;
45 int valence;
46 uint objects_empty_len = 0;
47 uint failed_axis_len = 0;
48 uint failed_verts_len = 0;
49
50 turns = RNA_int_get(op->ptr, "turns");
51 steps = RNA_int_get(op->ptr, "steps");
52 RNA_float_get_array(op->ptr, "center", cent);
53 RNA_float_get_array(op->ptr, "axis", axis);
54
55 const Main *bmain = CTX_data_main(C);
56 const Scene *scene = CTX_data_scene(C);
57 ViewLayer *view_layer = CTX_data_view_layer(C);
59 *bmain, scene, view_layer, CTX_wm_view3d(C));
60
61 for (Object *obedit : objects) {
63
64 if (bm->totvertsel < 2) {
65 if (bm->totvertsel == 0) {
66 objects_empty_len++;
67 }
68 continue;
69 }
70
71 if (is_zero_v3(axis)) {
72 failed_axis_len++;
73 continue;
74 }
75
76 /* find two vertices with valence count == 1, more or less is wrong */
77 v1 = nullptr;
78 v2 = nullptr;
79
80 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
81 valence = 0;
82 BM_ITER_ELEM (eed, &eiter, eve, BM_EDGES_OF_VERT) {
84 valence++;
85 }
86 }
87
88 if (valence == 1) {
89 if (v1 == nullptr) {
90 v1 = eve;
91 }
92 else if (v2 == nullptr) {
93 v2 = eve;
94 }
95 else {
96 v1 = nullptr;
97 break;
98 }
99 }
100 }
101
102 if (v1 == nullptr || v2 == nullptr) {
103 failed_verts_len++;
104 continue;
105 }
106
107 copy_v3_v3(nor, obedit->object_to_world().ptr()[2]);
108
109 /* calculate dvec */
110 mul_v3_m4v3(v1_co_global, obedit->object_to_world().ptr(), v1->co);
111 mul_v3_m4v3(v2_co_global, obedit->object_to_world().ptr(), v2->co);
112 sub_v3_v3v3(dvec, v1_co_global, v2_co_global);
113 mul_v3_fl(dvec, 1.0f / steps);
114
115 if (dot_v3v3(nor, dvec) > 0.0f) {
116 negate_v3(dvec);
117 }
118
119 BMOperator spinop;
120 if (!EDBM_op_init(
121 bm,
122 &spinop,
123 op,
124 "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i angle=%f space=%m4 use_duplicate=%b",
126 cent,
127 axis,
128 dvec,
129 turns * steps,
130 DEG2RADF(360.0f * turns),
131 obedit->object_to_world().ptr(),
132 false))
133 {
134 continue;
135 }
136
137 BMO_op_exec(bm, &spinop);
140 bm, spinop.slots_out, "geom_last.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, true);
141
142 if (!EDBM_op_finish(bm, &spinop, op, true)) {
143 continue;
144 }
145
146 EDBMUpdate_Params params{};
147 params.calc_looptris = true;
148 params.calc_normals = false;
149 params.is_destructive = true;
150 EDBM_update(id_cast<Mesh *>(obedit->data), &params);
151 }
152
153 if (failed_axis_len == objects.size() - objects_empty_len) {
154 BKE_report(op->reports, RPT_ERROR, "Invalid/unset axis");
155 }
156 else if (failed_verts_len == objects.size() - objects_empty_len) {
157 BKE_report(op->reports, RPT_ERROR, "You have to select a string of connected vertices too");
158 }
159
160 return OPERATOR_FINISHED;
161}
162
163/* get center and axis, in global coords */
165{
166 Scene *scene = CTX_data_scene(C);
168
169 PropertyRNA *prop;
170 prop = RNA_struct_find_property(op->ptr, "center");
171 if (!RNA_property_is_set(op->ptr, prop)) {
173 }
174 if (rv3d) {
175 prop = RNA_struct_find_property(op->ptr, "axis");
176 if (!RNA_property_is_set(op->ptr, prop)) {
177 RNA_property_float_set_array(op->ptr, prop, rv3d->viewinv[1]);
178 }
179 }
180
181 return edbm_screw_exec(C, op);
182}
183
185{
186 /* identifiers */
187 ot->name = "Screw";
188 ot->description =
189 "Extrude selected vertices in screw-shaped rotation around the cursor in indicated viewport";
190 ot->idname = "MESH_OT_screw";
191
192 /* API callbacks. */
194 ot->exec = edbm_screw_exec;
196
197 /* flags */
199
200 /* props */
201 RNA_def_int(ot->srna, "steps", 9, 1, 100000, "Steps", "Steps", 3, 256);
202 RNA_def_int(ot->srna, "turns", 1, 1, 100000, "Turns", "Turns", 1, 256);
203
205 "center",
206 3,
207 nullptr,
208 -1e12f,
209 1e12f,
210 "Center",
211 "Center in global view space",
212 -1e4f,
213 1e4f);
215 ot->srna, "axis", 3, nullptr, -1.0f, 1.0f, "Axis", "Axis in global view space", -1.0f, 1.0f);
216}
217
219
220} // namespace blender
#define DEG2RADF(_deg)
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
#define BM_ALL_NOLOOP
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
int64_t size() const
BMesh Iterators.
void EDBM_flag_disable_all(BMesh *bm, char hflag)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
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.
bool EDBM_op_init(BMesh *bm, BMOperator *bmop, wmOperator *op, const char *fmt,...)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void MESH_OT_screw(wmOperatorType *ot)
void EDBM_update(Mesh *mesh, const EDBMUpdate_Params *params)
int RNA_int_get(PointerRNA *ptr, const char *name)
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
RegionView3D * ED_view3d_context_rv3d(bContext *C)
void BMO_op_exec(BMesh *bm, BMOperator *op)
BMESH OPSTACK EXEC OP.
ViewLayer * CTX_data_view_layer(const bContext *C)
MINLINE void mul_v3_fl(float r[3], float f)
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)
bool ED_operator_editmesh(bContext *C)
bool EDBM_op_finish(BMesh *bm, BMOperator *bmop, wmOperator *op, const bool do_report)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
MINLINE void negate_v3(float r[3])
static wmOperatorStatus edbm_screw_invoke(bContext *C, wmOperator *op, const wmEvent *)
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)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
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)
static wmOperatorStatus edbm_screw_exec(bContext *C, wmOperator *op)
Main * CTX_data_main(const bContext *C)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
Scene * CTX_data_scene(const bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
View3D * CTX_wm_view3d(const bContext *C)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
View3DCursor cursor
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports