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