From e201f26e6df633c1c8d94edb9cd84817762539c8 Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Thu, 1 Aug 2024 11:45:22 -0400 Subject: [PATCH] --exit calc if not strictly triangle-based mesh; make temp dedup copy --- src/esp/assets/ResourceManager.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/esp/assets/ResourceManager.cpp b/src/esp/assets/ResourceManager.cpp index 0794af8298..9c8f0a4fce 100644 --- a/src/esp/assets/ResourceManager.cpp +++ b/src/esp/assets/ResourceManager.cpp @@ -1044,26 +1044,40 @@ void ResourceManager::computeGeneralMeshAreaAndVolume( "transforms does not match number of drawables.", ); for (uint32_t iEntry = 0; iEntry < staticDrawableInfo.size(); ++iEntry) { + // Current drawable's meshID const int meshID = staticDrawableInfo[iEntry].meshID; + // Current drawable's scene node + scene::SceneNode& node = staticDrawableInfo[iEntry].node; Cr::Containers::Optional& meshData = meshes_.at(meshID)->getMeshData(); + if (meshData->primitive() != Mn::MeshPrimitive::Triangles) { + // These calculations rely on this mesh being purely triangle-based + // Make sure mesh's topology is set to unknown so area/volume values are + // not trusted + node.setMeshTopology(scene::DrawableMeshTopology::Unknown); + continue; + } CORRADE_ASSERT( meshData, "::computeGeneralMeshAreaAndVolume: The mesh data specified at ID:" << meshID << "is empty/undefined. Aborting", ); + // Make temp copy that removes dupes for volume calc + Cr::Containers::Optional newMeshData = + Mn::MeshTools::removeDuplicates(Mn::MeshTools::filterOnlyAttributes( + *meshData, {Mn::Trade::MeshAttribute::Position})); // Precalc all transformed verts - only use first position array for this Cr::Containers::Array posArray = - meshData->positions3DAsArray(0); + newMeshData->positions3DAsArray(0); Mn::MeshTools::transformPointsInPlace(absTransforms[iEntry], posArray); // Getting the view properly relies on having the appropriate type of the // loaded data - // const auto idxView = meshData->indices(); - const auto idxAra = meshData->indicesAsArray(); + // const auto idxView = newMeshData->indices(); + const auto idxAra = newMeshData->indicesAsArray(); // # of indices - uint32_t numIdxs = meshData->indexCount(); + uint32_t numIdxs = newMeshData->indexCount(); // Assuming no duplicate vertices with different idxs // Determine that all edges have exactly 2 sides -> // idxAra describes exactly 2 pairs of the same idxs, a->b and b->a @@ -1100,8 +1114,6 @@ void ResourceManager::computeGeneralMeshAreaAndVolume( } } - // locate the scene node which contains the current drawable - scene::SceneNode& node = staticDrawableInfo[iEntry].node; // Surface area of the mesh : .5 * ba.cross(bc) double ttlSurfaceArea = 0.0; // Volume of the mesh : 1/6 * (OA.dot(ba.cross(bc)))