Blender V5.0
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
10#include "DNA_object_types.h"
11
12#include "BLI_listbase.h"
13#include "BLI_math_matrix.h"
14#include "BLI_math_rotation.h"
15#include "BLI_math_vector.h"
16
17#include "BKE_context.hh"
18#include "BKE_editmesh.hh"
19#include "BKE_layer.hh"
20#include "BKE_object_types.hh"
21#include "BKE_report.hh"
22
23#include "RNA_access.hh"
24#include "RNA_define.hh"
25
26#include "WM_api.hh"
27#include "WM_types.hh"
28
29#include "ED_mesh.hh"
30#include "ED_screen.hh"
31#include "ED_transform.hh"
32#include "ED_view3d.hh"
33
34#include "mesh_intern.hh" /* own include */
35
36using blender::Vector;
37
38/* -------------------------------------------------------------------- */
41
43 Object *obedit, BMEditMesh *em, const char hflag, BMOperator *op, BMOpSlot *slot_edges_exclude)
44{
45 BMesh *bm = em->bm;
46
47 /* If a mirror modifier with clipping is on, we need to adjust some
48 * of the cases above to handle edges on the line of symmetry.
49 */
50 LISTBASE_FOREACH (ModifierData *, md, &obedit->modifiers) {
51 if ((md->type == eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) {
53
54 if (mmd->flag & MOD_MIR_CLIPPING) {
55 BMIter iter;
56 BMEdge *edge;
57
58 float mtx[4][4];
59 if (mmd->mirror_ob) {
60 float imtx[4][4];
61 invert_m4_m4(imtx, mmd->mirror_ob->object_to_world().ptr());
62 mul_m4_m4m4(mtx, imtx, obedit->object_to_world().ptr());
63 }
64
65 BM_ITER_MESH (edge, &iter, bm, BM_EDGES_OF_MESH) {
66 if (BM_elem_flag_test(edge, hflag) && BM_edge_is_boundary(edge) &&
67 BM_elem_flag_test(edge->l->f, hflag))
68 {
69 float co1[3], co2[3];
70
71 copy_v3_v3(co1, edge->v1->co);
72 copy_v3_v3(co2, edge->v2->co);
73
74 if (mmd->mirror_ob) {
75 mul_v3_m4v3(co1, mtx, co1);
76 mul_v3_m4v3(co2, mtx, co2);
77 }
78
79 if (mmd->flag & MOD_MIR_AXIS_X) {
80 if ((fabsf(co1[0]) < mmd->tolerance) && (fabsf(co2[0]) < mmd->tolerance)) {
81 BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
82 }
83 }
84 if (mmd->flag & MOD_MIR_AXIS_Y) {
85 if ((fabsf(co1[1]) < mmd->tolerance) && (fabsf(co2[1]) < mmd->tolerance)) {
86 BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
87 }
88 }
89 if (mmd->flag & MOD_MIR_AXIS_Z) {
90 if ((fabsf(co1[2]) < mmd->tolerance) && (fabsf(co2[2]) < mmd->tolerance)) {
91 BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
92 }
93 }
94 }
95 }
96 }
97 }
98 }
99}
100
101/* individual face extrude */
102/* will use vertex normals for extrusion directions, so *nor is unaffected */
103static bool edbm_extrude_discrete_faces(BMEditMesh *em, wmOperator *op, const char hflag)
104{
105 BMOIter siter;
106 BMIter liter;
107 BMFace *f;
108 BMLoop *l;
109 BMOperator bmop;
110
112 em, &bmop, op, "extrude_discrete_faces faces=%hf use_select_history=%b", hflag, true);
113
114 /* deselect original verts */
116
117 BMO_op_exec(em->bm, &bmop);
118
119 BMO_ITER (f, &siter, bmop.slots_out, "faces.out", BM_FACE) {
120 BM_face_select_set(em->bm, f, true);
121
122 /* set face vertex normals to face normal */
123 BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
124 copy_v3_v3(l->v->no, f->no);
125 }
126 }
127
128 if (!EDBM_op_finish(em, &bmop, op, true)) {
129 return false;
130 }
131
132 return true;
133}
134
136 wmOperator *op,
137 const char hflag,
138 const bool use_normal_flip)
139{
140 BMesh *bm = em->bm;
141 BMOperator bmop;
142
143 EDBM_op_init(em,
144 &bmop,
145 op,
146 "extrude_edge_only edges=%he use_normal_flip=%b use_select_history=%b",
147 hflag,
148 use_normal_flip,
149 true);
150
151 /* deselect original verts */
155
156 BMO_op_exec(em->bm, &bmop);
158 em->bm, bmop.slots_out, "geom.out", BM_VERT | BM_EDGE, BM_ELEM_SELECT, true);
159
160 if (!EDBM_op_finish(em, &bmop, op, true)) {
161 return false;
162 }
163
164 return true;
165}
166
167/* extrudes individual vertices */
168static bool edbm_extrude_verts_indiv(BMEditMesh *em, wmOperator *op, const char hflag)
169{
170 BMOperator bmop;
171
172 EDBM_op_init(em, &bmop, op, "extrude_vert_indiv verts=%hv use_select_history=%b", hflag, true);
173
174 /* deselect original verts */
176
177 BMO_op_exec(em->bm, &bmop);
178 BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "verts.out", BM_VERT, BM_ELEM_SELECT, true);
179
180 if (!EDBM_op_finish(em, &bmop, op, true)) {
181 return false;
182 }
183
184 return true;
185}
186
188{
189 char htype = BM_ALL_NOLOOP;
190
191 if (em->selectmode & SCE_SELECT_VERTEX) {
192 /* pass */
193 }
194 else if (em->selectmode & SCE_SELECT_EDGE) {
195 htype &= ~BM_VERT;
196 }
197 else {
198 htype &= ~(BM_VERT | BM_EDGE);
199 }
200
201 if (em->bm->totedgesel == 0) {
202 htype &= ~(BM_EDGE | BM_FACE);
203 }
204 else if (em->bm->totfacesel == 0) {
205 htype &= ~BM_FACE;
206 }
207
208 return htype;
209}
210
211static bool edbm_extrude_ex(Object *obedit,
212 BMEditMesh *em,
213 char htype,
214 const char hflag,
215 const bool use_normal_flip,
216 const bool use_dissolve_ortho_edges,
217 const bool use_mirror,
218 const bool use_select_history)
219{
220 BMesh *bm = em->bm;
221 BMOIter siter;
222 BMOperator extop;
223 BMElem *ele;
224
225 /* needed to remove the faces left behind */
226 if (htype & BM_FACE) {
227 htype |= BM_EDGE;
228 }
229
230 BMO_op_init(bm, &extop, BMO_FLAG_DEFAULTS, "extrude_face_region");
231 BMO_slot_bool_set(extop.slots_in, "use_normal_flip", use_normal_flip);
232 BMO_slot_bool_set(extop.slots_in, "use_dissolve_ortho_edges", use_dissolve_ortho_edges);
233 BMO_slot_bool_set(extop.slots_in, "use_select_history", use_select_history);
234 BMO_slot_buffer_from_enabled_hflag(bm, &extop, extop.slots_in, "geom", htype, hflag);
235
236 if (use_mirror) {
237 BMOpSlot *slot_edges_exclude;
238 slot_edges_exclude = BMO_slot_get(extop.slots_in, "edges_exclude");
239
240 edbm_extrude_edge_exclude_mirror(obedit, em, hflag, &extop, slot_edges_exclude);
241 }
242
246
247 BMO_op_exec(bm, &extop);
248
249 BMO_ITER (ele, &siter, extop.slots_out, "geom.out", BM_ALL_NOLOOP) {
250 BM_elem_select_set(bm, ele, true);
251 }
252
253 BMO_op_finish(bm, &extop);
254
255 return true;
256}
257
259
260/* -------------------------------------------------------------------- */
263
265{
266
267 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset");
268 const int steps = RNA_int_get(op->ptr, "steps");
269 const float scale_offset = RNA_float_get(op->ptr, "scale_offset");
270 float offset[3];
271
272 if (!RNA_property_is_set(op->ptr, prop)) {
274 if (rv3d != nullptr) {
275 normalize_v3_v3(offset, rv3d->persinv[2]);
276 }
277 else {
278 const float up[3] = {0, 0, 1};
279 copy_v3_v3(offset, up);
280 }
281 RNA_property_float_set_array(op->ptr, prop, offset);
282 }
283 else {
284 RNA_property_float_get_array(op->ptr, prop, offset);
285 }
286
287 mul_v3_fl(offset, scale_offset);
288
289 const Scene *scene = CTX_data_scene(C);
290 ViewLayer *view_layer = CTX_data_view_layer(C);
292 scene, view_layer, CTX_wm_view3d(C));
293
294 for (Object *obedit : objects) {
295 float offset_local[3], tmat[3][3];
296
298
299 copy_m3_m4(tmat, obedit->object_to_world().ptr());
300 invert_m3(tmat);
301 mul_v3_m3v3(offset_local, tmat, offset);
302
303 for (int a = 0; a < steps; a++) {
304 edbm_extrude_ex(obedit, em, BM_ALL_NOLOOP, BM_ELEM_SELECT, false, false, false, true);
306 em->bm, BMO_FLAG_DEFAULTS, "translate vec=%v verts=%hv", offset_local, BM_ELEM_SELECT);
307 }
308
310 params.calc_looptris = true;
311 params.calc_normals = true;
312 params.is_destructive = true;
313 EDBM_update(static_cast<Mesh *>(obedit->data), &params);
314 }
315
316 return OPERATOR_FINISHED;
317}
318
320{
321 /* identifiers */
322 ot->name = "Extrude Repeat";
323 ot->description = "Extrude selected vertices, edges or faces repeatedly";
324 ot->idname = "MESH_OT_extrude_repeat";
325
326 /* API callbacks. */
328 ot->poll = ED_operator_editmesh;
329
330 /* flags */
332
333 /* props */
334 RNA_def_int(ot->srna, "steps", 10, 0, 1000000, "Steps", "", 0, 180);
336 "offset",
337 3,
338 nullptr,
339 -100000,
340 100000,
341 "Offset",
342 "Offset vector",
343 -1000.0f,
344 1000.0f);
346 RNA_def_float(ot->srna, "scale_offset", 1.0f, 0.0f, 1e12f, "Scale Offset", "", 0.0f, 100.0f);
347}
348
350
351/* -------------------------------------------------------------------- */
354
356static bool edbm_extrude_mesh(Object *obedit, BMEditMesh *em, wmOperator *op)
357{
358 const bool use_normal_flip = RNA_boolean_get(op->ptr, "use_normal_flip");
359 const bool use_dissolve_ortho_edges = RNA_boolean_get(op->ptr, "use_dissolve_ortho_edges");
360 const char htype = edbm_extrude_htype_from_em_select(em);
361 enum { NONE = 0, ELEM_FLAG, VERT_ONLY, EDGE_ONLY } nr;
362 bool changed = false;
363
364 if (em->selectmode & SCE_SELECT_VERTEX) {
365 if (em->bm->totvertsel == 0) {
366 nr = NONE;
367 }
368 else if (em->bm->totvertsel == 1) {
369 nr = VERT_ONLY;
370 }
371 else if (em->bm->totedgesel == 0) {
372 nr = VERT_ONLY;
373 }
374 else {
375 nr = ELEM_FLAG;
376 }
377 }
378 else if (em->selectmode & SCE_SELECT_EDGE) {
379 if (em->bm->totedgesel == 0) {
380 nr = NONE;
381 }
382 else if (em->bm->totfacesel == 0) {
383 nr = EDGE_ONLY;
384 }
385 else {
386 nr = ELEM_FLAG;
387 }
388 }
389 else {
390 if (em->bm->totfacesel == 0) {
391 nr = NONE;
392 }
393 else {
394 nr = ELEM_FLAG;
395 }
396 }
397
398 switch (nr) {
399 case NONE:
400 return false;
401 case ELEM_FLAG:
402 changed = edbm_extrude_ex(obedit,
403 em,
404 htype,
406 use_normal_flip,
407 use_dissolve_ortho_edges,
408 true,
409 true);
410 break;
411 case VERT_ONLY:
412 changed = edbm_extrude_verts_indiv(em, op, BM_ELEM_SELECT);
413 break;
414 case EDGE_ONLY:
415 changed = edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, use_normal_flip);
416 break;
417 }
418
419 if (changed) {
420 return true;
421 }
422
423 BKE_report(op->reports, RPT_ERROR, "Not a valid selection for extrude");
424 return false;
425}
426
427/* extrude without transform */
429{
430 const Scene *scene = CTX_data_scene(C);
431 ViewLayer *view_layer = CTX_data_view_layer(C);
433 scene, view_layer, CTX_wm_view3d(C));
434
435 for (Object *obedit : objects) {
437 if (em->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. */
447 params.calc_looptris = true;
448 params.calc_normals = true;
449 params.is_destructive = true;
450 EDBM_update(static_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;
465 ot->poll = ED_operator_editmesh;
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 Scene *scene = CTX_data_scene(C);
487 ViewLayer *view_layer = CTX_data_view_layer(C);
489 scene, view_layer, CTX_wm_view3d(C));
490
491 for (Object *obedit : objects) {
493 if (em->bm->totvertsel == 0) {
494 continue;
495 }
496
497 edbm_extrude_mesh(obedit, em, op);
498
499 /* This normally happens when pushing undo but modal operators
500 * like this one don't push undo data until after modal mode is done. */
502 params.calc_looptris = true;
503 params.calc_normals = true;
504 params.is_destructive = true;
505 EDBM_update(static_cast<Mesh *>(obedit->data), &params);
506 }
507 return OPERATOR_FINISHED;
508}
509
511{
512 /* identifiers */
513 ot->name = "Extrude Context";
514 ot->idname = "MESH_OT_extrude_context";
515 ot->description = "Extrude selection";
516
517 /* API callbacks. */
519 ot->poll = ED_operator_editmesh;
520
521 /* flags */
523
524 RNA_def_boolean(ot->srna, "use_normal_flip", false, "Flip Normals", "");
525 RNA_def_boolean(ot->srna, "use_dissolve_ortho_edges", false, "Dissolve Orthogonal Edges", "");
527}
528
530
531/* -------------------------------------------------------------------- */
534
536{
537 const Scene *scene = CTX_data_scene(C);
538 ViewLayer *view_layer = CTX_data_view_layer(C);
540 scene, view_layer, CTX_wm_view3d(C));
541
542 for (Object *obedit : objects) {
544 if (em->bm->totvertsel == 0) {
545 continue;
546 }
547
549
551 params.calc_looptris = true;
552 params.calc_normals = false;
553 params.is_destructive = true;
554 EDBM_update(static_cast<Mesh *>(obedit->data), &params);
555 }
556
557 return OPERATOR_FINISHED;
558}
559
561{
562 /* identifiers */
563 ot->name = "Extrude Only Vertices";
564 ot->idname = "MESH_OT_extrude_verts_indiv";
565 ot->description = "Extrude individual vertices only";
566
567 /* API callbacks. */
569 ot->poll = ED_operator_editmesh;
570
571 /* flags */
573
574 /* to give to transform */
576}
577
579
580/* -------------------------------------------------------------------- */
583
585{
586 const bool use_normal_flip = RNA_boolean_get(op->ptr, "use_normal_flip");
587 const Scene *scene = CTX_data_scene(C);
588 ViewLayer *view_layer = CTX_data_view_layer(C);
590 scene, view_layer, CTX_wm_view3d(C));
591
592 for (Object *obedit : objects) {
594 if (em->bm->totedgesel == 0) {
595 continue;
596 }
597
598 edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, use_normal_flip);
599
601 params.calc_looptris = true;
602 params.calc_normals = false;
603 params.is_destructive = true;
604 EDBM_update(static_cast<Mesh *>(obedit->data), &params);
605 }
606
607 return OPERATOR_FINISHED;
608}
609
611{
612 /* identifiers */
613 ot->name = "Extrude Only Edges";
614 ot->idname = "MESH_OT_extrude_edges_indiv";
615 ot->description = "Extrude individual edges only";
616
617 /* API callbacks. */
619 ot->poll = ED_operator_editmesh;
620
621 /* flags */
623
624 /* to give to transform */
625 RNA_def_boolean(ot->srna, "use_normal_flip", false, "Flip Normals", "");
627}
628
630
631/* -------------------------------------------------------------------- */
634
636{
637 const Scene *scene = CTX_data_scene(C);
638 ViewLayer *view_layer = CTX_data_view_layer(C);
640 scene, view_layer, CTX_wm_view3d(C));
641
642 for (Object *obedit : objects) {
644 if (em->bm->totfacesel == 0) {
645 continue;
646 }
647
649
651 params.calc_looptris = true;
652 params.calc_normals = false;
653 params.is_destructive = true;
654 EDBM_update(static_cast<Mesh *>(obedit->data), &params);
655 }
656
657 return OPERATOR_FINISHED;
658}
659
661{
662 /* identifiers */
663 ot->name = "Extrude Individual Faces";
664 ot->idname = "MESH_OT_extrude_faces_indiv";
665 ot->description = "Extrude individual faces only";
666
667 /* API callbacks. */
669 ot->poll = ED_operator_editmesh;
670
671 /* flags */
673
675}
676
678
679/* -------------------------------------------------------------------- */
684
686 wmOperator *op,
687 const wmEvent *event)
688{
690 BMVert *v1;
691 BMIter iter;
692 float center[3];
693 uint verts_len;
694
696 const Object *object_active = vc.obact;
697
698 const bool rot_src = RNA_boolean_get(op->ptr, "rotate_source");
699 const bool use_proj = ((vc.scene->toolsettings->snap_flag & SCE_SNAP) &&
702
703 /* First calculate the center of transformation. */
704 zero_v3(center);
705 verts_len = 0;
706
708 vc.scene, vc.view_layer, vc.v3d);
709 for (Object *obedit : objects) {
711 const int local_verts_len = vc.em->bm->totvertsel;
712
713 if (vc.em->bm->totvertsel == 0) {
714 continue;
715 }
716
717 float local_center[3];
718 zero_v3(local_center);
719
720 BM_ITER_MESH (v1, &iter, vc.em->bm, BM_VERTS_OF_MESH) {
722 add_v3_v3(local_center, v1->co);
723 }
724 }
725
726 mul_v3_fl(local_center, 1.0f / float(local_verts_len));
727 mul_m4_v3(vc.obedit->object_to_world().ptr(), local_center);
728 mul_v3_fl(local_center, float(local_verts_len));
729
730 add_v3_v3(center, local_center);
731 verts_len += local_verts_len;
732 }
733
734 if (verts_len != 0) {
735 mul_v3_fl(center, 1.0f / float(verts_len));
736 }
737
738 /* Then we process the meshes. */
739 for (Object *obedit : objects) {
741
742 if (verts_len != 0) {
743 if (vc.em->bm->totvertsel == 0) {
744 continue;
745 }
746 }
747 else if (obedit != object_active) {
748 continue;
749 }
750
751 invert_m4_m4(vc.obedit->runtime->world_to_object.ptr(), vc.obedit->object_to_world().ptr());
753
754 float local_center[3];
755 mul_v3_m4v3(local_center, vc.obedit->world_to_object().ptr(), center);
756
757 /* call extrude? */
758 if (verts_len != 0) {
759 const char extrude_htype = edbm_extrude_htype_from_em_select(vc.em);
760 BMEdge *eed;
761 float mat[3][3];
762 float vec[3], ofs[3];
763 float nor[3] = {0.0, 0.0, 0.0};
764
765 /* 2D normal calc */
766 const float mval_f[2] = {float(event->mval[0]), float(event->mval[1])};
767
768 /* check for edges that are half selected, use for rotation */
769 bool done = false;
770 BM_ITER_MESH (eed, &iter, vc.em->bm, BM_EDGES_OF_MESH) {
772 float co1[2], co2[2];
773
778 {
779 /* 2D rotate by 90d while adding.
780 * (x, y) = (y, -x)
781 *
782 * Accumulate the screen-space normal in 2D,
783 * with screen-space edge length weighting the result. */
784 if (line_point_side_v2(co1, co2, mval_f) >= 0.0f) {
785 nor[0] += (co1[1] - co2[1]);
786 nor[1] += -(co1[0] - co2[0]);
787 }
788 else {
789 nor[0] += (co2[1] - co1[1]);
790 nor[1] += -(co2[0] - co1[0]);
791 }
792 done = true;
793 }
794 }
795 }
796
797 if (done) {
798 float view_vec[3], cross[3];
799
800 /* convert the 2D normal into 3D */
801 mul_mat3_m4_v3(vc.rv3d->viewinv, nor); /* World-space. */
802 mul_mat3_m4_v3(vc.obedit->world_to_object().ptr(), nor); /* Local-space. */
803
804 /* correct the normal to be aligned on the view plane */
805 mul_v3_mat3_m4v3(view_vec, vc.obedit->world_to_object().ptr(), vc.rv3d->viewinv[2]);
806 cross_v3_v3v3(cross, nor, view_vec);
807 cross_v3_v3v3(nor, view_vec, cross);
809 }
810
811 /* center */
812 copy_v3_v3(ofs, local_center);
813
814 mul_m4_v3(vc.obedit->object_to_world().ptr(), ofs); /* view space */
815 ED_view3d_win_to_3d_int(vc.v3d, vc.region, ofs, event->mval, ofs);
816 mul_m4_v3(vc.obedit->world_to_object().ptr(), ofs); /* back in object space */
817
818 sub_v3_v3(ofs, local_center);
819
820 /* calculate rotation */
821 unit_m3(mat);
822 if (done) {
823 float angle;
824
825 normalize_v3_v3(vec, ofs);
826
828
829 if (angle != 0.0f) {
830 float axis[3];
831
832 cross_v3_v3v3(axis, nor, vec);
833
834 /* halve the rotation if its applied twice */
835 if (rot_src) {
836 angle *= 0.5f;
837 }
838
839 axis_angle_to_mat3(mat, axis, angle);
840 }
841 }
842
843 if (rot_src) {
845 vc.em, op, "rotate verts=%hv cent=%v matrix=%m3", BM_ELEM_SELECT, local_center, mat);
846
847 /* Also project the source, for retopology workflow. */
848 if (use_proj) {
850 }
851 }
852
853 edbm_extrude_ex(vc.obedit, vc.em, extrude_htype, BM_ELEM_SELECT, false, false, true, true);
855 vc.em, op, "rotate verts=%hv cent=%v matrix=%m3", BM_ELEM_SELECT, local_center, mat);
856 EDBM_op_callf(vc.em, op, "translate verts=%hv vec=%v", BM_ELEM_SELECT, ofs);
857 }
858 else {
859 /* This only runs for the active object. */
860 const float *cursor = vc.scene->cursor.location;
861 BMOperator bmop;
862 BMOIter oiter;
863
864 copy_v3_v3(local_center, cursor);
865 ED_view3d_win_to_3d_int(vc.v3d, vc.region, local_center, event->mval, local_center);
866
867 mul_m4_v3(vc.obedit->world_to_object().ptr(), local_center); /* back in object space */
868
869 EDBM_op_init(vc.em, &bmop, op, "create_vert co=%v", local_center);
870 BMO_op_exec(vc.em->bm, &bmop);
871
872 BMO_ITER (v1, &oiter, bmop.slots_out, "vert.out", BM_VERT) {
873 BM_vert_select_set(vc.em->bm, v1, true);
874 }
875
876 if (!EDBM_op_finish(vc.em, &bmop, op, true)) {
877 continue;
878 }
879 }
880
881 if (use_proj) {
883 }
884
885 /* This normally happens when pushing undo but modal operators
886 * like this one don't push undo data until after modal mode is done. */
888 params.calc_looptris = true;
889 params.calc_normals = true;
890 params.is_destructive = true;
891 EDBM_update(static_cast<Mesh *>(vc.obedit->data), &params);
892
893 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
894 WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
895 }
896
897 /* Support dragging to move after extrude, see: #114282. */
900}
901
903{
904 /* identifiers */
905 ot->name = "Extrude to Cursor or Add";
906 ot->idname = "MESH_OT_dupli_extrude_cursor";
907 ot->description =
908 "Duplicate and extrude selected vertices, edges or faces towards the mouse cursor";
909
910 /* API callbacks. */
913
914 /* flags */
916
917 RNA_def_boolean(ot->srna,
918 "rotate_source",
919 true,
920 "Rotate Source",
921 "Rotate initial selection giving better shape");
922}
923
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
RegionView3D * CTX_wm_region_view3d(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 LISTBASE_FOREACH(type, var, list)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void unit_m3(float m[3][3])
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void mul_m4_v3(const float M[4][4], float r[3])
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
void mul_v3_mat3_m4v3(float r[3], const float mat[4][4], const float vec[3])
bool invert_m3(float mat[3][3])
void mul_mat3_m4_v3(const float mat[4][4], float r[3])
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float normalize_v3(float n[3])
unsigned int uint
@ eModifierMode_Realtime
@ eModifierType_Mirror
@ MOD_MIR_AXIS_Z
@ MOD_MIR_CLIPPING
@ MOD_MIR_AXIS_X
@ MOD_MIR_AXIS_Y
Object is a sort of wrapper for general info.
@ SCE_SNAP
@ SCE_SELECT_VERTEX
@ SCE_SELECT_EDGE
@ SCE_SNAP_TO_FACE
@ SCE_SNAP_INDIVIDUAL_PROJECT
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
void EDBM_flag_disable_all(BMEditMesh *em, char hflag)
void EDBM_update(Mesh *mesh, const EDBMUpdate_Params *params)
void EDBM_project_snap_verts(bContext *C, Depsgraph *depsgraph, ARegion *region, Object *obedit, BMEditMesh *em)
ViewContext em_setup_viewcontext(bContext *C)
bool ED_operator_editmesh_region_view3d(bContext *C)
bool ED_operator_editmesh(bContext *C)
#define P_NO_DEFAULTS
#define P_MIRROR_DUMMY
@ V3D_PROJ_TEST_NOP
Definition ED_view3d.hh:279
eV3DProjStatus ED_view3d_project_float_object(const ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
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])
void ED_view3d_init_mats_rv3d(const Object *ob, RegionView3D *rv3d)
@ V3D_PROJ_RET_OK
Definition ED_view3d.hh:256
void ED_view3d_viewcontext_init_object(ViewContext *vc, Object *obact)
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
@ PROP_SKIP_SAVE
Definition RNA_types.hh:344
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:393
#define ND_DATA
Definition WM_types.hh:509
@ OPTYPE_DEPENDS_ON_CURSOR
Definition WM_types.hh:218
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
#define ND_SELECT
Definition WM_types.hh:508
#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_EDGES_OF_MESH
@ BM_VERTS_OF_MESH
@ BM_LOOPS_OF_FACE
BMesh * bm
void BM_face_select_set(BMesh *bm, BMFace *f, const bool select)
Select Face.
void BM_elem_select_set(BMesh *bm, BMElem *ele, const bool select)
void BM_vert_select_set(BMesh *bm, BMVert *v, const bool select)
Select Vert.
#define BM_SELECT_HISTORY_BACKUP(bm)
#define BM_SELECT_HISTORY_RESTORE(bm)
#define BM_FACE
#define BM_EDGE
#define BM_VERT
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_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 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)
BMOpSlot * BMO_slot_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK GET SLOT.
void BMO_op_exec(BMesh *bm, BMOperator *op)
BMESH OPSTACK EXEC OP.
void BMO_op_init(BMesh *bm, BMOperator *op, int flag, const char *opname)
BMESH OPSTACK INIT OP.
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
void BMO_op_finish(BMesh *bm, BMOperator *op)
BMESH OPSTACK FINISH OP.
bool BMO_op_callf(BMesh *bm, int flag, const char *fmt,...)
#define BMO_FLAG_DEFAULTS
void BMO_slot_bool_set(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, bool i)
BLI_INLINE void BMO_slot_map_empty_insert(BMOperator *op, BMOpSlot *slot, const void *element)
BLI_INLINE bool BM_edge_is_boundary(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
ATTR_WARN_UNUSED_RESULT const BMLoop * l
BPy_StructRNA * depsgraph
@ NONE
nullptr float
void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot)
static wmOperatorStatus edbm_extrude_edges_exec(bContext *C, wmOperator *op)
static wmOperatorStatus edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus edbm_extrude_repeat_exec(bContext *C, wmOperator *op)
bool edbm_extrude_edges_indiv(BMEditMesh *em, wmOperator *op, const char hflag, const bool use_normal_flip)
static bool edbm_extrude_discrete_faces(BMEditMesh *em, wmOperator *op, const char hflag)
void MESH_OT_extrude_context(wmOperatorType *ot)
static wmOperatorStatus edbm_extrude_faces_exec(bContext *C, wmOperator *op)
static wmOperatorStatus edbm_extrude_context_exec(bContext *C, wmOperator *op)
static wmOperatorStatus edbm_extrude_verts_exec(bContext *C, wmOperator *op)
static bool edbm_extrude_verts_indiv(BMEditMesh *em, wmOperator *op, const char hflag)
static bool edbm_extrude_mesh(Object *obedit, BMEditMesh *em, wmOperator *op)
void MESH_OT_extrude_faces_indiv(wmOperatorType *ot)
static char edbm_extrude_htype_from_em_select(BMEditMesh *em)
static bool edbm_extrude_ex(Object *obedit, BMEditMesh *em, 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)
static wmOperatorStatus edbm_extrude_region_exec(bContext *C, wmOperator *op)
void MESH_OT_extrude_region(wmOperatorType *ot)
void MESH_OT_extrude_edges_indiv(wmOperatorType *ot)
static void edbm_extrude_edge_exclude_mirror(Object *obedit, BMEditMesh *em, const char hflag, BMOperator *op, BMOpSlot *slot_edges_exclude)
void MESH_OT_extrude_repeat(wmOperatorType *ot)
void MESH_OT_extrude_verts_indiv(wmOperatorType *ot)
bool EDBM_op_callf(BMEditMesh *em, wmOperator *op, const char *fmt,...)
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
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void properties_register(wmOperatorType *ot, int flags)
#define fabsf
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
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)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
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_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)
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)
BMVert * v1
BMVert * v2
struct BMLoop * l
short selectmode
float no[3]
struct BMFace * f
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
float co[3]
int totfacesel
int totvertsel
int totedgesel
struct Object * mirror_ob
ObjectRuntimeHandle * runtime
ListBase modifiers
float persinv[4][4]
float viewinv[4][4]
struct ToolSettings * toolsettings
View3DCursor cursor
RegionView3D * rv3d
Definition ED_view3d.hh:80
ARegion * region
Definition ED_view3d.hh:77
Scene * scene
Definition ED_view3d.hh:73
BMEditMesh * em
Definition ED_view3d.hh:81
ViewLayer * view_layer
Definition ED_view3d.hh:74
View3D * v3d
Definition ED_view3d.hh:78
Object * obact
Definition ED_view3d.hh:75
Object * obedit
Definition ED_view3d.hh:76
int mval[2]
Definition WM_types.hh:763
struct ReportList * reports
struct PointerRNA * ptr
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4237
wmOperatorStatus WM_operator_flag_only_pass_through_on_press(wmOperatorStatus retval, const wmEvent *event)