Blender V4.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
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" /* 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/* -------------------------------------------------------------------- */
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, nullptr, 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, nullptr, 2, l->head.data);
157}
158
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 = static_cast<BMLoop *(*)[2]>(MEM_mallocN(sizeof(*larr_x_a) * (xtot - 1), __func__));
249 larr_x_b = static_cast<BMLoop *(*)[2]>(MEM_mallocN(sizeof(*larr_x_b) * (xtot - 1), __func__));
250
251 larr_y_a = static_cast<BMLoop *(*)[2]>(MEM_mallocN(sizeof(*larr_y_a) * (ytot - 1), __func__));
252 larr_y_b = static_cast<BMLoop *(*)[2]>(MEM_mallocN(sizeof(*larr_y_b) * (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, nullptr, 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 = static_cast<BMVert **>(
491 MEM_callocN(sizeof(BMVert *) * size_t(xtot * ytot), __func__));
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 = static_cast<LinkData *>(lb_a->first), i = 0; el; el = el->next, i++) {
515 v_grid[i] = static_cast<BMVert *>(el->data);
516 }
517 for (el = static_cast<LinkData *>(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 = static_cast<LinkData *>(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 = static_cast<LinkData *>(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 ListBase *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 = static_cast<LinkData *>(lb_iter[i]->first); el && (el_next = el->next);
543 el = el->next)
544 {
545 BMEdge *e = BM_edge_exists(static_cast<BMVert *>(el->data),
546 static_cast<BMVert *>(el_next->data));
547 if (BM_edge_is_boundary(e)) {
548 winding_votes += (e->l->v == el->data) ? lb_iter_dir[i] : -lb_iter_dir[i];
549 }
550 }
551 }
552 use_flip = (winding_votes < 0);
553 }
554#endif
555
556 bm_grid_fill_array(bm, v_grid, xtot, ytot, mat_nr, use_smooth, use_flip, use_interp_simple);
557 MEM_freeN(v_grid);
558
559#undef USE_FLIP_DETECT
560}
561
562static void bm_edgeloop_flag_set(BMEdgeLoopStore *estore, char hflag, bool set)
563{
564 /* only handle closed loops in this case */
565 LinkData *link = static_cast<LinkData *>(BM_edgeloop_verts_get(estore)->first);
566 link = link->next;
567 while (link) {
568 BMEdge *e = BM_edge_exists(static_cast<BMVert *>(link->data),
569 static_cast<BMVert *>(link->prev->data));
570 if (e) {
571 BM_elem_flag_set(e, hflag, set);
572 }
573 link = link->next;
574 }
575}
576
577static bool bm_edge_test_cb(BMEdge *e, void *bm_v)
578{
579 return BMO_edge_flag_test_bool((BMesh *)bm_v, e, EDGE_MARK);
580}
581
582static bool bm_edge_test_rail_cb(BMEdge *e, void * /*bm_v*/)
583{
584 /* Normally operators don't check for hidden state
585 * but alternative would be to pass slot of rail edges. */
587 return false;
588 }
590}
591
593{
594 ListBase eloops = {nullptr, nullptr};
595 ListBase eloops_rail = {nullptr, nullptr};
596 BMEdgeLoopStore *estore_a, *estore_b;
597 BMEdgeLoopStore *estore_rail_a, *estore_rail_b;
598 BMVert *v_a_first, *v_a_last;
599 BMVert *v_b_first, *v_b_last;
600 const short mat_nr = short(BMO_slot_int_get(op->slots_in, "mat_nr"));
601 const bool use_smooth = BMO_slot_bool_get(op->slots_in, "use_smooth");
602 const bool use_interp_simple = BMO_slot_bool_get(op->slots_in, "use_interp_simple");
603 GSet *split_edges = nullptr;
604
605 int count;
606 bool changed = false;
608
609 count = BM_mesh_edgeloops_find(bm, &eloops, bm_edge_test_cb, (void *)bm);
610
611 if (count != 2) {
612 /* Note that this error message has been adjusted to make sense when called
613 * from the operator 'MESH_OT_fill_grid' which has a 'prepare' pass which can
614 * extract two 'rail' loops from a single edge loop, see #72075. */
616 op,
618 "Select two edge loops "
619 "or a single closed edge loop from which two edge loops can be calculated");
620 goto cleanup;
621 }
622
623 estore_a = static_cast<BMEdgeLoopStore *>(eloops.first);
624 estore_b = static_cast<BMEdgeLoopStore *>(eloops.last);
625
626 v_a_first = static_cast<BMVert *>(((LinkData *)BM_edgeloop_verts_get(estore_a)->first)->data);
627 v_a_last = static_cast<BMVert *>(((LinkData *)BM_edgeloop_verts_get(estore_a)->last)->data);
628 v_b_first = static_cast<BMVert *>(((LinkData *)BM_edgeloop_verts_get(estore_b)->first)->data);
629 v_b_last = static_cast<BMVert *>(((LinkData *)BM_edgeloop_verts_get(estore_b)->last)->data);
630
631 if (BM_edgeloop_is_closed(estore_a) || BM_edgeloop_is_closed(estore_b)) {
632 BMO_error_raise(bm, op, BMO_ERROR_CANCEL, "Closed loops unsupported");
633 goto cleanup;
634 }
635
636 /* ok. all error checking done, now we can find the rail edges */
637
638 /* cheat here, temp hide all edges so they won't be included in rails
639 * this puts the mesh in an invalid state for a short time. */
640 bm_edgeloop_flag_set(estore_a, BM_ELEM_HIDDEN, true);
641 bm_edgeloop_flag_set(estore_b, BM_ELEM_HIDDEN, true);
642
644 bm, &eloops_rail, bm_edge_test_rail_cb, bm, v_a_first, v_b_first) &&
645 BM_mesh_edgeloops_find_path(bm, &eloops_rail, bm_edge_test_rail_cb, bm, v_a_last, v_b_last))
646 {
647 estore_rail_a = static_cast<BMEdgeLoopStore *>(eloops_rail.first);
648 estore_rail_b = static_cast<BMEdgeLoopStore *>(eloops_rail.last);
649 }
650 else {
651 BM_mesh_edgeloops_free(&eloops_rail);
652
654 bm, &eloops_rail, bm_edge_test_rail_cb, bm, v_a_first, v_b_last) &&
656 bm, &eloops_rail, bm_edge_test_rail_cb, bm, v_a_last, v_b_first))
657 {
658 estore_rail_a = static_cast<BMEdgeLoopStore *>(eloops_rail.first);
659 estore_rail_b = static_cast<BMEdgeLoopStore *>(eloops_rail.last);
660 BM_edgeloop_flip(bm, estore_b);
661 }
662 else {
663 BM_mesh_edgeloops_free(&eloops_rail);
664 }
665 }
666
667 bm_edgeloop_flag_set(estore_a, BM_ELEM_HIDDEN, false);
668 bm_edgeloop_flag_set(estore_b, BM_ELEM_HIDDEN, false);
669
670 if (BLI_listbase_is_empty(&eloops_rail)) {
671 BMO_error_raise(bm, op, BMO_ERROR_CANCEL, "Loops are not connected by wire/boundary edges");
672 goto cleanup;
673 }
674
675 BLI_assert(estore_a != estore_b);
676 BLI_assert(v_a_last != v_b_last);
677
678 if (BM_edgeloop_overlap_check(estore_rail_a, estore_rail_b)) {
679 BMO_error_raise(bm, op, BMO_ERROR_CANCEL, "Connecting edge loops overlap");
680 goto cleanup;
681 }
682
683 /* add vertices if needed */
684 {
685 BMEdgeLoopStore *estore_pairs[2][2] = {
686 {estore_a, estore_b},
687 {estore_rail_a, estore_rail_b},
688 };
689 int i;
690
691 for (i = 0; i < 2; i++) {
692 const int len_a = BM_edgeloop_length_get(estore_pairs[i][0]);
693 const int len_b = BM_edgeloop_length_get(estore_pairs[i][1]);
694 if (len_a != len_b) {
695 if (split_edges == nullptr) {
696 split_edges = BLI_gset_ptr_new(__func__);
697 }
698
699 if (len_a < len_b) {
700 BM_edgeloop_expand(bm, estore_pairs[i][0], len_b, true, split_edges);
701 }
702 else {
703 BM_edgeloop_expand(bm, estore_pairs[i][1], len_a, true, split_edges);
704 }
705 }
706 }
707 }
708
709 /* finally we have all edge loops needed */
711 bm, estore_a, estore_b, estore_rail_a, estore_rail_b, mat_nr, use_smooth, use_interp_simple);
712
713 changed = true;
714
715 if (split_edges) {
716 GSetIterator gs_iter;
717 GSET_ITER (gs_iter, split_edges) {
718 BMEdge *e = static_cast<BMEdge *>(BLI_gsetIterator_getKey(&gs_iter));
719 BM_edge_collapse(bm, e, e->v2, true, true);
720 }
721 BLI_gset_free(split_edges, nullptr);
722 }
723
724cleanup:
725 BM_mesh_edgeloops_free(&eloops);
726 BM_mesh_edgeloops_free(&eloops_rail);
727
728 if (changed) {
730 }
731}
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, const float *sub_weights, int count, void *dst_block)
#define BLI_assert(a)
Definition BLI_assert.h:50
struct GSet GSet
Definition BLI_ghash.h:341
GSet * BLI_gset_ptr_new(const char *info)
BLI_INLINE void * BLI_gsetIterator_getKey(GSetIterator *gsi)
Definition BLI_ghash.h:459
#define GSET_ITER(gs_iter_, gset_)
Definition BLI_ghash.h:472
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition BLI_ghash.c:1034
BLI_INLINE bool BLI_listbase_is_empty(const struct 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)
Definition math_vector.c:36
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.
@ BM_ELEM_HIDDEN
@ BM_ELEM_SMOOTH
#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.
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
@ BM_CREATE_NOP
Definition bmesh_core.hh:24
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)
ATTR_WARN_UNUSED_RESULT 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 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])
#define FACE_OUT
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])
#define EDGE_MARK
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
draw_view in_light_buf[] float
int count
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 float3 cos(float3 v)
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
CustomData vdata
CustomData ldata
void * data
struct LinkData * next
struct LinkData * prev
void * last
void * first