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