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