Blender V5.3
bmo_fill_grid.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 "BLI_listbase.hh"
14#include "BLI_math_geom_c.hh"
15#include "BLI_math_vector_c.hh"
16
17#include "BKE_customdata.hh"
18
19#include "bmesh.hh"
20
21#include "intern/bmesh_operators_private.hh" /* own include */
22
23#include "BLI_strict_flags.hh" /* IWYU pragma: keep. Keep last. */
24
25namespace blender {
26
27#define EDGE_MARK 4
28#define FACE_OUT 16
29
30#define BARYCENTRIC_INTERP
31
32#ifdef BARYCENTRIC_INTERP
36static void quad_edges_to_normal(float no[3],
37 const float co_a1[3],
38 const float co_a2[3],
39 const float co_b1[3],
40 const float co_b2[3])
41{
42 float diff_a[3];
43 float diff_b[3];
44
45 sub_v3_v3v3(diff_a, co_a2, co_a1);
46 sub_v3_v3v3(diff_b, co_b2, co_b1);
47 normalize_v3(diff_a);
48 normalize_v3(diff_b);
49 add_v3_v3v3(no, diff_a, diff_b);
50 normalize_v3(no);
51}
52
53static void quad_verts_to_barycentric_tri(float tri[3][3],
54 const float co_a[3],
55 const float co_b[3],
56
57 const float co_a_next[3],
58 const float co_b_next[3],
59
60 const float co_a_prev[3],
61 const float co_b_prev[3],
62 const bool is_flip)
63{
64 float no[3];
65
66 copy_v3_v3(tri[0], co_a);
67 copy_v3_v3(tri[1], co_b);
68
69 quad_edges_to_normal(no, co_a, co_a_next, co_b, co_b_next);
70
71 if (co_a_prev) {
72 float no_t[3];
73 quad_edges_to_normal(no_t, co_a_prev, co_a, co_b_prev, co_b);
74 add_v3_v3(no, no_t);
75 normalize_v3(no);
76 }
77
78 if (is_flip) {
79 negate_v3(no);
80 }
81 mul_v3_fl(no, len_v3v3(tri[0], tri[1]));
82
83 mid_v3_v3v3(tri[2], tri[0], tri[1]);
84 add_v3_v3(tri[2], no);
85}
86
87#endif
88
89/* -------------------------------------------------------------------- */
92
96static void bm_loop_pair_from_verts(BMVert *v_a, BMVert *v_b, BMLoop *l_pair[2])
97{
98 BMEdge *e = BM_edge_exists(v_a, v_b);
99 if (e->l) {
100 if (e->l->v == v_a) {
101 l_pair[0] = e->l;
102 l_pair[1] = e->l->next;
103 }
104 else {
105 l_pair[0] = e->l->next;
106 l_pair[1] = e->l;
107 }
108 }
109 else {
110 l_pair[0] = nullptr;
111 l_pair[1] = nullptr;
112 }
113}
114
120static void bm_loop_pair_test_copy(BMLoop *l_pair_a[2], BMLoop *l_pair_b[2])
121{
122 /* if the first one is set, we know the second is too */
123 if (l_pair_a[0] && l_pair_b[0] == nullptr) {
124 l_pair_b[0] = l_pair_a[1];
125 l_pair_b[1] = l_pair_a[0];
126 }
127 else if (l_pair_b[0] && l_pair_a[0] == nullptr) {
128 l_pair_a[0] = l_pair_b[1];
129 l_pair_a[1] = l_pair_b[0];
130 }
131}
132
139 BMLoop *l,
140 BMLoop *l_bound[4],
141 const float w[4])
142{
143 const void *l_cdata[4] = {
144 l_bound[0]->head.data, l_bound[1]->head.data, l_bound[2]->head.data, l_bound[3]->head.data};
145
146 CustomData_bmesh_interp(&bm->ldata, l_cdata, w, 4, l->head.data);
147}
148
150 BMLoop *l,
151 BMLoop *l_bound[2],
152 const float t)
153{
154 const void *l_cdata[2] = {l_bound[0]->head.data, l_bound[1]->head.data};
155
156 const float w[2] = {1.0f - t, t};
157
158 CustomData_bmesh_interp(&bm->ldata, l_cdata, w, 2, l->head.data);
159}
160
162
167 const uint ytot,
168 float (*weight_table)[4])
169{
170 float x_step = 1.0f / float(xtot - 1);
171 float y_step = 1.0f / float(ytot - 1);
172 uint i = 0;
173 float xy_fl[2];
174
175 uint x, y;
176 for (y = 0; y < ytot; y++) {
177 xy_fl[1] = y_step * float(y);
178 for (x = 0; x < xtot; x++) {
179 xy_fl[0] = x_step * float(x);
180 {
181 const float cos[4][2] = {
182 {xy_fl[0], 0.0f}, {0.0f, xy_fl[1]}, {xy_fl[0], 1.0f}, {1.0f, xy_fl[1]}};
183 barycentric_weights_v2_quad(UNPACK4(cos), xy_fl, weight_table[i++]);
184 }
185 }
186 }
187}
188
195 BMVert **v_grid,
196 const uint xtot,
197 const uint ytot,
198 const short mat_nr,
199 const bool use_smooth,
200 const bool use_flip,
201 const bool use_interp_simple)
202{
203 const bool use_vert_interp = CustomData_has_interp(&bm->vdata);
204 const bool use_loop_interp = CustomData_has_interp(&bm->ldata);
205 uint x, y;
206
207 /* for use_loop_interp */
208 BMLoop *(*larr_x_a)[2], *(*larr_x_b)[2], *(*larr_y_a)[2], *(*larr_y_b)[2];
209
210 float (*weight_table)[4];
211
212#define XY(_x, _y) ((_x) + ((_y) * (xtot)))
213
214#ifdef BARYCENTRIC_INTERP
215 float tri_a[3][3];
216 float tri_b[3][3];
217 float tri_t[3][3]; /* temp */
218
220 v_grid[XY(0, 0)]->co,
221 v_grid[XY(xtot - 1, 0)]->co,
222 v_grid[XY(0, 1)]->co,
223 v_grid[XY(xtot - 1, 1)]->co,
224 nullptr,
225 nullptr,
226 false);
227
229 v_grid[XY(0, (ytot - 1))]->co,
230 v_grid[XY(xtot - 1, (ytot - 1))]->co,
231 v_grid[XY(0, (ytot - 2))]->co,
232 v_grid[XY(xtot - 1, (ytot - 2))]->co,
233 nullptr,
234 nullptr,
235 true);
236#endif
237
238 if (use_interp_simple || use_vert_interp || use_loop_interp) {
239 weight_table = MEM_new_array_uninitialized<float[4]>(xtot * ytot, __func__);
240 barycentric_weights_v2_grid_cache(xtot, ytot, weight_table);
241 }
242 else {
243 weight_table = nullptr;
244 }
245
246 /* Store loops */
247 if (use_loop_interp) {
248 /* x2 because each edge connects 2 loops */
249 larr_x_a = MEM_new_array_uninitialized<BMLoop *[2]>((xtot - 1), __func__);
250 larr_x_b = MEM_new_array_uninitialized<BMLoop *[2]>((xtot - 1), __func__);
251
252 larr_y_a = MEM_new_array_uninitialized<BMLoop *[2]>((ytot - 1), __func__);
253 larr_y_b = MEM_new_array_uninitialized<BMLoop *[2]>((ytot - 1), __func__);
254
255 /* fill in the loops */
256 for (x = 0; x < xtot - 1; x++) {
257 bm_loop_pair_from_verts(v_grid[XY(x, 0)], v_grid[XY(x + 1, 0)], larr_x_a[x]);
258 bm_loop_pair_from_verts(v_grid[XY(x, ytot - 1)], v_grid[XY(x + 1, ytot - 1)], larr_x_b[x]);
259 bm_loop_pair_test_copy(larr_x_a[x], larr_x_b[x]);
260 }
261
262 for (y = 0; y < ytot - 1; y++) {
263 bm_loop_pair_from_verts(v_grid[XY(0, y)], v_grid[XY(0, y + 1)], larr_y_a[y]);
264 bm_loop_pair_from_verts(v_grid[XY(xtot - 1, y)], v_grid[XY(xtot - 1, y + 1)], larr_y_b[y]);
265 bm_loop_pair_test_copy(larr_y_a[y], larr_y_b[y]);
266 }
267 }
268
269 /* Build Verts */
270 for (y = 1; y < ytot - 1; y++) {
271#ifdef BARYCENTRIC_INTERP
273 v_grid[XY(0, y + 0)]->co,
274 v_grid[XY(xtot - 1, y + 0)]->co,
275 v_grid[XY(0, y + 1)]->co,
276 v_grid[XY(xtot - 1, y + 1)]->co,
277 v_grid[XY(0, y - 1)]->co,
278 v_grid[XY(xtot - 1, y - 1)]->co,
279 false);
280#endif
281 for (x = 1; x < xtot - 1; x++) {
282 float co[3];
283 BMVert *v;
284 /* we may want to allow sparse filled arrays, but for now, ensure its empty */
285 BLI_assert(v_grid[(y * xtot) + x] == nullptr);
286
287/* place the vertex */
288#ifdef BARYCENTRIC_INTERP
289 if (use_interp_simple == false) {
290 float co_a[3], co_b[3];
291
293 co_a, v_grid[x]->co, tri_t[0], tri_t[1], tri_t[2], tri_a[0], tri_a[1], tri_a[2]);
295 v_grid[(xtot * ytot) + (x - xtot)]->co,
296 tri_t[0],
297 tri_t[1],
298 tri_t[2],
299 tri_b[0],
300 tri_b[1],
301 tri_b[2]);
302
303 interp_v3_v3v3(co, co_a, co_b, float(y) / (float(ytot) - 1));
304 }
305 else
306#endif
307 {
308 const float *w = weight_table[XY(x, y)];
309
310 zero_v3(co);
311 madd_v3_v3fl(co, v_grid[XY(x, 0)]->co, w[0]);
312 madd_v3_v3fl(co, v_grid[XY(0, y)]->co, w[1]);
313 madd_v3_v3fl(co, v_grid[XY(x, ytot - 1)]->co, w[2]);
314 madd_v3_v3fl(co, v_grid[XY(xtot - 1, y)]->co, w[3]);
315 }
316
317 v = BM_vert_create(bm, co, nullptr, BM_CREATE_NOP);
318 v_grid[(y * xtot) + x] = v;
319
320 /* Interpolate only along one axis, this could be changed
321 * but from user POV gives predictable results since these are selected loop. */
322 if (use_vert_interp) {
323 const float *w = weight_table[XY(x, y)];
324
325 const void *v_cdata[4] = {
326 v_grid[XY(x, 0)]->head.data,
327 v_grid[XY(0, y)]->head.data,
328 v_grid[XY(x, ytot - 1)]->head.data,
329 v_grid[XY(xtot - 1, y)]->head.data,
330 };
331
332 CustomData_bmesh_interp(&bm->vdata, v_cdata, w, 4, v->head.data);
333 }
334 }
335 }
336
337 /* Build Faces */
338 for (x = 0; x < xtot - 1; x++) {
339 for (y = 0; y < ytot - 1; y++) {
340 BMFace *f;
341
342 if (use_flip) {
344 v_grid[XY(x, y + 0)], /* BL */
345 v_grid[XY(x, y + 1)], /* TL */
346 v_grid[XY(x + 1, y + 1)], /* TR */
347 v_grid[XY(x + 1, y + 0)], /* BR */
348 nullptr,
350 }
351 else {
353 v_grid[XY(x + 1, y + 0)], /* BR */
354 v_grid[XY(x + 1, y + 1)], /* TR */
355 v_grid[XY(x, y + 1)], /* TL */
356 v_grid[XY(x, y + 0)], /* BL */
357 nullptr,
359 }
360
361 if (use_loop_interp && (larr_x_a[x][0] || larr_y_a[y][0])) {
362 /* bottom/left/top/right */
363 BMLoop *l_quad[4];
364 BMLoop *l_bound[4];
365 BMLoop *l_tmp;
366 uint x_side, y_side, i;
367 char interp_from;
368
369 if (larr_x_a[x][0] && larr_y_a[y][0]) {
370 interp_from = 'B'; /* B == both */
371 l_tmp = larr_x_a[x][0];
372 }
373 else if (larr_x_a[x][0]) {
374 interp_from = 'X';
375 l_tmp = larr_x_a[x][0];
376 }
377 else {
378 interp_from = 'Y';
379 l_tmp = larr_y_a[y][0];
380 }
381
382 BM_elem_attrs_copy(bm, l_tmp->f, f);
383
385
386 l_tmp = BM_FACE_FIRST_LOOP(f);
387
388 if (use_flip) {
389 l_quad[0] = l_tmp;
390 l_tmp = l_tmp->next;
391 l_quad[1] = l_tmp;
392 l_tmp = l_tmp->next;
393 l_quad[3] = l_tmp;
394 l_tmp = l_tmp->next;
395 l_quad[2] = l_tmp;
396 }
397 else {
398 l_quad[2] = l_tmp;
399 l_tmp = l_tmp->next;
400 l_quad[3] = l_tmp;
401 l_tmp = l_tmp->next;
402 l_quad[1] = l_tmp;
403 l_tmp = l_tmp->next;
404 l_quad[0] = l_tmp;
405 }
406
407 i = 0;
408
409 for (x_side = 0; x_side < 2; x_side++) {
410 for (y_side = 0; y_side < 2; y_side++) {
411 if (interp_from == 'B') {
412 const float *w = weight_table[XY(x + x_side, y + y_side)];
413 l_bound[0] = larr_x_a[x][x_side]; /* B */
414 l_bound[1] = larr_y_a[y][y_side]; /* L */
415 l_bound[2] = larr_x_b[x][x_side]; /* T */
416 l_bound[3] = larr_y_b[y][y_side]; /* R */
417
418 bm_loop_interp_from_grid_boundary_4(bm, l_quad[i++], l_bound, w);
419 }
420 else if (interp_from == 'X') {
421 const float t = float(y + y_side) / float(ytot - 1);
422 l_bound[0] = larr_x_a[x][x_side]; /* B */
423 l_bound[1] = larr_x_b[x][x_side]; /* T */
424
425 bm_loop_interp_from_grid_boundary_2(bm, l_quad[i++], l_bound, t);
426 }
427 else if (interp_from == 'Y') {
428 const float t = float(x + x_side) / float(xtot - 1);
429 l_bound[0] = larr_y_a[y][y_side]; /* L */
430 l_bound[1] = larr_y_b[y][y_side]; /* R */
431
432 bm_loop_interp_from_grid_boundary_2(bm, l_quad[i++], l_bound, t);
433 }
434 else {
435 BLI_assert(0);
436 }
437 }
438 }
439 }
440 /* end interp */
441
443 f->mat_nr = mat_nr;
444 if (use_smooth) {
446 }
447 }
448 }
449
450 if (use_loop_interp) {
451 MEM_delete(larr_x_a);
452 MEM_delete(larr_y_a);
453 MEM_delete(larr_x_b);
454 MEM_delete(larr_y_b);
455 }
456
457 if (weight_table) {
458 MEM_delete(weight_table);
459 }
460
461#undef XY
462}
463
464static void bm_grid_fill(BMesh *bm,
465 BMEdgeLoopStore *estore_a,
466 BMEdgeLoopStore *estore_b,
467 BMEdgeLoopStore *estore_rail_a,
468 BMEdgeLoopStore *estore_rail_b,
469 const short mat_nr,
470 const bool use_smooth,
471 const bool use_interp_simple)
472{
473#define USE_FLIP_DETECT
474
475 const uint xtot = uint(BM_edgeloop_length_get(estore_a));
476 const uint ytot = uint(BM_edgeloop_length_get(estore_rail_a));
477 // BMVert *v;
478 uint i;
479#ifndef NDEBUG
480 uint x, y;
481#endif
482 LinkData *el;
483 bool use_flip = false;
484
485 ListBaseT<LinkData> *lb_a = BM_edgeloop_verts_get(estore_a);
486 ListBaseT<LinkData> *lb_b = BM_edgeloop_verts_get(estore_b);
487
488 ListBaseT<LinkData> *lb_rail_a = BM_edgeloop_verts_get(estore_rail_a);
489 ListBaseT<LinkData> *lb_rail_b = BM_edgeloop_verts_get(estore_rail_b);
490
491 BMVert **v_grid = MEM_new_array_zeroed<BMVert *>(size_t(xtot) * ytot, __func__);
508
509 BLI_assert(((LinkData *)lb_a->first_)->data == ((LinkData *)lb_rail_a->first_)->data); /* BL */
510 BLI_assert(((LinkData *)lb_b->first_)->data == ((LinkData *)lb_rail_a->last())->data); /* TL */
511 BLI_assert(((LinkData *)lb_b->last())->data == ((LinkData *)lb_rail_b->last())->data); /* TR */
512 BLI_assert(((LinkData *)lb_a->last())->data == ((LinkData *)lb_rail_b->first_)->data); /* BR */
513
514 for (el = lb_a->first(), i = 0; el; el = el->next, i++) {
515 v_grid[i] = static_cast<BMVert *>(el->data);
516 }
517 for (el = lb_b->first(), i = 0; el; el = el->next, i++) {
518 v_grid[(ytot * xtot) + (i - xtot)] = static_cast<BMVert *>(el->data);
519 }
520 for (el = lb_rail_a->first(), i = 0; el; el = el->next, i++) {
521 v_grid[xtot * i] = static_cast<BMVert *>(el->data);
522 }
523 for (el = lb_rail_b->first(), i = 0; el; el = el->next, i++) {
524 v_grid[(xtot * i) + (xtot - 1)] = static_cast<BMVert *>(el->data);
525 }
526#ifndef NDEBUG
527 for (x = 1; x < xtot - 1; x++) {
528 for (y = 1; y < ytot - 1; y++) {
529 BLI_assert(v_grid[(y * xtot) + x] == nullptr);
530 }
531 }
532#endif
533
534#ifdef USE_FLIP_DETECT
535 {
536 ListBaseT<LinkData> *lb_iter[4] = {lb_a, lb_b, lb_rail_a, lb_rail_b};
537 const int lb_iter_dir[4] = {-1, 1, 1, -1};
538 int winding_votes = 0;
539
540 for (i = 0; i < 4; i++) {
541 LinkData *el_next;
542 for (el = lb_iter[i]->first(); el && (el_next = el->next); el = el->next) {
543 BMEdge *e = BM_edge_exists(static_cast<BMVert *>(el->data),
544 static_cast<BMVert *>(el_next->data));
545 if (BM_edge_is_boundary(e)) {
546 winding_votes += (e->l->v == el->data) ? lb_iter_dir[i] : -lb_iter_dir[i];
547 }
548 }
549 }
550 use_flip = (winding_votes < 0);
551 }
552#endif
553
554 bm_grid_fill_array(bm, v_grid, xtot, ytot, mat_nr, use_smooth, use_flip, use_interp_simple);
555 MEM_delete(v_grid);
556
557#undef USE_FLIP_DETECT
558}
559
560static void bm_edgeloop_flag_set(BMEdgeLoopStore *estore, char hflag, bool set)
561{
562 /* only handle closed loops in this case */
563 LinkData *link = BM_edgeloop_verts_get(estore)->first();
564 link = link->next;
565 while (link) {
566 BMEdge *e = BM_edge_exists(static_cast<BMVert *>(link->data),
567 static_cast<BMVert *>(link->prev->data));
568 if (e) {
569 BM_elem_flag_set(e, hflag, set);
570 }
571 link = link->next;
572 }
573}
574
576{
577 ListBaseT<BMEdgeLoopStore> eloops = {nullptr, nullptr};
578 ListBaseT<BMEdgeLoopStore> eloops_rail = {nullptr, nullptr};
579 BMEdgeLoopStore *estore_a, *estore_b;
580 BMEdgeLoopStore *estore_rail_a, *estore_rail_b;
581 BMVert *v_a_first, *v_a_last;
582 BMVert *v_b_first, *v_b_last;
583 const short mat_nr = short(BMO_slot_int_get(op->slots_in, "mat_nr"));
584 const bool use_smooth = BMO_slot_bool_get(op->slots_in, "use_smooth");
585 const bool use_interp_simple = BMO_slot_bool_get(op->slots_in, "use_interp_simple");
586 std::unique_ptr<Set<BMEdge *>> split_edges;
587
588 int count;
589 bool changed = false;
590
591 const auto edge_test_rail_fn = [](BMEdge *e) {
592 /* Normally operators don't check for hidden state
593 * but alternative would be to pass slot of rail edges. */
595 return false;
596 }
598 };
599
601
603 bm, &eloops, [&](BMEdge *e) { return BMO_edge_flag_test(bm, e, EDGE_MARK); });
604
605 if (count != 2) {
606 /* Note that this error message has been adjusted to make sense when called
607 * from the operator `MESH_OT_fill_grid` which has a 'prepare' pass which can
608 * extract two 'rail' loops from a single edge loop, see #72075. */
610 op,
612 "Select two edge loops "
613 "or a single closed edge loop from which two edge loops can be calculated");
614 goto cleanup;
615 }
616
617 estore_a = eloops.first();
618 estore_b = eloops.last();
619
620 v_a_first = static_cast<BMVert *>((BM_edgeloop_verts_get(estore_a)->first())->data);
621 v_a_last = static_cast<BMVert *>((BM_edgeloop_verts_get(estore_a)->last())->data);
622 v_b_first = static_cast<BMVert *>((BM_edgeloop_verts_get(estore_b)->first())->data);
623 v_b_last = static_cast<BMVert *>((BM_edgeloop_verts_get(estore_b)->last())->data);
624
625 if (BM_edgeloop_is_closed(estore_a) || BM_edgeloop_is_closed(estore_b)) {
626 BMO_error_raise(bm, op, BMO_ERROR_CANCEL, "Closed loops unsupported");
627 goto cleanup;
628 }
629
630 /* ok. all error checking done, now we can find the rail edges */
631
632 /* cheat here, temp hide all edges so they won't be included in rails
633 * this puts the mesh in an invalid state for a short time. */
634 bm_edgeloop_flag_set(estore_a, BM_ELEM_HIDDEN, true);
635 bm_edgeloop_flag_set(estore_b, BM_ELEM_HIDDEN, true);
636
637 if (BM_mesh_edgeloops_find_path(bm, &eloops_rail, edge_test_rail_fn, v_a_first, v_b_first) &&
638 BM_mesh_edgeloops_find_path(bm, &eloops_rail, edge_test_rail_fn, v_a_last, v_b_last))
639 {
640 estore_rail_a = eloops_rail.first();
641 estore_rail_b = eloops_rail.last();
642 }
643 else {
644 BM_mesh_edgeloops_free(&eloops_rail);
645
646 if (BM_mesh_edgeloops_find_path(bm, &eloops_rail, edge_test_rail_fn, v_a_first, v_b_last) &&
647 BM_mesh_edgeloops_find_path(bm, &eloops_rail, edge_test_rail_fn, v_a_last, v_b_first))
648 {
649 estore_rail_a = eloops_rail.first();
650 estore_rail_b = eloops_rail.last();
651 BM_edgeloop_flip(bm, estore_b);
652 }
653 else {
654 BM_mesh_edgeloops_free(&eloops_rail);
655 }
656 }
657
658 bm_edgeloop_flag_set(estore_a, BM_ELEM_HIDDEN, false);
659 bm_edgeloop_flag_set(estore_b, BM_ELEM_HIDDEN, false);
660
661 if (eloops_rail.is_empty()) {
662 BMO_error_raise(bm, op, BMO_ERROR_CANCEL, "Loops are not connected by wire/boundary edges");
663 goto cleanup;
664 }
665
666 BLI_assert(estore_a != estore_b);
667 BLI_assert(v_a_last != v_b_last);
668
669 if (BM_edgeloop_overlap_check(estore_rail_a, estore_rail_b)) {
670 BMO_error_raise(bm, op, BMO_ERROR_CANCEL, "Connecting edge loops overlap");
671 goto cleanup;
672 }
673
674 /* add vertices if needed */
675 {
676 BMEdgeLoopStore *estore_pairs[2][2] = {
677 {estore_a, estore_b},
678 {estore_rail_a, estore_rail_b},
679 };
680 int i;
681
682 for (i = 0; i < 2; i++) {
683 const int len_a = BM_edgeloop_length_get(estore_pairs[i][0]);
684 const int len_b = BM_edgeloop_length_get(estore_pairs[i][1]);
685 if (len_a != len_b) {
686 if (split_edges == nullptr) {
687 split_edges = std::make_unique<Set<BMEdge *>>();
688 }
689
690 if (len_a < len_b) {
691 BM_edgeloop_expand(bm, estore_pairs[i][0], len_b, true, split_edges.get());
692 }
693 else {
694 BM_edgeloop_expand(bm, estore_pairs[i][1], len_a, true, split_edges.get());
695 }
696 }
697 }
698 }
699
700 /* finally we have all edge loops needed */
702 bm, estore_a, estore_b, estore_rail_a, estore_rail_b, mat_nr, use_smooth, use_interp_simple);
703
704 changed = true;
705
706 if (split_edges) {
707 for (BMEdge *e : *split_edges) {
708 BM_edge_collapse(bm, e, e->v2, true, true);
709 }
710 }
711
712cleanup:
713 BM_mesh_edgeloops_free(&eloops);
714 BM_mesh_edgeloops_free(&eloops_rail);
715
716 if (changed) {
718 }
719}
720
721} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
Read Blender memory allocation and freeing.
#define UNPACK4(a)
#define BM_FACE_FIRST_LOOP(p)
#define BM_elem_flag_set(ele, hflag, val)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
#define BMO_edge_flag_test(bm, e, oflag)
#define BMO_face_flag_enable(bm, e, oflag)
#define FACE_OUT
Definition bmo_bridge.cc:30
#define EDGE_MARK
Definition bmo_bridge.cc:28
#define XY(_x, _y)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
#define cos
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ListBaseT< LinkData > * BM_edgeloop_verts_get(BMEdgeLoopStore *el_store)
int BM_mesh_edgeloops_find(BMesh *bm, ListBaseT< BMEdgeLoopStore > *r_eloops, FunctionRef< bool(BMEdge *)> test_fn, const BMEdgeLoopFind_Params *params)
static void bm_loop_pair_test_copy(BMLoop *l_pair_a[2], BMLoop *l_pair_b[2])
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
BLI_INLINE bool BM_edge_is_wire(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BM_face_as_array_loop_quad(BMFace *f, BMLoop *r_loops[4])
void BM_edgeloop_flip(BMesh *, BMEdgeLoopStore *el_store)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BM_edgeloop_expand(BMesh *bm, BMEdgeLoopStore *el_store, int el_store_len, bool split, Set< BMEdge * > *split_edges)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void BM_mesh_edgeloops_free(ListBaseT< BMEdgeLoopStore > *eloops)
static void barycentric_weights_v2_grid_cache(const uint xtot, const uint ytot, float(*weight_table)[4])
bool CustomData_has_interp(const CustomData *data)
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.
void CustomData_bmesh_interp(CustomData *data, const void **src_blocks, const float *weights, int count, void *dst_block)
static void quad_verts_to_barycentric_tri(float tri[3][3], const float co_a[3], const float co_b[3], const float co_a_next[3], const float co_b_next[3], const float co_a_prev[3], const float co_b_prev[3], const bool is_flip)
static void bm_loop_pair_from_verts(BMVert *v_a, BMVert *v_b, BMLoop *l_pair[2])
void transform_point_by_tri_v3(float pt_tar[3], float const pt_src[3], const float tri_tar_p1[3], const float tri_tar_p2[3], const float tri_tar_p3[3], const float tri_src_p1[3], const float tri_src_p2[3], const float tri_src_p3[3])
bool BM_mesh_edgeloops_find_path(BMesh *bm, ListBaseT< BMEdgeLoopStore > *r_eloops, FunctionRef< bool(BMEdge *)> test_fn, BMVert *v_src, BMVert *v_dst)
ATTR_WARN_UNUSED_RESULT const BMVert * v
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.
BMVert * BM_edge_collapse(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool do_del, const bool kill_degenerate_faces)
MINLINE void mul_v3_fl(float r[3], float f)
bool BM_edgeloop_is_closed(BMEdgeLoopStore *el_store)
int BM_edgeloop_length_get(BMEdgeLoopStore *el_store)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
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.
static void quad_edges_to_normal(float no[3], const float co_a1[3], const float co_a2[3], const float co_b1[3], const float co_b2[3])
@ BM_CREATE_NOP
Definition bmesh_core.hh:34
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)
void bmo_grid_fill_exec(BMesh *bm, BMOperator *op)
void barycentric_weights_v2_quad(const float v1[2], const float v2[2], const float v3[2], const float v4[2], const float co[2], float w[4])
static void bm_grid_fill_array(BMesh *bm, BMVert **v_grid, const uint xtot, const uint ytot, const short mat_nr, const bool use_smooth, const bool use_flip, const bool use_interp_simple)
MINLINE void negate_v3(float r[3])
BLI_INLINE bool BM_edge_is_boundary(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
static void bm_edgeloop_flag_set(BMEdgeLoopStore *estore, char hflag, bool set)
MINLINE void zero_v3(float r[3])
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
static void bm_loop_interp_from_grid_boundary_2(BMesh *bm, BMLoop *l, BMLoop *l_bound[2], const float t)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
bool BM_edgeloop_overlap_check(BMEdgeLoopStore *el_store_a, BMEdgeLoopStore *el_store_b)
static void bm_loop_interp_from_grid_boundary_4(BMesh *bm, BMLoop *l, BMLoop *l_bound[4], const float w[4])
void BMO_error_raise(BMesh *bm, BMOperator *owner, eBMOpErrorLevel level, const char *msg) ATTR_NONNULL(1
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
@ BMO_ERROR_CANCEL
static void bm_grid_fill(BMesh *bm, BMEdgeLoopStore *estore_a, BMEdgeLoopStore *estore_b, BMEdgeLoopStore *estore_rail_a, BMEdgeLoopStore *estore_rail_b, const short mat_nr, const bool use_smooth, const bool use_interp_simple)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct BMLoop * next
struct BMFace * f
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct LinkData * prev
struct LinkData * next