Blender V5.3
mesh_evaluate.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_mesh_types.h"
14#include "DNA_meshdata_types.h"
15
16#include "BLI_array_utils.hh"
17#include "BLI_index_range.hh"
18#include "BLI_math_geom_c.hh"
19#include "BLI_span.hh"
20#include "BLI_utildefines.hh"
21#include "BLI_virtual_array.hh"
22
23#include "BKE_attribute.hh"
24#include "BKE_mesh.hh"
25
26namespace blender {
27
28/* -------------------------------------------------------------------- */
31
32namespace bke::mesh {
33
34static float3 face_center_calc_ngon(const Span<float3> vert_positions, const Span<int> face_verts)
35{
36 const float w = 1.0f / float(face_verts.size());
37
38 float3 center(0);
39 for (const int i : face_verts.index_range()) {
40 center += vert_positions[face_verts[i]] * w;
41 }
42 return center;
43}
44
45float3 face_center_calc(const Span<float3> vert_positions, const Span<int> face_verts)
46{
47 if (face_verts.size() == 3) {
48 float3 center;
49 mid_v3_v3v3v3(center,
50 vert_positions[face_verts[0]],
51 vert_positions[face_verts[1]],
52 vert_positions[face_verts[2]]);
53 return center;
54 }
55 if (face_verts.size() == 4) {
56 float3 center;
57 mid_v3_v3v3v3v3(center,
58 vert_positions[face_verts[0]],
59 vert_positions[face_verts[1]],
60 vert_positions[face_verts[2]],
61 vert_positions[face_verts[3]]);
62 return center;
63 }
64 return face_center_calc_ngon(vert_positions, face_verts);
65}
66
67float face_area_calc(const Span<float3> vert_positions, const Span<int> face_verts)
68{
69 if (face_verts.size() == 3) {
70 return area_tri_v3(vert_positions[face_verts[0]],
71 vert_positions[face_verts[1]],
72 vert_positions[face_verts[2]]);
73 }
74 Array<float3, 32> coords(face_verts.size());
75 for (const int i : face_verts.index_range()) {
76 coords[i] = vert_positions[face_verts[i]];
77 }
78 return area_poly_v3(reinterpret_cast<const float (*)[3]>(coords.data()), face_verts.size());
79}
80
81} // namespace bke::mesh
82
84{
85 const Span<float3> positions = mesh->vert_positions();
86 const OffsetIndices faces = mesh->faces();
87 const Span<int> corner_verts = mesh->corner_verts();
88
89 float total_area = 0.0f;
90 for (const int i : faces.index_range()) {
91 total_area += bke::mesh::face_area_calc(positions, corner_verts.slice(faces[i]));
92 }
93 return total_area;
94}
95
96static float UNUSED_FUNCTION(mesh_calc_face_volume_centroid)(const int *face_verts,
97 const int face_size,
98 const float (*positions)[3],
99 float r_cent[3])
100{
101 const float *v_pivot, *v_step1;
102 float total_volume = 0.0f;
103
104 zero_v3(r_cent);
105
106 v_pivot = positions[face_verts[0]];
107 v_step1 = positions[face_verts[1]];
108
109 for (int i = 2; i < face_size; i++) {
110 const float *v_step2 = positions[face_verts[i]];
111
112 /* Calculate the 6x volume of the tetrahedron formed by the 3 vertices
113 * of the triangle and the origin as the fourth vertex */
114 const float tetra_volume = volume_tri_tetrahedron_signed_v3_6x(v_pivot, v_step1, v_step2);
115 total_volume += tetra_volume;
116
117 /* Calculate the centroid of the tetrahedron formed by the 3 vertices
118 * of the triangle and the origin as the fourth vertex.
119 * The centroid is simply the average of the 4 vertices.
120 *
121 * Note that the vector is 4x the actual centroid
122 * so the division can be done once at the end. */
123 for (uint j = 0; j < 3; j++) {
124 r_cent[j] += tetra_volume * (v_pivot[j] + v_step1[j] + v_step2[j]);
125 }
126
127 v_step1 = v_step2;
128 }
129
130 return total_volume;
131}
132
133namespace bke::mesh {
134
141 const Span<int> face_verts,
142 const float3 &reference_center,
143 float r_cent[3])
144{
145 /* See: mesh_calc_face_volume_centroid for comments. */
146 float v_pivot[3], v_step1[3];
147 float total_volume = 0.0f;
148 zero_v3(r_cent);
149 sub_v3_v3v3(v_pivot, positions[face_verts[0]], reference_center);
150 sub_v3_v3v3(v_step1, positions[face_verts[1]], reference_center);
151 for (int i = 2; i < face_verts.size(); i++) {
152 float v_step2[3];
153 sub_v3_v3v3(v_step2, positions[face_verts[i]], reference_center);
154 const float tetra_volume = volume_tri_tetrahedron_signed_v3_6x(v_pivot, v_step1, v_step2);
155 total_volume += tetra_volume;
156 for (uint j = 0; j < 3; j++) {
157 r_cent[j] += tetra_volume * (v_pivot[j] + v_step1[j] + v_step2[j]);
158 }
159 copy_v3_v3(v_step1, v_step2);
160 }
161 return total_volume;
162}
163
170static float face_area_centroid_calc(const Span<float3> positions,
171 const Span<int> face_verts,
172 float r_cent[3])
173{
174 float total_area = 0.0f;
175 float v1[3], v2[3], v3[3], tri_cent[3];
176
177 const float3 normal = bke::mesh::face_normal_calc(positions, face_verts);
178
179 copy_v3_v3(v1, positions[face_verts[0]]);
180 copy_v3_v3(v2, positions[face_verts[1]]);
181
182 zero_v3(r_cent);
183
184 for (int i = 2; i < face_verts.size(); i++) {
185 copy_v3_v3(v3, positions[face_verts[i]]);
186
187 float tri_area = area_tri_signed_v3(v1, v2, v3, normal);
188 total_area += tri_area;
189
190 mid_v3_v3v3v3(tri_cent, v1, v2, v3);
191 madd_v3_v3fl(r_cent, tri_cent, tri_area);
192
193 copy_v3_v3(v2, v3);
194 }
195
196 mul_v3_fl(r_cent, 1.0f / total_area);
197
198 return total_area;
199}
200
201void face_angles_calc(const Span<float3> vert_positions,
202 const Span<int> face_verts,
203 MutableSpan<float> angles)
204{
205 float nor_prev[3];
206 float nor_next[3];
207
208 int i_this = face_verts.size() - 1;
209 int i_next = 0;
210
212 nor_prev, vert_positions[face_verts[i_this - 1]], vert_positions[face_verts[i_this]]);
213 normalize_v3(nor_prev);
214
215 while (i_next < face_verts.size()) {
216 sub_v3_v3v3(nor_next, vert_positions[face_verts[i_this]], vert_positions[face_verts[i_next]]);
217 normalize_v3(nor_next);
218 angles[i_this] = angle_normalized_v3v3(nor_prev, nor_next);
219
220 /* step */
221 copy_v3_v3(nor_prev, nor_next);
222 i_this = i_next;
223 i_next++;
224 }
225}
226
227} // namespace bke::mesh
228
230
231/* -------------------------------------------------------------------- */
234
235bool BKE_mesh_center_median(const Mesh *mesh, float r_cent[3])
236{
237 float3 center = array_utils::compute_sum<float3>(mesh->vert_positions());
238
239 /* otherwise we get NAN for 0 verts */
240 if (mesh->verts_num) {
241 mul_v3_fl(center, 1.0 / float(mesh->verts_num));
242 }
243
244 copy_v3_v3(r_cent, center);
245
246 return (mesh->verts_num != 0);
247}
248
249bool BKE_mesh_center_median_from_faces(const Mesh *mesh, float r_cent[3])
250{
251 int tot = 0;
252 const Span<float3> positions = mesh->vert_positions();
253 const OffsetIndices faces = mesh->faces();
254 const Span<int> corner_verts = mesh->corner_verts();
255 zero_v3(r_cent);
256 for (const int i : faces.index_range()) {
257 for (const int vert : corner_verts.slice(faces[i])) {
258 add_v3_v3(r_cent, positions[vert]);
259 }
260 tot += faces[i].size();
261 }
262 /* otherwise we get NAN for 0 verts */
263 if (mesh->faces_num) {
264 mul_v3_fl(r_cent, 1.0f / float(tot));
265 }
266 return (mesh->faces_num != 0);
267}
268
269bool BKE_mesh_center_of_surface(const Mesh *mesh, float r_cent[3])
270{
271 float face_area;
272 float total_area = 0.0f;
273 float face_cent[3];
274 const Span<float3> positions = mesh->vert_positions();
275 const OffsetIndices faces = mesh->faces();
276 const Span<int> corner_verts = mesh->corner_verts();
277
278 zero_v3(r_cent);
279
280 /* calculate a weighted average of face centroids */
281 for (const int i : faces.index_range()) {
283 positions, corner_verts.slice(faces[i]), face_cent);
284
285 madd_v3_v3fl(r_cent, face_cent, face_area);
286 total_area += face_area;
287 }
288 /* otherwise we get NAN for 0 faces */
289 if (mesh->faces_num) {
290 mul_v3_fl(r_cent, 1.0f / total_area);
291 }
292
293 /* zero area faces cause this, fallback to median */
294 if (!is_finite_v3(r_cent)) [[unlikely]] {
295 return BKE_mesh_center_median(mesh, r_cent);
296 }
297
298 return (mesh->faces_num != 0);
299}
300
301bool BKE_mesh_center_of_volume(const Mesh *mesh, float r_cent[3])
302{
303 float face_volume;
304 float total_volume = 0.0f;
305 float face_cent[3];
306 const Span<float3> positions = mesh->vert_positions();
307 const OffsetIndices faces = mesh->faces();
308 const Span<int> corner_verts = mesh->corner_verts();
309
310 /* Use an initial center to avoid numeric instability of geometry far away from the center. */
311 float init_cent[3];
312 const bool init_cent_result = BKE_mesh_center_median_from_faces(mesh, init_cent);
313
314 zero_v3(r_cent);
315
316 /* calculate a weighted average of polyhedron centroids */
317 for (const int i : faces.index_range()) {
319 positions, corner_verts.slice(faces[i]), init_cent, face_cent);
320
321 /* face_cent is already volume-weighted, so no need to multiply by the volume */
322 add_v3_v3(r_cent, face_cent);
323 total_volume += face_volume;
324 }
325 /* otherwise we get NAN for 0 faces */
326 if (total_volume != 0.0f) {
327 /* multiply by 0.25 to get the correct centroid */
328 /* no need to divide volume by 6 as the centroid is weighted by 6x the volume,
329 * so it all cancels out. */
330 mul_v3_fl(r_cent, 0.25f / total_volume);
331 }
332
333 /* this can happen for non-manifold objects, fallback to median */
334 if (!is_finite_v3(r_cent)) [[unlikely]] {
335 copy_v3_v3(r_cent, init_cent);
336 return init_cent_result;
337 }
338 add_v3_v3(r_cent, init_cent);
339 return (mesh->faces_num != 0);
340}
341
343
344/* -------------------------------------------------------------------- */
347
348static bool mesh_calc_center_centroid_ex(const float (*positions)[3],
349 int /*mverts_num*/,
350 const int3 *corner_tris,
351 int corner_tris_num,
352 const int *corner_verts,
353 float r_center[3])
354{
355
356 zero_v3(r_center);
357
358 if (corner_tris_num == 0) {
359 return false;
360 }
361
362 float totweight = 0.0f;
363 int i;
364 for (i = 0; i < corner_tris_num; i++) {
365 const float *v1 = positions[corner_verts[corner_tris[i][0]]];
366 const float *v2 = positions[corner_verts[corner_tris[i][1]]];
367 const float *v3 = positions[corner_verts[corner_tris[i][2]]];
368 float area;
369
370 area = area_tri_v3(v1, v2, v3);
371 madd_v3_v3fl(r_center, v1, area);
372 madd_v3_v3fl(r_center, v2, area);
373 madd_v3_v3fl(r_center, v3, area);
374 totweight += area;
375 }
376 if (totweight == 0.0f) {
377 return false;
378 }
379
380 mul_v3_fl(r_center, 1.0f / (3.0f * totweight));
381
382 return true;
383}
384
385void BKE_mesh_calc_volume(const float (*vert_positions)[3],
386 const int mverts_num,
387 const int3 *corner_tris,
388 const int corner_tris_num,
389 const int *corner_verts,
390 float *r_volume,
391 float r_center[3])
392{
393 float center[3];
394 float totvol;
395 int i;
396
397 if (r_volume) {
398 *r_volume = 0.0f;
399 }
400 if (r_center) {
401 zero_v3(r_center);
402 }
403
404 if (corner_tris_num == 0) {
405 return;
406 }
407
409 vert_positions, mverts_num, corner_tris, corner_tris_num, corner_verts, center))
410 {
411 return;
412 }
413
414 totvol = 0.0f;
415
416 for (i = 0; i < corner_tris_num; i++) {
417 const float *v1 = vert_positions[corner_verts[corner_tris[i][0]]];
418 const float *v2 = vert_positions[corner_verts[corner_tris[i][1]]];
419 const float *v3 = vert_positions[corner_verts[corner_tris[i][2]]];
420 float vol;
421
422 vol = volume_tetrahedron_signed_v3(center, v1, v2, v3);
423 if (r_volume) {
424 totvol += vol;
425 }
426 if (r_center) {
427 /* averaging factor 1/3 is applied in the end */
428 madd_v3_v3fl(r_center, v1, vol);
429 madd_v3_v3fl(r_center, v2, vol);
430 madd_v3_v3fl(r_center, v3, vol);
431 }
432 }
433
434 /* NOTE: Depending on arbitrary centroid position,
435 * totvol can become negative even for a valid mesh.
436 * The true value is always the positive value.
437 */
438 if (r_volume) {
439 *r_volume = fabsf(totvol);
440 }
441 if (r_center) {
442 /* NOTE: Factor 1/3 is applied once for all vertices here.
443 * This also automatically negates the vector if totvol is negative.
444 */
445 if (totvol != 0.0f) {
446 mul_v3_fl(r_center, (1.0f / 3.0f) / totvol);
447 }
448 }
449}
450
452
453/* -------------------------------------------------------------------- */
456
457void BKE_mesh_mdisp_flip(MDisps *md, const bool use_loop_mdisp_flip)
458{
459 if (!md->totdisp || !md->disps) [[unlikely]] {
460 return;
461 }
462
463 const int sides = int(sqrt(md->totdisp));
464 float (*co)[3] = md->disps;
465
466 for (int x = 0; x < sides; x++) {
467 float *co_a, *co_b;
468
469 for (int y = 0; y < x; y++) {
470 co_a = co[y * sides + x];
471 co_b = co[x * sides + y];
472
473 swap_v3_v3(co_a, co_b);
474 std::swap(co_a[0], co_a[1]);
475 std::swap(co_b[0], co_b[1]);
476
477 if (use_loop_mdisp_flip) {
478 co_a[2] *= -1.0f;
479 co_b[2] *= -1.0f;
480 }
481 }
482
483 co_a = co[x * sides + x];
484
485 std::swap(co_a[0], co_a[1]);
486
487 if (use_loop_mdisp_flip) {
488 co_a[2] *= -1.0f;
489 }
490 }
491}
492
494
495/* -------------------------------------------------------------------- */
498
499namespace bke {
500
502 const Span<bool> hide_vert,
503 MutableSpan<bool> hide_edge)
504{
505 threading::parallel_for(edges.index_range(), 4096, [&](const IndexRange range) {
506 for (const int i : range) {
507 hide_edge[i] = hide_vert[edges[i][0]] || hide_vert[edges[i][1]];
508 }
509 });
510}
511
513 const Span<int> corner_verts,
514 const Span<bool> hide_vert,
515 MutableSpan<bool> hide_poly)
516{
517 threading::parallel_for(faces.index_range(), 4096, [&](const IndexRange range) {
518 for (const int i : range) {
519 const Span<int> face_verts = corner_verts.slice(faces[i]);
520 hide_poly[i] = std::any_of(
521 face_verts.begin(), face_verts.end(), [&](const int vert) { return hide_vert[vert]; });
522 }
523 });
524}
525
527{
528 MutableAttributeAccessor attributes = mesh.attributes_for_write();
529
530 const VArray<bool> hide_vert = *attributes.lookup_or_default<bool>(
531 ".hide_vert", AttrDomain::Point, false);
532 if (hide_vert.is_single() && !hide_vert.get_internal_single()) {
533 attributes.remove(".hide_edge");
534 attributes.remove(".hide_poly");
535 return;
536 }
537 const VArraySpan<bool> hide_vert_span{hide_vert};
538
540 ".hide_edge", AttrDomain::Edge);
542 ".hide_poly", AttrDomain::Face);
543
544 mesh_edge_hide_from_vert(mesh.edges(), hide_vert_span, hide_edge.span);
545 mesh_face_hide_from_vert(mesh.faces(), mesh.corner_verts(), hide_vert_span, hide_poly.span);
546
547 hide_edge.finish();
548 hide_poly.finish();
549}
550
552{
553 MutableAttributeAccessor attributes = mesh.attributes_for_write();
554
555 const VArray<bool> hide_poly = *attributes.lookup_or_default<bool>(
556 ".hide_poly", AttrDomain::Face, false);
557 if (hide_poly.is_single() && !hide_poly.get_internal_single()) {
558 attributes.remove(".hide_vert");
559 attributes.remove(".hide_edge");
560 return;
561 }
562 const VArraySpan<bool> hide_poly_span{hide_poly};
563 const OffsetIndices faces = mesh.faces();
564 const Span<int> corner_verts = mesh.corner_verts();
565 const Span<int> corner_edges = mesh.corner_edges();
566
567 const bool vert_attr_existed = attributes.contains(".hide_vert");
568 const bool edge_attr_existed = attributes.contains(".hide_edge");
569
571 ".hide_vert", AttrDomain::Point);
573 ".hide_edge", AttrDomain::Edge);
574
575 /* If the attribute is newly created, ensure the loose edges and vertices are properly
576 * initialized, as the face-based fill below will not guarantee this. */
577 if (!vert_attr_existed) {
578 index_mask::masked_fill(hide_vert.span, false, mesh.loose_verts());
579 index_mask::masked_fill(hide_vert.span, false, mesh.verts_no_face());
580 }
581
582 if (!edge_attr_existed) {
583 index_mask::masked_fill(hide_edge.span, false, mesh.loose_edges());
584 }
585
586 /* Hide all edges or vertices connected to hidden polygons. */
587 threading::parallel_for(faces.index_range(), 1024, [&](const IndexRange range) {
588 for (const int i : range) {
589 if (hide_poly_span[i]) {
590 hide_vert.span.fill_indices(corner_verts.slice(faces[i]), true);
591 hide_edge.span.fill_indices(corner_edges.slice(faces[i]), true);
592 }
593 }
594 });
595 /* Unhide vertices and edges connected to visible polygons. */
596 threading::parallel_for(faces.index_range(), 1024, [&](const IndexRange range) {
597 for (const int i : range) {
598 if (!hide_poly_span[i]) {
599 hide_vert.span.fill_indices(corner_verts.slice(faces[i]), false);
600 hide_edge.span.fill_indices(corner_edges.slice(faces[i]), false);
601 }
602 }
603 });
604
605 hide_vert.finish();
606 hide_edge.finish();
607}
608
610
611/* -------------------------------------------------------------------- */
614
616{
617 MutableAttributeAccessor attributes = mesh.attributes_for_write();
618 const VArray<bool> select_poly = *attributes.lookup_or_default<bool>(
619 ".select_poly", AttrDomain::Face, false);
620 if (select_poly.is_single() && !select_poly.get_internal_single()) {
621 attributes.remove(".select_vert");
622 attributes.remove(".select_edge");
623 return;
624 }
626 ".select_vert", AttrDomain::Point);
628 ".select_edge", AttrDomain::Edge);
629
630 /* Use generic domain interpolation to read the face attribute on the other domains.
631 * Assume selected faces are not hidden and none of their vertices/edges are hidden. */
632 array_utils::copy(*attributes.lookup_or_default<bool>(".select_poly", AttrDomain::Point, false),
633 select_vert.span);
634 array_utils::copy(*attributes.lookup_or_default<bool>(".select_poly", AttrDomain::Edge, false),
635 select_edge.span);
636
637 select_vert.finish();
638 select_edge.finish();
639}
640
642{
643 MutableAttributeAccessor attributes = mesh.attributes_for_write();
644 const VArray<bool> select_vert = *attributes.lookup_or_default<bool>(
645 ".select_vert", AttrDomain::Point, false);
646 if (select_vert.is_single() && !select_vert.get_internal_single()) {
647 attributes.remove(".select_edge");
648 attributes.remove(".select_poly");
649 return;
650 }
652 ".select_edge", AttrDomain::Edge);
654 ".select_poly", AttrDomain::Face);
655 {
656 IndexMaskMemory memory;
657 const VArray<bool> hide_edge = *attributes.lookup_or_default<bool>(
658 ".hide_edge", AttrDomain::Edge, false);
660 *attributes.lookup_or_default<bool>(".select_vert", AttrDomain::Edge, false),
661 IndexMask::from_bools(hide_edge, memory).complement(hide_edge.index_range(), memory),
662 select_edge.span);
663 }
664 {
665 IndexMaskMemory memory;
666 const VArray<bool> hide_poly = *attributes.lookup_or_default<bool>(
667 ".hide_poly", AttrDomain::Face, false);
669 *attributes.lookup_or_default<bool>(".select_vert", AttrDomain::Face, false),
670 IndexMask::from_bools(hide_poly, memory).complement(hide_poly.index_range(), memory),
671 select_poly.span);
672 }
673 select_edge.finish();
674 select_poly.finish();
675}
676
678{
679 MutableAttributeAccessor attributes = mesh.attributes_for_write();
680 const VArray<bool> select_edge = *attributes.lookup_or_default<bool>(
681 ".select_edge", AttrDomain::Point, false);
682 if (select_edge.is_single() && !select_edge.get_internal_single()) {
683 attributes.remove(".select_vert");
684 attributes.remove(".select_poly");
685 return;
686 }
688 ".select_vert", AttrDomain::Point);
690 ".select_poly", AttrDomain::Face);
691 {
692 IndexMaskMemory memory;
693 const VArray<bool> hide_vert = *attributes.lookup_or_default<bool>(
694 ".hide_vert", AttrDomain::Point, false);
696 *attributes.lookup_or_default<bool>(".select_edge", AttrDomain::Point, false),
697 IndexMask::from_bools(hide_vert, memory).complement(hide_vert.index_range(), memory),
698 select_vert.span);
699 }
700 {
701 IndexMaskMemory memory;
702 const VArray<bool> hide_poly = *attributes.lookup_or_default<bool>(
703 ".hide_poly", AttrDomain::Face, false);
705 *attributes.lookup_or_default<bool>(".select_edge", AttrDomain::Face, false),
706 IndexMask::from_bools(hide_poly, memory).complement(hide_poly.index_range(), memory),
707 select_poly.span);
708 }
709 select_vert.finish();
710 select_poly.finish();
711}
712
713} // namespace bke
714
716
717/* -------------------------------------------------------------------- */
720
721void BKE_mesh_calc_relative_deform(const int *face_offsets,
722 const int faces_num,
723 const int *corner_verts,
724 const int totvert,
725
726 const float (*vert_cos_src)[3],
727 const float (*vert_cos_dst)[3],
728
729 const float (*vert_cos_org)[3],
730 float (*vert_cos_new)[3])
731{
732 const OffsetIndices<int> faces({face_offsets, faces_num + 1});
733
734 int *vert_accum = MEM_new_array_zeroed<int>(totvert, __func__);
735
736 memset(vert_cos_new, '\0', sizeof(*vert_cos_new) * size_t(totvert));
737
738 for (const int i : faces.index_range()) {
739 const IndexRange face = faces[i];
740 const int *face_verts = &corner_verts[face.start()];
741
742 for (int j = 0; j < face.size(); j++) {
743 const int v_prev = face_verts[(face.size() + (j - 1)) % face.size()];
744 const int v_curr = face_verts[j];
745 const int v_next = face_verts[(j + 1) % face.size()];
746
747 float tvec[3];
748
750 vert_cos_dst[v_curr],
751 vert_cos_org[v_prev],
752 vert_cos_org[v_curr],
753 vert_cos_org[v_next],
754 vert_cos_src[v_prev],
755 vert_cos_src[v_curr],
756 vert_cos_src[v_next]);
757
758 add_v3_v3(vert_cos_new[v_curr], tvec);
759 vert_accum[v_curr] += 1;
760 }
761 }
762
763 for (int i = 0; i < totvert; i++) {
764 if (vert_accum[i]) {
765 mul_v3_fl(vert_cos_new[i], 1.0f / float(vert_accum[i]));
766 }
767 else {
768 copy_v3_v3(vert_cos_new[i], vert_cos_org[i]);
769 }
770 }
771
772 MEM_delete(vert_accum);
773}
774
776
777} // namespace blender
Read Blender memory allocation and freeing.
#define UNUSED_FUNCTION(x)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
const T * data() const
Definition BLI_array.hh:323
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
constexpr int64_t size() const
constexpr int64_t start() const
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
IndexRange index_range() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
bool contains(StringRef name) const
GSpanAttributeWriter convert_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
T compute_sum(const Span< T > data)
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void face_angles_calc(Span< float3 > vert_positions, Span< int > face_verts, MutableSpan< float > angles)
float3 face_normal_calc(Span< float3 > vert_positions, Span< int > face_verts)
static float3 face_center_calc_ngon(const Span< float3 > vert_positions, const Span< int > face_verts)
float face_area_calc(Span< float3 > vert_positions, Span< int > face_verts)
static float face_area_centroid_calc(const Span< float3 > positions, const Span< int > face_verts, float r_cent[3])
float3 face_center_calc(Span< float3 > vert_positions, Span< int > face_verts)
static float mesh_calc_face_volume_centroid_with_reference_center(const Span< float3 > positions, const Span< int > face_verts, const float3 &reference_center, float r_cent[3])
void mesh_select_vert_flush(Mesh &mesh)
void mesh_face_hide_from_vert(OffsetIndices< int > faces, Span< int > corner_verts, Span< bool > hide_vert, MutableSpan< bool > hide_poly)
void mesh_hide_vert_flush(Mesh &mesh)
void mesh_hide_face_flush(Mesh &mesh)
void mesh_select_edge_flush(Mesh &mesh)
void mesh_edge_hide_from_vert(Span< int2 > edges, Span< bool > hide_vert, MutableSpan< bool > hide_edge)
void mesh_select_face_flush(Mesh &mesh)
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BMesh Iterators.
bool BKE_mesh_center_median(const Mesh *mesh, float r_cent[3])
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
static bool mesh_calc_center_centroid_ex(const float(*positions)[3], int, const int3 *corner_tris, int corner_tris_num, const int *corner_verts, float r_center[3])
MINLINE bool is_finite_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
void mid_v3_v3v3v3v3(float v[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void mid_v3_v3v3v3(float v[3], const float v1[3], const float v2[3], const float v3[3])
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])
float area_tri_signed_v3(const float v1[3], const float v2[3], const float v3[3], const float normal[3])
Definition math_geom.cc:119
static float UNUSED_FUNCTION mesh_calc_face_volume_centroid(const int *face_verts, const int face_size, const float(*positions)[3], float r_cent[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
float BKE_mesh_calc_area(const Mesh *mesh)
VecBase< int32_t, 3 > int3
bool BKE_mesh_center_of_surface(const Mesh *mesh, float r_cent[3])
MINLINE void swap_v3_v3(float a[3], float b[3])
bool BKE_mesh_center_median_from_faces(const Mesh *mesh, float r_cent[3])
sqrt(x)+1/max(0
void BKE_mesh_mdisp_flip(MDisps *md, bool use_loop_mdisp_flip)
void BKE_mesh_calc_relative_deform(const int *face_offsets, int faces_num, const int *corner_verts, int totvert, const float(*vert_cos_src)[3], const float(*vert_cos_dst)[3], const float(*vert_cos_org)[3], float(*vert_cos_new)[3])
MINLINE void zero_v3(float r[3])
void BKE_mesh_calc_volume(const float(*vert_positions)[3], int mverts_num, const int3 *corner_tris, int corner_tris_num, const int *corner_verts, float *r_volume, float r_center[3])
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
float area_tri_v3(const float v1[3], const float v2[3], const float v3[3])
Definition math_geom.cc:104
bool BKE_mesh_center_of_volume(const Mesh *mesh, float r_cent[3])
VecBase< float, 3 > float3
float area_poly_v3(const float verts[][3], unsigned int nr)
Definition math_geom.cc:137
float volume_tri_tetrahedron_signed_v3_6x(const float v1[3], const float v2[3], const float v3[3])
Definition math_geom.cc:275
float volume_tetrahedron_signed_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3])
Definition math_geom.cc:263
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float