Blender V4.3
bmesh_polygon.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
12#include "DNA_listBase.h"
13#include "DNA_modifier_types.h"
14
15#include "MEM_guardedalloc.h"
16
17#include "BLI_alloca.h"
18#include "BLI_linklist.h"
19#include "BLI_math_base.hh"
20#include "BLI_math_geom.h"
21#include "BLI_math_matrix.h"
22#include "BLI_math_vector.h"
23#include "BLI_memarena.h"
24#include "BLI_polyfill_2d.h"
26
27#include "bmesh.hh"
28#include "bmesh_tools.hh"
29
30#include "BKE_customdata.hh"
31
33
34using blender::float3;
35using blender::Span;
36
42static float bm_face_calc_poly_normal(const BMFace *f, float n[3])
43{
44 BMLoop *l_first = BM_FACE_FIRST_LOOP(f);
45 BMLoop *l_iter = l_first;
46 const float *v_prev = l_first->prev->v->co;
47 const float *v_curr = l_first->v->co;
48
49 zero_v3(n);
50
51 /* Newell's Method */
52 do {
53 add_newell_cross_v3_v3v3(n, v_prev, v_curr);
54
55 l_iter = l_iter->next;
56 v_prev = v_curr;
57 v_curr = l_iter->v->co;
58
59 } while (l_iter != l_first);
60
61 return normalize_v3(n);
62}
63
71 float r_no[3],
72 const Span<float3> vertexCos)
73{
74 BMLoop *l_first = BM_FACE_FIRST_LOOP(f);
75 BMLoop *l_iter = l_first;
76 const float *v_prev = vertexCos[BM_elem_index_get(l_first->prev->v)];
77 const float *v_curr = vertexCos[BM_elem_index_get(l_first->v)];
78
79 zero_v3(r_no);
80
81 /* Newell's Method */
82 do {
83 add_newell_cross_v3_v3v3(r_no, v_prev, v_curr);
84
85 l_iter = l_iter->next;
86 v_prev = v_curr;
87 v_curr = vertexCos[BM_elem_index_get(l_iter->v)];
88 } while (l_iter != l_first);
89
90 return normalize_v3(r_no);
91}
92
97 const BMFace *f, float r_cent[3], const blender::Span<blender::float3> vert_positions)
98{
99 const BMLoop *l_first, *l_iter;
100
101 zero_v3(r_cent);
102
103 /* Newell's Method */
104 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
105 do {
106 add_v3_v3(r_cent, vert_positions[BM_elem_index_get(l_iter->v)]);
107 } while ((l_iter = l_iter->next) != l_first);
108 mul_v3_fl(r_cent, 1.0f / f->len);
109}
110
112 const bool use_fixed_quad,
113 BMLoop **r_loops,
114 uint (*r_index)[3])
115{
116 BMLoop *l_first = BM_FACE_FIRST_LOOP(f);
117 BMLoop *l_iter;
118
119 if (f->len == 3) {
120 *r_loops++ = (l_iter = l_first);
121 *r_loops++ = (l_iter = l_iter->next);
122 *r_loops++ = (l_iter->next);
123
124 r_index[0][0] = 0;
125 r_index[0][1] = 1;
126 r_index[0][2] = 2;
127 }
128 else if (f->len == 4 && use_fixed_quad) {
129 *r_loops++ = (l_iter = l_first);
130 *r_loops++ = (l_iter = l_iter->next);
131 *r_loops++ = (l_iter = l_iter->next);
132 *r_loops++ = (l_iter->next);
133
134 r_index[0][0] = 0;
135 r_index[0][1] = 1;
136 r_index[0][2] = 2;
137
138 r_index[1][0] = 0;
139 r_index[1][1] = 2;
140 r_index[1][2] = 3;
141 }
142 else {
143 float axis_mat[3][3];
144 float(*projverts)[2] = BLI_array_alloca(projverts, f->len);
145 int j;
146
147 axis_dominant_v3_to_m3_negate(axis_mat, f->no);
148
149 j = 0;
150 l_iter = l_first;
151 do {
152 mul_v2_m3v3(projverts[j], axis_mat, l_iter->v->co);
153 r_loops[j] = l_iter;
154 j++;
155 } while ((l_iter = l_iter->next) != l_first);
156
157 /* complete the loop */
158 BLI_polyfill_calc(projverts, f->len, 1, r_index);
159 }
160}
161
162void BM_face_calc_point_in_face(const BMFace *f, float r_co[3])
163{
164 const BMLoop *ltri[3];
165
166 if (f->len == 3) {
167 const BMLoop *l = BM_FACE_FIRST_LOOP(f);
168 ARRAY_SET_ITEMS(ltri, l, l->next, l->prev);
169 }
170 else {
171 /* tessellation here seems overkill when in many cases this will be the center,
172 * but without this we can't be sure the point is inside a concave face. */
173 const int tottri = f->len - 2;
174 BMLoop **loops = BLI_array_alloca(loops, f->len);
175 uint(*index)[3] = BLI_array_alloca(index, tottri);
176 int j;
177 int j_best = 0; /* use as fallback when unset */
178 float area_best = -1.0f;
179
180 BM_face_calc_tessellation(f, false, loops, index);
181
182 for (j = 0; j < tottri; j++) {
183 const float *p1 = loops[index[j][0]]->v->co;
184 const float *p2 = loops[index[j][1]]->v->co;
185 const float *p3 = loops[index[j][2]]->v->co;
186 const float area = area_squared_tri_v3(p1, p2, p3);
187 if (area > area_best) {
188 j_best = j;
189 area_best = area;
190 }
191 }
192
194 ltri, loops[index[j_best][0]], loops[index[j_best][1]], loops[index[j_best][2]]);
195 }
196
197 mid_v3_v3v3v3(r_co, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co);
198}
199
201{
202 /* inline 'area_poly_v3' logic, avoid creating a temp array */
203 const BMLoop *l_iter, *l_first;
204 float n[3];
205
206 zero_v3(n);
207 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
208 do {
209 add_newell_cross_v3_v3v3(n, l_iter->v->co, l_iter->next->v->co);
210 } while ((l_iter = l_iter->next) != l_first);
211 return len_v3(n) * 0.5f;
212}
213
214float BM_face_calc_area_with_mat3(const BMFace *f, const float mat3[3][3])
215{
216 /* inline 'area_poly_v3' logic, avoid creating a temp array */
217 const BMLoop *l_iter, *l_first;
218 float co[3];
219 float n[3];
220
221 zero_v3(n);
222 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
223 mul_v3_m3v3(co, mat3, l_iter->v->co);
224 do {
225 float co_next[3];
226 mul_v3_m3v3(co_next, mat3, l_iter->next->v->co);
227 add_newell_cross_v3_v3v3(n, co, co_next);
228 copy_v3_v3(co, co_next);
229 } while ((l_iter = l_iter->next) != l_first);
230 return len_v3(n) * 0.5f;
231}
232
233float BM_face_calc_area_uv_signed(const BMFace *f, int cd_loop_uv_offset)
234{
235 /* inline 'area_poly_v2' logic, avoid creating a temp array */
236 const BMLoop *l_iter, *l_first;
237
238 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
239 /* Green's theorem applied to area of a polygon.
240 * TODO: `cross` should be of type `double` to reduce rounding error. */
241 float cross = 0.0f;
242 do {
243 const float *luv = BM_ELEM_CD_GET_FLOAT_P(l_iter, cd_loop_uv_offset);
244 const float *luv_next = BM_ELEM_CD_GET_FLOAT_P(l_iter->next, cd_loop_uv_offset);
245 cross += (luv_next[0] - luv[0]) * (luv_next[1] + luv[1]);
246 } while ((l_iter = l_iter->next) != l_first);
247 return cross * 0.5f;
248}
249
250float BM_face_calc_area_uv(const BMFace *f, int cd_loop_uv_offset)
251{
252 return fabsf(BM_face_calc_area_uv_signed(f, cd_loop_uv_offset));
253}
254
256{
257 const BMLoop *l_iter, *l_first;
258 float perimeter = 0.0f;
259
260 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
261 do {
262 perimeter += len_v3v3(l_iter->v->co, l_iter->next->v->co);
263 } while ((l_iter = l_iter->next) != l_first);
264
265 return perimeter;
266}
267
268float BM_face_calc_perimeter_with_mat3(const BMFace *f, const float mat3[3][3])
269{
270 const BMLoop *l_iter, *l_first;
271 float co[3];
272 float perimeter = 0.0f;
273
274 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
275 mul_v3_m3v3(co, mat3, l_iter->v->co);
276 do {
277 float co_next[3];
278 mul_v3_m3v3(co_next, mat3, l_iter->next->v->co);
279 perimeter += len_v3v3(co, co_next);
280 copy_v3_v3(co, co_next);
281 } while ((l_iter = l_iter->next) != l_first);
282
283 return perimeter;
284}
285
292{
293/* find the most 'unique' loop, (greatest difference to others) */
294#if 1
295 /* Optimized version that avoids `sqrt`. */
296 float difs[3];
297 for (int i_prev = 1, i_curr = 2, i_next = 0; i_next < 3; i_prev = i_curr, i_curr = i_next++) {
298 const float *co = verts[i_curr]->co;
299 const float *co_other[2] = {verts[i_prev]->co, verts[i_next]->co};
300 float proj_dir[3];
301 mid_v3_v3v3(proj_dir, co_other[0], co_other[1]);
302 sub_v3_v3(proj_dir, co);
303
304 float proj_pair[2][3];
305 project_v3_v3v3(proj_pair[0], co_other[0], proj_dir);
306 project_v3_v3v3(proj_pair[1], co_other[1], proj_dir);
307 difs[i_next] = len_squared_v3v3(proj_pair[0], proj_pair[1]);
308 }
309#else
310 const float lens[3] = {
311 len_v3v3(verts[0]->co, verts[1]->co),
312 len_v3v3(verts[1]->co, verts[2]->co),
313 len_v3v3(verts[2]->co, verts[0]->co),
314 };
315 const float difs[3] = {
316 fabsf(lens[1] - lens[2]),
317 fabsf(lens[2] - lens[0]),
318 fabsf(lens[0] - lens[1]),
319 };
320#endif
321
322 int order[3] = {0, 1, 2};
323 axis_sort_v3(difs, order);
324
325 return order[0];
326}
327
328void BM_vert_tri_calc_tangent_edge(BMVert *verts[3], float r_tangent[3])
329{
330 const int index = bm_vert_tri_find_unique_edge(verts);
331
332 sub_v3_v3v3(r_tangent, verts[index]->co, verts[(index + 1) % 3]->co);
333
334 normalize_v3(r_tangent);
335}
336
338{
339 const int index = bm_vert_tri_find_unique_edge(verts);
340
341 const float *v_a = verts[index]->co;
342 const float *v_b = verts[(index + 1) % 3]->co;
343 const float *v_other = verts[(index + 2) % 3]->co;
344
345 mid_v3_v3v3(r_tangent, v_a, v_b);
346 sub_v3_v3v3(r_tangent, v_other, r_tangent);
347
348 normalize_v3(r_tangent);
349}
350
351void BM_face_calc_tangent_edge(const BMFace *f, float r_tangent[3])
352{
353 const BMLoop *l_long = BM_face_find_longest_loop((BMFace *)f);
354
355 sub_v3_v3v3(r_tangent, l_long->v->co, l_long->next->v->co);
356
357 normalize_v3(r_tangent);
358}
359
360void BM_face_calc_tangent_edge_pair(const BMFace *f, float r_tangent[3])
361{
362 if (f->len == 3) {
363 BMVert *verts[3];
364
366
368 }
369 else if (f->len == 4) {
370 /* Use longest edge pair */
371 BMVert *verts[4];
372 float vec[3], vec_a[3], vec_b[3];
373
375
376 sub_v3_v3v3(vec_a, verts[3]->co, verts[2]->co);
377 sub_v3_v3v3(vec_b, verts[0]->co, verts[1]->co);
378 add_v3_v3v3(r_tangent, vec_a, vec_b);
379
380 sub_v3_v3v3(vec_a, verts[0]->co, verts[3]->co);
381 sub_v3_v3v3(vec_b, verts[1]->co, verts[2]->co);
382 add_v3_v3v3(vec, vec_a, vec_b);
383 /* use the longest edge length */
384 if (len_squared_v3(r_tangent) < len_squared_v3(vec)) {
385 copy_v3_v3(r_tangent, vec);
386 }
387 }
388 else {
389 /* For ngons use two longest disconnected edges */
391 BMLoop *l_long_other = nullptr;
392
393 float len_max_sq = 0.0f;
394 float vec_a[3], vec_b[3];
395
396 BMLoop *l_iter = l_long->prev->prev;
397 BMLoop *l_last = l_long->next;
398
399 do {
400 const float len_sq = len_squared_v3v3(l_iter->v->co, l_iter->next->v->co);
401 if (len_sq >= len_max_sq) {
402 l_long_other = l_iter;
403 len_max_sq = len_sq;
404 }
405 } while ((l_iter = l_iter->prev) != l_last);
406
407 sub_v3_v3v3(vec_a, l_long->next->v->co, l_long->v->co);
408 sub_v3_v3v3(vec_b, l_long_other->v->co, l_long_other->next->v->co);
409 add_v3_v3v3(r_tangent, vec_a, vec_b);
410
411 /* Edges may not be opposite side of the ngon,
412 * this could cause problems for ngons with multiple-aligned edges of the same length.
413 * Fallback to longest edge. */
414 if (UNLIKELY(normalize_v3(r_tangent) == 0.0f)) {
415 normalize_v3_v3(r_tangent, vec_a);
416 }
417 }
418}
419
420void BM_face_calc_tangent_edge_diagonal(const BMFace *f, float r_tangent[3])
421{
422 BMLoop *l_iter, *l_first;
423
424 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
425
426 /* In case of degenerate faces. */
427 zero_v3(r_tangent);
428
429 /* WARNING: O(n^2) loop here, take care! */
430 float dist_max_sq = 0.0f;
431 do {
432 BMLoop *l_iter_other = l_iter->next;
433 BMLoop *l_iter_last = l_iter->prev;
434 do {
435 BLI_assert(!ELEM(l_iter->v, l_iter_other->v, l_iter_other->next->v));
436 float co_other[3], vec[3];
438 co_other, l_iter->v->co, l_iter_other->v->co, l_iter_other->next->v->co);
439 sub_v3_v3v3(vec, l_iter->v->co, co_other);
440
441 const float dist_sq = len_squared_v3(vec);
442 if (dist_sq > dist_max_sq) {
443 dist_max_sq = dist_sq;
444 copy_v3_v3(r_tangent, vec);
445 }
446 } while ((l_iter_other = l_iter_other->next) != l_iter_last);
447 } while ((l_iter = l_iter->next) != l_first);
448
449 normalize_v3(r_tangent);
450}
451
452void BM_face_calc_tangent_vert_diagonal(const BMFace *f, float r_tangent[3])
453{
454 BMLoop *l_iter, *l_first;
455
456 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
457
458 /* In case of degenerate faces. */
459 zero_v3(r_tangent);
460
461 /* WARNING: O(n^2) loop here, take care! */
462 float dist_max_sq = 0.0f;
463 do {
464 BMLoop *l_iter_other = l_iter->next;
465 do {
466 float vec[3];
467 sub_v3_v3v3(vec, l_iter->v->co, l_iter_other->v->co);
468
469 const float dist_sq = len_squared_v3(vec);
470 if (dist_sq > dist_max_sq) {
471 dist_max_sq = dist_sq;
472 copy_v3_v3(r_tangent, vec);
473 }
474 } while ((l_iter_other = l_iter_other->next) != l_iter);
475 } while ((l_iter = l_iter->next) != l_first);
476
477 normalize_v3(r_tangent);
478}
479
480void BM_face_calc_tangent_auto(const BMFace *f, float r_tangent[3])
481{
482 if (f->len == 3) {
483 /* most 'unique' edge of a triangle */
484 BMVert *verts[3];
487 }
488 else if (f->len == 4) {
489 /* longest edge pair of a quad */
490 BM_face_calc_tangent_edge_pair((BMFace *)f, r_tangent);
491 }
492 else {
493 /* longest edge of an ngon */
494 BM_face_calc_tangent_edge((BMFace *)f, r_tangent);
495 }
496}
497
498void BM_face_calc_bounds_expand(const BMFace *f, float min[3], float max[3])
499{
500 const BMLoop *l_iter, *l_first;
501 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
502 do {
503 minmax_v3v3_v3(min, max, l_iter->v->co);
504 } while ((l_iter = l_iter->next) != l_first);
505}
506
507void BM_face_calc_center_bounds(const BMFace *f, float r_cent[3])
508{
509 const BMLoop *l_iter, *l_first;
510 float min[3], max[3];
511
512 INIT_MINMAX(min, max);
513
514 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
515 do {
516 minmax_v3v3_v3(min, max, l_iter->v->co);
517 } while ((l_iter = l_iter->next) != l_first);
518
519 mid_v3_v3v3(r_cent, min, max);
520}
521
523 const BMFace *f,
524 float r_cent[3],
525 const blender::Span<blender::float3> vert_positions)
526{
527 /* must have valid index data */
529 (void)bm;
530
531 const BMLoop *l_iter, *l_first;
532 float min[3], max[3];
533
534 INIT_MINMAX(min, max);
535
536 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
537 do {
538 minmax_v3v3_v3(min, max, vert_positions[BM_elem_index_get(l_iter->v)]);
539 } while ((l_iter = l_iter->next) != l_first);
540
541 mid_v3_v3v3(r_cent, min, max);
542}
543
544void BM_face_calc_center_median(const BMFace *f, float r_cent[3])
545{
546 const BMLoop *l_iter, *l_first;
547
548 zero_v3(r_cent);
549
550 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
551 do {
552 add_v3_v3(r_cent, l_iter->v->co);
553 } while ((l_iter = l_iter->next) != l_first);
554 mul_v3_fl(r_cent, 1.0f / float(f->len));
555}
556
557void BM_face_calc_center_median_weighted(const BMFace *f, float r_cent[3])
558{
559 const BMLoop *l_iter;
560 const BMLoop *l_first;
561 float totw = 0.0f;
562 float w_prev;
563
564 zero_v3(r_cent);
565
566 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
567 w_prev = BM_edge_calc_length(l_iter->prev->e);
568 do {
569 const float w_curr = BM_edge_calc_length(l_iter->e);
570 const float w = (w_curr + w_prev);
571 madd_v3_v3fl(r_cent, l_iter->v->co, w);
572 totw += w;
573 w_prev = w_curr;
574 } while ((l_iter = l_iter->next) != l_first);
575
576 if (totw != 0.0f) {
577 mul_v3_fl(r_cent, 1.0f / float(totw));
578 }
579}
580
581void poly_rotate_plane(const float normal[3], float (*verts)[3], const uint nverts)
582{
583 float mat[3][3];
584 float co[3];
585 uint i;
586
587 co[2] = 0.0f;
588
589 axis_dominant_v3_to_m3(mat, normal);
590 for (i = 0; i < nverts; i++) {
591 mul_v2_m3v3(co, mat, verts[i]);
592 copy_v3_v3(verts[i], co);
593 }
594}
595
597{
598 BMIter iter;
599 BMFace *f;
600
601 BM_ITER_ELEM (f, &iter, e, BM_FACES_OF_EDGE) {
603 }
604
607}
608
609static void bm_loop_normal_accum(const BMLoop *l, float no[3])
610{
611 float vec1[3], vec2[3], fac;
612
613 /* Same calculation used in BM_mesh_normals_update */
614 sub_v3_v3v3(vec1, l->v->co, l->prev->v->co);
615 sub_v3_v3v3(vec2, l->next->v->co, l->v->co);
616 normalize_v3(vec1);
617 normalize_v3(vec2);
618
619 fac = blender::math::safe_acos_approx(-dot_v3v3(vec1, vec2));
620
621 madd_v3_v3fl(no, l->f->no, fac);
622}
623
624bool BM_vert_calc_normal_ex(const BMVert *v, const char hflag, float r_no[3])
625{
626 int len = 0;
627
628 zero_v3(r_no);
629
630 if (v->e) {
631 const BMEdge *e = v->e;
632 do {
633 if (e->l) {
634 const BMLoop *l = e->l;
635 do {
636 if (l->v == v) {
637 if (BM_elem_flag_test(l->f, hflag)) {
638 bm_loop_normal_accum(l, r_no);
639 len++;
640 }
641 }
642 } while ((l = l->radial_next) != e->l);
643 }
644 } while ((e = bmesh_disk_edge_next(e, v)) != v->e);
645 }
646
647 if (len) {
648 normalize_v3(r_no);
649 return true;
650 }
651 return false;
652}
653
654bool BM_vert_calc_normal(const BMVert *v, float r_no[3])
655{
656 int len = 0;
657
658 zero_v3(r_no);
659
660 if (v->e) {
661 const BMEdge *e = v->e;
662 do {
663 if (e->l) {
664 const BMLoop *l = e->l;
665 do {
666 if (l->v == v) {
667 bm_loop_normal_accum(l, r_no);
668 len++;
669 }
670 } while ((l = l->radial_next) != e->l);
671 }
672 } while ((e = bmesh_disk_edge_next(e, v)) != v->e);
673 }
674
675 if (len) {
676 normalize_v3(r_no);
677 return true;
678 }
679 return false;
680}
681
683{
684 int len = 0;
685
686 zero_v3(v->no);
687
688 if (v->e) {
689 const BMEdge *e = v->e;
690 do {
691 if (e->l) {
692 const BMLoop *l = e->l;
693 do {
694 if (l->v == v) {
697 len++;
698 }
699 } while ((l = l->radial_next) != e->l);
700 }
701 } while ((e = bmesh_disk_edge_next(e, v)) != v->e);
702 }
703
704 if (len) {
705 normalize_v3(v->no);
706 }
707}
708
713
714float BM_face_calc_normal(const BMFace *f, float r_no[3])
715{
716 BMLoop *l;
717
718 /* common cases first */
719 switch (f->len) {
720 case 4: {
721 const float *co1 = (l = BM_FACE_FIRST_LOOP(f))->v->co;
722 const float *co2 = (l = l->next)->v->co;
723 const float *co3 = (l = l->next)->v->co;
724 const float *co4 = (l->next)->v->co;
725
726 return normal_quad_v3(r_no, co1, co2, co3, co4);
727 }
728 case 3: {
729 const float *co1 = (l = BM_FACE_FIRST_LOOP(f))->v->co;
730 const float *co2 = (l = l->next)->v->co;
731 const float *co3 = (l->next)->v->co;
732
733 return normal_tri_v3(r_no, co1, co2, co3);
734 }
735 default: {
736 return bm_face_calc_poly_normal(f, r_no);
737 }
738 }
739}
741{
742 BM_face_calc_normal(f, f->no);
743}
744
746 const BMFace *f,
747 float r_no[3],
748 const Span<float3> vertexCos)
749{
750 BMLoop *l;
751
752 /* must have valid index data */
754 (void)bm;
755
756 /* common cases first */
757 switch (f->len) {
758 case 4: {
759 const float *co1 = vertexCos[BM_elem_index_get((l = BM_FACE_FIRST_LOOP(f))->v)];
760 const float *co2 = vertexCos[BM_elem_index_get((l = l->next)->v)];
761 const float *co3 = vertexCos[BM_elem_index_get((l = l->next)->v)];
762 const float *co4 = vertexCos[BM_elem_index_get((l->next)->v)];
763
764 return normal_quad_v3(r_no, co1, co2, co3, co4);
765 }
766 case 3: {
767 const float *co1 = vertexCos[BM_elem_index_get((l = BM_FACE_FIRST_LOOP(f))->v)];
768 const float *co2 = vertexCos[BM_elem_index_get((l = l->next)->v)];
769 const float *co3 = vertexCos[BM_elem_index_get((l->next)->v)];
770
771 return normal_tri_v3(r_no, co1, co2, co3);
772 }
773 default: {
774 return bm_face_calc_poly_normal_vertex_cos(f, r_no, vertexCos);
775 }
776 }
777}
778
780 BMVert **varr, int varr_len, float r_normal[3], float r_center[3], int *r_index_tangent)
781{
782 const float varr_len_inv = 1.0f / float(varr_len);
783
784 /* Get the center point and collect vector array since we loop over these a lot. */
785 float center[3] = {0.0f, 0.0f, 0.0f};
786 for (int i = 0; i < varr_len; i++) {
787 madd_v3_v3fl(center, varr[i]->co, varr_len_inv);
788 }
789
790 /* Find the 'co_a' point from center. */
791 int co_a_index = 0;
792 const float *co_a = nullptr;
793 {
794 float dist_sq_max = -1.0f;
795 for (int i = 0; i < varr_len; i++) {
796 const float dist_sq_test = len_squared_v3v3(varr[i]->co, center);
797 if (!(dist_sq_test <= dist_sq_max)) {
798 co_a = varr[i]->co;
799 co_a_index = i;
800 dist_sq_max = dist_sq_test;
801 }
802 }
803 }
804
805 float dir_a[3];
806 sub_v3_v3v3(dir_a, co_a, center);
807 normalize_v3(dir_a);
808
809 const float *co_b = nullptr;
810 float dir_b[3] = {0.0f, 0.0f, 0.0f};
811 {
812 float dist_sq_max = -1.0f;
813 for (int i = 0; i < varr_len; i++) {
814 if (varr[i]->co == co_a) {
815 continue;
816 }
817 float dir_test[3];
818 sub_v3_v3v3(dir_test, varr[i]->co, center);
819 project_plane_normalized_v3_v3v3(dir_test, dir_test, dir_a);
820 const float dist_sq_test = len_squared_v3(dir_test);
821 if (!(dist_sq_test <= dist_sq_max)) {
822 co_b = varr[i]->co;
823 dist_sq_max = dist_sq_test;
824 copy_v3_v3(dir_b, dir_test);
825 }
826 }
827 }
828
829 if (varr_len <= 3) {
830 normal_tri_v3(r_normal, center, co_a, co_b);
831 goto finally;
832 }
833
834 {
835 normalize_v3(dir_b);
836
837 const float *co_a_opposite = nullptr;
838 const float *co_b_opposite = nullptr;
839
840 {
841 float dot_a_min = FLT_MAX;
842 float dot_b_min = FLT_MAX;
843 for (int i = 0; i < varr_len; i++) {
844 const float *co_test = varr[i]->co;
845 float dot_test;
846
847 if (co_test != co_a) {
848 dot_test = dot_v3v3(dir_a, co_test);
849 if (dot_test < dot_a_min) {
850 dot_a_min = dot_test;
851 co_a_opposite = co_test;
852 }
853 }
854
855 if (co_test != co_b) {
856 dot_test = dot_v3v3(dir_b, co_test);
857 if (dot_test < dot_b_min) {
858 dot_b_min = dot_test;
859 co_b_opposite = co_test;
860 }
861 }
862 }
863 }
864
865 normal_quad_v3(r_normal, co_a, co_b, co_a_opposite, co_b_opposite);
866 }
867
868finally:
869 if (r_center != nullptr) {
870 copy_v3_v3(r_center, center);
871 }
872 if (r_index_tangent != nullptr) {
873 *r_index_tangent = co_a_index;
874 }
875}
876
877void BM_verts_calc_normal_from_cloud(BMVert **varr, int varr_len, float r_normal[3])
878{
879 BM_verts_calc_normal_from_cloud_ex(varr, varr_len, r_normal, nullptr, nullptr);
880}
881
882float BM_face_calc_normal_subset(const BMLoop *l_first, const BMLoop *l_last, float r_no[3])
883{
884 const float *v_prev, *v_curr;
885
886 /* Newell's Method */
887 const BMLoop *l_iter = l_first;
888 const BMLoop *l_term = l_last->next;
889
890 zero_v3(r_no);
891
892 v_prev = l_last->v->co;
893 do {
894 v_curr = l_iter->v->co;
895 add_newell_cross_v3_v3v3(r_no, v_prev, v_curr);
896 v_prev = v_curr;
897 } while ((l_iter = l_iter->next) != l_term);
898
899 return normalize_v3(r_no);
900}
901
903 const BMFace *f,
904 float r_cent[3],
905 const blender::Span<blender::float3> vert_positions)
906{
907 /* must have valid index data */
909 (void)bm;
910
911 bm_face_calc_poly_center_median_vertex_cos(f, r_cent, vert_positions);
912}
913
915 BMFace *f,
916 const int cd_loop_mdisp_offset,
917 const bool use_loop_mdisp_flip)
918{
919 bmesh_kernel_loop_reverse(bm, f, cd_loop_mdisp_offset, use_loop_mdisp_flip);
920 negate_v3(f->no);
921}
922
924{
925 const int cd_loop_mdisp_offset = CustomData_get_offset(&bm->ldata, CD_MDISPS);
926 BM_face_normal_flip_ex(bm, f, cd_loop_mdisp_offset, true);
927}
928
929bool BM_face_point_inside_test(const BMFace *f, const float co[3])
930{
931 float axis_mat[3][3];
932 float(*projverts)[2] = BLI_array_alloca(projverts, f->len);
933
934 float co_2d[2];
935 BMLoop *l_iter;
936 int i;
937
939
940 axis_dominant_v3_to_m3(axis_mat, f->no);
941
942 mul_v2_m3v3(co_2d, axis_mat, co);
943
944 for (i = 0, l_iter = BM_FACE_FIRST_LOOP(f); i < f->len; i++, l_iter = l_iter->next) {
945 mul_v2_m3v3(projverts[i], axis_mat, l_iter->v->co);
946 }
947
948 return isect_point_poly_v2(co_2d, projverts, f->len);
949}
950
952 BMFace *f,
953 BMFace **r_faces_new,
954 int *r_faces_new_tot,
955 BMEdge **r_edges_new,
956 int *r_edges_new_tot,
957 LinkNode **r_faces_double,
958 const int quad_method,
959 const int ngon_method,
960 const bool use_tag,
961 /* use for ngons only! */
962 MemArena *pf_arena,
963
964 /* use for MOD_TRIANGULATE_NGON_BEAUTY only! */
965 Heap *pf_heap)
966{
967 const int cd_loop_mdisp_offset = CustomData_get_offset(&bm->ldata, CD_MDISPS);
968 const bool use_beauty = (ngon_method == MOD_TRIANGULATE_NGON_BEAUTY);
969 BMLoop *l_first, *l_new;
970 BMFace *f_new;
971 int nf_i = 0;
972 int ne_i = 0;
973
975
976 /* ensure both are valid or nullptr */
977 BLI_assert((r_faces_new == nullptr) == (r_faces_new_tot == nullptr));
978
979 BLI_assert(f->len > 3);
980
981 {
982 BMLoop **loops = BLI_array_alloca(loops, f->len);
983 uint(*tris)[3] = BLI_array_alloca(tris, f->len);
984 const int totfilltri = f->len - 2;
985 const int last_tri = f->len - 3;
986 int i;
987 /* for mdisps */
988 float f_center[3];
989
990 if (f->len == 4) {
991 /* even though we're not using BLI_polyfill, fill in 'tris' and 'loops'
992 * so we can share code to handle face creation afterwards. */
993 BMLoop *l_v1, *l_v2;
994
995 l_first = BM_FACE_FIRST_LOOP(f);
996
997 switch (quad_method) {
999 l_v1 = l_first;
1000 l_v2 = l_first->next->next;
1001 break;
1002 }
1004 l_v1 = l_first->next;
1005 l_v2 = l_first->prev;
1006 break;
1007 }
1011 default: {
1012 BMLoop *l_v3, *l_v4;
1013 bool split_24;
1014
1015 l_v1 = l_first->next;
1016 l_v2 = l_first->next->next;
1017 l_v3 = l_first->prev;
1018 l_v4 = l_first;
1019
1020 if (quad_method == MOD_TRIANGULATE_QUAD_SHORTEDGE) {
1021 float d1, d2;
1022 d1 = len_squared_v3v3(l_v4->v->co, l_v2->v->co);
1023 d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co);
1024 split_24 = ((d2 - d1) > 0.0f);
1025 }
1026 else if (quad_method == MOD_TRIANGULATE_QUAD_LONGEDGE) {
1027 float d1, d2;
1028 d1 = len_squared_v3v3(l_v4->v->co, l_v2->v->co);
1029 d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co);
1030 split_24 = ((d2 - d1) < 0.0f);
1031 }
1032 else {
1033 /* first check if the quad is concave on either diagonal */
1034 const int flip_flag = is_quad_flip_v3(
1035 l_v1->v->co, l_v2->v->co, l_v3->v->co, l_v4->v->co);
1036 if (UNLIKELY(flip_flag & (1 << 0))) {
1037 split_24 = true;
1038 }
1039 else if (UNLIKELY(flip_flag & (1 << 1))) {
1040 split_24 = false;
1041 }
1042 else {
1043 split_24 = (BM_verts_calc_rotate_beauty(l_v1->v, l_v2->v, l_v3->v, l_v4->v, 0, 0) >
1044 0.0f);
1045 }
1046 }
1047
1048 /* named confusingly, l_v1 is in fact the second vertex */
1049 if (split_24) {
1050 l_v1 = l_v4;
1051 // l_v2 = l_v2;
1052 }
1053 else {
1054 // l_v1 = l_v1;
1055 l_v2 = l_v3;
1056 }
1057 break;
1058 }
1059 }
1060
1061 loops[0] = l_v1;
1062 loops[1] = l_v1->next;
1063 loops[2] = l_v2;
1064 loops[3] = l_v2->next;
1065
1066 ARRAY_SET_ITEMS(tris[0], 0, 1, 2);
1067 ARRAY_SET_ITEMS(tris[1], 0, 2, 3);
1068 }
1069 else {
1070 BMLoop *l_iter;
1071 float axis_mat[3][3];
1072 float(*projverts)[2] = BLI_array_alloca(projverts, f->len);
1073
1074 axis_dominant_v3_to_m3_negate(axis_mat, f->no);
1075
1076 for (i = 0, l_iter = BM_FACE_FIRST_LOOP(f); i < f->len; i++, l_iter = l_iter->next) {
1077 loops[i] = l_iter;
1078 mul_v2_m3v3(projverts[i], axis_mat, l_iter->v->co);
1079 }
1080
1081 BLI_polyfill_calc_arena(projverts, f->len, 1, tris, pf_arena);
1082
1083 if (use_beauty) {
1084 BLI_polyfill_beautify(projverts, f->len, tris, pf_arena, pf_heap);
1085 }
1086
1087 BLI_memarena_clear(pf_arena);
1088 }
1089
1090 if (cd_loop_mdisp_offset != -1) {
1091 BM_face_calc_center_median(f, f_center);
1092 }
1093
1094 /* loop over calculated triangles and create new geometry */
1095 for (i = 0; i < totfilltri; i++) {
1096 BMLoop *ltri[3] = {loops[tris[i][0]], loops[tris[i][1]], loops[tris[i][2]]};
1097
1098 BMVert *v_tri[3] = {ltri[0]->v, ltri[1]->v, ltri[2]->v};
1099
1100 f_new = BM_face_create_verts(bm, v_tri, 3, f, BM_CREATE_NOP, true);
1101 l_new = BM_FACE_FIRST_LOOP(f_new);
1102
1103 BLI_assert(v_tri[0] == l_new->v);
1104
1105 /* check for duplicate */
1106 if (l_new->radial_next != l_new) {
1107 BMLoop *l_iter = l_new->radial_next;
1108 do {
1109 if (UNLIKELY((l_iter->f->len == 3) && (l_new->prev->v == l_iter->prev->v))) {
1110 /* Check the last tri because we swap last f_new with f at the end... */
1111 BLI_linklist_prepend(r_faces_double, (i != last_tri) ? f_new : f);
1112 break;
1113 }
1114 } while ((l_iter = l_iter->radial_next) != l_new);
1115 }
1116
1117 /* copy CD data */
1118 BM_elem_attrs_copy(bm, ltri[0], l_new);
1119 BM_elem_attrs_copy(bm, ltri[1], l_new->next);
1120 BM_elem_attrs_copy(bm, ltri[2], l_new->prev);
1121
1122 /* add all but the last face which is swapped and removed (below) */
1123 if (i != last_tri) {
1124 if (use_tag) {
1126 }
1127 if (r_faces_new) {
1128 r_faces_new[nf_i++] = f_new;
1129 }
1130 }
1131
1132 if (use_tag || r_edges_new) {
1133 /* new faces loops */
1134 BMLoop *l_iter;
1135
1136 l_iter = l_first = l_new;
1137 do {
1138 BMEdge *e = l_iter->e;
1139 /* Confusing! if its not a boundary now, we know it will be later since this will be an
1140 * edge of one of the new faces which we're in the middle of creating. */
1141 bool is_new_edge = (l_iter == l_iter->radial_next);
1142
1143 if (is_new_edge) {
1144 if (use_tag) {
1146 }
1147 if (r_edges_new) {
1148 r_edges_new[ne_i++] = e;
1149 }
1150 }
1151 /* NOTE: never disable tag's. */
1152 } while ((l_iter = l_iter->next) != l_first);
1153 }
1154
1155 if (cd_loop_mdisp_offset != -1) {
1156 float f_new_center[3];
1157 BM_face_calc_center_median(f_new, f_new_center);
1158 BM_face_interp_multires_ex(bm, f_new, f, f_new_center, f_center, cd_loop_mdisp_offset);
1159 }
1160 }
1161
1162 {
1163 /* we can't delete the real face, because some of the callers expect it to remain valid.
1164 * so swap data and delete the last created tri */
1165 bmesh_face_swap_data(f, f_new);
1166 BM_face_kill(bm, f_new);
1167 }
1168 }
1170
1171 if (r_faces_new_tot) {
1172 *r_faces_new_tot = nf_i;
1173 }
1174
1175 if (r_edges_new_tot) {
1176 *r_edges_new_tot = ne_i;
1177 }
1178}
1179
1181{
1182 float out[2] = {-FLT_MAX, -FLT_MAX};
1183 float center[2] = {0.0f, 0.0f};
1184 float axis_mat[3][3];
1185 float(*projverts)[2] = BLI_array_alloca(projverts, f->len);
1186 const float *(*edgeverts)[2] = BLI_array_alloca(edgeverts, len);
1187 BMLoop *l;
1188 int i, i_prev, j;
1189
1191
1192 axis_dominant_v3_to_m3(axis_mat, f->no);
1193
1194 for (i = 0, l = BM_FACE_FIRST_LOOP(f); i < f->len; i++, l = l->next) {
1195 mul_v2_m3v3(projverts[i], axis_mat, l->v->co);
1196 add_v2_v2(center, projverts[i]);
1197 }
1198
1199 /* first test for completely convex face */
1200 if (is_poly_convex_v2(projverts, f->len)) {
1201 return;
1202 }
1203
1204 mul_v2_fl(center, 1.0f / f->len);
1205
1206 for (i = 0, l = BM_FACE_FIRST_LOOP(f); i < f->len; i++, l = l->next) {
1207 BM_elem_index_set(l, i); /* set_dirty */
1208
1209 /* center the projection for maximum accuracy */
1210 sub_v2_v2(projverts[i], center);
1211
1212 out[0] = max_ff(out[0], projverts[i][0]);
1213 out[1] = max_ff(out[1], projverts[i][1]);
1214 }
1216
1217 /* ensure we are well outside the face bounds (value is arbitrary) */
1218 add_v2_fl(out, 1.0f);
1219
1220 for (i = 0; i < len; i++) {
1221 edgeverts[i][0] = projverts[BM_elem_index_get(loops[i][0])];
1222 edgeverts[i][1] = projverts[BM_elem_index_get(loops[i][1])];
1223 }
1224
1225 /* do convexity test */
1226 for (i = 0; i < len; i++) {
1227 float mid[2];
1228 mid_v2_v2v2(mid, edgeverts[i][0], edgeverts[i][1]);
1229
1230 int isect = 0;
1231 int j_prev;
1232 for (j = 0, j_prev = f->len - 1; j < f->len; j_prev = j++) {
1233 const float *f_edge[2] = {projverts[j_prev], projverts[j]};
1234 if (isect_seg_seg_v2(UNPACK2(f_edge), mid, out) == ISECT_LINE_LINE_CROSS) {
1235 isect++;
1236 }
1237 }
1238
1239 if (isect % 2 == 0) {
1240 loops[i][0] = nullptr;
1241 }
1242 }
1243
1244#define EDGE_SHARE_VERT(e1, e2) \
1245 (ELEM((e1)[0], (e2)[0], (e2)[1]) || ELEM((e1)[1], (e2)[0], (e2)[1]))
1246
1247 /* do line crossing tests */
1248 for (i = 0, i_prev = f->len - 1; i < f->len; i_prev = i++) {
1249 const float *f_edge[2] = {projverts[i_prev], projverts[i]};
1250 for (j = 0; j < len; j++) {
1251 if ((loops[j][0] != nullptr) && !EDGE_SHARE_VERT(f_edge, edgeverts[j])) {
1252 if (isect_seg_seg_v2(UNPACK2(f_edge), UNPACK2(edgeverts[j])) == ISECT_LINE_LINE_CROSS) {
1253 loops[j][0] = nullptr;
1254 }
1255 }
1256 }
1257 }
1258
1259 /* self intersect tests */
1260 for (i = 0; i < len; i++) {
1261 if (loops[i][0]) {
1262 for (j = i + 1; j < len; j++) {
1263 if ((loops[j][0] != nullptr) && !EDGE_SHARE_VERT(edgeverts[i], edgeverts[j])) {
1264 if (isect_seg_seg_v2(UNPACK2(edgeverts[i]), UNPACK2(edgeverts[j])) ==
1266 {
1267 loops[i][0] = nullptr;
1268 break;
1269 }
1270 }
1271 }
1272 }
1273 }
1274
1275#undef EDGE_SHARE_VERT
1276}
1277
1279{
1280 int i;
1281
1282 for (i = 0; i < len; i++) {
1283 BMLoop *l_a_dummy, *l_b_dummy;
1285 loops[i][0]->v, loops[i][1]->v, &l_a_dummy, &l_b_dummy, false))
1286 {
1287 loops[i][0] = nullptr;
1288 }
1289 }
1290}
1291
1293{
1295
1296 BLI_assert(f->len == 3);
1297
1298 r_verts[0] = l->v;
1299 l = l->next;
1300 r_verts[1] = l->v;
1301 l = l->next;
1302 r_verts[2] = l->v;
1303}
1304
1306{
1308
1309 BLI_assert(f->len == 4);
1310
1311 r_verts[0] = l->v;
1312 l = l->next;
1313 r_verts[1] = l->v;
1314 l = l->next;
1315 r_verts[2] = l->v;
1316 l = l->next;
1317 r_verts[3] = l->v;
1318}
1319
1321{
1323
1324 BLI_assert(f->len == 3);
1325
1326 r_loops[0] = l;
1327 l = l->next;
1328 r_loops[1] = l;
1329 l = l->next;
1330 r_loops[2] = l;
1331}
1332
1334{
1336
1337 BLI_assert(f->len == 4);
1338
1339 r_loops[0] = l;
1340 l = l->next;
1341 r_loops[1] = l;
1342 l = l->next;
1343 r_loops[2] = l;
1344 l = l->next;
1345 r_loops[3] = l;
1346}
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
#define BLI_array_alloca(arr, realsize)
Definition BLI_alloca.h:25
#define BLI_assert(a)
Definition BLI_assert.h:50
MINLINE float max_ff(float a, float b)
int isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
float normal_quad_v3(float n[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
Definition math_geom.cc:56
int is_quad_flip_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3])
bool isect_point_poly_v2(const float pt[2], const float verts[][2], unsigned int nr)
float closest_to_line_segment_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3])
Definition math_geom.cc:385
void axis_dominant_v3_to_m3_negate(float r_mat[3][3], const float normal[3])
void axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3])
Normal to x,y matrix.
float area_squared_tri_v3(const float v1[3], const float v2[3], const float v3[3])
Definition math_geom.cc:105
bool is_poly_convex_v2(const float verts[][2], unsigned int nr)
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
Definition math_geom.cc:39
#define ISECT_LINE_LINE_CROSS
void mul_v2_m3v3(float r[2], const float M[3][3], const float a[3])
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
void axis_sort_v3(const float axis_values[3], int r_axis_order[3])
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void sub_v2_v2(float r[2], const float a[2])
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void project_v3_v3v3(float out[3], const float p[3], const float v_proj[3])
MINLINE void add_v2_v2(float r[2], const float a[2])
void project_plane_normalized_v3_v3v3(float out[3], const float p[3], const float v_plane[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void add_v2_fl(float r[2], float f)
MINLINE void negate_v3(float r[3])
void mid_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE float normalize_v3_v3(float r[3], const float a[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])
void mid_v3_v3v3v3(float v[3], const float v1[3], const float v2[3], const float v3[3])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
void void BLI_memarena_clear(MemArena *ma) ATTR_NONNULL(1)
void BLI_polyfill_calc(const float(*coords)[2], unsigned int coords_num, int coords_sign, unsigned int(*r_tris)[3])
void BLI_polyfill_calc_arena(const float(*coords)[2], unsigned int coords_num, int coords_sign, unsigned int(*r_tris)[3], struct MemArena *arena)
void BLI_polyfill_beautify(const float(*coords)[2], unsigned int coords_num, unsigned int(*tris)[3], struct MemArena *arena, struct Heap *eheap)
unsigned int uint
#define UNPACK2(a)
#define INIT_MINMAX(min, max)
#define ARRAY_SET_ITEMS(...)
#define UNLIKELY(x)
#define ELEM(...)
These structs are the foundation for all linked lists in the library system.
@ MOD_TRIANGULATE_QUAD_SHORTEDGE
@ MOD_TRIANGULATE_QUAD_FIXED
@ MOD_TRIANGULATE_QUAD_LONGEDGE
@ MOD_TRIANGULATE_QUAD_BEAUTY
@ MOD_TRIANGULATE_QUAD_ALTERNATE
@ MOD_TRIANGULATE_NGON_BEAUTY
Read Guarded memory(de)allocation.
float BM_verts_calc_rotate_beauty(const BMVert *v1, const BMVert *v2, const BMVert *v3, const BMVert *v4, const short flag, const short method)
@ BM_LOOP
@ BM_ELEM_TAG
#define BM_FACE_FIRST_LOOP(p)
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
void bmesh_face_swap_data(BMFace *f_a, BMFace *f_b)
void BM_face_kill(BMesh *bm, BMFace *f)
BMFace * BM_face_create_verts(BMesh *bm, BMVert **vert_arr, const int len, const BMFace *f_example, const eBMCreateFlag create_flag, const bool create_edges)
void bmesh_kernel_loop_reverse(BMesh *bm, BMFace *f, const int cd_loop_mdisp_offset, const bool use_loop_mdisp_flip)
Loop Reverse.
@ BM_CREATE_NOP
Definition bmesh_core.hh:24
#define BM_elem_index_get(ele)
#define BM_elem_index_set(ele, index)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
void BM_face_interp_multires_ex(BMesh *bm, BMFace *f_dst, const BMFace *f_src, const float f_dst_center[3], const float f_src_center[3], const int cd_loop_mdisp_offset)
#define BM_ITER_ELEM(ele, iter, data, itype)
@ BM_FACES_OF_EDGE
ATTR_WARN_UNUSED_RESULT BMesh * bm
#define BM_FACE
#define BM_VERT
void BM_face_calc_tangent_edge_pair(const BMFace *f, float r_tangent[3])
void BM_face_as_array_loop_tri(BMFace *f, BMLoop *r_loops[3])
float BM_face_calc_area_uv(const BMFace *f, int cd_loop_uv_offset)
void poly_rotate_plane(const float normal[3], float(*verts)[3], const uint nverts)
POLY ROTATE PLANE.
void BM_face_splits_check_optimal(BMFace *f, BMLoop *(*loops)[2], int len)
void BM_face_calc_center_bounds(const BMFace *f, float r_cent[3])
static void bm_face_calc_poly_center_median_vertex_cos(const BMFace *f, float r_cent[3], const blender::Span< blender::float3 > vert_positions)
COMPUTE POLY CENTER (BMFace)
void BM_vert_normal_update(BMVert *v)
void BM_face_splits_check_legal(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len)
void BM_face_calc_tangent_vert_diagonal(const BMFace *f, float r_tangent[3])
void BM_face_as_array_vert_quad(BMFace *f, BMVert *r_verts[4])
static int bm_vert_tri_find_unique_edge(BMVert *verts[3])
float BM_face_calc_area_with_mat3(const BMFace *f, const float mat3[3][3])
void BM_face_calc_point_in_face(const BMFace *f, float r_co[3])
void BM_verts_calc_normal_from_cloud(BMVert **varr, int varr_len, float r_normal[3])
bool BM_face_point_inside_test(const BMFace *f, const float co[3])
float BM_face_calc_area_uv_signed(const BMFace *f, int cd_loop_uv_offset)
bool BM_vert_calc_normal(const BMVert *v, float r_no[3])
void BM_face_calc_tangent_edge_diagonal(const BMFace *f, float r_tangent[3])
void BM_face_calc_center_bounds_vcos(const BMesh *bm, const BMFace *f, float r_cent[3], const blender::Span< blender::float3 > vert_positions)
void BM_face_normal_flip_ex(BMesh *bm, BMFace *f, const int cd_loop_mdisp_offset, const bool use_loop_mdisp_flip)
Face Flip Normal.
void BM_vert_tri_calc_tangent_edge(BMVert *verts[3], float r_tangent[3])
void BM_face_normal_update(BMFace *f)
void BM_face_as_array_vert_tri(BMFace *f, BMVert *r_verts[3])
bool BM_vert_calc_normal_ex(const BMVert *v, const char hflag, float r_no[3])
void BM_face_as_array_loop_quad(BMFace *f, BMLoop *r_loops[4])
float BM_face_calc_normal_vcos(const BMesh *bm, const BMFace *f, float r_no[3], const Span< float3 > vertexCos)
void BM_face_normal_flip(BMesh *bm, BMFace *f)
void BM_face_calc_tangent_edge(const BMFace *f, float r_tangent[3])
void BM_face_calc_center_median_vcos(const BMesh *bm, const BMFace *f, float r_cent[3], const blender::Span< blender::float3 > vert_positions)
void BM_verts_calc_normal_from_cloud_ex(BMVert **varr, int varr_len, float r_normal[3], float r_center[3], int *r_index_tangent)
void BM_face_calc_bounds_expand(const BMFace *f, float min[3], float max[3])
float BM_face_calc_area(const BMFace *f)
#define EDGE_SHARE_VERT(e1, e2)
float BM_face_calc_normal_subset(const BMLoop *l_first, const BMLoop *l_last, float r_no[3])
float BM_face_calc_normal(const BMFace *f, float r_no[3])
BMESH UPDATE FACE NORMAL.
float BM_face_calc_perimeter_with_mat3(const BMFace *f, const float mat3[3][3])
void BM_face_triangulate(BMesh *bm, BMFace *f, BMFace **r_faces_new, int *r_faces_new_tot, BMEdge **r_edges_new, int *r_edges_new_tot, LinkNode **r_faces_double, const int quad_method, const int ngon_method, const bool use_tag, MemArena *pf_arena, Heap *pf_heap)
static float bm_face_calc_poly_normal_vertex_cos(const BMFace *f, float r_no[3], const Span< float3 > vertexCos)
COMPUTE POLY NORMAL (BMFace)
static void bm_loop_normal_accum(const BMLoop *l, float no[3])
void BM_vert_tri_calc_tangent_edge_pair(BMVert *verts[3], float r_tangent[3])
void BM_face_calc_tessellation(const BMFace *f, const bool use_fixed_quad, BMLoop **r_loops, uint(*r_index)[3])
void BM_face_calc_center_median(const BMFace *f, float r_cent[3])
void BM_face_calc_tangent_auto(const BMFace *f, float r_tangent[3])
static float bm_face_calc_poly_normal(const BMFace *f, float n[3])
COMPUTE POLY NORMAL (BMFace)
void BM_face_calc_center_median_weighted(const BMFace *f, float r_cent[3])
void BM_vert_normal_update_all(BMVert *v)
float BM_face_calc_perimeter(const BMFace *f)
void BM_edge_normals_update(BMEdge *e)
bool BM_face_is_normal_valid(const BMFace *f)
BMFace * BM_vert_pair_share_face_by_angle(BMVert *v_a, BMVert *v_b, BMLoop **r_l_a, BMLoop **r_l_b, const bool allow_adjacent)
BMLoop * BM_face_find_longest_loop(BMFace *f)
float BM_edge_calc_length(const BMEdge *e)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
BLI_INLINE BMEdge * bmesh_disk_edge_next(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
#define fabsf(x)
int len
draw_view in_light_buf[] float
static float verts[][3]
ccl_device_inline float cross(const float2 a, const float2 b)
float safe_acos_approx(float x)
#define min(a, b)
Definition sort.c:32
#define FLT_MAX
Definition stdcycles.h:14
float no[3]
struct BMVert * v
struct BMEdge * e
struct BMLoop * radial_next
struct BMLoop * prev
struct BMFace * f
struct BMLoop * next
float co[3]
struct BMEdge * e
float no[3]
char elem_index_dirty
CustomData ldata