Blender  V3.3
editmesh_extrude.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2004 Blender Foundation. All rights reserved. */
3 
8 #include "DNA_modifier_types.h"
9 #include "DNA_object_types.h"
10 
11 #include "BLI_listbase.h"
12 #include "BLI_math.h"
13 
14 #include "BKE_context.h"
15 #include "BKE_editmesh.h"
16 #include "BKE_layer.h"
17 #include "BKE_report.h"
18 
19 #include "RNA_access.h"
20 #include "RNA_define.h"
21 
22 #include "WM_api.h"
23 #include "WM_types.h"
24 
25 #include "ED_mesh.h"
26 #include "ED_screen.h"
27 #include "ED_transform.h"
28 #include "ED_view3d.h"
29 
30 #include "MEM_guardedalloc.h"
31 
32 #include "mesh_intern.h" /* own include */
33 
34 /* -------------------------------------------------------------------- */
39  Object *obedit, BMEditMesh *em, const char hflag, BMOperator *op, BMOpSlot *slot_edges_exclude)
40 {
41  BMesh *bm = em->bm;
42  ModifierData *md;
43 
44  /* If a mirror modifier with clipping is on, we need to adjust some
45  * of the cases above to handle edges on the line of symmetry.
46  */
47  for (md = obedit->modifiers.first; md; md = md->next) {
48  if ((md->type == eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) {
50 
51  if (mmd->flag & MOD_MIR_CLIPPING) {
52  BMIter iter;
53  BMEdge *edge;
54 
55  float mtx[4][4];
56  if (mmd->mirror_ob) {
57  float imtx[4][4];
58  invert_m4_m4(imtx, mmd->mirror_ob->obmat);
59  mul_m4_m4m4(mtx, imtx, obedit->obmat);
60  }
61 
62  BM_ITER_MESH (edge, &iter, bm, BM_EDGES_OF_MESH) {
63  if (BM_elem_flag_test(edge, hflag) && BM_edge_is_boundary(edge) &&
64  BM_elem_flag_test(edge->l->f, hflag)) {
65  float co1[3], co2[3];
66 
67  copy_v3_v3(co1, edge->v1->co);
68  copy_v3_v3(co2, edge->v2->co);
69 
70  if (mmd->mirror_ob) {
71  mul_v3_m4v3(co1, mtx, co1);
72  mul_v3_m4v3(co2, mtx, co2);
73  }
74 
75  if (mmd->flag & MOD_MIR_AXIS_X) {
76  if ((fabsf(co1[0]) < mmd->tolerance) && (fabsf(co2[0]) < mmd->tolerance)) {
77  BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
78  }
79  }
80  if (mmd->flag & MOD_MIR_AXIS_Y) {
81  if ((fabsf(co1[1]) < mmd->tolerance) && (fabsf(co2[1]) < mmd->tolerance)) {
82  BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
83  }
84  }
85  if (mmd->flag & MOD_MIR_AXIS_Z) {
86  if ((fabsf(co1[2]) < mmd->tolerance) && (fabsf(co2[2]) < mmd->tolerance)) {
87  BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
88  }
89  }
90  }
91  }
92  }
93  }
94  }
95 }
96 
97 /* individual face extrude */
98 /* will use vertex normals for extrusion directions, so *nor is unaffected */
99 static bool edbm_extrude_discrete_faces(BMEditMesh *em, wmOperator *op, const char hflag)
100 {
101  BMOIter siter;
102  BMIter liter;
103  BMFace *f;
104  BMLoop *l;
105  BMOperator bmop;
106 
107  EDBM_op_init(
108  em, &bmop, op, "extrude_discrete_faces faces=%hf use_select_history=%b", hflag, true);
109 
110  /* deselect original verts */
112 
113  BMO_op_exec(em->bm, &bmop);
114 
115  BMO_ITER (f, &siter, bmop.slots_out, "faces.out", BM_FACE) {
116  BM_face_select_set(em->bm, f, true);
117 
118  /* set face vertex normals to face normal */
119  BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
120  copy_v3_v3(l->v->no, f->no);
121  }
122  }
123 
124  if (!EDBM_op_finish(em, &bmop, op, true)) {
125  return false;
126  }
127 
128  return true;
129 }
130 
132  wmOperator *op,
133  const char hflag,
134  const bool use_normal_flip)
135 {
136  BMesh *bm = em->bm;
137  BMOperator bmop;
138 
139  EDBM_op_init(em,
140  &bmop,
141  op,
142  "extrude_edge_only edges=%he use_normal_flip=%b use_select_history=%b",
143  hflag,
144  use_normal_flip,
145  true);
146 
147  /* deselect original verts */
151 
152  BMO_op_exec(em->bm, &bmop);
154  em->bm, bmop.slots_out, "geom.out", BM_VERT | BM_EDGE, BM_ELEM_SELECT, true);
155 
156  if (!EDBM_op_finish(em, &bmop, op, true)) {
157  return false;
158  }
159 
160  return true;
161 }
162 
163 /* extrudes individual vertices */
164 static bool edbm_extrude_verts_indiv(BMEditMesh *em, wmOperator *op, const char hflag)
165 {
166  BMOperator bmop;
167 
168  EDBM_op_init(em, &bmop, op, "extrude_vert_indiv verts=%hv use_select_history=%b", hflag, true);
169 
170  /* deselect original verts */
171  BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_in, "verts", BM_VERT, BM_ELEM_SELECT, true);
172 
173  BMO_op_exec(em->bm, &bmop);
174  BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "verts.out", BM_VERT, BM_ELEM_SELECT, true);
175 
176  if (!EDBM_op_finish(em, &bmop, op, true)) {
177  return false;
178  }
179 
180  return true;
181 }
182 
184 {
185  char htype = BM_ALL_NOLOOP;
186 
187  if (em->selectmode & SCE_SELECT_VERTEX) {
188  /* pass */
189  }
190  else if (em->selectmode & SCE_SELECT_EDGE) {
191  htype &= ~BM_VERT;
192  }
193  else {
194  htype &= ~(BM_VERT | BM_EDGE);
195  }
196 
197  if (em->bm->totedgesel == 0) {
198  htype &= ~(BM_EDGE | BM_FACE);
199  }
200  else if (em->bm->totfacesel == 0) {
201  htype &= ~BM_FACE;
202  }
203 
204  return htype;
205 }
206 
207 static bool edbm_extrude_ex(Object *obedit,
208  BMEditMesh *em,
209  char htype,
210  const char hflag,
211  const bool use_normal_flip,
212  const bool use_dissolve_ortho_edges,
213  const bool use_mirror,
214  const bool use_select_history)
215 {
216  BMesh *bm = em->bm;
217  BMOIter siter;
218  BMOperator extop;
219  BMElem *ele;
220 
221  /* needed to remove the faces left behind */
222  if (htype & BM_FACE) {
223  htype |= BM_EDGE;
224  }
225 
226  BMO_op_init(bm, &extop, BMO_FLAG_DEFAULTS, "extrude_face_region");
227  BMO_slot_bool_set(extop.slots_in, "use_normal_flip", use_normal_flip);
228  BMO_slot_bool_set(extop.slots_in, "use_dissolve_ortho_edges", use_dissolve_ortho_edges);
229  BMO_slot_bool_set(extop.slots_in, "use_select_history", use_select_history);
230  BMO_slot_buffer_from_enabled_hflag(bm, &extop, extop.slots_in, "geom", htype, hflag);
231 
232  if (use_mirror) {
233  BMOpSlot *slot_edges_exclude;
234  slot_edges_exclude = BMO_slot_get(extop.slots_in, "edges_exclude");
235 
236  edbm_extrude_edge_exclude_mirror(obedit, em, hflag, &extop, slot_edges_exclude);
237  }
238 
242 
243  BMO_op_exec(bm, &extop);
244 
245  BMO_ITER (ele, &siter, extop.slots_out, "geom.out", BM_ALL_NOLOOP) {
246  BM_elem_select_set(bm, ele, true);
247  }
248 
249  BMO_op_finish(bm, &extop);
250 
251  return true;
252 }
253 
256 /* -------------------------------------------------------------------- */
261 {
262 
263  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset");
264  const int steps = RNA_int_get(op->ptr, "steps");
265  const float scale_offset = RNA_float_get(op->ptr, "scale_offset");
266  float offset[3];
267 
268  if (!RNA_property_is_set(op->ptr, prop)) {
270  if (rv3d != NULL) {
271  normalize_v3_v3(offset, rv3d->persinv[2]);
272  }
273  else {
274  copy_v3_v3(offset, (const float[3]){0, 0, 1});
275  }
277  }
278  else {
280  }
281 
282  mul_v3_fl(offset, scale_offset);
283 
284  ViewLayer *view_layer = CTX_data_view_layer(C);
285  uint objects_len = 0;
287  view_layer, CTX_wm_view3d(C), &objects_len);
288 
289  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
290  float offset_local[3], tmat[3][3];
291 
292  Object *obedit = objects[ob_index];
293  BMEditMesh *em = BKE_editmesh_from_object(obedit);
294 
295  copy_m3_m4(tmat, obedit->obmat);
296  invert_m3(tmat);
297  mul_v3_m3v3(offset_local, tmat, offset);
298 
299  for (int a = 0; a < steps; a++) {
300  edbm_extrude_ex(obedit, em, BM_ALL_NOLOOP, BM_ELEM_SELECT, false, false, false, true);
301  BMO_op_callf(
302  em->bm, BMO_FLAG_DEFAULTS, "translate vec=%v verts=%hv", offset_local, BM_ELEM_SELECT);
303  }
304 
305  EDBM_update(obedit->data,
306  &(const struct EDBMUpdate_Params){
307  .calc_looptri = true,
308  .calc_normals = true,
309  .is_destructive = true,
310  });
311  }
312 
313  MEM_freeN(objects);
314 
315  return OPERATOR_FINISHED;
316 }
317 
319 {
320  /* identifiers */
321  ot->name = "Extrude Repeat";
322  ot->description = "Extrude selected vertices, edges or faces repeatedly";
323  ot->idname = "MESH_OT_extrude_repeat";
324 
325  /* api callbacks */
328 
329  /* flags */
331 
332  /* props */
333  RNA_def_int(ot->srna, "steps", 10, 0, 1000000, "Steps", "", 0, 180);
335  ot->srna, "offset", 3, NULL, -100000, 100000, "Offset", "Offset vector", -1000.0f, 1000.0f);
337  RNA_def_float(ot->srna, "scale_offset", 1.0f, 0.0f, 1e12f, "Scale Offset", "", 0.0f, 100.0f);
338 }
339 
342 /* -------------------------------------------------------------------- */
346 /* generic extern called extruder */
347 static bool edbm_extrude_mesh(Object *obedit, BMEditMesh *em, wmOperator *op)
348 {
349  const bool use_normal_flip = RNA_boolean_get(op->ptr, "use_normal_flip");
350  const bool use_dissolve_ortho_edges = RNA_boolean_get(op->ptr, "use_dissolve_ortho_edges");
351  const char htype = edbm_extrude_htype_from_em_select(em);
352  enum { NONE = 0, ELEM_FLAG, VERT_ONLY, EDGE_ONLY } nr;
353  bool changed = false;
354 
355  if (em->selectmode & SCE_SELECT_VERTEX) {
356  if (em->bm->totvertsel == 0) {
357  nr = NONE;
358  }
359  else if (em->bm->totvertsel == 1) {
360  nr = VERT_ONLY;
361  }
362  else if (em->bm->totedgesel == 0) {
363  nr = VERT_ONLY;
364  }
365  else {
366  nr = ELEM_FLAG;
367  }
368  }
369  else if (em->selectmode & SCE_SELECT_EDGE) {
370  if (em->bm->totedgesel == 0) {
371  nr = NONE;
372  }
373  else if (em->bm->totfacesel == 0) {
374  nr = EDGE_ONLY;
375  }
376  else {
377  nr = ELEM_FLAG;
378  }
379  }
380  else {
381  if (em->bm->totfacesel == 0) {
382  nr = NONE;
383  }
384  else {
385  nr = ELEM_FLAG;
386  }
387  }
388 
389  switch (nr) {
390  case NONE:
391  return false;
392  case ELEM_FLAG:
393  changed = edbm_extrude_ex(obedit,
394  em,
395  htype,
397  use_normal_flip,
398  use_dissolve_ortho_edges,
399  true,
400  true);
401  break;
402  case VERT_ONLY:
403  changed = edbm_extrude_verts_indiv(em, op, BM_ELEM_SELECT);
404  break;
405  case EDGE_ONLY:
406  changed = edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, use_normal_flip);
407  break;
408  }
409 
410  if (changed) {
411  return true;
412  }
413 
414  BKE_report(op->reports, RPT_ERROR, "Not a valid selection for extrude");
415  return false;
416 }
417 
418 /* extrude without transform */
420 {
421  ViewLayer *view_layer = CTX_data_view_layer(C);
422  uint objects_len = 0;
424  view_layer, CTX_wm_view3d(C), &objects_len);
425 
426  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
427  Object *obedit = objects[ob_index];
428  BMEditMesh *em = BKE_editmesh_from_object(obedit);
429  if (em->bm->totvertsel == 0) {
430  continue;
431  }
432 
433  if (!edbm_extrude_mesh(obedit, em, op)) {
434  continue;
435  }
436  /* This normally happens when pushing undo but modal operators
437  * like this one don't push undo data until after modal mode is done. */
438  EDBM_update(obedit->data,
439  &(const struct EDBMUpdate_Params){
440  .calc_looptri = true,
441  .calc_normals = true,
442  .is_destructive = true,
443  });
444  }
445  MEM_freeN(objects);
446  return OPERATOR_FINISHED;
447 }
448 
450 {
451  /* identifiers */
452  ot->name = "Extrude Region";
453  ot->idname = "MESH_OT_extrude_region";
454  ot->description = "Extrude region of faces";
455 
456  /* api callbacks */
457  // ot->invoke = mesh_extrude_region_invoke;
460 
461  /* flags */
463 
464  RNA_def_boolean(ot->srna, "use_normal_flip", false, "Flip Normals", "");
465  RNA_def_boolean(ot->srna, "use_dissolve_ortho_edges", false, "Dissolve Orthogonal Edges", "");
467 }
468 
471 /* -------------------------------------------------------------------- */
477 /* extrude without transform */
479 {
480  ViewLayer *view_layer = CTX_data_view_layer(C);
481  uint objects_len = 0;
483  view_layer, CTX_wm_view3d(C), &objects_len);
484 
485  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
486  Object *obedit = objects[ob_index];
487  BMEditMesh *em = BKE_editmesh_from_object(obedit);
488  if (em->bm->totvertsel == 0) {
489  continue;
490  }
491 
492  edbm_extrude_mesh(obedit, em, op);
493 
494  /* This normally happens when pushing undo but modal operators
495  * like this one don't push undo data until after modal mode is done. */
496  EDBM_update(obedit->data,
497  &(const struct EDBMUpdate_Params){
498  .calc_looptri = true,
499  .calc_normals = true,
500  .is_destructive = true,
501  });
502  }
503  MEM_freeN(objects);
504  return OPERATOR_FINISHED;
505 }
506 
508 {
509  /* identifiers */
510  ot->name = "Extrude Context";
511  ot->idname = "MESH_OT_extrude_context";
512  ot->description = "Extrude selection";
513 
514  /* api callbacks */
517 
518  /* flags */
520 
521  RNA_def_boolean(ot->srna, "use_normal_flip", false, "Flip Normals", "");
522  RNA_def_boolean(ot->srna, "use_dissolve_ortho_edges", false, "Dissolve Orthogonal Edges", "");
524 }
525 
528 /* -------------------------------------------------------------------- */
533 {
534  ViewLayer *view_layer = CTX_data_view_layer(C);
535  uint objects_len = 0;
537  view_layer, CTX_wm_view3d(C), &objects_len);
538 
539  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
540  Object *obedit = objects[ob_index];
541  BMEditMesh *em = BKE_editmesh_from_object(obedit);
542  if (em->bm->totvertsel == 0) {
543  continue;
544  }
545 
547 
548  EDBM_update(obedit->data,
549  &(const struct EDBMUpdate_Params){
550  .calc_looptri = true,
551  .calc_normals = false,
552  .is_destructive = true,
553  });
554  }
555  MEM_freeN(objects);
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 */
570 
571  /* flags */
573 
574  /* to give to transform */
576 }
577 
580 /* -------------------------------------------------------------------- */
585 {
586  const bool use_normal_flip = RNA_boolean_get(op->ptr, "use_normal_flip");
587  ViewLayer *view_layer = CTX_data_view_layer(C);
588  uint objects_len = 0;
590  view_layer, CTX_wm_view3d(C), &objects_len);
591 
592  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
593  Object *obedit = objects[ob_index];
594  BMEditMesh *em = BKE_editmesh_from_object(obedit);
595  if (em->bm->totedgesel == 0) {
596  continue;
597  }
598 
599  edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, use_normal_flip);
600 
601  EDBM_update(obedit->data,
602  &(const struct EDBMUpdate_Params){
603  .calc_looptri = true,
604  .calc_normals = false,
605  .is_destructive = true,
606  });
607  }
608  MEM_freeN(objects);
609 
610  return OPERATOR_FINISHED;
611 }
612 
614 {
615  /* identifiers */
616  ot->name = "Extrude Only Edges";
617  ot->idname = "MESH_OT_extrude_edges_indiv";
618  ot->description = "Extrude individual edges only";
619 
620  /* api callbacks */
623 
624  /* flags */
626 
627  /* to give to transform */
628  RNA_def_boolean(ot->srna, "use_normal_flip", false, "Flip Normals", "");
630 }
631 
634 /* -------------------------------------------------------------------- */
639 {
640  ViewLayer *view_layer = CTX_data_view_layer(C);
641  uint objects_len = 0;
643  view_layer, CTX_wm_view3d(C), &objects_len);
644 
645  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
646  Object *obedit = objects[ob_index];
647  BMEditMesh *em = BKE_editmesh_from_object(obedit);
648  if (em->bm->totfacesel == 0) {
649  continue;
650  }
651 
653 
654  EDBM_update(obedit->data,
655  &(const struct EDBMUpdate_Params){
656  .calc_looptri = true,
657  .calc_normals = false,
658  .is_destructive = true,
659  });
660  }
661  MEM_freeN(objects);
662 
663  return OPERATOR_FINISHED;
664 }
665 
667 {
668  /* identifiers */
669  ot->name = "Extrude Individual Faces";
670  ot->idname = "MESH_OT_extrude_faces_indiv";
671  ot->description = "Extrude individual faces only";
672 
673  /* api callbacks */
676 
677  /* flags */
679 
681 }
682 
685 /* -------------------------------------------------------------------- */
692 {
694  ViewContext vc;
695  BMVert *v1;
696  BMIter iter;
697  float center[3];
698  uint verts_len;
699 
700  em_setup_viewcontext(C, &vc);
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) &&
706 
707  /* First calculate the center of transformation. */
708  zero_v3(center);
709  verts_len = 0;
710 
711  uint objects_len = 0;
713  vc.view_layer, vc.v3d, &objects_len);
714  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
715  Object *obedit = objects[ob_index];
717  const int local_verts_len = vc.em->bm->totvertsel;
718 
719  if (vc.em->bm->totvertsel == 0) {
720  continue;
721  }
722 
723  float local_center[3];
724  zero_v3(local_center);
725 
726  BM_ITER_MESH (v1, &iter, vc.em->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->obmat, 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 (uint ob_index = 0; ob_index < objects_len; ob_index++) {
746  Object *obedit = objects[ob_index];
748 
749  if (verts_len != 0) {
750  if (vc.em->bm->totvertsel == 0) {
751  continue;
752  }
753  }
754  else if (obedit != object_active) {
755  continue;
756  }
757 
758  invert_m4_m4(vc.obedit->imat, vc.obedit->obmat);
760 
761  float local_center[3];
762  mul_v3_m4v3(local_center, vc.obedit->imat, center);
763 
764  /* call extrude? */
765  if (verts_len != 0) {
766  const char extrude_htype = edbm_extrude_htype_from_em_select(vc.em);
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, vc.em->bm, BM_EDGES_OF_MESH) {
778  if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
779  float co1[2], co2[2];
780 
782  V3D_PROJ_RET_OK) &&
784  V3D_PROJ_RET_OK)) {
785  /* 2D rotate by 90d while adding.
786  * (x, y) = (y, -x)
787  *
788  * accumulate the screenspace normal in 2D,
789  * with screenspace edge length weighting the result. */
790  if (line_point_side_v2(co1, co2, mval_f) >= 0.0f) {
791  nor[0] += (co1[1] - co2[1]);
792  nor[1] += -(co1[0] - co2[0]);
793  }
794  else {
795  nor[0] += (co2[1] - co1[1]);
796  nor[1] += -(co2[0] - co1[0]);
797  }
798  done = true;
799  }
800  }
801  }
802 
803  if (done) {
804  float view_vec[3], cross[3];
805 
806  /* convert the 2D normal into 3D */
807  mul_mat3_m4_v3(vc.rv3d->viewinv, nor); /* World-space. */
808  mul_mat3_m4_v3(vc.obedit->imat, nor); /* Local-space. */
809 
810  /* correct the normal to be aligned on the view plane */
811  mul_v3_mat3_m4v3(view_vec, vc.obedit->imat, vc.rv3d->viewinv[2]);
812  cross_v3_v3v3(cross, nor, view_vec);
813  cross_v3_v3v3(nor, view_vec, cross);
814  normalize_v3(nor);
815  }
816 
817  /* center */
818  copy_v3_v3(ofs, local_center);
819 
820  mul_m4_v3(vc.obedit->obmat, ofs); /* view space */
821  ED_view3d_win_to_3d_int(vc.v3d, vc.region, ofs, event->mval, ofs);
822  mul_m4_v3(vc.obedit->imat, ofs); /* back in object space */
823 
824  sub_v3_v3(ofs, local_center);
825 
826  /* calculate rotation */
827  unit_m3(mat);
828  if (done) {
829  float angle;
830 
831  normalize_v3_v3(vec, ofs);
832 
834 
835  if (angle != 0.0f) {
836  float axis[3];
837 
838  cross_v3_v3v3(axis, nor, vec);
839 
840  /* halve the rotation if its applied twice */
841  if (rot_src) {
842  angle *= 0.5f;
843  }
844 
845  axis_angle_to_mat3(mat, axis, angle);
846  }
847  }
848 
849  if (rot_src) {
851  vc.em, op, "rotate verts=%hv cent=%v matrix=%m3", BM_ELEM_SELECT, local_center, mat);
852 
853  /* also project the source, for retopo workflow */
854  if (use_proj) {
856  }
857  }
858 
859  edbm_extrude_ex(vc.obedit, vc.em, extrude_htype, BM_ELEM_SELECT, false, false, true, true);
861  vc.em, op, "rotate verts=%hv cent=%v matrix=%m3", BM_ELEM_SELECT, local_center, mat);
862  EDBM_op_callf(vc.em, op, "translate verts=%hv vec=%v", BM_ELEM_SELECT, ofs);
863  }
864  else {
865  /* This only runs for the active object. */
866  const float *cursor = vc.scene->cursor.location;
867  BMOperator bmop;
868  BMOIter oiter;
869 
870  copy_v3_v3(local_center, cursor);
871  ED_view3d_win_to_3d_int(vc.v3d, vc.region, local_center, event->mval, local_center);
872 
873  mul_m4_v3(vc.obedit->imat, local_center); /* back in object space */
874 
875  EDBM_op_init(vc.em, &bmop, op, "create_vert co=%v", local_center);
876  BMO_op_exec(vc.em->bm, &bmop);
877 
878  BMO_ITER (v1, &oiter, bmop.slots_out, "vert.out", BM_VERT) {
879  BM_vert_select_set(vc.em->bm, v1, true);
880  }
881 
882  if (!EDBM_op_finish(vc.em, &bmop, op, true)) {
883  continue;
884  }
885  }
886 
887  if (use_proj) {
889  }
890 
891  /* This normally happens when pushing undo but modal operators
892  * like this one don't push undo data until after modal mode is done. */
893  EDBM_update(vc.obedit->data,
894  &(const struct EDBMUpdate_Params){
895  .calc_looptri = true,
896  .calc_normals = true,
897  .is_destructive = true,
898  });
899 
902  }
903  MEM_freeN(objects);
904 
905  /* Support dragging to move after extrude, see: #114282. */
906  const int retval = OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
907  return WM_operator_flag_only_pass_through_on_press(retval, event);
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 
typedef float(TangentPoint)[2]
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1100
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1528
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:784
struct RegionView3D * CTX_wm_region_view3d(const bContext *C)
Definition: context.c:793
BMEditMesh * BKE_editmesh_from_object(struct Object *ob)
Return the BMEditMesh for a given object.
Definition: editmesh.c:58
#define BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, v3d, r_len)
Definition: BKE_layer.h:542
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
void unit_m3(float m[3][3])
Definition: math_matrix.c:40
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:87
void mul_mat3_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:790
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1287
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:729
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:739
bool invert_m3(float R[3][3])
Definition: math_matrix.c:1171
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
Definition: math_matrix.c:897
void mul_v3_mat3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:800
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
MINLINE float normalize_v3(float r[3])
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
Definition: math_vector.c:445
MINLINE void add_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition: BLI_sys_types.h:67
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
@ 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.
#define SCE_SELECT_VERTEX
@ SCE_SNAP
#define SCE_SELECT_EDGE
@ SCE_SNAP_MODE_FACE_RAYCAST
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
void EDBM_update(struct Mesh *me, const struct EDBMUpdate_Params *params)
void EDBM_project_snap_verts(struct bContext *C, struct Depsgraph *depsgraph, struct ARegion *region, struct Object *obedit, struct BMEditMesh *em)
void em_setup_viewcontext(struct bContext *C, struct ViewContext *vc)
void EDBM_flag_disable_all(struct BMEditMesh *em, char hflag)
bool ED_operator_editmesh_region_view3d(struct bContext *C)
Definition: screen_ops.c:447
bool ED_operator_editmesh(struct bContext *C)
Definition: screen_ops.c:433
void Transform_Properties(struct wmOperatorType *ot, int flags)
#define P_NO_DEFAULTS
Definition: ED_transform.h:120
#define P_MIRROR_DUMMY
Definition: ED_transform.h:109
@ V3D_PROJ_TEST_NOP
Definition: ED_view3d.h:234
void ED_view3d_win_to_3d_int(const struct View3D *v3d, const struct ARegion *region, const float depth_pt[3], const int mval[2], float r_out[3])
@ V3D_PROJ_RET_OK
Definition: ED_view3d.h:217
void ED_view3d_viewcontext_init_object(struct ViewContext *vc, struct Object *obact)
eV3DProjStatus ED_view3d_project_float_object(const struct ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
void ED_view3d_init_mats_rv3d(const struct Object *ob, struct RegionView3D *rv3d)
Definition: space_view3d.c:166
NSNotificationCenter * center
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
Read Guarded memory(de)allocation.
@ PROP_SKIP_SAVE
Definition: RNA_types.h:218
#define C
Definition: RandGen.cpp:25
@ OPTYPE_DEPENDS_ON_CURSOR
Definition: WM_types.h:184
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define NC_GEOM
Definition: WM_types.h:343
#define ND_DATA
Definition: WM_types.h:456
#define ND_SELECT
Definition: WM_types.h:455
#define BM_ALL_NOLOOP
Definition: bmesh_class.h:411
@ BM_FACE
Definition: bmesh_class.h:386
@ BM_VERT
Definition: bmesh_class.h:383
@ BM_EDGE
Definition: bmesh_class.h:384
@ BM_ELEM_SELECT
Definition: bmesh_class.h:471
#define BM_elem_flag_test(ele, hflag)
Definition: bmesh_inline.h:12
#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
ATTR_WARN_UNUSED_RESULT 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)
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)
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,...)
BMOpSlot * BMO_slot_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK GET SLOT.
#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
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
const Depsgraph * depsgraph
void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot)
static int edbm_extrude_context_exec(bContext *C, wmOperator *op)
static int edbm_extrude_region_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)
static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void MESH_OT_extrude_context(wmOperatorType *ot)
static int edbm_extrude_faces_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)
static int edbm_extrude_repeat_exec(bContext *C, wmOperator *op)
void MESH_OT_extrude_faces_indiv(wmOperatorType *ot)
static char edbm_extrude_htype_from_em_select(BMEditMesh *em)
static int edbm_extrude_edges_exec(bContext *C, wmOperator *op)
static int edbm_extrude_verts_exec(bContext *C, wmOperator *op)
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)
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
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
#define fabsf(x)
Definition: metal/compat.h:219
static unsigned a[3]
Definition: RandGen.cpp:78
vec_base< T, 3 > cross(const vec_base< T, 3 > &a, const vec_base< T, 3 > &b)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
Definition: rna_access.c:2879
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:5271
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:717
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4910
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4957
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
Definition: rna_access.c:2978
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3836
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
PropertyRNA * RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3894
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3597
static const int steps
Definition: sky_nishita.cpp:19
BMVert * v1
Definition: bmesh_class.h:122
BMVert * v2
Definition: bmesh_class.h:122
short selectmode
Definition: BKE_editmesh.h:52
struct BMesh * bm
Definition: BKE_editmesh.h:40
float no[3]
Definition: bmesh_class.h:271
struct BMVert * v
Definition: bmesh_class.h:153
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
float co[3]
Definition: bmesh_class.h:87
float no[3]
Definition: bmesh_class.h:88
int totfacesel
Definition: bmesh_class.h:298
int totvertsel
Definition: bmesh_class.h:298
int totedgesel
Definition: bmesh_class.h:298
void * first
Definition: DNA_listBase.h:31
struct Object * mirror_ob
struct ModifierData * next
ListBase modifiers
float imat[4][4]
float obmat[4][4]
void * data
float persinv[4][4]
float viewinv[4][4]
struct ToolSettings * toolsettings
View3DCursor cursor
struct Scene * scene
Definition: ED_view3d.h:65
struct ARegion * region
Definition: ED_view3d.h:69
struct ViewLayer * view_layer
Definition: ED_view3d.h:66
struct BMEditMesh * em
Definition: ED_view3d.h:73
struct Object * obact
Definition: ED_view3d.h:67
struct Object * obedit
Definition: ED_view3d.h:68
struct View3D * v3d
Definition: ED_view3d.h:70
struct RegionView3D * rv3d
Definition: ED_view3d.h:72
int mval[2]
Definition: WM_types.h:684
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
struct ReportList * reports
struct PointerRNA * ptr
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3479
int WM_operator_flag_only_pass_through_on_press(int retval, const struct wmEvent *event)