Blender  V2.93
editmesh_extrude.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2004 by Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "DNA_modifier_types.h"
25 #include "DNA_object_types.h"
26 
27 #include "BLI_listbase.h"
28 #include "BLI_math.h"
29 
30 #include "BKE_context.h"
31 #include "BKE_editmesh.h"
32 #include "BKE_layer.h"
33 #include "BKE_report.h"
34 
35 #include "RNA_access.h"
36 #include "RNA_define.h"
37 
38 #include "WM_api.h"
39 #include "WM_types.h"
40 
41 #include "ED_mesh.h"
42 #include "ED_screen.h"
43 #include "ED_transform.h"
44 #include "ED_view3d.h"
45 
46 #include "MEM_guardedalloc.h"
47 
48 #include "mesh_intern.h" /* own include */
49 
50 /* -------------------------------------------------------------------- */
55  Object *obedit, BMEditMesh *em, const char hflag, BMOperator *op, BMOpSlot *slot_edges_exclude)
56 {
57  BMesh *bm = em->bm;
58  ModifierData *md;
59 
60  /* If a mirror modifier with clipping is on, we need to adjust some
61  * of the cases above to handle edges on the line of symmetry.
62  */
63  for (md = obedit->modifiers.first; md; md = md->next) {
64  if ((md->type == eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) {
66 
67  if (mmd->flag & MOD_MIR_CLIPPING) {
68  BMIter iter;
69  BMEdge *edge;
70 
71  float mtx[4][4];
72  if (mmd->mirror_ob) {
73  float imtx[4][4];
74  invert_m4_m4(imtx, mmd->mirror_ob->obmat);
75  mul_m4_m4m4(mtx, imtx, obedit->obmat);
76  }
77 
78  BM_ITER_MESH (edge, &iter, bm, BM_EDGES_OF_MESH) {
79  if (BM_elem_flag_test(edge, hflag) && BM_edge_is_boundary(edge) &&
80  BM_elem_flag_test(edge->l->f, hflag)) {
81  float co1[3], co2[3];
82 
83  copy_v3_v3(co1, edge->v1->co);
84  copy_v3_v3(co2, edge->v2->co);
85 
86  if (mmd->mirror_ob) {
87  mul_v3_m4v3(co1, mtx, co1);
88  mul_v3_m4v3(co2, mtx, co2);
89  }
90 
91  if (mmd->flag & MOD_MIR_AXIS_X) {
92  if ((fabsf(co1[0]) < mmd->tolerance) && (fabsf(co2[0]) < mmd->tolerance)) {
93  BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
94  }
95  }
96  if (mmd->flag & MOD_MIR_AXIS_Y) {
97  if ((fabsf(co1[1]) < mmd->tolerance) && (fabsf(co2[1]) < mmd->tolerance)) {
98  BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
99  }
100  }
101  if (mmd->flag & MOD_MIR_AXIS_Z) {
102  if ((fabsf(co1[2]) < mmd->tolerance) && (fabsf(co2[2]) < mmd->tolerance)) {
103  BMO_slot_map_empty_insert(op, slot_edges_exclude, edge);
104  }
105  }
106  }
107  }
108  }
109  }
110  }
111 }
112 
113 /* individual face extrude */
114 /* will use vertex normals for extrusion directions, so *nor is unaffected */
115 static bool edbm_extrude_discrete_faces(BMEditMesh *em, wmOperator *op, const char hflag)
116 {
117  BMOIter siter;
118  BMIter liter;
119  BMFace *f;
120  BMLoop *l;
121  BMOperator bmop;
122 
123  EDBM_op_init(
124  em, &bmop, op, "extrude_discrete_faces faces=%hf use_select_history=%b", hflag, true);
125 
126  /* deselect original verts */
128 
129  BMO_op_exec(em->bm, &bmop);
130 
131  BMO_ITER (f, &siter, bmop.slots_out, "faces.out", BM_FACE) {
132  BM_face_select_set(em->bm, f, true);
133 
134  /* set face vertex normals to face normal */
135  BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
136  copy_v3_v3(l->v->no, f->no);
137  }
138  }
139 
140  if (!EDBM_op_finish(em, &bmop, op, true)) {
141  return false;
142  }
143 
144  return true;
145 }
146 
147 /* extrudes individual edges */
149  wmOperator *op,
150  const char hflag,
151  const bool use_normal_flip)
152 {
153  BMesh *bm = em->bm;
154  BMOperator bmop;
155 
156  EDBM_op_init(em,
157  &bmop,
158  op,
159  "extrude_edge_only edges=%he use_normal_flip=%b use_select_history=%b",
160  hflag,
161  use_normal_flip,
162  true);
163 
164  /* deselect original verts */
168 
169  BMO_op_exec(em->bm, &bmop);
171  em->bm, bmop.slots_out, "geom.out", BM_VERT | BM_EDGE, BM_ELEM_SELECT, true);
172 
173  if (!EDBM_op_finish(em, &bmop, op, true)) {
174  return false;
175  }
176 
177  return true;
178 }
179 
180 /* extrudes individual vertices */
181 static bool edbm_extrude_verts_indiv(BMEditMesh *em, wmOperator *op, const char hflag)
182 {
183  BMOperator bmop;
184 
185  EDBM_op_init(em, &bmop, op, "extrude_vert_indiv verts=%hv use_select_history=%b", hflag, true);
186 
187  /* deselect original verts */
188  BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_in, "verts", BM_VERT, BM_ELEM_SELECT, true);
189 
190  BMO_op_exec(em->bm, &bmop);
191  BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "verts.out", BM_VERT, BM_ELEM_SELECT, true);
192 
193  if (!EDBM_op_finish(em, &bmop, op, true)) {
194  return false;
195  }
196 
197  return true;
198 }
199 
201 {
202  char htype = BM_ALL_NOLOOP;
203 
204  if (em->selectmode & SCE_SELECT_VERTEX) {
205  /* pass */
206  }
207  else if (em->selectmode & SCE_SELECT_EDGE) {
208  htype &= ~BM_VERT;
209  }
210  else {
211  htype &= ~(BM_VERT | BM_EDGE);
212  }
213 
214  if (em->bm->totedgesel == 0) {
215  htype &= ~(BM_EDGE | BM_FACE);
216  }
217  else if (em->bm->totfacesel == 0) {
218  htype &= ~BM_FACE;
219  }
220 
221  return htype;
222 }
223 
224 static bool edbm_extrude_ex(Object *obedit,
225  BMEditMesh *em,
226  char htype,
227  const char hflag,
228  const bool use_normal_flip,
229  const bool use_dissolve_ortho_edges,
230  const bool use_mirror,
231  const bool use_select_history)
232 {
233  BMesh *bm = em->bm;
234  BMOIter siter;
235  BMOperator extop;
236  BMElem *ele;
237 
238  /* needed to remove the faces left behind */
239  if (htype & BM_FACE) {
240  htype |= BM_EDGE;
241  }
242 
243  BMO_op_init(bm, &extop, BMO_FLAG_DEFAULTS, "extrude_face_region");
244  BMO_slot_bool_set(extop.slots_in, "use_normal_flip", use_normal_flip);
245  BMO_slot_bool_set(extop.slots_in, "use_dissolve_ortho_edges", use_dissolve_ortho_edges);
246  BMO_slot_bool_set(extop.slots_in, "use_select_history", use_select_history);
247  BMO_slot_buffer_from_enabled_hflag(bm, &extop, extop.slots_in, "geom", htype, hflag);
248 
249  if (use_mirror) {
250  BMOpSlot *slot_edges_exclude;
251  slot_edges_exclude = BMO_slot_get(extop.slots_in, "edges_exclude");
252 
253  edbm_extrude_edge_exclude_mirror(obedit, em, hflag, &extop, slot_edges_exclude);
254  }
255 
259 
260  BMO_op_exec(bm, &extop);
261 
262  BMO_ITER (ele, &siter, extop.slots_out, "geom.out", BM_ALL_NOLOOP) {
263  BM_elem_select_set(bm, ele, true);
264  }
265 
266  BMO_op_finish(bm, &extop);
267 
268  return true;
269 }
270 
273 /* -------------------------------------------------------------------- */
278 {
279 
280  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset");
281  const int steps = RNA_int_get(op->ptr, "steps");
282  const float scale_offset = RNA_float_get(op->ptr, "scale_offset");
283  float offset[3];
284 
285  if (!RNA_property_is_set(op->ptr, prop)) {
287  if (rv3d != NULL) {
288  normalize_v3_v3(offset, rv3d->persinv[2]);
289  }
290  else {
291  copy_v3_v3(offset, (const float[3]){0, 0, 1});
292  }
293  RNA_property_float_set_array(op->ptr, prop, offset);
294  }
295  else {
296  RNA_property_float_get_array(op->ptr, prop, offset);
297  }
298 
299  mul_v3_fl(offset, scale_offset);
300 
301  ViewLayer *view_layer = CTX_data_view_layer(C);
302  uint objects_len = 0;
304  view_layer, CTX_wm_view3d(C), &objects_len);
305 
306  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
307  float offset_local[3], tmat[3][3];
308 
309  Object *obedit = objects[ob_index];
310  BMEditMesh *em = BKE_editmesh_from_object(obedit);
311 
312  copy_m3_m4(tmat, obedit->obmat);
313  invert_m3(tmat);
314  mul_v3_m3v3(offset_local, tmat, offset);
315 
316  for (int a = 0; a < steps; a++) {
317  edbm_extrude_ex(obedit, em, BM_ALL_NOLOOP, BM_ELEM_SELECT, false, false, false, true);
318  BMO_op_callf(
319  em->bm, BMO_FLAG_DEFAULTS, "translate vec=%v verts=%hv", offset_local, BM_ELEM_SELECT);
320  }
321 
323 
324  EDBM_update_generic(obedit->data, true, true);
325  }
326 
327  MEM_freeN(objects);
328 
329  return OPERATOR_FINISHED;
330 }
331 
333 {
334  /* identifiers */
335  ot->name = "Extrude Repeat";
336  ot->description = "Extrude selected vertices, edges or faces repeatedly";
337  ot->idname = "MESH_OT_extrude_repeat";
338 
339  /* api callbacks */
342 
343  /* flags */
345 
346  /* props */
347  RNA_def_int(ot->srna, "steps", 10, 0, 1000000, "Steps", "", 0, 180);
349  ot->srna, "offset", 3, NULL, -100000, 100000, "Offset", "Offset vector", -1000.0f, 1000.0f);
351  RNA_def_float(ot->srna, "scale_offset", 1.0f, 0.0f, 1e12f, "Scale Offset", "", 0.0f, 100.0f);
352 }
353 
356 /* -------------------------------------------------------------------- */
360 /* generic extern called extruder */
361 static bool edbm_extrude_mesh(Object *obedit, BMEditMesh *em, wmOperator *op)
362 {
363  const bool use_normal_flip = RNA_boolean_get(op->ptr, "use_normal_flip");
364  const bool use_dissolve_ortho_edges = RNA_boolean_get(op->ptr, "use_dissolve_ortho_edges");
365  const char htype = edbm_extrude_htype_from_em_select(em);
366  enum { NONE = 0, ELEM_FLAG, VERT_ONLY, EDGE_ONLY } nr;
367  bool changed = false;
368 
369  if (em->selectmode & SCE_SELECT_VERTEX) {
370  if (em->bm->totvertsel == 0) {
371  nr = NONE;
372  }
373  else if (em->bm->totvertsel == 1) {
374  nr = VERT_ONLY;
375  }
376  else if (em->bm->totedgesel == 0) {
377  nr = VERT_ONLY;
378  }
379  else {
380  nr = ELEM_FLAG;
381  }
382  }
383  else if (em->selectmode & SCE_SELECT_EDGE) {
384  if (em->bm->totedgesel == 0) {
385  nr = NONE;
386  }
387  else if (em->bm->totfacesel == 0) {
388  nr = EDGE_ONLY;
389  }
390  else {
391  nr = ELEM_FLAG;
392  }
393  }
394  else {
395  if (em->bm->totfacesel == 0) {
396  nr = NONE;
397  }
398  else {
399  nr = ELEM_FLAG;
400  }
401  }
402 
403  switch (nr) {
404  case NONE:
405  return false;
406  case ELEM_FLAG:
407  changed = edbm_extrude_ex(obedit,
408  em,
409  htype,
411  use_normal_flip,
412  use_dissolve_ortho_edges,
413  true,
414  true);
415  break;
416  case VERT_ONLY:
417  changed = edbm_extrude_verts_indiv(em, op, BM_ELEM_SELECT);
418  break;
419  case EDGE_ONLY:
420  changed = edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, use_normal_flip);
421  break;
422  }
423 
424  if (changed) {
425  return true;
426  }
427 
428  BKE_report(op->reports, RPT_ERROR, "Not a valid selection for extrude");
429  return false;
430 }
431 
432 /* extrude without transform */
434 {
435  ViewLayer *view_layer = CTX_data_view_layer(C);
436  uint objects_len = 0;
438  view_layer, CTX_wm_view3d(C), &objects_len);
439 
440  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
441  Object *obedit = objects[ob_index];
442  BMEditMesh *em = BKE_editmesh_from_object(obedit);
443  if (em->bm->totvertsel == 0) {
444  continue;
445  }
446 
447  if (!edbm_extrude_mesh(obedit, em, op)) {
448  continue;
449  }
450  /* This normally happens when pushing undo but modal operators
451  * like this one don't push undo data until after modal mode is
452  * done.*/
454 
455  EDBM_update_generic(obedit->data, true, true);
456  }
457  MEM_freeN(objects);
458  return OPERATOR_FINISHED;
459 }
460 
462 {
463  /* identifiers */
464  ot->name = "Extrude Region";
465  ot->idname = "MESH_OT_extrude_region";
466  ot->description = "Extrude region of faces";
467 
468  /* api callbacks */
469  // ot->invoke = mesh_extrude_region_invoke;
472 
473  /* flags */
475 
476  RNA_def_boolean(ot->srna, "use_normal_flip", false, "Flip Normals", "");
477  RNA_def_boolean(ot->srna, "use_dissolve_ortho_edges", false, "Dissolve Orthogonal Edges", "");
479 }
480 
483 /* -------------------------------------------------------------------- */
489 /* extrude without transform */
491 {
492  ViewLayer *view_layer = CTX_data_view_layer(C);
493  uint objects_len = 0;
495  view_layer, CTX_wm_view3d(C), &objects_len);
496 
497  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
498  Object *obedit = objects[ob_index];
499  BMEditMesh *em = BKE_editmesh_from_object(obedit);
500  if (em->bm->totvertsel == 0) {
501  continue;
502  }
503 
504  edbm_extrude_mesh(obedit, em, op);
505  /* This normally happens when pushing undo but modal operators
506  * like this one don't push undo data until after modal mode is
507  * done.*/
508 
510 
511  EDBM_update_generic(obedit->data, true, true);
512  }
513  MEM_freeN(objects);
514  return OPERATOR_FINISHED;
515 }
516 
518 {
519  /* identifiers */
520  ot->name = "Extrude Context";
521  ot->idname = "MESH_OT_extrude_context";
522  ot->description = "Extrude selection";
523 
524  /* api callbacks */
527 
528  /* flags */
530 
531  RNA_def_boolean(ot->srna, "use_normal_flip", false, "Flip Normals", "");
532  RNA_def_boolean(ot->srna, "use_dissolve_ortho_edges", false, "Dissolve Orthogonal Edges", "");
534 }
535 
538 /* -------------------------------------------------------------------- */
543 {
544  ViewLayer *view_layer = CTX_data_view_layer(C);
545  uint objects_len = 0;
547  view_layer, CTX_wm_view3d(C), &objects_len);
548 
549  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
550  Object *obedit = objects[ob_index];
551  BMEditMesh *em = BKE_editmesh_from_object(obedit);
552  if (em->bm->totvertsel == 0) {
553  continue;
554  }
555 
557 
558  EDBM_update_generic(obedit->data, true, true);
559  }
560  MEM_freeN(objects);
561 
562  return OPERATOR_FINISHED;
563 }
564 
566 {
567  /* identifiers */
568  ot->name = "Extrude Only Vertices";
569  ot->idname = "MESH_OT_extrude_verts_indiv";
570  ot->description = "Extrude individual vertices only";
571 
572  /* api callbacks */
575 
576  /* flags */
578 
579  /* to give to transform */
581 }
582 
585 /* -------------------------------------------------------------------- */
590 {
591  const bool use_normal_flip = RNA_boolean_get(op->ptr, "use_normal_flip");
592  ViewLayer *view_layer = CTX_data_view_layer(C);
593  uint objects_len = 0;
595  view_layer, CTX_wm_view3d(C), &objects_len);
596 
597  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
598  Object *obedit = objects[ob_index];
599  BMEditMesh *em = BKE_editmesh_from_object(obedit);
600  if (em->bm->totedgesel == 0) {
601  continue;
602  }
603 
604  edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, use_normal_flip);
605 
606  EDBM_update_generic(obedit->data, true, true);
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_generic(obedit->data, true, true);
655  }
656  MEM_freeN(objects);
657 
658  return OPERATOR_FINISHED;
659 }
660 
662 {
663  /* identifiers */
664  ot->name = "Extrude Individual Faces";
665  ot->idname = "MESH_OT_extrude_faces_indiv";
666  ot->description = "Extrude individual faces only";
667 
668  /* api callbacks */
671 
672  /* flags */
674 
676 }
677 
680 /* -------------------------------------------------------------------- */
687 {
689  ViewContext vc;
690  BMVert *v1;
691  BMIter iter;
692  float center[3];
693  uint verts_len;
694 
695  em_setup_viewcontext(C, &vc);
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) &&
701 
702  /* First calculate the center of transformation. */
703  zero_v3(center);
704  verts_len = 0;
705 
706  uint objects_len = 0;
708  vc.view_layer, vc.v3d, &objects_len);
709  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
710  Object *obedit = objects[ob_index];
712  const int local_verts_len = vc.em->bm->totvertsel;
713 
714  if (vc.em->bm->totvertsel == 0) {
715  continue;
716  }
717 
718  float local_center[3];
719  zero_v3(local_center);
720 
721  BM_ITER_MESH (v1, &iter, vc.em->bm, BM_VERTS_OF_MESH) {
723  add_v3_v3(local_center, v1->co);
724  }
725  }
726 
727  mul_v3_fl(local_center, 1.0f / (float)local_verts_len);
728  mul_m4_v3(vc.obedit->obmat, local_center);
729  mul_v3_fl(local_center, (float)local_verts_len);
730 
731  add_v3_v3(center, local_center);
732  verts_len += local_verts_len;
733  }
734 
735  if (verts_len != 0) {
736  mul_v3_fl(center, 1.0f / (float)verts_len);
737  }
738 
739  /* Then we process the meshes. */
740  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
741  Object *obedit = objects[ob_index];
743 
744  if (verts_len != 0) {
745  if (vc.em->bm->totvertsel == 0) {
746  continue;
747  }
748  }
749  else if (obedit != object_active) {
750  continue;
751  }
752 
753  invert_m4_m4(vc.obedit->imat, vc.obedit->obmat);
755 
756  float local_center[3];
757  mul_v3_m4v3(local_center, vc.obedit->imat, center);
758 
759  /* call extrude? */
760  if (verts_len != 0) {
761  const char extrude_htype = edbm_extrude_htype_from_em_select(vc.em);
762  BMEdge *eed;
763  float mat[3][3];
764  float vec[3], ofs[3];
765  float nor[3] = {0.0, 0.0, 0.0};
766 
767  /* 2D normal calc */
768  const float mval_f[2] = {(float)event->mval[0], (float)event->mval[1]};
769 
770  /* check for edges that are half selected, use for rotation */
771  bool done = false;
772  BM_ITER_MESH (eed, &iter, vc.em->bm, BM_EDGES_OF_MESH) {
773  if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
774  float co1[2], co2[2];
775 
777  V3D_PROJ_RET_OK) &&
779  V3D_PROJ_RET_OK)) {
780  /* 2D rotate by 90d while adding.
781  * (x, y) = (y, -x)
782  *
783  * accumulate the screenspace normal in 2D,
784  * with screenspace edge length weighting the result. */
785  if (line_point_side_v2(co1, co2, mval_f) >= 0.0f) {
786  nor[0] += (co1[1] - co2[1]);
787  nor[1] += -(co1[0] - co2[0]);
788  }
789  else {
790  nor[0] += (co2[1] - co1[1]);
791  nor[1] += -(co2[0] - co1[0]);
792  }
793  done = true;
794  }
795  }
796  }
797 
798  if (done) {
799  float view_vec[3], cross[3];
800 
801  /* convert the 2D normal into 3D */
802  mul_mat3_m4_v3(vc.rv3d->viewinv, nor); /* worldspace */
803  mul_mat3_m4_v3(vc.obedit->imat, nor); /* local space */
804 
805  /* correct the normal to be aligned on the view plane */
806  mul_v3_mat3_m4v3(view_vec, vc.obedit->imat, vc.rv3d->viewinv[2]);
807  cross_v3_v3v3(cross, nor, view_vec);
808  cross_v3_v3v3(nor, view_vec, cross);
809  normalize_v3(nor);
810  }
811 
812  /* center */
813  copy_v3_v3(ofs, local_center);
814 
815  mul_m4_v3(vc.obedit->obmat, ofs); /* view space */
816  ED_view3d_win_to_3d_int(vc.v3d, vc.region, ofs, event->mval, ofs);
817  mul_m4_v3(vc.obedit->imat, ofs); /* back in object space */
818 
819  sub_v3_v3(ofs, local_center);
820 
821  /* calculate rotation */
822  unit_m3(mat);
823  if (done) {
824  float angle;
825 
826  normalize_v3_v3(vec, ofs);
827 
829 
830  if (angle != 0.0f) {
831  float axis[3];
832 
833  cross_v3_v3v3(axis, nor, vec);
834 
835  /* halve the rotation if its applied twice */
836  if (rot_src) {
837  angle *= 0.5f;
838  }
839 
840  axis_angle_to_mat3(mat, axis, angle);
841  }
842  }
843 
844  if (rot_src) {
846  vc.em, op, "rotate verts=%hv cent=%v matrix=%m3", BM_ELEM_SELECT, local_center, mat);
847 
848  /* also project the source, for retopo workflow */
849  if (use_proj) {
851  }
852  }
853 
854  edbm_extrude_ex(vc.obedit, vc.em, extrude_htype, BM_ELEM_SELECT, false, false, true, true);
856  vc.em, op, "rotate verts=%hv cent=%v matrix=%m3", BM_ELEM_SELECT, local_center, mat);
857  EDBM_op_callf(vc.em, op, "translate verts=%hv vec=%v", BM_ELEM_SELECT, ofs);
858  }
859  else {
860  /* This only runs for the active object. */
861  const float *cursor = vc.scene->cursor.location;
862  BMOperator bmop;
863  BMOIter oiter;
864 
865  copy_v3_v3(local_center, cursor);
866  ED_view3d_win_to_3d_int(vc.v3d, vc.region, local_center, event->mval, local_center);
867 
868  mul_m4_v3(vc.obedit->imat, local_center); /* back in object space */
869 
870  EDBM_op_init(vc.em, &bmop, op, "create_vert co=%v", local_center);
871  BMO_op_exec(vc.em->bm, &bmop);
872 
873  BMO_ITER (v1, &oiter, bmop.slots_out, "vert.out", BM_VERT) {
874  BM_vert_select_set(vc.em->bm, v1, true);
875  }
876 
877  if (!EDBM_op_finish(vc.em, &bmop, op, true)) {
878  continue;
879  }
880  }
881 
882  if (use_proj) {
884  }
885 
886  /* This normally happens when pushing undo but modal operators
887  * like this one don't push undo data until after modal mode is
888  * done. */
890 
891  EDBM_update_generic(vc.obedit->data, true, true);
892 
895  }
896  MEM_freeN(objects);
897 
898  return OPERATOR_FINISHED;
899 }
900 
902 {
903  /* identifiers */
904  ot->name = "Duplicate or Extrude to Cursor";
905  ot->idname = "MESH_OT_dupli_extrude_cursor";
906  ot->description =
907  "Duplicate and extrude selected vertices, edges or faces towards the mouse cursor";
908 
909  /* api callbacks */
912 
913  /* flags */
915 
917  "rotate_source",
918  true,
919  "Rotate Source",
920  "Rotate initial selection giving better shape");
921 }
922 
typedef float(TangentPoint)[2]
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:760
struct RegionView3D * CTX_wm_region_view3d(const bContext *C)
Definition: context.c:769
BMEditMesh * BKE_editmesh_from_object(struct Object *ob)
Return the BMEditMesh for a given object.
Definition: editmesh.c:85
#define BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, v3d, r_len)
Definition: BKE_layer.h:426
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
void unit_m3(float m[3][3])
Definition: math_matrix.c:58
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:105
void mul_mat3_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:794
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1278
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:732
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:742
bool invert_m3(float R[3][3])
Definition: math_matrix.c:1152
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
Definition: math_matrix.c:901
void mul_v3_mat3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:804
void axis_angle_to_mat3(float R[3][3], const float axis[3], const 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:505
MINLINE void add_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition: BLI_sys_types.h:83
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
@ 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_SNAP
#define SCE_SNAP_MODE_FACE
#define SCE_SELECT_VERTEX
#define SCE_SELECT_EDGE
@ OPERATOR_FINISHED
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_update_generic(struct Mesh *me, const bool do_tessellation, const bool is_destructive)
void EDBM_flag_disable_all(struct BMEditMesh *em, const char hflag)
void EDBM_mesh_normals_update(struct BMEditMesh *em)
bool ED_operator_editmesh_region_view3d(struct bContext *C)
Definition: screen_ops.c:418
bool ED_operator_editmesh(struct bContext *C)
Definition: screen_ops.c:404
void Transform_Properties(struct wmOperatorType *ot, int flags)
#define P_NO_DEFAULTS
Definition: ED_transform.h:134
#define P_MIRROR_DUMMY
Definition: ED_transform.h:123
void ED_view3d_init_mats_rv3d(struct Object *ob, struct RegionView3D *rv3d)
Definition: space_view3d.c:190
@ V3D_PROJ_TEST_NOP
Definition: ED_view3d.h:193
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])
eV3DProjStatus ED_view3d_project_float_object(const struct ARegion *region, const float co[3], float r_co[2], const eV3DProjTest flag)
@ V3D_PROJ_RET_OK
Definition: ED_view3d.h:176
void ED_view3d_viewcontext_init_object(struct ViewContext *vc, struct Object *obact)
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:204
#define C
Definition: RandGen.cpp:39
#define NC_GEOM
Definition: WM_types.h:294
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define ND_DATA
Definition: WM_types.h:408
#define ND_SELECT
Definition: WM_types.h:407
#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:26
#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, const char htype, const char hflag, const bool do_flush)
BMO_FLAG_BUFFER.
void BMO_slot_bool_set(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, const bool i)
void BMO_slot_buffer_from_enabled_hflag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, const char htype, const char hflag)
void BMO_slot_buffer_hflag_disable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, const char htype, const char hflag, const bool do_flush)
BMO_FLAG_BUFFER.
void BMO_op_exec(BMesh *bm, BMOperator *op)
BMESH OPSTACK EXEC OP.
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
void BMO_op_finish(BMesh *bm, BMOperator *op)
BMESH OPSTACK FINISH OP.
BMOpSlot * BMO_slot_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK GET SLOT.
#define BMO_FLAG_DEFAULTS
void BMO_op_init(BMesh *bm, BMOperator *op, const int flag, const char *opname)
BMESH OPSTACK INIT OP.
bool BMO_op_callf(BMesh *bm, const int flag, const char *fmt,...)
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
#define fabsf(x)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
static unsigned a[3]
Definition: RandGen.cpp:92
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
Definition: rna_access.c:3033
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6655
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6308
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6355
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
Definition: rna_access.c:3132
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
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:3825
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
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:3883
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
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:3585
static const int steps
Definition: sky_nishita.cpp:28
BMVert * v1
Definition: bmesh_class.h:134
BMVert * v2
Definition: bmesh_class.h:134
struct BMLoop * l
Definition: bmesh_class.h:140
short selectmode
Definition: BKE_editmesh.h:72
struct BMesh * bm
Definition: BKE_editmesh.h:52
float no[3]
Definition: bmesh_class.h:280
struct BMVert * v
Definition: bmesh_class.h:165
struct BMFace * f
Definition: bmesh_class.h:183
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
float co[3]
Definition: bmesh_class.h:99
float no[3]
Definition: bmesh_class.h:100
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:47
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:76
struct ARegion * region
Definition: ED_view3d.h:80
struct ViewLayer * view_layer
Definition: ED_view3d.h:77
struct BMEditMesh * em
Definition: ED_view3d.h:84
struct Object * obact
Definition: ED_view3d.h:78
struct Object * obedit
Definition: ED_view3d.h:79
struct View3D * v3d
Definition: ED_view3d.h:81
struct RegionView3D * rv3d
Definition: ED_view3d.h:83
int mval[2]
Definition: WM_types.h:583
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct ReportList * reports
struct PointerRNA * ptr
__forceinline avxf cross(const avxf &a, const avxf &b)
Definition: util_avxf.h:119
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3156