From 7132c7a53c22c65a38fbdcd9315a0188fd88ca18 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 20 Dec 2023 20:45:15 -0500 Subject: [PATCH] Cleanup: Replace MVertTri type with C++ vector Similar to 7c69c8827b6552950717. Remove more unused includes. --- intern/quadriflow/quadriflow_capi.hpp | 4 +- source/blender/blenkernel/BKE_cloth.hh | 3 +- source/blender/blenkernel/BKE_collision.h | 13 +- source/blender/blenkernel/BKE_mesh.hh | 7 + source/blender/blenkernel/BKE_mesh_runtime.hh | 11 -- source/blender/blenkernel/intern/cloth.cc | 53 +++--- source/blender/blenkernel/intern/collision.cc | 165 +++++++++--------- .../blenkernel/intern/mesh_remesh_voxel.cc | 23 +-- .../blender/blenkernel/intern/mesh_runtime.cc | 13 -- .../blenkernel/intern/mesh_tessellate.cc | 8 + .../blenkernel/intern/particle_system.cc | 14 +- source/blender/blenkernel/intern/softbody.cc | 84 +++++---- .../editors/sculpt_paint/sculpt_cloth.cc | 9 +- source/blender/io/usd/hydra/mesh.cc | 8 +- source/blender/makesdna/DNA_meshdata_types.h | 6 - .../blender/makesdna/DNA_modifier_defaults.h | 2 +- source/blender/makesdna/DNA_modifier_types.h | 2 +- .../blender/modifiers/intern/MOD_collision.cc | 35 ++-- .../simulation/intern/SIM_mass_spring.cc | 54 +++--- 19 files changed, 235 insertions(+), 279 deletions(-) diff --git a/intern/quadriflow/quadriflow_capi.hpp b/intern/quadriflow/quadriflow_capi.hpp index ef2e1bbea92..7981750c71e 100644 --- a/intern/quadriflow/quadriflow_capi.hpp +++ b/intern/quadriflow/quadriflow_capi.hpp @@ -10,8 +10,8 @@ extern "C" { #endif typedef struct QuadriflowRemeshData { - float *verts; - int *faces; + const float *verts; + const int *faces; int totfaces; int totverts; diff --git a/source/blender/blenkernel/BKE_cloth.hh b/source/blender/blenkernel/BKE_cloth.hh index 8c7a3371c88..c17ce880194 100644 --- a/source/blender/blenkernel/BKE_cloth.hh +++ b/source/blender/blenkernel/BKE_cloth.hh @@ -21,7 +21,6 @@ struct Implicit_Data; struct Depsgraph; struct LinkNode; struct Mesh; -struct MVertTri; struct Object; struct Scene; @@ -77,7 +76,7 @@ struct Cloth { short pad3; BVHTree *bvhtree; /* collision tree for this cloth object */ BVHTree *bvhselftree; /* collision tree for this cloth object (may be same as bvhtree) */ - MVertTri *tri; + blender::int3 *vert_tris; Implicit_Data *implicit; /* our implicit solver connects to this pointer */ blender::Set edgeset; /* used for selfcollisions */ int last_frame; diff --git a/source/blender/blenkernel/BKE_collision.h b/source/blender/blenkernel/BKE_collision.h index 99026b92ec0..2e96fd36f77 100644 --- a/source/blender/blenkernel/BKE_collision.h +++ b/source/blender/blenkernel/BKE_collision.h @@ -7,15 +7,12 @@ * \ingroup bke */ -#ifdef __cplusplus -extern "C" { -#endif +#include "BLI_math_vector_types.hh" struct BVHTree; struct Collection; struct CollisionModifierData; struct Depsgraph; -struct MVertTri; struct Object; //////////////////////////////////////// @@ -90,13 +87,13 @@ typedef struct FaceCollPair { ///////////////////////////////////////////////// struct BVHTree *bvhtree_build_from_mvert(const float (*positions)[3], - const struct MVertTri *tri, + const blender::int3 *vert_tris, int tri_num, float epsilon); void bvhtree_update_from_mvert(struct BVHTree *bvhtree, const float (*positions)[3], const float (*positions_moving)[3], - const struct MVertTri *tri, + const blender::int3 *vert_tris, int tri_num, bool moving); @@ -165,7 +162,3 @@ void BKE_collider_cache_free(struct ListBase **colliders); ///////////////////////////////////////////////// ///////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/blenkernel/BKE_mesh.hh b/source/blender/blenkernel/BKE_mesh.hh index a75e09b2b57..ada46e788af 100644 --- a/source/blender/blenkernel/BKE_mesh.hh +++ b/source/blender/blenkernel/BKE_mesh.hh @@ -49,6 +49,13 @@ void corner_tris_calc_with_normals(Span vert_positions, void corner_tris_calc_face_indices(OffsetIndices faces, MutableSpan tri_faces); +/** + * Convert triangles encoded as face corner indices to triangles encoded as vertex indices. + */ +void vert_tris_from_corner_tris(Span corner_verts, + Span corner_tris, + MutableSpan vert_tris); + /** Return the triangle's three edge indices they are real edges, otherwise -1. */ int3 corner_tri_get_real_edges(Span edges, Span corner_verts, diff --git a/source/blender/blenkernel/BKE_mesh_runtime.hh b/source/blender/blenkernel/BKE_mesh_runtime.hh index adc7ed081de..ebc7009902d 100644 --- a/source/blender/blenkernel/BKE_mesh_runtime.hh +++ b/source/blender/blenkernel/BKE_mesh_runtime.hh @@ -9,12 +9,9 @@ * This file contains access functions for the Mesh.runtime struct. */ -#include "BKE_mesh_types.hh" - struct CustomData_MeshMasks; struct Depsgraph; struct KeyBlock; -struct MVertTri; struct Mesh; struct Object; struct Scene; @@ -44,14 +41,6 @@ void BKE_mesh_runtime_clear_geometry(Mesh *mesh); */ void BKE_mesh_runtime_clear_cache(Mesh *mesh); -/** - * Convert triangles encoded as face corner indices to triangles encoded as vertex indices. - */ -void BKE_mesh_runtime_verttris_from_corner_tris(MVertTri *r_verttri, - const int *corner_verts, - const blender::int3 *corner_tris, - int corner_tris_num); - /* NOTE: the functions below are defined in DerivedMesh.cc, and are intended to be moved * to a more suitable location when that file is removed. * They should also be renamed to use conventions from BKE, not old DerivedMesh.cc. diff --git a/source/blender/blenkernel/intern/cloth.cc b/source/blender/blenkernel/intern/cloth.cc index e5ca219c23d..900a26913a4 100644 --- a/source/blender/blenkernel/intern/cloth.cc +++ b/source/blender/blenkernel/intern/cloth.cc @@ -77,7 +77,7 @@ static BVHTree *bvhtree_build_from_cloth(ClothModifierData *clmd, float epsilon) } ClothVertex *verts = cloth->verts; - const MVertTri *vt = cloth->tri; + const blender::int3 *vert_tris = cloth->vert_tris; /* in the moment, return zero if no faces there */ if (!cloth->primitive_num) { @@ -89,12 +89,12 @@ static BVHTree *bvhtree_build_from_cloth(ClothModifierData *clmd, float epsilon) /* fill tree */ if (clmd->hairdata == nullptr) { - for (int i = 0; i < cloth->primitive_num; i++, vt++) { + for (int i = 0; i < cloth->primitive_num; i++) { float co[3][3]; - copy_v3_v3(co[0], verts[vt->tri[0]].xold); - copy_v3_v3(co[1], verts[vt->tri[1]].xold); - copy_v3_v3(co[2], verts[vt->tri[2]].xold); + copy_v3_v3(co[0], verts[vert_tris[i][0]].xold); + copy_v3_v3(co[1], verts[vert_tris[i][1]].xold); + copy_v3_v3(co[2], verts[vert_tris[i][2]].xold); BLI_bvhtree_insert(bvhtree, i, co[0], 3); } @@ -124,7 +124,6 @@ void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving, bool self) Cloth *cloth = clmd->clothObject; BVHTree *bvhtree; ClothVertex *verts = cloth->verts; - const MVertTri *vt; BLI_assert(!(clmd->hairdata != nullptr && self)); @@ -139,32 +138,32 @@ void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving, bool self) return; } - vt = cloth->tri; + const blender::int3 *vert_tris = cloth->vert_tris; /* update vertex position in bvh tree */ if (clmd->hairdata == nullptr) { - if (verts && vt) { - for (i = 0; i < cloth->primitive_num; i++, vt++) { + if (verts && vert_tris) { + for (i = 0; i < cloth->primitive_num; i++) { float co[3][3], co_moving[3][3]; bool ret; /* copy new locations into array */ if (moving) { - copy_v3_v3(co[0], verts[vt->tri[0]].txold); - copy_v3_v3(co[1], verts[vt->tri[1]].txold); - copy_v3_v3(co[2], verts[vt->tri[2]].txold); + copy_v3_v3(co[0], verts[vert_tris[i][0]].txold); + copy_v3_v3(co[1], verts[vert_tris[i][1]].txold); + copy_v3_v3(co[2], verts[vert_tris[i][2]].txold); /* update moving positions */ - copy_v3_v3(co_moving[0], verts[vt->tri[0]].tx); - copy_v3_v3(co_moving[1], verts[vt->tri[1]].tx); - copy_v3_v3(co_moving[2], verts[vt->tri[2]].tx); + copy_v3_v3(co_moving[0], verts[vert_tris[i][0]].tx); + copy_v3_v3(co_moving[1], verts[vert_tris[i][1]].tx); + copy_v3_v3(co_moving[2], verts[vert_tris[i][2]].tx); ret = BLI_bvhtree_update_node(bvhtree, i, co[0], co_moving[0], 3); } else { - copy_v3_v3(co[0], verts[vt->tri[0]].tx); - copy_v3_v3(co[1], verts[vt->tri[1]].tx); - copy_v3_v3(co[2], verts[vt->tri[2]].tx); + copy_v3_v3(co[0], verts[vert_tris[i][0]].tx); + copy_v3_v3(co[1], verts[vert_tris[i][1]].tx); + copy_v3_v3(co[2], verts[vert_tris[i][2]].tx); ret = BLI_bvhtree_update_node(bvhtree, i, co[0], nullptr, 3); } @@ -478,8 +477,8 @@ void cloth_free_modifier(ClothModifierData *clmd) } /* we save our faces for collision objects */ - if (cloth->tri) { - MEM_freeN(cloth->tri); + if (cloth->vert_tris) { + MEM_freeN(cloth->vert_tris); } #if 0 @@ -546,8 +545,8 @@ void cloth_free_modifier_extern(ClothModifierData *clmd) } /* we save our faces for collision objects */ - if (cloth->tri) { - MEM_freeN(cloth->tri); + if (cloth->vert_tris) { + MEM_freeN(cloth->vert_tris); } #if 0 @@ -848,15 +847,15 @@ static void cloth_from_mesh(ClothModifierData *clmd, const Object *ob, Mesh *mes clmd->clothObject->primitive_num = mesh->edges_num; } - clmd->clothObject->tri = static_cast( - MEM_malloc_arrayN(corner_tris.size(), sizeof(MVertTri), __func__)); - if (clmd->clothObject->tri == nullptr) { + clmd->clothObject->vert_tris = static_cast( + MEM_malloc_arrayN(corner_tris.size(), sizeof(blender::int3), __func__)); + if (clmd->clothObject->vert_tris == nullptr) { cloth_free_modifier(clmd); BKE_modifier_set_error(ob, &(clmd->modifier), "Out of memory on allocating triangles"); return; } - BKE_mesh_runtime_verttris_from_corner_tris( - clmd->clothObject->tri, corner_verts.data(), corner_tris.data(), corner_tris.size()); + blender::bke::mesh::vert_tris_from_corner_tris( + corner_verts, corner_tris, {clmd->clothObject->vert_tris, corner_tris.size()}); clmd->clothObject->edges = mesh->edges().data(); diff --git a/source/blender/blenkernel/intern/collision.cc b/source/blender/blenkernel/intern/collision.cc index 49425de420f..0ab38fd4729 100644 --- a/source/blender/blenkernel/intern/collision.cc +++ b/source/blender/blenkernel/intern/collision.cc @@ -11,7 +11,6 @@ #include "DNA_cloth_types.h" #include "DNA_collection_types.h" #include "DNA_effect_types.h" -#include "DNA_meshdata_types.h" #include "DNA_object_force_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" @@ -88,27 +87,25 @@ void collision_move_object(CollisionModifierData *collmd, bvhtree_update_from_mvert(collmd->bvhtree, collmd->current_xnew, collmd->current_x, - collmd->tri, + reinterpret_cast(collmd->vert_tris), collmd->tri_num, moving_bvh); } BVHTree *bvhtree_build_from_mvert(const float (*positions)[3], - const MVertTri *tri, + const blender::int3 *vert_tris, int tri_num, float epsilon) { BVHTree *tree = BLI_bvhtree_new(tri_num, epsilon, 4, 26); /* fill tree */ - int i; - const MVertTri *vt; - for (i = 0, vt = tri; i < tri_num; i++, vt++) { + for (int i = 0; i < tri_num; i++) { float co[3][3]; - copy_v3_v3(co[0], positions[vt->tri[0]]); - copy_v3_v3(co[1], positions[vt->tri[1]]); - copy_v3_v3(co[2], positions[vt->tri[2]]); + copy_v3_v3(co[0], positions[vert_tris[i][0]]); + copy_v3_v3(co[1], positions[vert_tris[i][1]]); + copy_v3_v3(co[2], positions[vert_tris[i][2]]); BLI_bvhtree_insert(tree, i, co[0], 3); } @@ -122,7 +119,7 @@ BVHTree *bvhtree_build_from_mvert(const float (*positions)[3], void bvhtree_update_from_mvert(BVHTree *bvhtree, const float (*positions)[3], const float (*positions_moving)[3], - const MVertTri *tri, + const blender::int3 *vert_tris, int tri_num, bool moving) { @@ -135,23 +132,21 @@ void bvhtree_update_from_mvert(BVHTree *bvhtree, moving = false; } - const MVertTri *vt; - int i; - for (i = 0, vt = tri; i < tri_num; i++, vt++) { + for (int i = 0; i < tri_num; i++) { float co[3][3]; bool ret; - copy_v3_v3(co[0], positions[vt->tri[0]]); - copy_v3_v3(co[1], positions[vt->tri[1]]); - copy_v3_v3(co[2], positions[vt->tri[2]]); + copy_v3_v3(co[0], positions[vert_tris[i][0]]); + copy_v3_v3(co[1], positions[vert_tris[i][1]]); + copy_v3_v3(co[2], positions[vert_tris[i][2]]); /* copy new locations into array */ if (moving) { float co_moving[3][3]; /* update moving positions */ - copy_v3_v3(co_moving[0], positions_moving[vt->tri[0]]); - copy_v3_v3(co_moving[1], positions_moving[vt->tri[1]]); - copy_v3_v3(co_moving[2], positions_moving[vt->tri[2]]); + copy_v3_v3(co_moving[0], positions_moving[vert_tris[i][0]]); + copy_v3_v3(co_moving[1], positions_moving[vert_tris[i][1]]); + copy_v3_v3(co_moving[2], positions_moving[vert_tris[i][2]]); ret = BLI_bvhtree_update_node(bvhtree, i, &co[0][0], &co_moving[0][0], 3); } @@ -957,13 +952,13 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd, static bool cloth_bvh_collision_is_active(const ClothModifierData * /*clmd*/, const Cloth *cloth, - const MVertTri *tri_a) + const blender::int3 vert_tri_a) { const ClothVertex *verts = cloth->verts; /* Fully pinned triangles don't need collision processing. */ - const int flags_a = verts[tri_a->tri[0]].flags & verts[tri_a->tri[1]].flags & - verts[tri_a->tri[2]].flags; + const int flags_a = verts[vert_tri_a[0]].flags & verts[vert_tri_a[1]].flags & + verts[vert_tri_a[2]].flags; if (flags_a & (CLOTH_VERT_FLAG_PINNED | CLOTH_VERT_FLAG_NOOBJCOLL)) { return false; @@ -981,23 +976,22 @@ static void cloth_collision(void *__restrict userdata, ClothModifierData *clmd = data->clmd; CollisionModifierData *collmd = data->collmd; CollPair *collpair = data->collisions; - const MVertTri *tri_a, *tri_b; ClothVertex *verts1 = clmd->clothObject->verts; float distance = 0.0f; float epsilon1 = clmd->coll_parms->epsilon; float epsilon2 = BLI_bvhtree_get_epsilon(collmd->bvhtree); float pa[3], pb[3], vect[3]; - tri_a = &clmd->clothObject->tri[data->overlap[index].indexA]; - tri_b = &collmd->tri[data->overlap[index].indexB]; + const blender::int3 vert_tri_a = clmd->clothObject->vert_tris[data->overlap[index].indexA]; + const blender::int3 vert_tri_b = collmd->vert_tris[data->overlap[index].indexB]; /* Compute distance and normal. */ - distance = compute_collision_point_tri_tri(verts1[tri_a->tri[0]].tx, - verts1[tri_a->tri[1]].tx, - verts1[tri_a->tri[2]].tx, - collmd->current_xnew[tri_b->tri[0]], - collmd->current_xnew[tri_b->tri[1]], - collmd->current_xnew[tri_b->tri[2]], + distance = compute_collision_point_tri_tri(verts1[vert_tri_a[0]].tx, + verts1[vert_tri_a[1]].tx, + verts1[vert_tri_a[2]].tx, + collmd->current_xnew[vert_tri_b[0]], + collmd->current_xnew[vert_tri_b[1]], + collmd->current_xnew[vert_tri_b[2]], data->culling, data->use_normal, pa, @@ -1005,13 +999,13 @@ static void cloth_collision(void *__restrict userdata, vect); if ((distance <= (epsilon1 + epsilon2 + ALMOST_ZERO)) && (len_squared_v3(vect) > ALMOST_ZERO)) { - collpair[index].ap1 = tri_a->tri[0]; - collpair[index].ap2 = tri_a->tri[1]; - collpair[index].ap3 = tri_a->tri[2]; + collpair[index].ap1 = vert_tri_a[0]; + collpair[index].ap2 = vert_tri_a[1]; + collpair[index].ap3 = vert_tri_a[2]; - collpair[index].bp1 = tri_b->tri[0]; - collpair[index].bp2 = tri_b->tri[1]; - collpair[index].bp3 = tri_b->tri[2]; + collpair[index].bp1 = vert_tri_b[0]; + collpair[index].bp2 = vert_tri_b[1]; + collpair[index].bp3 = vert_tri_b[2]; copy_v3_v3(collpair[index].pa, pa); copy_v3_v3(collpair[index].pb, pb); @@ -1026,17 +1020,17 @@ static void cloth_collision(void *__restrict userdata, /* Compute barycentric coordinates for both collision points. */ collision_compute_barycentric(pa, - verts1[tri_a->tri[0]].tx, - verts1[tri_a->tri[1]].tx, - verts1[tri_a->tri[2]].tx, + verts1[vert_tri_a[0]].tx, + verts1[vert_tri_a[1]].tx, + verts1[vert_tri_a[2]].tx, &collpair[index].aw1, &collpair[index].aw2, &collpair[index].aw3); collision_compute_barycentric(pb, - collmd->current_xnew[tri_b->tri[0]], - collmd->current_xnew[tri_b->tri[1]], - collmd->current_xnew[tri_b->tri[2]], + collmd->current_xnew[vert_tri_b[0]], + collmd->current_xnew[vert_tri_b[1]], + collmd->current_xnew[vert_tri_b[2]], &collpair[index].bw1, &collpair[index].bw2, &collpair[index].bw3); @@ -1048,16 +1042,16 @@ static void cloth_collision(void *__restrict userdata, static bool cloth_bvh_selfcollision_is_active(const ClothModifierData *clmd, const Cloth *cloth, - const MVertTri *tri_a, - const MVertTri *tri_b) + const blender::int3 vert_tri_a, + const blender::int3 vert_tri_b) { const ClothVertex *verts = cloth->verts; /* Skip when either triangle is excluded. */ - const int flags_a = verts[tri_a->tri[0]].flags & verts[tri_a->tri[1]].flags & - verts[tri_a->tri[2]].flags; - const int flags_b = verts[tri_b->tri[0]].flags & verts[tri_b->tri[1]].flags & - verts[tri_b->tri[2]].flags; + const int flags_a = verts[vert_tri_a[0]].flags & verts[vert_tri_a[1]].flags & + verts[vert_tri_a[2]].flags; + const int flags_b = verts[vert_tri_b[0]].flags & verts[vert_tri_b[1]].flags & + verts[vert_tri_b[2]].flags; if ((flags_a | flags_b) & CLOTH_VERT_FLAG_NOSELFCOLL) { return false; @@ -1073,12 +1067,12 @@ static bool cloth_bvh_selfcollision_is_active(const ClothModifierData *clmd, for (uint i = 0; i < 3; i++) { for (uint j = 0; j < 3; j++) { - if (tri_a->tri[i] == tri_b->tri[j]) { + if (vert_tri_a[i] == vert_tri_b[j]) { return false; } if (sewing_active) { - if (cloth->sew_edge_graph.contains({tri_a->tri[i], tri_b->tri[j]})) { + if (cloth->sew_edge_graph.contains({vert_tri_a[i], vert_tri_b[j]})) { return false; } } @@ -1096,7 +1090,6 @@ static void cloth_selfcollision(void *__restrict userdata, ClothModifierData *clmd = data->clmd; CollPair *collpair = data->collisions; - const MVertTri *tri_a, *tri_b; ClothVertex *verts1 = clmd->clothObject->verts; float distance = 0.0f; float epsilon = clmd->coll_parms->selfepsilon; @@ -1109,18 +1102,18 @@ static void cloth_selfcollision(void *__restrict userdata, SWAP(int, indexA, indexB); } - tri_a = &clmd->clothObject->tri[indexA]; - tri_b = &clmd->clothObject->tri[indexB]; + const blender::int3 vert_tri_a = clmd->clothObject->vert_tris[indexA]; + const blender::int3 vert_tri_b = clmd->clothObject->vert_tris[indexB]; BLI_assert(cloth_bvh_selfcollision_is_active(clmd, clmd->clothObject, tri_a, tri_b)); /* Compute distance and normal. */ - distance = compute_collision_point_tri_tri(verts1[tri_a->tri[0]].tx, - verts1[tri_a->tri[1]].tx, - verts1[tri_a->tri[2]].tx, - verts1[tri_b->tri[0]].tx, - verts1[tri_b->tri[1]].tx, - verts1[tri_b->tri[2]].tx, + distance = compute_collision_point_tri_tri(verts1[vert_tri_a[0]].tx, + verts1[vert_tri_a[1]].tx, + verts1[vert_tri_a[2]].tx, + verts1[vert_tri_b[0]].tx, + verts1[vert_tri_b[1]].tx, + verts1[vert_tri_b[2]].tx, false, false, pa, @@ -1128,13 +1121,13 @@ static void cloth_selfcollision(void *__restrict userdata, vect); if ((distance <= (epsilon * 2.0f + ALMOST_ZERO)) && (len_squared_v3(vect) > ALMOST_ZERO)) { - collpair[index].ap1 = tri_a->tri[0]; - collpair[index].ap2 = tri_a->tri[1]; - collpair[index].ap3 = tri_a->tri[2]; + collpair[index].ap1 = vert_tri_a[0]; + collpair[index].ap2 = vert_tri_a[1]; + collpair[index].ap3 = vert_tri_a[2]; - collpair[index].bp1 = tri_b->tri[0]; - collpair[index].bp2 = tri_b->tri[1]; - collpair[index].bp3 = tri_b->tri[2]; + collpair[index].bp1 = vert_tri_b[0]; + collpair[index].bp2 = vert_tri_b[1]; + collpair[index].bp3 = vert_tri_b[2]; copy_v3_v3(collpair[index].pa, pa); copy_v3_v3(collpair[index].pb, pb); @@ -1149,17 +1142,17 @@ static void cloth_selfcollision(void *__restrict userdata, /* Compute barycentric coordinates for both collision points. */ collision_compute_barycentric(pa, - verts1[tri_a->tri[0]].tx, - verts1[tri_a->tri[1]].tx, - verts1[tri_a->tri[2]].tx, + verts1[vert_tri_a[0]].tx, + verts1[vert_tri_a[1]].tx, + verts1[vert_tri_a[2]].tx, &collpair[index].aw1, &collpair[index].aw2, &collpair[index].aw3); collision_compute_barycentric(pb, - verts1[tri_b->tri[0]].tx, - verts1[tri_b->tri[1]].tx, - verts1[tri_b->tri[2]].tx, + verts1[vert_tri_b[0]].tx, + verts1[vert_tri_b[1]].tx, + verts1[vert_tri_b[2]].tx, &collpair[index].bw1, &collpair[index].bw2, &collpair[index].bw3); @@ -1178,7 +1171,6 @@ static void hair_collision(void *__restrict userdata, ClothModifierData *clmd = data->clmd; CollisionModifierData *collmd = data->collmd; CollPair *collpair = data->collisions; - const MVertTri *tri_coll; ClothVertex *verts1 = clmd->clothObject->verts; float distance = 0.0f; float epsilon1 = clmd->coll_parms->epsilon; @@ -1189,14 +1181,14 @@ static void hair_collision(void *__restrict userdata, * avoid walking the list every time. */ const blender::int2 &edge_coll = reinterpret_cast( clmd->clothObject->edges)[data->overlap[index].indexA]; - tri_coll = &collmd->tri[data->overlap[index].indexB]; + const blender::int3 tri_coll = collmd->vert_tris[data->overlap[index].indexB]; /* Compute distance and normal. */ distance = compute_collision_point_edge_tri(verts1[edge_coll[0]].tx, verts1[edge_coll[1]].tx, - collmd->current_x[tri_coll->tri[0]], - collmd->current_x[tri_coll->tri[1]], - collmd->current_x[tri_coll->tri[2]], + collmd->current_x[tri_coll[0]], + collmd->current_x[tri_coll[1]], + collmd->current_x[tri_coll[2]], data->culling, data->use_normal, pa, @@ -1207,9 +1199,9 @@ static void hair_collision(void *__restrict userdata, collpair[index].ap1 = edge_coll[0]; collpair[index].ap2 = edge_coll[1]; - collpair[index].bp1 = tri_coll->tri[0]; - collpair[index].bp2 = tri_coll->tri[1]; - collpair[index].bp3 = tri_coll->tri[2]; + collpair[index].bp1 = tri_coll[0]; + collpair[index].bp2 = tri_coll[1]; + collpair[index].bp3 = tri_coll[2]; copy_v3_v3(collpair[index].pa, pa); copy_v3_v3(collpair[index].pb, pb); @@ -1229,9 +1221,9 @@ static void hair_collision(void *__restrict userdata, collpair[index].aw1 = 1.0f - collpair[index].aw2; collision_compute_barycentric(pb, - collmd->current_xnew[tri_coll->tri[0]], - collmd->current_xnew[tri_coll->tri[1]], - collmd->current_xnew[tri_coll->tri[2]], + collmd->current_xnew[tri_coll[0]], + collmd->current_xnew[tri_coll[1]], + collmd->current_xnew[tri_coll[2]], &collpair[index].bw1, &collpair[index].bw2, &collpair[index].bw3); @@ -1537,7 +1529,7 @@ static bool cloth_bvh_obj_overlap_cb(void *userdata, int index_a, int /*index_b* { ClothModifierData *clmd = (ClothModifierData *)userdata; Cloth *clothObject = clmd->clothObject; - const MVertTri *tri_a = &clothObject->tri[index_a]; + const blender::int3 tri_a = clothObject->vert_tris[index_a]; return cloth_bvh_collision_is_active(clmd, clothObject, tri_a); } @@ -1549,9 +1541,8 @@ static bool cloth_bvh_self_overlap_cb(void *userdata, int index_a, int index_b, if (index_a != index_b) { ClothModifierData *clmd = (ClothModifierData *)userdata; Cloth *clothObject = clmd->clothObject; - const MVertTri *tri_a, *tri_b; - tri_a = &clothObject->tri[index_a]; - tri_b = &clothObject->tri[index_b]; + const blender::int3 tri_a = clothObject->vert_tris[index_a]; + const blender::int3 tri_b = clothObject->vert_tris[index_b]; if (cloth_bvh_selfcollision_is_active(clmd, clothObject, tri_a, tri_b)) { return true; diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc index fd652c288b5..a0777f8265c 100644 --- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc +++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc @@ -23,8 +23,6 @@ #include "BLI_span.hh" #include "BLI_task.hh" -#include "DNA_meshdata_types.h" - #include "BKE_attribute.hh" #include "BKE_attribute_math.hh" #include "BKE_bvhutils.hh" @@ -73,28 +71,19 @@ static Mesh *remesh_quadriflow(const Mesh *input_mesh, const Span corner_tris = input_mesh->corner_tris(); /* Gather the required data for export to the internal quadriflow mesh format. */ - Array verttri(corner_tris.size()); - BKE_mesh_runtime_verttris_from_corner_tris( - verttri.data(), input_corner_verts.data(), corner_tris.data(), corner_tris.size()); + Array vert_tris(corner_tris.size()); + mesh::vert_tris_from_corner_tris(input_corner_verts, corner_tris, vert_tris); const int totfaces = corner_tris.size(); const int totverts = input_mesh->verts_num; - Array faces(totfaces * 3); - - for (const int i : IndexRange(totfaces)) { - MVertTri &vt = verttri[i]; - faces[i * 3] = vt.tri[0]; - faces[i * 3 + 1] = vt.tri[1]; - faces[i * 3 + 2] = vt.tri[2]; - } /* Fill out the required input data */ QuadriflowRemeshData qrd; - qrd.totfaces = totfaces; - qrd.totverts = totverts; - qrd.verts = (float *)input_positions.data(); - qrd.faces = faces.data(); + qrd.totfaces = corner_tris.size(); + qrd.totverts = input_positions.size(); + qrd.verts = input_positions.cast().data(); + qrd.faces = vert_tris.as_span().cast().data(); qrd.target_faces = target_faces; qrd.preserve_sharp = preserve_sharp; diff --git a/source/blender/blenkernel/intern/mesh_runtime.cc b/source/blender/blenkernel/intern/mesh_runtime.cc index 1313b05885d..d80f50db55c 100644 --- a/source/blender/blenkernel/intern/mesh_runtime.cc +++ b/source/blender/blenkernel/intern/mesh_runtime.cc @@ -10,7 +10,6 @@ #include "MEM_guardedalloc.h" -#include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "BLI_array_utils.hh" @@ -270,18 +269,6 @@ int BKE_mesh_runtime_corner_tris_len(const Mesh *mesh) return poly_to_tri_count(mesh->faces_num, mesh->corners_num); } -void BKE_mesh_runtime_verttris_from_corner_tris(MVertTri *r_verttri, - const int *corner_verts, - const blender::int3 *corner_tris, - int corner_tris_num) -{ - for (int i = 0; i < corner_tris_num; i++) { - r_verttri[i].tri[0] = corner_verts[corner_tris[i][0]]; - r_verttri[i].tri[1] = corner_verts[corner_tris[i][1]]; - r_verttri[i].tri[2] = corner_verts[corner_tris[i][2]]; - } -} - void BKE_mesh_runtime_ensure_edit_data(Mesh *mesh) { if (!mesh->runtime->edit_data) { diff --git a/source/blender/blenkernel/intern/mesh_tessellate.cc b/source/blender/blenkernel/intern/mesh_tessellate.cc index 7de9edbf4ba..02b7f3bf743 100644 --- a/source/blender/blenkernel/intern/mesh_tessellate.cc +++ b/source/blender/blenkernel/intern/mesh_tessellate.cc @@ -11,6 +11,7 @@ * \see `bmesh_mesh_tessellate.cc` for the #BMesh equivalent of this file. */ +#include "BLI_array_utils.hh" #include "BLI_enumerable_thread_specific.hh" #include "BLI_math_geom.h" #include "BLI_math_matrix.h" @@ -324,6 +325,13 @@ void corner_tris_calc_with_normals(const Span vert_positions, /** \} */ +void vert_tris_from_corner_tris(const Span corner_verts, + const Span corner_tris, + MutableSpan vert_tris) +{ + array_utils::gather(corner_verts, corner_tris.cast(), vert_tris.cast()); +} + int3 corner_tri_get_real_edges(const Span edges, const Span corner_verts, const Span corner_edges, diff --git a/source/blender/blenkernel/intern/particle_system.cc b/source/blender/blenkernel/intern/particle_system.cc index c8ede5db370..d8cfc3652f0 100644 --- a/source/blender/blenkernel/intern/particle_system.cc +++ b/source/blender/blenkernel/intern/particle_system.cc @@ -2803,19 +2803,19 @@ void BKE_psys_collision_neartest_cb(void *userdata, { ParticleCollision *col = (ParticleCollision *)userdata; ParticleCollisionElement pce; - const MVertTri *vt = &col->md->tri[index]; + const blender::int3 vert_tri = &col->md->vert_tris[index]; float(*x)[3] = col->md->x; float(*v)[3] = col->md->current_v; float t = hit->dist / col->original_ray_length; int collision = 0; - pce.x[0] = x[vt->tri[0]]; - pce.x[1] = x[vt->tri[1]]; - pce.x[2] = x[vt->tri[2]]; + pce.x[0] = x[vert_tri[0]]; + pce.x[1] = x[vert_tri[1]]; + pce.x[2] = x[vert_tri[2]]; - pce.v[0] = v[vt->tri[0]]; - pce.v[1] = v[vt->tri[1]]; - pce.v[2] = v[vt->tri[2]]; + pce.v[0] = v[vert_tri[0]]; + pce.v[1] = v[vert_tri[1]]; + pce.v[2] = v[vert_tri[2]]; pce.tot = 3; pce.inside = 0; diff --git a/source/blender/blenkernel/intern/softbody.cc b/source/blender/blenkernel/intern/softbody.cc index f7ab67fe699..74b1f3ba669 100644 --- a/source/blender/blenkernel/intern/softbody.cc +++ b/source/blender/blenkernel/intern/softbody.cc @@ -260,7 +260,7 @@ typedef struct ccd_Mesh { int mvert_num, tri_num; const float (*vert_positions)[3]; const float (*vert_positions_prev)[3]; - const MVertTri *tri; + const blender::int3 *vert_tris; int safety; ccdf_minmax *mima; /* Axis Aligned Bounding Box AABB */ @@ -273,7 +273,6 @@ static ccd_Mesh *ccd_mesh_make(Object *ob) CollisionModifierData *cmd; ccd_Mesh *pccd_M = nullptr; ccdf_minmax *mima; - const MVertTri *vt; float hull; int i; @@ -316,20 +315,20 @@ static ccd_Mesh *ccd_mesh_make(Object *ob) pccd_M->bbmax[2] = max_ff(pccd_M->bbmax[2], v[2] + hull); } /* Allocate and copy faces. */ - pccd_M->tri = static_cast(MEM_dupallocN(cmd->tri)); + pccd_M->vert_tris = static_cast(MEM_dupallocN(cmd->vert_tris)); /* OBBs for idea1 */ pccd_M->mima = static_cast( MEM_mallocN(sizeof(ccdf_minmax) * pccd_M->tri_num, "ccd_Mesh_Faces_mima")); /* Anyhow we need to walk the list of faces and find OBB they live in. */ - for (i = 0, mima = pccd_M->mima, vt = pccd_M->tri; i < pccd_M->tri_num; i++, mima++, vt++) { + for (i = 0, mima = pccd_M->mima; i < pccd_M->tri_num; i++, mima++) { const float *v; mima->minx = mima->miny = mima->minz = 1e30f; mima->maxx = mima->maxy = mima->maxz = -1e30f; - v = pccd_M->vert_positions[vt->tri[0]]; + v = pccd_M->vert_positions[pccd_M->vert_tris[i][0]]; mima->minx = min_ff(mima->minx, v[0] - hull); mima->miny = min_ff(mima->miny, v[1] - hull); mima->minz = min_ff(mima->minz, v[2] - hull); @@ -337,7 +336,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob) mima->maxy = max_ff(mima->maxy, v[1] + hull); mima->maxz = max_ff(mima->maxz, v[2] + hull); - v = pccd_M->vert_positions[vt->tri[1]]; + v = pccd_M->vert_positions[pccd_M->vert_tris[i][1]]; mima->minx = min_ff(mima->minx, v[0] - hull); mima->miny = min_ff(mima->miny, v[1] - hull); mima->minz = min_ff(mima->minz, v[2] - hull); @@ -345,7 +344,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob) mima->maxy = max_ff(mima->maxy, v[1] + hull); mima->maxz = max_ff(mima->maxz, v[2] + hull); - v = pccd_M->vert_positions[vt->tri[2]]; + v = pccd_M->vert_positions[pccd_M->vert_tris[i][2]]; mima->minx = min_ff(mima->minx, v[0] - hull); mima->miny = min_ff(mima->miny, v[1] - hull); mima->minz = min_ff(mima->minz, v[2] - hull); @@ -360,7 +359,6 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M) { CollisionModifierData *cmd; ccdf_minmax *mima; - const MVertTri *vt; float hull; int i; @@ -418,14 +416,14 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M) } /* Anyhow we need to walk the list of faces and find OBB they live in. */ - for (i = 0, mima = pccd_M->mima, vt = pccd_M->tri; i < pccd_M->tri_num; i++, mima++, vt++) { + for (i = 0, mima = pccd_M->mima; i < pccd_M->tri_num; i++, mima++) { const float *v; mima->minx = mima->miny = mima->minz = 1e30f; mima->maxx = mima->maxy = mima->maxz = -1e30f; /* vert_positions */ - v = pccd_M->vert_positions[vt->tri[0]]; + v = pccd_M->vert_positions[pccd_M->vert_tris[i][0]]; mima->minx = min_ff(mima->minx, v[0] - hull); mima->miny = min_ff(mima->miny, v[1] - hull); mima->minz = min_ff(mima->minz, v[2] - hull); @@ -433,7 +431,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M) mima->maxy = max_ff(mima->maxy, v[1] + hull); mima->maxz = max_ff(mima->maxz, v[2] + hull); - v = pccd_M->vert_positions[vt->tri[1]]; + v = pccd_M->vert_positions[pccd_M->vert_tris[i][1]]; mima->minx = min_ff(mima->minx, v[0] - hull); mima->miny = min_ff(mima->miny, v[1] - hull); mima->minz = min_ff(mima->minz, v[2] - hull); @@ -441,7 +439,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M) mima->maxy = max_ff(mima->maxy, v[1] + hull); mima->maxz = max_ff(mima->maxz, v[2] + hull); - v = pccd_M->vert_positions[vt->tri[2]]; + v = pccd_M->vert_positions[pccd_M->vert_tris[i][2]]; mima->minx = min_ff(mima->minx, v[0] - hull); mima->miny = min_ff(mima->miny, v[1] - hull); mima->minz = min_ff(mima->minz, v[2] - hull); @@ -450,7 +448,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M) mima->maxz = max_ff(mima->maxz, v[2] + hull); /* vert_positions_prev */ - v = pccd_M->vert_positions_prev[vt->tri[0]]; + v = pccd_M->vert_positions_prev[pccd_M->vert_tris[i][0]]; mima->minx = min_ff(mima->minx, v[0] - hull); mima->miny = min_ff(mima->miny, v[1] - hull); mima->minz = min_ff(mima->minz, v[2] - hull); @@ -458,7 +456,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M) mima->maxy = max_ff(mima->maxy, v[1] + hull); mima->maxz = max_ff(mima->maxz, v[2] + hull); - v = pccd_M->vert_positions_prev[vt->tri[1]]; + v = pccd_M->vert_positions_prev[pccd_M->vert_tris[i][1]]; mima->minx = min_ff(mima->minx, v[0] - hull); mima->miny = min_ff(mima->miny, v[1] - hull); mima->minz = min_ff(mima->minz, v[2] - hull); @@ -466,7 +464,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M) mima->maxy = max_ff(mima->maxy, v[1] + hull); mima->maxz = max_ff(mima->maxz, v[2] + hull); - v = pccd_M->vert_positions_prev[vt->tri[2]]; + v = pccd_M->vert_positions_prev[pccd_M->vert_tris[i][2]]; mima->minx = min_ff(mima->minx, v[0] - hull); mima->miny = min_ff(mima->miny, v[1] - hull); mima->minz = min_ff(mima->minz, v[2] - hull); @@ -481,7 +479,7 @@ static void ccd_mesh_free(ccd_Mesh *ccdm) /* Make sure we're not nuking objects we don't know. */ if (ccdm && (ccdm->safety == CCD_SAFETY)) { MEM_freeN((void *)ccdm->vert_positions); - MEM_freeN((void *)ccdm->tri); + MEM_freeN((void *)ccdm->vert_tris); if (ccdm->vert_positions_prev) { MEM_freeN((void *)ccdm->vert_positions_prev); } @@ -1163,12 +1161,12 @@ static int sb_detect_face_collisionCached(const float face_v1[3], if (ob->pd && ob->pd->deflect) { const float(*vert_positions)[3] = nullptr; const float(*vert_positions_prev)[3] = nullptr; - const MVertTri *vt = nullptr; + const blender::int3 *vt = nullptr; const ccdf_minmax *mima = nullptr; if (ccdm) { vert_positions = ccdm->vert_positions; - vt = ccdm->tri; + vt = ccdm->vert_tris; vert_positions_prev = ccdm->vert_positions_prev; mima = ccdm->mima; a = ccdm->tri_num; @@ -1202,19 +1200,19 @@ static int sb_detect_face_collisionCached(const float face_v1[3], if (vert_positions) { - copy_v3_v3(nv1, vert_positions[vt->tri[0]]); - copy_v3_v3(nv2, vert_positions[vt->tri[1]]); - copy_v3_v3(nv3, vert_positions[vt->tri[2]]); + copy_v3_v3(nv1, vert_positions[(*vt)[0]]); + copy_v3_v3(nv2, vert_positions[(*vt)[1]]); + copy_v3_v3(nv3, vert_positions[(*vt)[2]]); if (vert_positions_prev) { mul_v3_fl(nv1, time); - madd_v3_v3fl(nv1, vert_positions_prev[vt->tri[0]], 1.0f - time); + madd_v3_v3fl(nv1, vert_positions_prev[(*vt)[0]], 1.0f - time); mul_v3_fl(nv2, time); - madd_v3_v3fl(nv2, vert_positions_prev[vt->tri[1]], 1.0f - time); + madd_v3_v3fl(nv2, vert_positions_prev[(*vt)[1]], 1.0f - time); mul_v3_fl(nv3, time); - madd_v3_v3fl(nv3, vert_positions_prev[vt->tri[2]], 1.0f - time); + madd_v3_v3fl(nv3, vert_positions_prev[(*vt)[2]], 1.0f - time); } } @@ -1344,13 +1342,13 @@ static int sb_detect_edge_collisionCached(const float edge_v1[3], if (ob->pd && ob->pd->deflect) { const float(*vert_positions)[3] = nullptr; const float(*vert_positions_prev)[3] = nullptr; - const MVertTri *vt = nullptr; + const blender::int3 *vt = nullptr; const ccdf_minmax *mima = nullptr; if (ccdm) { vert_positions = ccdm->vert_positions; vert_positions_prev = ccdm->vert_positions_prev; - vt = ccdm->tri; + vt = ccdm->vert_tris; mima = ccdm->mima; a = ccdm->tri_num; @@ -1383,19 +1381,19 @@ static int sb_detect_edge_collisionCached(const float edge_v1[3], if (vert_positions) { - copy_v3_v3(nv1, vert_positions[vt->tri[0]]); - copy_v3_v3(nv2, vert_positions[vt->tri[1]]); - copy_v3_v3(nv3, vert_positions[vt->tri[2]]); + copy_v3_v3(nv1, vert_positions[(*vt)[0]]); + copy_v3_v3(nv2, vert_positions[(*vt)[1]]); + copy_v3_v3(nv3, vert_positions[(*vt)[2]]); if (vert_positions_prev) { mul_v3_fl(nv1, time); - madd_v3_v3fl(nv1, vert_positions_prev[vt->tri[0]], 1.0f - time); + madd_v3_v3fl(nv1, vert_positions_prev[(*vt)[0]], 1.0f - time); mul_v3_fl(nv2, time); - madd_v3_v3fl(nv2, vert_positions_prev[vt->tri[1]], 1.0f - time); + madd_v3_v3fl(nv2, vert_positions_prev[(*vt)[1]], 1.0f - time); mul_v3_fl(nv3, time); - madd_v3_v3fl(nv3, vert_positions_prev[vt->tri[2]], 1.0f - time); + madd_v3_v3fl(nv3, vert_positions_prev[(*vt)[2]], 1.0f - time); } } @@ -1647,13 +1645,13 @@ static int sb_detect_vertex_collisionCached(float opco[3], if (ob->pd && ob->pd->deflect) { const float(*vert_positions)[3] = nullptr; const float(*vert_positions_prev)[3] = nullptr; - const MVertTri *vt = nullptr; + const blender::int3 *vt = nullptr; const ccdf_minmax *mima = nullptr; if (ccdm) { vert_positions = ccdm->vert_positions; vert_positions_prev = ccdm->vert_positions_prev; - vt = ccdm->tri; + vt = ccdm->vert_tris; mima = ccdm->mima; a = ccdm->tri_num; @@ -1700,9 +1698,9 @@ static int sb_detect_vertex_collisionCached(float opco[3], if (vert_positions) { - copy_v3_v3(nv1, vert_positions[vt->tri[0]]); - copy_v3_v3(nv2, vert_positions[vt->tri[1]]); - copy_v3_v3(nv3, vert_positions[vt->tri[2]]); + copy_v3_v3(nv1, vert_positions[(*vt)[0]]); + copy_v3_v3(nv2, vert_positions[(*vt)[1]]); + copy_v3_v3(nv3, vert_positions[(*vt)[2]]); if (vert_positions_prev) { /* Grab the average speed of the collider vertices before we spoil nvX @@ -1710,18 +1708,18 @@ static int sb_detect_vertex_collisionCached(float opco[3], * since the AABB reduced probability to get here drastically * it might be a nice tradeoff CPU <--> memory. */ - sub_v3_v3v3(vv1, nv1, vert_positions_prev[vt->tri[0]]); - sub_v3_v3v3(vv2, nv2, vert_positions_prev[vt->tri[1]]); - sub_v3_v3v3(vv3, nv3, vert_positions_prev[vt->tri[2]]); + sub_v3_v3v3(vv1, nv1, vert_positions_prev[(*vt)[0]]); + sub_v3_v3v3(vv2, nv2, vert_positions_prev[(*vt)[1]]); + sub_v3_v3v3(vv3, nv3, vert_positions_prev[(*vt)[2]]); mul_v3_fl(nv1, time); - madd_v3_v3fl(nv1, vert_positions_prev[vt->tri[0]], 1.0f - time); + madd_v3_v3fl(nv1, vert_positions_prev[(*vt)[0]], 1.0f - time); mul_v3_fl(nv2, time); - madd_v3_v3fl(nv2, vert_positions_prev[vt->tri[1]], 1.0f - time); + madd_v3_v3fl(nv2, vert_positions_prev[(*vt)[1]], 1.0f - time); mul_v3_fl(nv3, time); - madd_v3_v3fl(nv3, vert_positions_prev[vt->tri[2]], 1.0f - time); + madd_v3_v3fl(nv3, vert_positions_prev[(*vt)[2]], 1.0f - time); } } diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.cc b/source/blender/editors/sculpt_paint/sculpt_cloth.cc index fa94b54af17..792d56860aa 100644 --- a/source/blender/editors/sculpt_paint/sculpt_cloth.cc +++ b/source/blender/editors/sculpt_paint/sculpt_cloth.cc @@ -17,7 +17,6 @@ #include "DNA_brush_types.h" #include "DNA_customdata_types.h" -#include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" @@ -633,13 +632,13 @@ static void cloth_brush_collision_cb(void *userdata, { ClothBrushCollision *col = (ClothBrushCollision *)userdata; CollisionModifierData *col_data = col->col_data; - MVertTri *verttri = &col_data->tri[index]; + const int3 vert_tri = col_data->vert_tris[index]; float(*positions)[3] = col_data->x; float *tri[3], no[3], co[3]; - tri[0] = positions[verttri->tri[0]]; - tri[1] = positions[verttri->tri[1]]; - tri[2] = positions[verttri->tri[2]]; + tri[0] = positions[vert_tri[0]]; + tri[1] = positions[vert_tri[1]]; + tri[2] = positions[vert_tri[2]]; float dist = 0.0f; bool tri_hit = isect_ray_tri_watertight_v3( diff --git a/source/blender/io/usd/hydra/mesh.cc b/source/blender/io/usd/hydra/mesh.cc index eb7099e54e8..dea255354a0 100644 --- a/source/blender/io/usd/hydra/mesh.cc +++ b/source/blender/io/usd/hydra/mesh.cc @@ -304,10 +304,10 @@ static void copy_submesh(const Mesh &mesh, int dst_verts_num; VectorSet verts; if (copy_all_verts) { - /* Copy the vertex indices from the corner indices stored in every triangle. */ - array_utils::gather(corner_verts, - corner_tris.cast(), - MutableSpan(sm.face_vertex_indices.data(), sm.face_vertex_indices.size())); + bke::mesh::vert_tris_from_corner_tris( + corner_verts, + corner_tris, + MutableSpan(sm.face_vertex_indices.data(), sm.face_vertex_indices.size()).cast()); dst_verts_num = vert_positions.size(); } else { diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index afa60b1e541..24dff6b3cc4 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -93,12 +93,6 @@ enum { * real edges. */ -# -# -typedef struct MVertTri { - unsigned int tri[3]; -} MVertTri; - /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/makesdna/DNA_modifier_defaults.h b/source/blender/makesdna/DNA_modifier_defaults.h index 9709fd1fd13..4fc4a9341b1 100644 --- a/source/blender/makesdna/DNA_modifier_defaults.h +++ b/source/blender/makesdna/DNA_modifier_defaults.h @@ -195,7 +195,7 @@ .current_xnew = NULL, \ .current_x = NULL, \ .current_v = NULL, \ - .tri = NULL, \ + .vert_tris = NULL, \ .mvert_num = 0, \ .tri_num = 0, \ .time_x = -1000.0f, \ diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index a6fa48ead7a..fa19e5290d7 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -879,7 +879,7 @@ typedef struct CollisionModifierData { /** (xnew - x) at the actual inter-frame step. */ float (*current_v)[3]; - struct MVertTri *tri; + int (*vert_tris)[3]; unsigned int mvert_num; unsigned int tri_num; diff --git a/source/blender/modifiers/intern/MOD_collision.cc b/source/blender/modifiers/intern/MOD_collision.cc index e5fe1878744..faccf52d18e 100644 --- a/source/blender/modifiers/intern/MOD_collision.cc +++ b/source/blender/modifiers/intern/MOD_collision.cc @@ -15,8 +15,6 @@ #include "BLT_translation.h" #include "DNA_defaults.h" -#include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" #include "DNA_object_force_types.h" #include "DNA_object_types.h" #include "DNA_screen_types.h" @@ -73,7 +71,7 @@ static void free_data(ModifierData *md) MEM_SAFE_FREE(collmd->current_xnew); MEM_SAFE_FREE(collmd->current_v); - MEM_SAFE_FREE(collmd->tri); + MEM_SAFE_FREE(collmd->vert_tris); collmd->time_x = collmd->time_xnew = -1000; collmd->mvert_num = 0; @@ -157,16 +155,21 @@ static void deform_verts(ModifierData *md, { const blender::Span corner_tris = mesh->corner_tris(); collmd->tri_num = corner_tris.size(); - MVertTri *tri = static_cast( - MEM_mallocN(sizeof(*tri) * collmd->tri_num, __func__)); - BKE_mesh_runtime_verttris_from_corner_tris( - tri, mesh->corner_verts().data(), corner_tris.data(), collmd->tri_num); - collmd->tri = tri; + int(*vert_tris)[3] = static_cast( + MEM_malloc_arrayN(collmd->tri_num, sizeof(int[3]), __func__)); + blender::bke::mesh::vert_tris_from_corner_tris( + mesh->corner_verts(), + corner_tris, + {reinterpret_cast(vert_tris), collmd->tri_num}); + collmd->vert_tris = vert_tris; } /* create bounding box hierarchy */ collmd->bvhtree = bvhtree_build_from_mvert( - collmd->x, collmd->tri, collmd->tri_num, ob->pd->pdef_sboft); + collmd->x, + reinterpret_cast(collmd->vert_tris), + collmd->tri_num, + ob->pd->pdef_sboft); collmd->time_x = collmd->time_xnew = current_time; collmd->is_static = true; @@ -198,21 +201,27 @@ static void deform_verts(ModifierData *md, if (ob->pd->pdef_sboft != BLI_bvhtree_get_epsilon(collmd->bvhtree)) { BLI_bvhtree_free(collmd->bvhtree); collmd->bvhtree = bvhtree_build_from_mvert( - collmd->current_x, collmd->tri, collmd->tri_num, ob->pd->pdef_sboft); + collmd->current_x, + reinterpret_cast(collmd->vert_tris), + collmd->tri_num, + ob->pd->pdef_sboft); } } /* Happens on file load (ONLY when I un-comment changes in `readfile.cc`). */ if (!collmd->bvhtree) { collmd->bvhtree = bvhtree_build_from_mvert( - collmd->current_x, collmd->tri, collmd->tri_num, ob->pd->pdef_sboft); + collmd->current_x, + reinterpret_cast(collmd->vert_tris), + collmd->tri_num, + ob->pd->pdef_sboft); } else if (!collmd->is_static || !is_static) { /* recalc static bounding boxes */ bvhtree_update_from_mvert(collmd->bvhtree, collmd->current_x, collmd->current_xnew, - collmd->tri, + reinterpret_cast(collmd->vert_tris), collmd->tri_num, true); } @@ -272,7 +281,7 @@ static void blend_read(BlendDataReader * /*reader*/, ModifierData *md) collmd->tri_num = 0; collmd->is_static = false; collmd->bvhtree = nullptr; - collmd->tri = nullptr; + collmd->vert_tris = nullptr; } ModifierTypeInfo modifierType_Collision = { diff --git a/source/blender/simulation/intern/SIM_mass_spring.cc b/source/blender/simulation/intern/SIM_mass_spring.cc index fe589443ab0..cfe68e5dc9c 100644 --- a/source/blender/simulation/intern/SIM_mass_spring.cc +++ b/source/blender/simulation/intern/SIM_mass_spring.cc @@ -9,7 +9,6 @@ #include "MEM_guardedalloc.h" #include "DNA_cloth_types.h" -#include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" #include "DNA_object_force_types.h" #include "DNA_object_types.h" @@ -59,7 +58,7 @@ static int cloth_count_nondiag_blocks(Cloth *cloth) } static bool cloth_get_pressure_weights(ClothModifierData *clmd, - const MVertTri *vt, + const blender::int3 &vert_tri, float *r_weights) { /* We have custom vertex weights for pressure. */ @@ -68,7 +67,7 @@ static bool cloth_get_pressure_weights(ClothModifierData *clmd, ClothVertex *verts = cloth->verts; for (uint j = 0; j < 3; j++) { - r_weights[j] = verts[vt->tri[j]].pressure_factor; + r_weights[j] = verts[vert_tri[j]].pressure_factor; /* Skip the entire triangle if it has a zero weight. */ if (r_weights[j] == 0.0f) { @@ -99,7 +98,7 @@ static float cloth_calc_volume(ClothModifierData *clmd) { /* Calculate the (closed) cloth volume. */ Cloth *cloth = clmd->clothObject; - const MVertTri *tri = cloth->tri; + const blender::int3 *vert_tris = cloth->vert_tris; Implicit_Data *data = cloth->implicit; float weights[3] = {1.0f, 1.0f, 1.0f}; float vol = 0; @@ -110,10 +109,10 @@ static float cloth_calc_volume(ClothModifierData *clmd) } for (uint i = 0; i < cloth->primitive_num; i++) { - const MVertTri *vt = &tri[i]; + const blender::int3 tri = vert_tris[i]; - if (cloth_get_pressure_weights(clmd, vt, weights)) { - vol += SIM_tri_tetra_volume_signed_6x(data, vt->tri[0], vt->tri[1], vt->tri[2]); + if (cloth_get_pressure_weights(clmd, tri, weights)) { + vol += SIM_tri_tetra_volume_signed_6x(data, tri[0], tri[1], tri[2]); } } @@ -127,7 +126,7 @@ static float cloth_calc_rest_volume(ClothModifierData *clmd) { /* Calculate the (closed) cloth volume. */ Cloth *cloth = clmd->clothObject; - const MVertTri *tri = cloth->tri; + const blender::int3 *vert_tris = cloth->vert_tris; const ClothVertex *v = cloth->verts; float weights[3] = {1.0f, 1.0f, 1.0f}; float vol = 0; @@ -138,11 +137,11 @@ static float cloth_calc_rest_volume(ClothModifierData *clmd) } for (uint i = 0; i < cloth->primitive_num; i++) { - const MVertTri *vt = &tri[i]; + const blender::int3 tri = vert_tris[i]; - if (cloth_get_pressure_weights(clmd, vt, weights)) { + if (cloth_get_pressure_weights(clmd, tri, weights)) { vol += volume_tri_tetrahedron_signed_v3_6x( - v[vt->tri[0]].xrest, v[vt->tri[1]].xrest, v[vt->tri[2]].xrest); + v[tri[0]].xrest, v[tri[1]].xrest, v[tri[2]].xrest); } } @@ -155,20 +154,20 @@ static float cloth_calc_rest_volume(ClothModifierData *clmd) static float cloth_calc_average_pressure(ClothModifierData *clmd, const float *vertex_pressure) { Cloth *cloth = clmd->clothObject; - const MVertTri *tri = cloth->tri; + const blender::int3 *vert_tris = cloth->vert_tris; Implicit_Data *data = cloth->implicit; float weights[3] = {1.0f, 1.0f, 1.0f}; float total_force = 0; float total_area = 0; for (uint i = 0; i < cloth->primitive_num; i++) { - const MVertTri *vt = &tri[i]; + const blender::int3 tri = vert_tris[i]; - if (cloth_get_pressure_weights(clmd, vt, weights)) { - float area = SIM_tri_area(data, vt->tri[0], vt->tri[1], vt->tri[2]); + if (cloth_get_pressure_weights(clmd, tri, weights)) { + float area = SIM_tri_area(data, tri[0], tri[1], tri[2]); - total_force += (vertex_pressure[vt->tri[0]] + vertex_pressure[vt->tri[1]] + - vertex_pressure[vt->tri[2]]) * + total_force += (vertex_pressure[tri[0]] + vertex_pressure[tri[1]] + + vertex_pressure[tri[2]]) * area / 3.0f; total_area += area; } @@ -573,7 +572,7 @@ static void cloth_calc_force( uint i = 0; float drag = clmd->sim_parms->Cvi * 0.01f; /* viscosity of air scaled in percent */ float gravity[3] = {0.0f, 0.0f, 0.0f}; - const MVertTri *tri = cloth->tri; + const blender::int3 *vert_tris = cloth->vert_tris; uint mvert_num = cloth->mvert_num; ClothVertex *vert; @@ -680,16 +679,11 @@ static void cloth_calc_force( float weights[3] = {1.0f, 1.0f, 1.0f}; for (i = 0; i < cloth->primitive_num; i++) { - const MVertTri *vt = &tri[i]; + const blender::int3 tri = vert_tris[i]; - if (cloth_get_pressure_weights(clmd, vt, weights)) { - SIM_mass_spring_force_pressure(data, - vt->tri[0], - vt->tri[1], - vt->tri[2], - pressure_difference, - hydrostatic_pressure, - weights); + if (cloth_get_pressure_weights(clmd, tri, weights)) { + SIM_mass_spring_force_pressure( + data, tri[0], tri[1], tri[2], pressure_difference, hydrostatic_pressure, weights); } } } @@ -730,12 +724,12 @@ static void cloth_calc_force( /* Hair has only edges. */ if (is_not_hair) { for (i = 0; i < cloth->primitive_num; i++) { - const MVertTri *vt = &tri[i]; + const blender::int3 tri = vert_tris[i]; if (has_wind) { - SIM_mass_spring_force_face_wind(data, vt->tri[0], vt->tri[1], vt->tri[2], winvec); + SIM_mass_spring_force_face_wind(data, tri[0], tri[1], tri[2], winvec); } if (has_force) { - SIM_mass_spring_force_face_extern(data, vt->tri[0], vt->tri[1], vt->tri[2], forcevec); + SIM_mass_spring_force_face_extern(data, tri[0], tri[1], tri[2], forcevec); } } }