Blender V5.3
editmesh_extrude.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_modifier_types.h"
11#include "DNA_object_types.h"
12
13#include "BLI_listbase.hh"
14#include "BLI_math_matrix_c.hh"
16#include "BLI_math_vector_c.hh"
17
18#include "BKE_context.hh"
19#include "BKE_editmesh.hh"
20#include "BKE_layer.hh"
21#include "BKE_object_types.hh"
22#include "BKE_report.hh"
23
24#include "RNA_access.hh"
25#include "RNA_define.hh"
26
27#include "WM_api.hh"
28#include "WM_types.hh"
29
30#include "ED_mesh.hh"
31#include "ED_screen.hh"
32#include "ED_transform.hh"
33#include "ED_view3d.hh"
34
35#include "mesh_intern.hh" /* own include */
36
37namespace blender {
38
39/* -------------------------------------------------------------------- */
42
44 const char hflag,
45 BMOperator *op,
46 BMOpSlot *slot_edges_exclude)
47{
49
50 /* If a mirror modifier with clipping is on, we need to adjust some
51 * of the cases above to handle edges on the line of symmetry.
52 */
53 for (ModifierData &md : obedit->modifiers) {
55 MirrorModifierData *mmd = reinterpret_cast<MirrorModifierData *>(&md);
56
57 if (mmd->flag & MOD_MIR_CLIPPING) {
58 BMIter iter;
59 BMEdge *edge;
60
61 float mtx[4][4];
62 if (mmd->mirror_ob) {
63 float imtx[4][4];
64 invert_m4_m4(imtx, mmd->mirror_ob->object_to_world().ptr());
65 mul_m4_m4m4(mtx, imtx, obedit->object_to_world().ptr());
66 }
67
68 BM_ITER_MESH (edge, &iter, bm, BM_EDGES_OF_MESH) {
69 if (BM_elem_flag_test(edge, hflag) && BM_edge_is_boundary(edge) &&
70 BM_elem_flag_test(edge->l->f, hflag))
71 {
72 float co1[3], co2[3];
73
74 copy_v3_v3(co1, edge->v1->co);
75 copy_v3_v3(co2, edge->v2->co);
76
77 if (mmd->mirror_ob) {
78 mul_v3_m4v3(co1, mtx, co1);
79 mul_v3_m4v3(co2, mtx, co2);
80 }
81
82 if (mmd->flag & MOD_MIR_AXIS_X) {
83 if ((fabsf(co1[0]) < mmd->tolerance) && (fabsf(co2[0]) < mmd->tolerance)) {
84 BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
85 }
86 }
87 if (mmd->flag & MOD_MIR_AXIS_Y) {
88 if ((fabsf(co1[1]) < mmd->tolerance) && (fabsf(co2[1]) < mmd->tolerance)) {
89 BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
90 }
91 }
92 if (mmd->flag & MOD_MIR_AXIS_Z) {
93 if ((fabsf(co1[2]) < mmd->tolerance) && (fabsf(co2[2]) < mmd->tolerance)) {
94 BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
95 }
96 }
97 }
98 }
99 }
100 }
101 }
102}
103
104/* individual face extrude */
105/* will use vertex normals for extrusion directions, so *nor is unaffected */
106static bool edbm_extrude_discrete_faces(BMesh *bm, wmOperator *op, const char hflag)
107{
108 BMOIter siter;
109 BMIter liter;
110 BMFace *f;
111 BMLoop *l;
112 BMOperator bmop;
113
115 bm, &bmop, op, "extrude_discrete_faces faces=%hf use_select_history=%b", hflag, true);
116
117 /* deselect original verts */
119
120 BMO_op_exec(bm, &bmop);
121
122 BMO_ITER (f, &siter, bmop.slots_out, "faces.out", BM_FACE) {
123 BM_face_select_set(bm, f, true);
124
125 /* set face vertex normals to face normal */
126 BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
127 copy_v3_v3(l->v->no, f->no);
128 }
129 }
130
131 if (!EDBM_op_finish(bm, &bmop, op, true)) {
132 return false;
133 }
134
135 return true;
136}
137
139 wmOperator *op,
140 const char hflag,
141 const bool use_normal_flip)
142{
143 BMOperator bmop;
144
146 &bmop,
147 op,
148 "extrude_edge_only edges=%he use_normal_flip=%b use_select_history=%b",
149 hflag,
150 use_normal_flip,
151 true);
152
153 /* deselect original verts */
157
158 BMO_op_exec(bm, &bmop);
160 bm, bmop.slots_out, "geom.out", BM_VERT | BM_EDGE, BM_ELEM_SELECT, true);
161
162 if (!EDBM_op_finish(bm, &bmop, op, true)) {
163 return false;
164 }
165
166 return true;
167}
168
169/* extrudes individual vertices */
170static bool edbm_extrude_verts_indiv(BMesh *bm, wmOperator *op, const char hflag)
171{
172 BMOperator bmop;
173
174 EDBM_op_init(bm, &bmop, op, "extrude_vert_indiv verts=%hv use_select_history=%b", hflag, true);
175
176 /* deselect original verts */
178
179 BMO_op_exec(bm, &bmop);
181
182 if (!EDBM_op_finish(bm, &bmop, op, true)) {
183 return false;
184 }
185
186 return true;
187}
188
189static char edbm_extrude_htype_from_em_select(BMesh *bm, const short selectmode)
190{
191 char htype = BM_ALL_NOLOOP;
192
193 if (selectmode & SCE_SELECT_VERTEX) {
194 /* pass */
195 }
196 else if (selectmode & SCE_SELECT_EDGE) {
197 htype &= ~BM_VERT;
198 }
199 else {
200 htype &= ~(BM_VERT | BM_EDGE);
201 }
202
203 if (bm->totedgesel == 0) {
204 htype &= ~(BM_EDGE | BM_FACE);
205 }
206 else if (bm->totfacesel == 0) {
207 htype &= ~BM_FACE;
208 }
209
210 return htype;
211}
212
213static bool edbm_extrude_ex(Object *obedit,
214 char htype,
215 const char hflag,
216 const bool use_normal_flip,
217 const bool use_dissolve_ortho_edges,
218 const bool use_mirror,
219 const bool use_select_history)
220{
222 BMOIter siter;
223 BMOperator extop;
224 BMElem *ele;
225
226 /* needed to remove the faces left behind */
227 if (htype & BM_FACE) {
228 htype |= BM_EDGE;
229 }
230
231 BMO_op_init(bm, &extop, BMO_FLAG_DEFAULTS, "extrude_face_region");
232 BMO_slot_bool_set(extop.slots_in, "use_normal_flip", use_normal_flip);
233 BMO_slot_bool_set(extop.slots_in, "use_dissolve_ortho_edges", use_dissolve_ortho_edges);
234 BMO_slot_bool_set(extop.slots_in, "use_select_history", use_select_history);
235 BMO_slot_buffer_from_enabled_hflag(bm, &extop, extop.slots_in, "geom", htype, hflag);
236
237 if (use_mirror) {
238 BMOpSlot *slot_edges_exclude;
239 slot_edges_exclude = BMO_slot_get(extop.slots_in, "edges_exclude");
240
241 edbm_extrude_edge_exclude_mirror(obedit, hflag, &extop, slot_edges_exclude);
242 }
243
247
248 BMO_op_exec(bm, &extop);
249
250 BMO_ITER (ele, &siter, extop.slots_out, "geom.out", BM_ALL_NOLOOP) {
251 BM_elem_select_set(bm, ele, true);
252 }
253
254 BMO_op_finish(bm, &extop);
255
256 return true;
257}
258
260
261/* -------------------------------------------------------------------- */
264
266{
267
268 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset");
269 const int steps = RNA_int_get(op->ptr, "steps");
270 const float scale_offset = RNA_float_get(op->ptr, "scale_offset");
271 float offset[3];
272
273 if (!RNA_property_is_set(op->ptr, prop)) {
275 if (rv3d != nullptr) {
276 normalize_v3_v3(offset, rv3d->persinv[2]);
277 }
278 else {
279 const float up[3] = {0, 0, 1};
280 copy_v3_v3(offset, up);
281 }
282 RNA_property_float_set_array(op->ptr, prop, offset);
283 }
284 else {
285 RNA_property_float_get_array(op->ptr, prop, offset);
286 }
287
288 mul_v3_fl(offset, scale_offset);
289
290 const Main *bmain = CTX_data_main(C);
291 const Scene *scene = CTX_data_scene(C);
292 ViewLayer *view_layer = CTX_data_view_layer(C);
294 *bmain, scene, view_layer, CTX_wm_view3d(C));
295
296 for (Object *obedit : objects) {
297 float offset_local[3], tmat[3][3];
298
300
301 copy_m3_m4(tmat, obedit->object_to_world().ptr());
302 invert_m3(tmat);
303 mul_v3_m3v3(offset_local, tmat, offset);
304
305 for (int a = 0; a < steps; a++) {
306 edbm_extrude_ex(obedit, BM_ALL_NOLOOP, BM_ELEM_SELECT, false, false, false, true);
308 bm, BMO_FLAG_DEFAULTS, "translate vec=%v verts=%hv", offset_local, BM_ELEM_SELECT);
309 }
310
311 EDBMUpdate_Params params{};
312 params.calc_looptris = true;
313 params.calc_normals = true;
314 params.is_destructive = true;
315 EDBM_update(id_cast<Mesh *>(obedit->data), &params);
316 }
317
318 return OPERATOR_FINISHED;
319}
320
322{
323 /* identifiers */
324 ot->name = "Extrude Repeat";
325 ot->description = "Extrude selected vertices, edges or faces repeatedly";
326 ot->idname = "MESH_OT_extrude_repeat";
327
328 /* API callbacks. */
331
332 /* flags */
334
335 /* props */
336 RNA_def_int(ot->srna, "steps", 10, 0, 1000000, "Steps", "", 0, 180);
338 "offset",
339 3,
340 nullptr,
341 -100000,
342 100000,
343 "Offset",
344 "Offset vector",
345 -1000.0f,
346 1000.0f);
348 RNA_def_float(ot->srna, "scale_offset", 1.0f, 0.0f, 1e12f, "Scale Offset", "", 0.0f, 100.0f);
349}
350
352
353/* -------------------------------------------------------------------- */
356
358static bool edbm_extrude_mesh(Object *obedit, BMEditMesh *em, wmOperator *op)
359{
361
362 const bool use_normal_flip = RNA_boolean_get(op->ptr, "use_normal_flip");
363 const bool use_dissolve_ortho_edges = RNA_boolean_get(op->ptr, "use_dissolve_ortho_edges");
364 const char htype = edbm_extrude_htype_from_em_select(bm, em->selectmode);
365 enum { NONE = 0, ELEM_FLAG, VERT_ONLY, EDGE_ONLY } nr;
366 bool changed = false;
367
368 if (em->selectmode & SCE_SELECT_VERTEX) {
369 if (bm->totvertsel == 0) {
370 nr = NONE;
371 }
372 else if (bm->totvertsel == 1) {
373 nr = VERT_ONLY;
374 }
375 else if (bm->totedgesel == 0) {
376 nr = VERT_ONLY;
377 }
378 else {
379 nr = ELEM_FLAG;
380 }
381 }
382 else if (em->selectmode & SCE_SELECT_EDGE) {
383 if (bm->totedgesel == 0) {
384 nr = NONE;
385 }
386 else if (bm->totfacesel == 0) {
387 nr = EDGE_ONLY;
388 }
389 else {
390 nr = ELEM_FLAG;
391 }
392 }
393 else {
394 if (bm->totfacesel == 0) {
395 nr = NONE;
396 }
397 else {
398 nr = ELEM_FLAG;
399 }
400 }
401
402 switch (nr) {
403 case NONE:
404 return false;
405 case ELEM_FLAG:
406 changed = edbm_extrude_ex(
407 obedit, htype, BM_ELEM_SELECT, use_normal_flip, use_dissolve_ortho_edges, true, true);
408 break;
409 case VERT_ONLY:
411 break;
412 case EDGE_ONLY:
413 changed = EDBM_extrude_edges_indiv(bm, op, BM_ELEM_SELECT, use_normal_flip);
414 break;
415 }
416
417 if (changed) {
418 return true;
419 }
420
421 BKE_report(op->reports, RPT_ERROR, "Not a valid selection for extrude");
422 return false;
423}
424
425/* extrude without transform */
427{
428 const Main *bmain = CTX_data_main(C);
429 const Scene *scene = CTX_data_scene(C);
430 ViewLayer *view_layer = CTX_data_view_layer(C);
432 *bmain, scene, view_layer, CTX_wm_view3d(C));
433
434 for (Object *obedit : objects) {
437 if (bm->totvertsel == 0) {
438 continue;
439 }
440
441 if (!edbm_extrude_mesh(obedit, em, op)) {
442 continue;
443 }
444 /* This normally happens when pushing undo but modal operators
445 * like this one don't push undo data until after modal mode is done. */
446 EDBMUpdate_Params params{};
447 params.calc_looptris = true;
448 params.calc_normals = true;
449 params.is_destructive = true;
450 EDBM_update(id_cast<Mesh *>(obedit->data), &params);
451 }
452 return OPERATOR_FINISHED;
453}
454
456{
457 /* identifiers */
458 ot->name = "Extrude Region";
459 ot->idname = "MESH_OT_extrude_region";
460 ot->description = "Extrude region of faces";
461
462 /* API callbacks. */
463 // ot->invoke = mesh_extrude_region_invoke;
466
467 /* flags */
469
470 RNA_def_boolean(ot->srna, "use_normal_flip", false, "Flip Normals", "");
471 RNA_def_boolean(ot->srna, "use_dissolve_ortho_edges", false, "Dissolve Orthogonal Edges", "");
473}
474
476
477/* -------------------------------------------------------------------- */
482
483/* extrude without transform */
485{
486 const Main *bmain = CTX_data_main(C);
487 const Scene *scene = CTX_data_scene(C);
488 ViewLayer *view_layer = CTX_data_view_layer(C);
490 *bmain, scene, view_layer, CTX_wm_view3d(C));
491
492 for (Object *obedit : objects) {
495 if (bm->totvertsel == 0) {
496 continue;
497 }
498
499 edbm_extrude_mesh(obedit, em, op);
500
501 /* This normally happens when pushing undo but modal operators
502 * like this one don't push undo data until after modal mode is done. */
503 EDBMUpdate_Params params{};
504 params.calc_looptris = true;
505 params.calc_normals = true;
506 params.is_destructive = true;
507 EDBM_update(id_cast<Mesh *>(obedit->data), &params);
508 }
509 return OPERATOR_FINISHED;
510}
511
513{
514 /* identifiers */
515 ot->name = "Extrude Context";
516 ot->idname = "MESH_OT_extrude_context";
517 ot->description = "Extrude selection";
518
519 /* API callbacks. */
522
523 /* flags */
525
526 RNA_def_boolean(ot->srna, "use_normal_flip", false, "Flip Normals", "");
527 RNA_def_boolean(ot->srna, "use_dissolve_ortho_edges", false, "Dissolve Orthogonal Edges", "");
529}
530
532
533/* -------------------------------------------------------------------- */
536
538{
539 const Main *bmain = CTX_data_main(C);
540 const Scene *scene = CTX_data_scene(C);
541 ViewLayer *view_layer = CTX_data_view_layer(C);
543 *bmain, scene, view_layer, CTX_wm_view3d(C));
544
545 for (Object *obedit : objects) {
547 if (bm->totvertsel == 0) {
548 continue;
549 }
550
552
553 EDBMUpdate_Params params{};
554 params.calc_looptris = true;
555 params.calc_normals = false;
556 params.is_destructive = true;
557 EDBM_update(id_cast<Mesh *>(obedit->data), &params);
558 }
559
560 return OPERATOR_FINISHED;
561}
562
564{
565 /* identifiers */
566 ot->name = "Extrude Only Vertices";
567 ot->idname = "MESH_OT_extrude_verts_indiv";
568 ot->description = "Extrude individual vertices only";
569
570 /* API callbacks. */
573
574 /* flags */
576
577 /* to give to transform */
579}
580
582
583/* -------------------------------------------------------------------- */
586
588{
589 const bool use_normal_flip = RNA_boolean_get(op->ptr, "use_normal_flip");
590 const Main *bmain = CTX_data_main(C);
591 const Scene *scene = CTX_data_scene(C);
592 ViewLayer *view_layer = CTX_data_view_layer(C);
594 *bmain, scene, view_layer, CTX_wm_view3d(C));
595
596 for (Object *obedit : objects) {
598 if (bm->totedgesel == 0) {
599 continue;
600 }
601
602 EDBM_extrude_edges_indiv(bm, op, BM_ELEM_SELECT, use_normal_flip);
603
604 EDBMUpdate_Params params{};
605 params.calc_looptris = true;
606 params.calc_normals = false;
607 params.is_destructive = true;
608 EDBM_update(id_cast<Mesh *>(obedit->data), &params);
609 }
610
611 return OPERATOR_FINISHED;
612}
613
615{
616 /* identifiers */
617 ot->name = "Extrude Only Edges";
618 ot->idname = "MESH_OT_extrude_edges_indiv";
619 ot->description = "Extrude individual edges only";
620
621 /* API callbacks. */
624
625 /* flags */
627
628 /* to give to transform */
629 RNA_def_boolean(ot->srna, "use_normal_flip", false, "Flip Normals", "");
631}
632
634
635/* -------------------------------------------------------------------- */
638
640{
641 const Main *bmain = CTX_data_main(C);
642 const Scene *scene = CTX_data_scene(C);
643 ViewLayer *view_layer = CTX_data_view_layer(C);
645 *bmain, scene, view_layer, CTX_wm_view3d(C));
646
647 for (Object *obedit : objects) {
649 if (bm->totfacesel == 0) {
650 continue;
651 }
652
654
655 EDBMUpdate_Params params{};
656 params.calc_looptris = true;
657 params.calc_normals = false;
658 params.is_destructive = true;
659 EDBM_update(id_cast<Mesh *>(obedit->data), &params);
660 }
661
662 return OPERATOR_FINISHED;
663}
664
666{
667 /* identifiers */
668 ot->name = "Extrude Individual Faces";
669 ot->idname = "MESH_OT_extrude_faces_indiv";
670 ot->description = "Extrude individual faces only";
671
672 /* API callbacks. */
675
676 /* flags */
678
680}
681
683
684/* -------------------------------------------------------------------- */
689
691 wmOperator *op,
692 const wmEvent *event)
693{
694 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
695 BMVert *v1;
696 BMIter iter;
697 float center[3];
698 uint verts_len;
699
701 const Object *object_active = vc.obact;
702
703 const bool rot_src = RNA_boolean_get(op->ptr, "rotate_source");
704 const bool use_proj = ((vc.scene->toolsettings->snap_flag & SCE_SNAP) &&
707
708 /* First calculate the center of transformation. */
709 zero_v3(center);
710 verts_len = 0;
711
713 *vc.bmain, vc.scene, vc.view_layer, vc.v3d);
714 for (Object *obedit : objects) {
717 const int local_verts_len = bm->totvertsel;
718
719 if (bm->totvertsel == 0) {
720 continue;
721 }
722
723 float local_center[3];
724 zero_v3(local_center);
725
726 BM_ITER_MESH (v1, &iter, bm, BM_VERTS_OF_MESH) {
728 add_v3_v3(local_center, v1->co);
729 }
730 }
731
732 mul_v3_fl(local_center, 1.0f / float(local_verts_len));
733 mul_m4_v3(vc.obedit->object_to_world().ptr(), local_center);
734 mul_v3_fl(local_center, float(local_verts_len));
735
736 add_v3_v3(center, local_center);
737 verts_len += local_verts_len;
738 }
739
740 if (verts_len != 0) {
741 mul_v3_fl(center, 1.0f / float(verts_len));
742 }
743
744 /* Then we process the meshes. */
745 for (Object *obedit : objects) {
748
749 if (verts_len != 0) {
750 if (bm->totvertsel == 0) {
751 continue;
752 }
753 }
754 else if (obedit != object_active) {
755 continue;
756 }
757
758 invert_m4_m4(vc.obedit->runtime->world_to_object.ptr(), vc.obedit->object_to_world().ptr());
760
761 float local_center[3];
762 mul_v3_m4v3(local_center, vc.obedit->world_to_object().ptr(), center);
763
764 /* call extrude? */
765 if (verts_len != 0) {
766 const char extrude_htype = edbm_extrude_htype_from_em_select(bm, vc.em->selectmode);
767 BMEdge *eed;
768 float mat[3][3];
769 float vec[3], ofs[3];
770 float nor[3] = {0.0, 0.0, 0.0};
771
772 /* 2D normal calc */
773 const float mval_f[2] = {float(event->mval[0]), float(event->mval[1])};
774
775 /* check for edges that are half selected, use for rotation */
776 bool done = false;
777 BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
779 float co1[2], co2[2];
780
785 {
786 /* 2D rotate by 90d while adding.
787 * (x, y) = (y, -x)
788 *
789 * Accumulate the screen-space normal in 2D,
790 * with screen-space edge length weighting the result. */
791 if (line_point_side_v2(co1, co2, mval_f) >= 0.0f) {
792 nor[0] += (co1[1] - co2[1]);
793 nor[1] += -(co1[0] - co2[0]);
794 }
795 else {
796 nor[0] += (co2[1] - co1[1]);
797 nor[1] += -(co2[0] - co1[0]);
798 }
799 done = true;
800 }
801 }
802 }
803
804 if (done) {
805 float view_vec[3], cross[3];
806
807 /* convert the 2D normal into 3D */
808 mul_mat3_m4_v3(vc.rv3d->viewinv, nor); /* World-space. */
809 mul_mat3_m4_v3(vc.obedit->world_to_object().ptr(), nor); /* Local-space. */
810
811 /* correct the normal to be aligned on the view plane */
812 mul_v3_mat3_m4v3(view_vec, vc.obedit->world_to_object().ptr(), vc.rv3d->viewinv[2]);
813 cross_v3_v3v3(cross, nor, view_vec);
814 cross_v3_v3v3(nor, view_vec, cross);
815 normalize_v3(nor);
816 }
817
818 /* center */
819 copy_v3_v3(ofs, local_center);
820
821 mul_m4_v3(vc.obedit->object_to_world().ptr(), ofs); /* view space */
822 ED_view3d_win_to_3d_int(vc.v3d, vc.region, ofs, event->mval, ofs);
823 mul_m4_v3(vc.obedit->world_to_object().ptr(), ofs); /* back in object space */
824
825 sub_v3_v3(ofs, local_center);
826
827 /* calculate rotation */
828 unit_m3(mat);
829 if (done) {
830 float angle;
831
832 normalize_v3_v3(vec, ofs);
833
834 angle = angle_normalized_v3v3(vec, nor);
835
836 if (angle != 0.0f) {
837 float axis[3];
838
839 cross_v3_v3v3(axis, nor, vec);
840
841 /* halve the rotation if its applied twice */
842 if (rot_src) {
843 angle *= 0.5f;
844 }
845
846 axis_angle_to_mat3(mat, axis, angle);
847 }
848 }
849
850 if (rot_src) {
852 bm, op, "rotate verts=%hv cent=%v matrix=%m3", BM_ELEM_SELECT, local_center, mat);
853
854 /* Re-project the rotated source for the retopology workflow.
855 * Check `done` so a single vertex source for example doesn't project, see: #89647. */
856 if (done && use_proj) {
857 EDBM_project_snap_verts(C, depsgraph, vc.region, vc.obedit);
858 }
859 }
860
861 edbm_extrude_ex(vc.obedit, extrude_htype, BM_ELEM_SELECT, false, false, true, true);
863 bm, op, "rotate verts=%hv cent=%v matrix=%m3", BM_ELEM_SELECT, local_center, mat);
864 EDBM_op_callf(bm, op, "translate verts=%hv vec=%v", BM_ELEM_SELECT, ofs);
865 }
866 else {
867 /* This only runs for the active object. */
868 const float *cursor = vc.scene->cursor.location;
869 BMOperator bmop;
870 BMOIter oiter;
871
872 copy_v3_v3(local_center, cursor);
873 ED_view3d_win_to_3d_int(vc.v3d, vc.region, local_center, event->mval, local_center);
874
875 mul_m4_v3(vc.obedit->world_to_object().ptr(), local_center); /* back in object space */
876
877 EDBM_op_init(bm, &bmop, op, "create_vert co=%v", local_center);
878 BMO_op_exec(bm, &bmop);
879
880 BMO_ITER (v1, &oiter, bmop.slots_out, "vert.out", BM_VERT) {
881 BM_vert_select_set(bm, v1, true);
882 }
883
884 if (!EDBM_op_finish(bm, &bmop, op, true)) {
885 continue;
886 }
887 }
888
889 if (use_proj) {
890 EDBM_project_snap_verts(C, depsgraph, vc.region, vc.obedit);
891 }
892
893 /* This normally happens when pushing undo but modal operators
894 * like this one don't push undo data until after modal mode is done. */
895 EDBMUpdate_Params params{};
896 params.calc_looptris = true;
897 params.calc_normals = true;
898 params.is_destructive = true;
899 EDBM_update(id_cast<Mesh *>(vc.obedit->data), &params);
900
901 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
902 WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
903 }
904
905 /* Support dragging to move after extrude, see: #114282. */
908}
909
911{
912 /* identifiers */
913 ot->name = "Extrude to Cursor or Add";
914 ot->idname = "MESH_OT_dupli_extrude_cursor";
915 ot->description =
916 "Duplicate and extrude selected vertices, edges or faces towards the mouse cursor";
917
918 /* API callbacks. */
921
922 /* flags */
924
926 "rotate_source",
927 true,
928 "Rotate Source",
929 "Rotate initial selection giving better shape");
930}
931
933
934} // namespace blender
Object is a sort of wrapper for general info.
#define P_NO_DEFAULTS
#define P_MIRROR_DUMMY
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define ND_SELECT
Definition WM_types.hh:551
#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)
#define BM_SELECT_HISTORY_BACKUP(bm)
#define BM_SELECT_HISTORY_RESTORE(bm)
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
#define BMO_FLAG_DEFAULTS
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
void properties_register(wmOperatorType *ot, int flags)
BMesh Iterators.
void EDBM_flag_disable_all(BMesh *bm, char hflag)
@ V3D_PROJ_RET_OK
Definition ED_view3d.hh:273
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
static wmOperatorStatus edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
bool EDBM_extrude_edges_indiv(BMesh *bm, wmOperator *op, char hflag, bool use_normal_flip)
wmOperatorStatus WM_operator_flag_only_pass_through_on_press(wmOperatorStatus retval, const wmEvent *event)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void copy_m3_m4(float m1[3][3], const float m2[4][4])
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,...)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
eV3DProjStatus ED_view3d_project_float_object(const ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void EDBM_update(Mesh *mesh, const EDBMUpdate_Params *params)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
bool EDBM_op_callf(BMesh *bm, wmOperator *op, const char *fmt,...)
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
static wmOperatorStatus edbm_extrude_faces_exec(bContext *C, wmOperator *op)
void mul_v3_mat3_m4v3(float r[3], const float mat[4][4], const float vec[3])
int RNA_int_get(PointerRNA *ptr, const char *name)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
void BMO_op_exec(BMesh *bm, BMOperator *op)
BMESH OPSTACK EXEC OP.
static bool edbm_extrude_mesh(Object *obedit, BMEditMesh *em, wmOperator *op)
static wmOperatorStatus edbm_extrude_edges_exec(bContext *C, wmOperator *op)
ViewLayer * CTX_data_view_layer(const bContext *C)
MINLINE void mul_v3_fl(float r[3], float f)
void MESH_OT_extrude_repeat(wmOperatorType *ot)
static char edbm_extrude_htype_from_em_select(BMesh *bm, const short selectmode)
BLI_INLINE void BMO_slot_map_empty_insert(BMOperator *op, BMOpSlot *slot, const void *element)
MINLINE void sub_v3_v3(float r[3], const float a[3])
static wmOperatorStatus edbm_extrude_verts_exec(bContext *C, wmOperator *op)
void ED_view3d_viewcontext_init_object(ViewContext *vc, Object *obact)
void MESH_OT_extrude_region(wmOperatorType *ot)
void mul_m4_v3(const float M[4][4], float r[3])
bool ED_operator_editmesh(bContext *C)
bool EDBM_op_finish(BMesh *bm, BMOperator *bmop, wmOperator *op, const bool do_report)
static void edbm_extrude_edge_exclude_mirror(Object *obedit, const char hflag, BMOperator *op, BMOpSlot *slot_edges_exclude)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
void BM_elem_select_set(BMesh *bm, BMElem *ele, const bool select)
void BM_face_select_set(BMesh *bm, BMFace *f, const bool select)
Select Face.
@ SCE_SNAP_INDIVIDUAL_PROJECT
void BMO_slot_bool_set(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, bool i)
static bool edbm_extrude_ex(Object *obedit, char htype, const char hflag, const bool use_normal_flip, const bool use_dissolve_ortho_edges, const bool use_mirror, const bool use_select_history)
BLI_INLINE bool BM_edge_is_boundary(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BMO_op_callf(BMesh *bm, int flag, const char *fmt,...)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
void MESH_OT_extrude_verts_indiv(wmOperatorType *ot)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void ED_view3d_init_mats_rv3d(const Object *ob, RegionView3D *rv3d)
MINLINE void zero_v3(float r[3])
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void BM_vert_select_set(BMesh *bm, BMVert *v, const bool select)
Select Vert.
void mul_mat3_m4_v3(const float mat[4][4], float r[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
BMOpSlot * BMO_slot_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK GET SLOT.
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:59
bool invert_m3(float mat[3][3])
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
ViewContext em_setup_viewcontext(bContext *C)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
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 wmOperatorStatus edbm_extrude_context_exec(bContext *C, wmOperator *op)
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_extrude_region_exec(bContext *C, wmOperator *op)
void MESH_OT_extrude_edges_indiv(wmOperatorType *ot)
Main * CTX_data_main(const bContext *C)
void unit_m3(float m[3][3])
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ V3D_PROJ_TEST_NOP
Definition ED_view3d.hh:295
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)
bool ED_operator_editmesh_region_view3d(bContext *C)
MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2]) ATTR_WARN_UNUSED_RESULT
void ED_view3d_win_to_3d_int(const View3D *v3d, const ARegion *region, const float depth_pt[3], const int mval[2], float r_out[3])
static wmOperatorStatus edbm_extrude_repeat_exec(bContext *C, wmOperator *op)
Scene * CTX_data_scene(const bContext *C)
void BMO_op_init(BMesh *bm, BMOperator *op, int flag, const char *opname)
BMESH OPSTACK INIT OP.
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_DEPENDS_ON_CURSOR
Definition WM_types.hh:228
void MESH_OT_extrude_faces_indiv(wmOperatorType *ot)
static bool edbm_extrude_verts_indiv(BMesh *bm, wmOperator *op, const char hflag)
void BMO_op_finish(BMesh *bm, BMOperator *op)
BMESH OPSTACK FINISH OP.
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
static bool edbm_extrude_discrete_faces(BMesh *bm, wmOperator *op, const char hflag)
void BMO_slot_buffer_hflag_disable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, char hflag, bool do_flush)
BMO_FLAG_BUFFER.
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
void BMO_slot_buffer_from_enabled_hflag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, char hflag)
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)
float RNA_float_get(PointerRNA *ptr, const char *name)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot)
View3D * CTX_wm_view3d(const bContext *C)
void MESH_OT_extrude_context(wmOperatorType *ot)
void EDBM_project_snap_verts(bContext *C, Depsgraph *depsgraph, ARegion *region, Object *obedit)
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct BMLoop * l
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
const c_style_mat & ptr() const
ListBaseT< ModifierData > modifiers
bke::ObjectRuntime * runtime
View3DCursor cursor
struct ToolSettings * toolsettings
ViewLayer * view_layer
Definition ED_view3d.hh:80
RegionView3D * rv3d
Definition ED_view3d.hh:86
BMEditMesh * em
Definition ED_view3d.hh:87
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