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