Blender V4.3
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
11#include "MEM_guardedalloc.h"
12
13#include "DNA_meshdata_types.h"
14
15#include "BLI_buffer.h"
16#include "BLI_math_geom.h"
17#include "BLI_math_vector.h"
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 */
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 */
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");
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 /* if not delorig, reverse loops of original face */
432 if (!delorig) {
433 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
436 }
437 }
438 }
439
440 BMVert **dissolve_verts = nullptr;
441 int dissolve_verts_len = 0;
442 float average_normal[3];
443 if (use_dissolve_ortho_edges) {
444 /* Calc average normal. */
445 zero_v3(average_normal);
446 BMO_ITER (f, &siter, dupeop.slots_out, "geom.out", BM_FACE) {
447 add_v3_v3(average_normal, f->no);
448 }
449 if (normalize_v3(average_normal) == 0.0f) {
450 average_normal[2] = 1.0f;
451 }
452
453 /* Allocate array to store possible vertices that will be dissolved. */
454 int boundary_edges_len = BMO_slot_map_len(dupeop.slots_out, "boundary_map.out");
455 /* We do not know the real number of boundary vertices. */
456 int boundary_verts_len_maybe = 2 * boundary_edges_len;
457 dissolve_verts = static_cast<BMVert **>(
458 MEM_mallocN(boundary_verts_len_maybe * sizeof(*dissolve_verts), __func__));
459 }
460
461 BMO_slot_copy(&dupeop, slots_out, "geom.out", op, slots_out, "geom.out");
462
463 slot_edges_exclude = BMO_slot_get(op->slots_in, "edges_exclude");
464 for (e = static_cast<BMEdge *>(BMO_iter_new(&siter, dupeop.slots_out, "boundary_map.out", 0)); e;
465 e = static_cast<BMEdge *>(BMO_iter_step(&siter)))
466 {
467 BMVert *f_verts[4];
468#ifdef USE_EDGE_REGION_FLAGS
469 BMEdge *f_edges[4];
470#endif
471
472 /* this should always be wire, so this is mainly a speedup to avoid map lookup */
473 if (BM_edge_is_wire(e) && BMO_slot_map_contains(slot_edges_exclude, e)) {
474 BMVert *v1 = e->v1, *v2 = e->v2;
475
476 /* The original edge was excluded,
477 * this would result in a standalone wire edge - see #30399. */
478 BM_edge_kill(bm, e);
479
480 /* kill standalone vertices from this edge - see #32341. */
481 if (!v1->e) {
482 BM_vert_kill(bm, v1);
483 }
484 if (!v2->e) {
486 }
487
488 continue;
489 }
490
491 /* skip creating face for excluded edges see #35503. */
492 if (BMO_slot_map_contains(slot_edges_exclude, e)) {
493 /* simply skip creating the face */
494 continue;
495 }
496
497 e_new = static_cast<BMEdge *>(BMO_iter_map_value_ptr(&siter));
498
499 if (!e_new) {
500 continue;
501 }
502
503 BMFace *join_face = nullptr;
504 if (use_dissolve_ortho_edges) {
505 if (BM_edge_is_boundary(e)) {
506 join_face = e->l->f;
507 if (fabs(dot_v3v3(average_normal, join_face->no)) > 0.0001f) {
508 join_face = nullptr;
509 }
510 }
511 }
512
513 bool edge_normal_flip;
514 if (use_normal_from_adjacent == false) {
515 /* Orient loop to give same normal as a loop of 'e_new'
516 * if it exists (will be one of the faces from the region),
517 * else same normal as a loop of e, if it exists. */
518 edge_normal_flip = !(e_new->l ? (e_new->l->v == e_new->v1) : (!e->l || !(e->l->v == e->v1)));
519 }
520 else {
521 /* Special case, needed for repetitive extrusions
522 * that use the normals from the previously created faces. */
523 edge_normal_flip = !(e->l && e->v1 != e->l->v);
524 }
525
526 if (edge_normal_flip == use_normal_flip) {
527 f_verts[0] = e->v1;
528 f_verts[1] = e->v2;
529 f_verts[2] = e_new->v2;
530 f_verts[3] = e_new->v1;
531 }
532 else {
533 f_verts[0] = e->v2;
534 f_verts[1] = e->v1;
535 f_verts[2] = e_new->v1;
536 f_verts[3] = e_new->v2;
537 }
538
539#ifdef USE_EDGE_REGION_FLAGS
540 /* handle new edges */
541 f_edges[0] = e;
542 f_edges[2] = e_new;
543
544 f_edges[1] = BM_edge_exists(f_verts[1], f_verts[2]);
545 if (f_edges[1] == nullptr) {
546 char e_hflag[2];
547 bool e_hflag_ok = bm_extrude_region_edge_flag(f_verts[2], e_hflag);
548 f_edges[1] = BM_edge_create(bm, f_verts[1], f_verts[2], nullptr, BM_CREATE_NOP);
549 if (e_hflag_ok) {
550 BM_elem_flag_enable(f_edges[1], e_hflag[0]);
551 BM_elem_flag_disable(f_edges[1], e_hflag[1]);
552 }
553 }
554
555 f_edges[3] = BM_edge_exists(f_verts[3], f_verts[0]);
556 if (f_edges[3] == nullptr) {
557 char e_hflag[2];
558 bool e_hflag_ok = bm_extrude_region_edge_flag(f_verts[3], e_hflag);
559 f_edges[3] = BM_edge_create(bm, f_verts[3], f_verts[0], nullptr, BM_CREATE_NOP);
560 if (e_hflag_ok) {
561 BM_elem_flag_enable(f_edges[3], e_hflag[0]);
562 BM_elem_flag_disable(f_edges[3], e_hflag[1]);
563 }
564 }
565
566 f = BM_face_create(bm, f_verts, f_edges, 4, nullptr, BM_CREATE_NOP);
567#else
568 f = BM_face_create_verts(bm, f_verts, 4, nullptr, BM_CREATE_NOP, true);
569#endif
570
572 if (join_face) {
573 BMVert *v1 = e->v1;
574 BMVert *v2 = e->v2;
575 if (!BMO_elem_flag_test(bm, v1, EXT_TAG)) {
577 dissolve_verts[dissolve_verts_len++] = v1;
578 }
581 dissolve_verts[dissolve_verts_len++] = v2;
582 }
583 /* Tag the edges that can collapse. */
584 BMO_elem_flag_enable(bm, f_edges[0], EXT_TAG);
585 BMO_elem_flag_enable(bm, f_edges[1], EXT_TAG);
586 bmesh_kernel_join_face_kill_edge(bm, join_face, f, e);
587 }
588 }
589
590 /* link isolated vert */
591 for (v = static_cast<BMVert *>(BMO_iter_new(&siter, dupeop.slots_out, "isovert_map.out", 0)); v;
592 v = static_cast<BMVert *>(BMO_iter_step(&siter)))
593 {
594 BMVert *v2 = static_cast<BMVert *>(BMO_iter_map_value_ptr(&siter));
595
596 /* not essential, but ensures face normals from extruded edges are contiguous */
597 if (BM_vert_is_wire_endpoint(v)) {
598 if (v->e->v1 == v) {
599 std::swap(v, v2);
600 }
601 }
602
604 }
605
606 if (dissolve_verts) {
607 BMVert **v_iter = &dissolve_verts[0];
608 for (int i = dissolve_verts_len; i--; v_iter++) {
609 v = *v_iter;
610 e = v->e;
611 BMEdge *e_other = BM_DISK_EDGE_NEXT(e, v);
612 if ((e_other == e) || (BM_DISK_EDGE_NEXT(e_other, v) == e)) {
613 /* Loose edge or BMVert is edge pair. */
614 BM_edge_collapse(bm, BMO_elem_flag_test(bm, e, EXT_TAG) ? e : e_other, v, true, true);
615 }
616 else {
618 }
619 }
620 MEM_freeN(dissolve_verts);
621 }
622
623 /* cleanup */
624 if (delorig) {
625 BMO_op_finish(bm, &delop);
626 }
627 BMO_op_finish(bm, &dupeop);
628}
629
630/*
631 * Compute higher-quality vertex normals used by solidify.
632 * Only considers geometry in the marked solidify region.
633 * Note that this does not work so well for non-manifold
634 * regions.
635 */
637{
638 BMIter viter, eiter, fiter;
639 BMVert *v;
640 BMEdge *e;
641 BMFace *f, *f1, *f2;
642 float edge_normal[3];
643 int i;
644
645 /* can't use BM_edge_face_count because we need to count only marked faces */
646 int *edge_face_count = static_cast<int *>(MEM_callocN(sizeof(int) * bm->totedge, __func__));
647
648 BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) {
650 }
651
653
654 BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
655 if (!BMO_face_flag_test(bm, f, FACE_MARK)) {
656 continue;
657 }
658
659 BM_ITER_ELEM (e, &eiter, f, BM_EDGES_OF_FACE) {
660
661 /* And mark all edges and vertices on the
662 * marked faces */
666 edge_face_count[BM_elem_index_get(e)]++;
667 }
668 }
669
670 BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) {
672 continue;
673 }
674
675 i = edge_face_count[BM_elem_index_get(e)];
676
677 if (i == 0 || i > 2) {
678 /* Edge & vertices are non-manifold even when considering
679 * only marked faces */
683 }
684 }
685 MEM_freeN(edge_face_count);
686 edge_face_count = nullptr; /* don't re-use */
687
688 BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) {
689 if (!BM_vert_is_manifold(v)) {
691 continue;
692 }
693
695 zero_v3(v->no);
696 }
697 }
698
699 BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) {
700
701 /* If the edge is not part of a the solidify region
702 * its normal should not be considered */
704 continue;
705 }
706
707 /* If the edge joins more than two marked faces high
708 * quality normal computation won't work */
710 continue;
711 }
712
713 f1 = f2 = nullptr;
714
715 BM_ITER_ELEM (f, &fiter, e, BM_FACES_OF_EDGE) {
717 if (f1 == nullptr) {
718 f1 = f;
719 }
720 else {
721 BLI_assert(f2 == nullptr);
722 f2 = f;
723 }
724 }
725 }
726
727 BLI_assert(f1 != nullptr);
728
729 if (f2 != nullptr) {
730 const float angle = angle_normalized_v3v3(f1->no, f2->no);
731
732 if (angle > 0.0f) {
733 /* two faces using this edge, calculate the edge normal
734 * using the angle between the faces as a weighting */
735 add_v3_v3v3(edge_normal, f1->no, f2->no);
736 normalize_v3_length(edge_normal, angle);
737 }
738 else {
739 /* can't do anything useful here!
740 * Set the face index for a vert in case it gets a zero normal */
743 continue;
744 }
745 }
746 else {
747 /* only one face attached to that edge */
748 /* an edge without another attached- the weight on this is undefined,
749 * M_PI_2 is 90d in radians and that seems good enough */
750 copy_v3_v3(edge_normal, f1->no);
751 mul_v3_fl(edge_normal, M_PI_2);
752 }
753
754 add_v3_v3(e->v1->no, edge_normal);
755 add_v3_v3(e->v2->no, edge_normal);
756 }
757
758 /* normalize accumulated vertex normal */
759 BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) {
761 continue;
762 }
763
765 /* use standard normals for vertices connected to non-manifold edges */
767 }
768 else if (normalize_v3(v->no) == 0.0f && !BM_elem_flag_test(v, BM_ELEM_TAG)) {
769 /* exceptional case, totally flat. use the normal
770 * of any marked face around the vertex */
771 BM_ITER_ELEM (f, &fiter, v, BM_FACES_OF_VERT) {
773 break;
774 }
775 }
776 copy_v3_v3(v->no, f->no);
777 }
778 }
779}
780
781static void solidify_add_thickness(BMesh *bm, const float dist)
782{
783 BMFace *f;
784 BMVert *v;
785 BMLoop *l;
786 BMIter iter, loopIter;
787 float *vert_angles = static_cast<float *>(
788 MEM_callocN(sizeof(float) * bm->totvert * 2, "solidify")); /* 2 in 1 */
789 float *vert_accum = vert_angles + bm->totvert;
790 int i, index;
791
794
796
797 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
799
800 /* array for passing verts to angle_poly_v3 */
801 float *face_angles = BLI_buffer_reinit_data(&face_angles_buf, float, f->len);
802 /* array for receiving angles from angle_poly_v3 */
803 float **verts = BLI_buffer_reinit_data(&verts_buf, float *, f->len);
804
805 BM_ITER_ELEM_INDEX (l, &loopIter, f, BM_LOOPS_OF_FACE, i) {
806 verts[i] = l->v->co;
807 }
808
809 angle_poly_v3(face_angles, (const float **)verts, f->len);
810
811 i = 0;
812 BM_ITER_ELEM (l, &loopIter, f, BM_LOOPS_OF_FACE) {
813 v = l->v;
814 index = BM_elem_index_get(v);
815 vert_accum[index] += face_angles[i];
816 vert_angles[index] += shell_v3v3_normalized_to_dist(v->no, f->no) * face_angles[i];
817 i++;
818 }
819 }
820 }
821
822 BLI_buffer_free(&face_angles_buf);
823 BLI_buffer_free(&verts_buf);
824
825 BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
826 index = BM_elem_index_get(v);
827 if (vert_accum[index]) { /* zero if unselected */
828 madd_v3_v3fl(v->co, v->no, dist * (vert_angles[index] / vert_accum[index]));
829 }
830 }
831
832 MEM_freeN(vert_angles);
833}
834
836{
837 BMOperator extrudeop;
838 BMOperator reverseop;
839 float thickness;
840
841 thickness = BMO_slot_float_get(op->slots_in, "thickness");
842
843 /* Flip original faces (so the shell is extruded inward) */
844 BMO_op_init(bm, &reverseop, op->flag, "reverse_faces");
845 BMO_slot_bool_set(reverseop.slots_in, "flip_multires", true);
846 BMO_slot_copy(op, slots_in, "geom", &reverseop, slots_in, "faces");
847 BMO_op_exec(bm, &reverseop);
848 BMO_op_finish(bm, &reverseop);
849
850 /* Extrude the region */
851 BMO_op_initf(bm, &extrudeop, op->flag, "extrude_face_region use_keep_orig=%b", true);
852 BMO_slot_copy(op, slots_in, "geom", &extrudeop, slots_in, "geom");
853 BMO_op_exec(bm, &extrudeop);
854
855 /* Push the verts of the extruded faces inward to create thickness */
856 BMO_slot_buffer_flag_enable(bm, extrudeop.slots_out, "geom.out", BM_FACE, FACE_MARK);
858 solidify_add_thickness(bm, thickness);
859
860 BMO_slot_copy(&extrudeop, slots_out, "geom.out", op, slots_out, "geom.out");
861
862 BMO_op_finish(bm, &extrudeop);
863}
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:50
#define BLI_buffer_reinit_data(buffer_, type_, new_count_)
Definition BLI_buffer.h:49
@ BLI_BUFFER_NOP
Definition BLI_buffer.h:23
#define BLI_buffer_declare_static(type_, name_, flag_, static_count_)
Definition BLI_buffer.h:27
#define BLI_buffer_free(name_)
Definition BLI_buffer.h:96
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.c:731
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.c: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
Read Guarded memory(de)allocation.
#define BM_DISK_EDGE_NEXT(e, v)
#define BM_DEFAULT_NGON_STACK_SIZE
#define BM_ALL_NOLOOP
@ BM_ELEM_HIDDEN
@ BM_ELEM_SEAM
@ BM_ELEM_SMOOTH
@ BM_ELEM_TAG
#define BM_FACE_FIRST_LOOP(p)
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:43
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:24
@ BM_CREATE_NO_DOUBLE
Definition bmesh_core.hh:26
#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)
ATTR_WARN_UNUSED_RESULT 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
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,...)
@ DEL_ONLYTAGGED
@ DEL_ONLYFACES
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 VERT_MARK
static void solidify_add_thickness(BMesh *bm, const float dist)
@ EXT_INPUT
@ EXT_TAG
@ EXT_KEEP
@ EXT_DEL
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)
#define FACE_MARK
void bmo_solidify_face_region_exec(BMesh *bm, BMOperator *op)
#define EDGE_MARK
#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)
static float verts[][3]
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
ccl_device_inline float2 fabs(const float2 a)
BMHeader head
BMVert * v1
BMVert * v2
struct BMLoop * l
float no[3]
void * data
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]
float co[3]
struct BMEdge * e
float no[3]
BMHeader head
int totvert
CustomData vdata
int totedge
BMFace * act_face