Blender V5.0
bmo_extrude.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_meshdata_types.h"
14
15#include "BLI_math_geom.h"
16#include "BLI_math_vector.h"
17#include "BLI_vector.hh"
18
19#include "BKE_customdata.hh"
20
21#include "bmesh.hh"
22
23#include "intern/bmesh_operators_private.hh" /* own include */
24
25#define USE_EDGE_REGION_FLAGS
26
27enum {
32};
33
34#define VERT_MARK 1
35#define EDGE_MARK 1
36#define FACE_MARK 1
37#define VERT_NONMAN 2
38#define EDGE_NONMAN 2
39
41{
42 const bool use_select_history = BMO_slot_bool_get(op->slots_in, "use_select_history");
43 GHash *select_history_map = nullptr;
44
45 BMOIter siter;
46 BMFace *f_org;
47
48 if (use_select_history) {
49 select_history_map = BM_select_history_map_create(bm);
50 }
51
52 BMO_ITER (f_org, &siter, op->slots_in, "faces", BM_FACE) {
53 BMFace *f_new;
54 BMLoop *l_org, *l_org_first;
55 BMLoop *l_new;
56
58
59 f_new = BM_face_copy(bm, f_org, true, true);
61
62 if (select_history_map) {
63 BMEditSelection *ese;
64 ese = static_cast<BMEditSelection *>(BLI_ghash_lookup(select_history_map, f_org));
65 if (ese) {
66 ese->ele = (BMElem *)f_new;
67 }
68 }
69
70 l_org = l_org_first = BM_FACE_FIRST_LOOP(f_org);
71 l_new = BM_FACE_FIRST_LOOP(f_new);
72
73 do {
74 BMFace *f_side;
75 BMLoop *l_side_iter;
76
77 BM_elem_attrs_copy(bm, l_org, l_new);
78
80 bm, l_org->next->v, l_new->next->v, l_new->v, l_org->v, f_org, BM_CREATE_NOP);
81
82 l_side_iter = BM_FACE_FIRST_LOOP(f_side);
83
84 BM_elem_attrs_copy(bm, l_org->next, l_side_iter);
85 l_side_iter = l_side_iter->next;
86 BM_elem_attrs_copy(bm, l_org->next, l_side_iter);
87 l_side_iter = l_side_iter->next;
88 BM_elem_attrs_copy(bm, l_org, l_side_iter);
89 l_side_iter = l_side_iter->next;
90 BM_elem_attrs_copy(bm, l_org, l_side_iter);
91
92 if (select_history_map) {
93 BMEditSelection *ese;
94
95 ese = static_cast<BMEditSelection *>(BLI_ghash_lookup(select_history_map, l_org->v));
96 if (ese) {
97 ese->ele = (BMElem *)l_new->v;
98 }
99 ese = static_cast<BMEditSelection *>(BLI_ghash_lookup(select_history_map, l_org->e));
100 if (ese) {
101 ese->ele = (BMElem *)l_new->e;
102 }
103 }
104
105 } while (((void)(l_new = l_new->next), (l_org = l_org->next)) != l_org_first);
106 }
107
108 if (select_history_map) {
109 BLI_ghash_free(select_history_map, nullptr, nullptr);
110 }
111
112 BMO_op_callf(bm, op->flag, "delete geom=%ff context=%i", EXT_DEL, DEL_ONLYFACES);
114}
115
127{
128 /* edge we are extruded from */
129 BMLoop *l_first_0 = BM_FACE_FIRST_LOOP(f);
130 BMLoop *l_first_1 = l_first_0->next;
131 BMLoop *l_first_2 = l_first_1->next;
132 BMLoop *l_first_3 = l_first_2->next;
133
134 BMLoop *l_other_0;
135 BMLoop *l_other_1;
136
137 if (UNLIKELY(l_first_0 == l_first_0->radial_next)) {
138 return;
139 }
140
141 l_other_0 = BM_edge_other_loop(l_first_0->e, l_first_0);
142 l_other_1 = BM_edge_other_loop(l_first_0->e, l_first_1);
143
144 /* copy data */
145 BM_elem_attrs_copy(bm, l_other_0->f, f);
146 BM_elem_flag_disable(f, BM_ELEM_HIDDEN); /* possibly we copy from a hidden face */
147
148 BM_elem_attrs_copy(bm, l_other_0, l_first_0);
149 BM_elem_attrs_copy(bm, l_other_0, l_first_3);
150
151 BM_elem_attrs_copy(bm, l_other_1, l_first_1);
152 BM_elem_attrs_copy(bm, l_other_1, l_first_2);
153}
154
155/* Disable the skin root flag on the input vert, assumes that the vert
156 * data includes an CD_MVERT_SKIN layer */
158{
159 MVertSkin *vs;
160
161 vs = static_cast<MVertSkin *>(CustomData_bmesh_get(&bm->vdata, v->head.data, CD_MVERT_SKIN));
162 vs->flag &= ~MVERT_SKIN_ROOT;
163}
164
166{
167 BMOIter siter;
168 BMOperator dupeop;
169 BMFace *f;
170 BMEdge *e, *e_new;
171 const bool use_normal_flip = BMO_slot_bool_get(op->slots_in, "use_normal_flip");
172
173 BMO_ITER (e, &siter, op->slots_in, "edges", BM_EDGE) {
177 }
178
180 &dupeop,
181 op->flag,
182 "duplicate geom=%fve use_select_history=%b",
183 EXT_INPUT,
184 BMO_slot_bool_get(op->slots_in, "use_select_history"));
185
186 BMO_op_exec(bm, &dupeop);
187
188 /* disable root flag on all new skin nodes */
189 if (CustomData_has_layer(&bm->vdata, CD_MVERT_SKIN)) {
190 BMVert *v;
191 BMO_ITER (v, &siter, dupeop.slots_out, "geom.out", BM_VERT) {
193 }
194 }
195
196 for (e = static_cast<BMEdge *>(BMO_iter_new(&siter, dupeop.slots_out, "boundary_map.out", 0)); e;
197 e = static_cast<BMEdge *>(BMO_iter_step(&siter)))
198 {
199 BMVert *f_verts[4];
200 e_new = static_cast<BMEdge *>(BMO_iter_map_value_ptr(&siter));
201
202 const bool edge_normal_flip = !(e->l && e->v1 != e->l->v);
203 if (edge_normal_flip == use_normal_flip) {
204 f_verts[0] = e->v1;
205 f_verts[1] = e->v2;
206 f_verts[2] = e_new->v2;
207 f_verts[3] = e_new->v1;
208 }
209 else {
210 f_verts[0] = e->v2;
211 f_verts[1] = e->v1;
212 f_verts[2] = e_new->v1;
213 f_verts[3] = e_new->v2;
214 }
215 /* not sure what to do about example face, pass nullptr for now */
216 f = BM_face_create_verts(bm, f_verts, 4, nullptr, BM_CREATE_NOP, true);
218
220 e = e_new;
221 }
222
227 }
228
229 BMO_op_finish(bm, &dupeop);
230
232}
233
235{
236 const bool use_select_history = BMO_slot_bool_get(op->slots_in, "use_select_history");
237 BMOIter siter;
238 BMVert *v, *dupev;
239 BMEdge *e;
240 const bool has_vskin = CustomData_has_layer(&bm->vdata, CD_MVERT_SKIN);
241 GHash *select_history_map = nullptr;
242
243 if (use_select_history) {
244 select_history_map = BM_select_history_map_create(bm);
245 }
246
247 for (v = static_cast<BMVert *>(BMO_iter_new(&siter, op->slots_in, "verts", BM_VERT)); v;
248 v = static_cast<BMVert *>(BMO_iter_step(&siter)))
249 {
250 dupev = BM_vert_create(bm, v->co, v, BM_CREATE_NOP);
252
253 if (has_vskin) {
255 }
256
257 if (select_history_map) {
258 BMEditSelection *ese;
259 ese = static_cast<BMEditSelection *>(BLI_ghash_lookup(select_history_map, v));
260 if (ese) {
261 ese->ele = (BMElem *)dupev;
262 }
263 }
264
265 /* not essential, but ensures face normals from extruded edges are contiguous */
266 if (BM_vert_is_wire_endpoint(v)) {
267 if (v->e->v1 == v) {
268 std::swap(v, dupev);
269 }
270 }
271
272 e = BM_edge_create(bm, v, dupev, nullptr, BM_CREATE_NOP);
274 }
275
276 if (select_history_map) {
277 BLI_ghash_free(select_history_map, nullptr, nullptr);
278 }
279
282}
283
284#ifdef USE_EDGE_REGION_FLAGS
289static bool bm_extrude_region_edge_flag(const BMVert *v, char r_e_hflag[2])
290{
291 BMEdge *e_iter;
292 const char hflag_enable = BM_ELEM_SEAM;
293 const char hflag_disable = BM_ELEM_SMOOTH;
294 bool ok = false;
295
296 r_e_hflag[0] = 0x0;
297 r_e_hflag[1] = 0xff;
298
299 /* clear flags on both disks */
300 e_iter = v->e;
301 do {
302 if (e_iter->l && !BM_edge_is_boundary(e_iter)) {
303 r_e_hflag[0] |= e_iter->head.hflag;
304 r_e_hflag[1] &= e_iter->head.hflag;
305 ok = true;
306 }
307 } while ((e_iter = BM_DISK_EDGE_NEXT(e_iter, v)) != v->e);
308
309 if (ok) {
310 r_e_hflag[0] &= hflag_enable;
311 r_e_hflag[1] = hflag_disable & ~r_e_hflag[1];
312 }
313 return ok;
314}
315#endif /* USE_EDGE_REGION_FLAGS */
316
318{
319 BMOperator dupeop, delop;
320 BMOIter siter;
321 BMIter iter, fiter, viter;
322 BMEdge *e, *e_new;
323 BMVert *v;
324 BMFace *f;
325 bool found, delorig = false;
326 BMOpSlot *slot_facemap_out;
327 BMOpSlot *slot_edges_exclude;
328 const bool use_normal_flip = BMO_slot_bool_get(op->slots_in, "use_normal_flip");
329 const bool use_normal_from_adjacent = BMO_slot_bool_get(op->slots_in,
330 "use_normal_from_adjacent");
331 const bool use_dissolve_ortho_edges = BMO_slot_bool_get(op->slots_in,
332 "use_dissolve_ortho_edges");
333
334 /* initialize our sub-operators */
336 &dupeop,
337 op->flag,
338 "duplicate use_select_history=%b",
339 BMO_slot_bool_get(op->slots_in, "use_select_history"));
340
342
343 /* if one flagged face is bordered by an un-flagged face, then we delete
344 * original geometry unless caller explicitly asked to keep it. */
345 if (!BMO_slot_bool_get(op->slots_in, "use_keep_orig")) {
346 BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
347
348 int edge_face_tot;
349
351 continue;
352 }
353
354 found = false; /* found a face that isn't input? */
355 edge_face_tot = 0; /* edge/face count */
356
357 BM_ITER_ELEM (f, &fiter, e, BM_FACES_OF_EDGE) {
358 if (!BMO_face_flag_test(bm, f, EXT_INPUT)) {
359 found = true;
360 delorig = true;
361 break;
362 }
363
364 edge_face_tot++;
365 }
366
367 if ((edge_face_tot > 1) && (found == false)) {
368 /* edge has a face user, that face isn't extrude input */
370 }
371 }
372 }
373
374 /* calculate verts to delete */
375 BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
376 if (v->e) { /* only deal with verts attached to geometry #33651. */
377 found = false;
378
379 BM_ITER_ELEM (e, &viter, v, BM_EDGES_OF_VERT) {
381 found = true;
382 break;
383 }
384 }
385
386 /* avoid an extra loop */
387 if (found == false) {
388 BM_ITER_ELEM (f, &viter, v, BM_FACES_OF_VERT) {
389 if (!BMO_face_flag_test(bm, f, EXT_INPUT)) {
390 found = true;
391 break;
392 }
393 }
394 }
395
396 if (found == false) {
398 }
399 }
400 }
401
402 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
405 }
406 }
407
408 if (delorig == true) {
409 BMO_op_initf(bm, &delop, op->flag, "delete geom=%fvef context=%i", EXT_DEL, DEL_ONLYTAGGED);
410 }
411
412 BMO_slot_copy(op, slots_in, "geom", &dupeop, slots_in, "geom");
413 BMO_op_exec(bm, &dupeop);
414
415 /* disable root flag on all new skin nodes */
416 if (CustomData_has_layer(&bm->vdata, CD_MVERT_SKIN)) {
417 BMO_ITER (v, &siter, dupeop.slots_out, "geom.out", BM_VERT) {
419 }
420 }
421
422 slot_facemap_out = BMO_slot_get(dupeop.slots_out, "face_map.out");
423 if (bm->act_face && BMO_face_flag_test(bm, bm->act_face, EXT_INPUT)) {
424 bm->act_face = static_cast<BMFace *>(BMO_slot_map_elem_get(slot_facemap_out, bm->act_face));
425 }
426
427 if (delorig) {
428 BMO_op_exec(bm, &delop);
429 }
430
431 const bool skip_input_flip = BMO_slot_bool_get(op->slots_in, "skip_input_flip");
432
433 /* Flip input faces only when originals are kept (!delorig)
434 * and the caller didn't request to skip flipping (!skip_input_flip).*/
435 if (!delorig && !skip_input_flip) {
436 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
439 }
440 }
441 }
442
443 BMVert **dissolve_verts = nullptr;
444 int dissolve_verts_len = 0;
445 float average_normal[3];
446 if (use_dissolve_ortho_edges) {
447 /* Calc average normal. */
448 zero_v3(average_normal);
449 BMO_ITER (f, &siter, dupeop.slots_out, "geom.out", BM_FACE) {
450 add_v3_v3(average_normal, f->no);
451 }
452 if (normalize_v3(average_normal) == 0.0f) {
453 average_normal[2] = 1.0f;
454 }
455
456 /* Allocate array to store possible vertices that will be dissolved. */
457 int boundary_edges_len = BMO_slot_map_len(dupeop.slots_out, "boundary_map.out");
458 /* We do not know the real number of boundary vertices. */
459 int boundary_verts_len_maybe = 2 * boundary_edges_len;
460 dissolve_verts = static_cast<BMVert **>(
461 MEM_mallocN(boundary_verts_len_maybe * sizeof(*dissolve_verts), __func__));
462 }
463
464 BMO_slot_copy(&dupeop, slots_out, "geom.out", op, slots_out, "geom.out");
465
466 slot_edges_exclude = BMO_slot_get(op->slots_in, "edges_exclude");
467 for (e = static_cast<BMEdge *>(BMO_iter_new(&siter, dupeop.slots_out, "boundary_map.out", 0)); e;
468 e = static_cast<BMEdge *>(BMO_iter_step(&siter)))
469 {
470 BMVert *f_verts[4];
471#ifdef USE_EDGE_REGION_FLAGS
472 BMEdge *f_edges[4];
473#endif
474
475 /* this should always be wire, so this is mainly a speedup to avoid map lookup */
476 if (BM_edge_is_wire(e) && BMO_slot_map_contains(slot_edges_exclude, e)) {
477 BMVert *v1 = e->v1, *v2 = e->v2;
478
479 /* The original edge was excluded,
480 * this would result in a standalone wire edge - see #30399. */
481 BM_edge_kill(bm, e);
482
483 /* kill standalone vertices from this edge - see #32341. */
484 if (!v1->e) {
485 BM_vert_kill(bm, v1);
486 }
487 if (!v2->e) {
489 }
490
491 continue;
492 }
493
494 /* skip creating face for excluded edges see #35503. */
495 if (BMO_slot_map_contains(slot_edges_exclude, e)) {
496 /* simply skip creating the face */
497 continue;
498 }
499
500 e_new = static_cast<BMEdge *>(BMO_iter_map_value_ptr(&siter));
501
502 if (!e_new) {
503 continue;
504 }
505
506 BMFace *join_face = nullptr;
507 if (use_dissolve_ortho_edges) {
508 if (BM_edge_is_boundary(e)) {
509 join_face = e->l->f;
510 if (fabs(dot_v3v3(average_normal, join_face->no)) > 0.0001f) {
511 join_face = nullptr;
512 }
513 }
514 }
515
516 bool edge_normal_flip;
517 if (use_normal_from_adjacent == false) {
518 /* Orient loop to give same normal as a loop of 'e_new'
519 * if it exists (will be one of the faces from the region),
520 * else same normal as a loop of e, if it exists. */
521 edge_normal_flip = !(e_new->l ? (e_new->l->v == e_new->v1) : (!e->l || !(e->l->v == e->v1)));
522 }
523 else {
524 /* Special case, needed for repetitive extrusions
525 * that use the normals from the previously created faces. */
526 edge_normal_flip = !(e->l && e->v1 != e->l->v);
527 }
528
529 if (edge_normal_flip == use_normal_flip) {
530 f_verts[0] = e->v1;
531 f_verts[1] = e->v2;
532 f_verts[2] = e_new->v2;
533 f_verts[3] = e_new->v1;
534 }
535 else {
536 f_verts[0] = e->v2;
537 f_verts[1] = e->v1;
538 f_verts[2] = e_new->v1;
539 f_verts[3] = e_new->v2;
540 }
541
542#ifdef USE_EDGE_REGION_FLAGS
543 /* handle new edges */
544 f_edges[0] = e;
545 f_edges[2] = e_new;
546
547 f_edges[1] = BM_edge_exists(f_verts[1], f_verts[2]);
548 if (f_edges[1] == nullptr) {
549 char e_hflag[2];
550 bool e_hflag_ok = bm_extrude_region_edge_flag(f_verts[2], e_hflag);
551 f_edges[1] = BM_edge_create(bm, f_verts[1], f_verts[2], nullptr, BM_CREATE_NOP);
552 if (e_hflag_ok) {
553 BM_elem_flag_enable(f_edges[1], e_hflag[0]);
554 BM_elem_flag_disable(f_edges[1], e_hflag[1]);
555 }
556 }
557
558 f_edges[3] = BM_edge_exists(f_verts[3], f_verts[0]);
559 if (f_edges[3] == nullptr) {
560 char e_hflag[2];
561 bool e_hflag_ok = bm_extrude_region_edge_flag(f_verts[3], e_hflag);
562 f_edges[3] = BM_edge_create(bm, f_verts[3], f_verts[0], nullptr, BM_CREATE_NOP);
563 if (e_hflag_ok) {
564 BM_elem_flag_enable(f_edges[3], e_hflag[0]);
565 BM_elem_flag_disable(f_edges[3], e_hflag[1]);
566 }
567 }
568
569 f = BM_face_create(bm, f_verts, f_edges, 4, nullptr, BM_CREATE_NOP);
570#else
571 f = BM_face_create_verts(bm, f_verts, 4, nullptr, BM_CREATE_NOP, true);
572#endif
573
575 if (join_face) {
576 BMVert *v1 = e->v1;
577 BMVert *v2 = e->v2;
578 if (!BMO_elem_flag_test(bm, v1, EXT_TAG)) {
580 dissolve_verts[dissolve_verts_len++] = v1;
581 }
584 dissolve_verts[dissolve_verts_len++] = v2;
585 }
586 /* Tag the edges that can collapse. */
587 BMO_elem_flag_enable(bm, f_edges[0], EXT_TAG);
588 BMO_elem_flag_enable(bm, f_edges[1], EXT_TAG);
589 bmesh_kernel_join_face_kill_edge(bm, join_face, f, e);
590 }
591 }
592
593 /* link isolated vert */
594 for (v = static_cast<BMVert *>(BMO_iter_new(&siter, dupeop.slots_out, "isovert_map.out", 0)); v;
595 v = static_cast<BMVert *>(BMO_iter_step(&siter)))
596 {
597 BMVert *v2 = static_cast<BMVert *>(BMO_iter_map_value_ptr(&siter));
598
599 /* not essential, but ensures face normals from extruded edges are contiguous */
600 if (BM_vert_is_wire_endpoint(v)) {
601 if (v->e->v1 == v) {
602 std::swap(v, v2);
603 }
604 }
605
607 }
608
609 if (dissolve_verts) {
610 BMVert **v_iter = &dissolve_verts[0];
611 for (int i = dissolve_verts_len; i--; v_iter++) {
612 v = *v_iter;
613 e = v->e;
614 BMEdge *e_other = BM_DISK_EDGE_NEXT(e, v);
615 if ((e_other == e) || (BM_DISK_EDGE_NEXT(e_other, v) == e)) {
616 /* Loose edge or BMVert is edge pair. */
617 BM_edge_collapse(bm, BMO_elem_flag_test(bm, e, EXT_TAG) ? e : e_other, v, true, true);
618 }
619 else {
621 }
622 }
623 MEM_freeN(dissolve_verts);
624 }
625
626 /* cleanup */
627 if (delorig) {
628 BMO_op_finish(bm, &delop);
629 }
630 BMO_op_finish(bm, &dupeop);
631}
632
633/*
634 * Compute higher-quality vertex normals used by solidify.
635 * Only considers geometry in the marked solidify region.
636 * Note that this does not work so well for non-manifold
637 * regions.
638 */
640{
641 BMIter viter, eiter, fiter;
642 BMVert *v;
643 BMEdge *e;
644 BMFace *f, *f1, *f2;
645 float edge_normal[3];
646 int i;
647
648 /* can't use BM_edge_face_count because we need to count only marked faces */
649 int *edge_face_count = MEM_calloc_arrayN<int>(bm->totedge, __func__);
650
651 BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) {
653 }
654
656
657 BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
658 if (!BMO_face_flag_test(bm, f, FACE_MARK)) {
659 continue;
660 }
661
662 BM_ITER_ELEM (e, &eiter, f, BM_EDGES_OF_FACE) {
663
664 /* And mark all edges and vertices on the
665 * marked faces */
669 edge_face_count[BM_elem_index_get(e)]++;
670 }
671 }
672
673 BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) {
675 continue;
676 }
677
678 i = edge_face_count[BM_elem_index_get(e)];
679
680 if (i == 0 || i > 2) {
681 /* Edge & vertices are non-manifold even when considering
682 * only marked faces */
686 }
687 }
688 MEM_freeN(edge_face_count);
689 edge_face_count = nullptr; /* don't re-use */
690
691 BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) {
692 if (!BM_vert_is_manifold(v)) {
694 continue;
695 }
696
698 zero_v3(v->no);
699 }
700 }
701
702 BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) {
703
704 /* If the edge is not part of the solidify region
705 * its normal should not be considered */
707 continue;
708 }
709
710 /* If the edge joins more than two marked faces high
711 * quality normal computation won't work */
713 continue;
714 }
715
716 f1 = f2 = nullptr;
717
718 BM_ITER_ELEM (f, &fiter, e, BM_FACES_OF_EDGE) {
720 if (f1 == nullptr) {
721 f1 = f;
722 }
723 else {
724 BLI_assert(f2 == nullptr);
725 f2 = f;
726 }
727 }
728 }
729
730 BLI_assert(f1 != nullptr);
731
732 if (f2 != nullptr) {
733 const float angle = angle_normalized_v3v3(f1->no, f2->no);
734
735 if (angle > 0.0f) {
736 /* two faces using this edge, calculate the edge normal
737 * using the angle between the faces as a weighting */
738 add_v3_v3v3(edge_normal, f1->no, f2->no);
739 normalize_v3_length(edge_normal, angle);
740 }
741 else {
742 /* can't do anything useful here!
743 * Set the face index for a vert in case it gets a zero normal */
746 continue;
747 }
748 }
749 else {
750 /* only one face attached to that edge */
751 /* an edge without another attached- the weight on this is undefined,
752 * M_PI_2 is 90d in radians and that seems good enough */
753 copy_v3_v3(edge_normal, f1->no);
754 mul_v3_fl(edge_normal, M_PI_2);
755 }
756
757 add_v3_v3(e->v1->no, edge_normal);
758 add_v3_v3(e->v2->no, edge_normal);
759 }
760
761 /* normalize accumulated vertex normal */
762 BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) {
764 continue;
765 }
766
768 /* use standard normals for vertices connected to non-manifold edges */
770 }
771 else if (normalize_v3(v->no) == 0.0f && !BM_elem_flag_test(v, BM_ELEM_TAG)) {
772 /* exceptional case, totally flat. use the normal
773 * of any marked face around the vertex */
774 BM_ITER_ELEM (f, &fiter, v, BM_FACES_OF_VERT) {
776 break;
777 }
778 }
779 copy_v3_v3(v->no, f->no);
780 }
781 }
782}
783
784static void solidify_add_thickness(BMesh *bm, const float dist)
785{
786 BMFace *f;
787 BMVert *v;
788 BMLoop *l;
789 BMIter iter, loopIter;
790 float *vert_angles = MEM_calloc_arrayN<float>(size_t(bm->totvert) * 2, "solidify"); /* 2 in 1 */
791 float *vert_accum = vert_angles + bm->totvert;
792 int i, index;
793
796
798
799 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
801
802 /* array for passing verts to angle_poly_v3 */
803 face_angles.resize(f->len);
804 /* array for receiving angles from angle_poly_v3 */
805 verts.resize(f->len);
806
807 BM_ITER_ELEM_INDEX (l, &loopIter, f, BM_LOOPS_OF_FACE, i) {
808 verts[i] = l->v->co;
809 }
810
811 angle_poly_v3(face_angles.data(), (const float **)verts.data(), f->len);
812
813 i = 0;
814 BM_ITER_ELEM (l, &loopIter, f, BM_LOOPS_OF_FACE) {
815 v = l->v;
816 index = BM_elem_index_get(v);
817 vert_accum[index] += face_angles[i];
818 vert_angles[index] += shell_v3v3_normalized_to_dist(v->no, f->no) * face_angles[i];
819 i++;
820 }
821 }
822 }
823
824 BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
825 index = BM_elem_index_get(v);
826 if (vert_accum[index]) { /* zero if unselected */
827 madd_v3_v3fl(v->co, v->no, dist * (vert_angles[index] / vert_accum[index]));
828 }
829 }
830
831 MEM_freeN(vert_angles);
832}
833
835{
836 BMOperator extrudeop;
837 BMOperator reverseop;
838 float thickness;
839
840 thickness = BMO_slot_float_get(op->slots_in, "thickness");
841
842 /* Flip original faces (so the shell is extruded inward) */
843 BMO_op_init(bm, &reverseop, op->flag, "reverse_faces");
844 BMO_slot_bool_set(reverseop.slots_in, "flip_multires", true);
845 BMO_slot_copy(op, slots_in, "geom", &reverseop, slots_in, "faces");
846 BMO_op_exec(bm, &reverseop);
847 BMO_op_finish(bm, &reverseop);
848
849 /* Extrude the region */
850 BMO_op_initf(bm, &extrudeop, op->flag, "extrude_face_region use_keep_orig=%b", true);
851 BMO_slot_copy(op, slots_in, "geom", &extrudeop, slots_in, "geom");
852 BMO_op_exec(bm, &extrudeop);
853
854 /* Push the verts of the extruded faces inward to create thickness */
855 BMO_slot_buffer_flag_enable(bm, extrudeop.slots_out, "geom.out", BM_FACE, FACE_MARK);
857 solidify_add_thickness(bm, thickness);
858
859 BMO_slot_copy(&extrudeop, slots_out, "geom.out", op, slots_out, "geom.out");
860
861 BMO_op_finish(bm, &extrudeop);
862}
CustomData interface, see also DNA_customdata_types.h.
void * CustomData_bmesh_get(const CustomData *data, void *block, eCustomDataType type)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
#define BLI_assert(a)
Definition BLI_assert.h:46
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:731
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:860
#define M_PI_2
MINLINE float shell_v3v3_normalized_to_dist(const float a[3], const float b[3])
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void angle_poly_v3(float *angles, const float *verts[3], int len)
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_length(float n[3], float unit_length)
MINLINE float normalize_v3(float n[3])
#define UNLIKELY(x)
@ CD_MVERT_SKIN
@ MVERT_SKIN_ROOT
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
Read Guarded memory(de)allocation.
#define BM_DISK_EDGE_NEXT(e, v)
#define BM_ALL_NOLOOP
#define BM_FACE_FIRST_LOOP(p)
@ BM_ELEM_HIDDEN
@ BM_ELEM_SEAM
@ BM_ELEM_SMOOTH
@ BM_ELEM_TAG
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
BMFace * BM_face_create_quad_tri(BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4, const BMFace *f_example, const eBMCreateFlag create_flag)
Make Quad/Triangle.
void BM_vert_kill(BMesh *bm, BMVert *v)
BMFace * bmesh_kernel_join_face_kill_edge(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e)
Join Face Kill Edge (JFKE).
BMFace * BM_face_create_verts(BMesh *bm, BMVert **vert_arr, const int len, const BMFace *f_example, const eBMCreateFlag create_flag, const bool create_edges)
BMFace * BM_face_copy(BMesh *bm_dst, const BMCustomDataCopyMap &cd_face_map, const BMCustomDataCopyMap &cd_loop_map, BMFace *f, const bool copy_verts, const bool copy_edges)
BMFace * BM_face_create(BMesh *bm, BMVert *const *verts, BMEdge *const *edges, const int len, const BMFace *f_example, const eBMCreateFlag create_flag)
void BM_edge_kill(BMesh *bm, BMEdge *e)
BMVert * BM_vert_create(BMesh *bm, const float co[3], const BMVert *v_example, const eBMCreateFlag create_flag)
Main function for creating a new vertex.
Definition bmesh_core.cc:41
BMEdge * BM_edge_create(BMesh *bm, BMVert *v1, BMVert *v2, const BMEdge *e_example, const eBMCreateFlag create_flag)
Main function for creating a new edge.
@ BM_CREATE_NOP
Definition bmesh_core.hh:28
@ BM_CREATE_NO_DOUBLE
Definition bmesh_core.hh:30
#define BM_elem_index_get(ele)
#define BM_elem_flag_disable(ele, hflag)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
@ BM_FACES_OF_EDGE
@ BM_FACES_OF_VERT
@ BM_EDGES_OF_MESH
@ BM_VERTS_OF_MESH
@ BM_FACES_OF_MESH
@ BM_EDGES_OF_VERT
@ BM_EDGES_OF_FACE
@ BM_LOOPS_OF_FACE
#define BM_ITER_ELEM_INDEX(ele, iter, data, itype, indexvar)
BMesh * bm
GHash * BM_select_history_map_create(BMesh *bm)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
BMVert * BM_edge_collapse(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool do_del, const bool kill_degenerate_faces)
#define BM_FACE
#define BM_EDGE
#define BM_VERT
@ DEL_ONLYTAGGED
@ DEL_ONLYFACES
void BMO_slot_buffer_flag_enable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, short oflag)
BMO_FLAG_BUFFER.
#define BMO_edge_flag_test(bm, e, oflag)
void * BMO_iter_map_value_ptr(BMOIter *iter)
#define BMO_edge_flag_enable(bm, e, oflag)
int BMO_slot_map_len(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
float BMO_slot_float_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
#define BMO_vert_flag_enable(bm, e, oflag)
void * BMO_iter_new(BMOIter *iter, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char restrictmask)
New Iterator.
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_slot_buffer_from_enabled_flag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, short oflag)
#define BMO_face_flag_enable(bm, e, oflag)
#define BMO_slot_copy(op_src, slots_src, slot_name_src, op_dst, slots_dst, slot_name_dst)
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)
#define BMO_vert_flag_test(bm, e, oflag)
bool BMO_op_initf(BMesh *bm, BMOperator *op, int flag, const char *fmt,...)
void BMO_op_finish(BMesh *bm, BMOperator *op)
BMESH OPSTACK FINISH OP.
#define BMO_elem_flag_enable(bm, ele, oflag)
bool BMO_op_callf(BMesh *bm, int flag, const char *fmt,...)
void BMO_slot_bool_set(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, bool i)
#define BMO_elem_flag_test(bm, ele, oflag)
#define BMO_face_flag_test(bm, e, oflag)
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
void * BMO_iter_step(BMOIter *iter)
void BM_vert_normal_update(BMVert *v)
void BM_face_normal_flip(BMesh *bm, BMFace *f)
bool BM_vert_is_manifold(const BMVert *v)
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
BMLoop * BM_edge_other_loop(BMEdge *e, BMLoop *l)
bool BM_vert_is_edge_pair(const BMVert *v)
BLI_INLINE bool BM_edge_is_boundary(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
BLI_INLINE bool BM_edge_is_wire(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define FACE_MARK
#define EDGE_MARK
Definition bmo_bridge.cc:26
#define VERT_MARK
static void solidify_add_thickness(BMesh *bm, const float dist)
void bmo_extrude_discrete_faces_exec(BMesh *bm, BMOperator *op)
static void bm_extrude_copy_face_loop_attributes(BMesh *bm, BMFace *f)
Copy the loop pair from an adjacent face to both sides of this quad.
static bool bm_extrude_region_edge_flag(const BMVert *v, char r_e_hflag[2])
void bmo_extrude_edge_only_exec(BMesh *bm, BMOperator *op)
void bmo_extrude_vert_indiv_exec(BMesh *bm, BMOperator *op)
void bmo_solidify_face_region_exec(BMesh *bm, BMOperator *op)
@ EXT_INPUT
@ EXT_TAG
@ EXT_KEEP
@ EXT_DEL
#define EDGE_NONMAN
#define VERT_NONMAN
static void bm_extrude_disable_skin_root(BMesh *bm, BMVert *v)
static void calc_solidify_normals(BMesh *bm)
void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op)
void resize(const int64_t new_size)
static float verts[][3]
void * MEM_mallocN(size_t len, const char *str)
Definition mallocn.cc:128
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:123
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
ccl_device_inline float2 fabs(const float2 a)
BMHeader head
BMVert * v1
BMVert * v2
struct BMLoop * l
float no[3]
struct BMVert * v
struct BMEdge * e
struct BMLoop * radial_next
struct BMFace * f
struct BMLoop * next
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
struct BMEdge * e
i
Definition text_draw.cc:230