36 const float w = 1.0f /
float(face_verts.
size());
40 center += vert_positions[face_verts[i]] *
w;
47 if (face_verts.
size() == 3) {
50 vert_positions[face_verts[0]],
51 vert_positions[face_verts[1]],
52 vert_positions[face_verts[2]]);
55 if (face_verts.
size() == 4) {
58 vert_positions[face_verts[0]],
59 vert_positions[face_verts[1]],
60 vert_positions[face_verts[2]],
61 vert_positions[face_verts[3]]);
69 if (face_verts.
size() == 3) {
71 vert_positions[face_verts[1]],
72 vert_positions[face_verts[2]]);
76 coords[i] = vert_positions[face_verts[i]];
89 float total_area = 0.0f;
98 const float (*positions)[3],
101 const float *v_pivot, *v_step1;
102 float total_volume = 0.0f;
106 v_pivot = positions[face_verts[0]];
107 v_step1 = positions[face_verts[1]];
109 for (
int i = 2; i < face_size; i++) {
110 const float *v_step2 = positions[face_verts[i]];
115 total_volume += tetra_volume;
123 for (
uint j = 0; j < 3; j++) {
124 r_cent[j] += tetra_volume * (v_pivot[j] + v_step1[j] + v_step2[j]);
142 const float3 &reference_center,
146 float v_pivot[3], v_step1[3];
147 float total_volume = 0.0f;
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++) {
153 sub_v3_v3v3(v_step2, positions[face_verts[i]], reference_center);
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]);
174 float total_area = 0.0f;
175 float v1[3],
v2[3], v3[3], tri_cent[3];
184 for (
int i = 2; i < face_verts.
size(); i++) {
188 total_area += tri_area;
208 int i_this = face_verts.
size() - 1;
212 nor_prev, vert_positions[face_verts[i_this - 1]], vert_positions[face_verts[i_this]]);
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]]);
240 if (
mesh->verts_num) {
246 return (
mesh->verts_num != 0);
257 for (
const int vert : corner_verts.
slice(faces[i])) {
260 tot += faces[i].
size();
263 if (
mesh->faces_num) {
266 return (
mesh->faces_num != 0);
272 float total_area = 0.0f;
283 positions, corner_verts.
slice(faces[i]), face_cent);
286 total_area += face_area;
289 if (
mesh->faces_num) {
298 return (
mesh->faces_num != 0);
304 float total_volume = 0.0f;
319 positions, corner_verts.
slice(faces[i]), init_cent, face_cent);
323 total_volume += face_volume;
326 if (total_volume != 0.0f) {
336 return init_cent_result;
339 return (
mesh->faces_num != 0);
350 const int3 *corner_tris,
352 const int *corner_verts,
358 if (corner_tris_num == 0) {
362 float totweight = 0.0f;
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]]];
376 if (totweight == 0.0f) {
380 mul_v3_fl(r_center, 1.0f / (3.0f * totweight));
386 const int mverts_num,
387 const int3 *corner_tris,
388 const int corner_tris_num,
389 const int *corner_verts,
404 if (corner_tris_num == 0) {
409 vert_positions, mverts_num, corner_tris, corner_tris_num, corner_verts, center))
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]]];
439 *r_volume =
fabsf(totvol);
445 if (totvol != 0.0f) {
446 mul_v3_fl(r_center, (1.0f / 3.0f) / totvol);
466 for (
int x = 0;
x < sides;
x++) {
469 for (
int y = 0;
y <
x;
y++) {
470 co_a = co[
y * sides +
x];
471 co_b = co[
x * sides +
y];
474 std::swap(co_a[0], co_a[1]);
475 std::swap(co_b[0], co_b[1]);
477 if (use_loop_mdisp_flip) {
483 co_a = co[
x * sides +
x];
485 std::swap(co_a[0], co_a[1]);
487 if (use_loop_mdisp_flip) {
506 for (const int i : range) {
507 hide_edge[i] = hide_vert[edges[i][0]] || hide_vert[edges[i][1]];
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]; });
533 attributes.
remove(
".hide_edge");
534 attributes.
remove(
".hide_poly");
558 attributes.
remove(
".hide_vert");
559 attributes.
remove(
".hide_edge");
567 const bool vert_attr_existed = attributes.
contains(
".hide_vert");
568 const bool edge_attr_existed = attributes.
contains(
".hide_edge");
577 if (!vert_attr_existed) {
582 if (!edge_attr_existed) {
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);
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);
621 attributes.
remove(
".select_vert");
622 attributes.
remove(
".select_edge");
638 select_edge.finish();
647 attributes.
remove(
".select_edge");
648 attributes.
remove(
".select_poly");
674 select_poly.finish();
683 attributes.
remove(
".select_vert");
684 attributes.
remove(
".select_poly");
710 select_poly.finish();
723 const int *corner_verts,
726 const float (*vert_cos_src)[3],
727 const float (*vert_cos_dst)[3],
729 const float (*vert_cos_org)[3],
730 float (*vert_cos_new)[3])
736 memset(vert_cos_new,
'\0',
sizeof(*vert_cos_new) *
size_t(totvert));
738 for (
const int i : faces.index_range()) {
740 const int *face_verts = &corner_verts[face.
start()];
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()];
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]);
759 vert_accum[v_curr] += 1;
763 for (
int i = 0; i < totvert; i++) {
765 mul_v3_fl(vert_cos_new[i], 1.0f /
float(vert_accum[i]));
772 MEM_delete(vert_accum);
Read Blender memory allocation and freeing.
#define UNUSED_FUNCTION(x)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
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
constexpr int64_t size() const
constexpr IndexRange index_range() const
IndexRange index_range() const
T get_internal_single() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
bool contains(StringRef name) const
bool remove(const StringRef name)
GSpanAttributeWriter convert_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
IndexRange index_range() const
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))
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])
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])
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])
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])
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)
float volume_tri_tetrahedron_signed_v3_6x(const float v1[3], const float v2[3], const float v3[3])
float volume_tetrahedron_signed_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3])
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
MutableVArraySpan< T > span