Skip to content

Commit 263679a

Browse files
committed
--exit calc if not strictly triangle-based mesh; make temp dedup copy
1 parent 1ed8b18 commit 263679a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/esp/assets/ResourceManager.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,22 +1048,30 @@ void ResourceManager::computeGeneralMeshAreaAndVolume(
10481048

10491049
Cr::Containers::Optional<Mn::Trade::MeshData>& meshData =
10501050
meshes_.at(meshID)->getMeshData();
1051+
if (meshData->primitive() != Mn::MeshPrimitive::Triangles) {
1052+
// These calculations rely on this mesh being purely triangle-based
1053+
continue;
1054+
}
10511055
CORRADE_ASSERT(
10521056
meshData,
10531057
"::computeGeneralMeshAreaAndVolume: The mesh data specified at ID:"
10541058
<< meshID << "is empty/undefined. Aborting", );
1059+
// Make temp copy that removes dupes for volume calc
1060+
Cr::Containers::Optional<Mn::Trade::MeshData> newMeshData =
1061+
Mn::MeshTools::removeDuplicates(Mn::MeshTools::filterOnlyAttributes(
1062+
*meshData, {Mn::Trade::MeshAttribute::Position}));
10551063

10561064
// Precalc all transformed verts - only use first position array for this
10571065
Cr::Containers::Array<Mn::Vector3> posArray =
1058-
meshData->positions3DAsArray(0);
1066+
newMeshData->positions3DAsArray(0);
10591067
Mn::MeshTools::transformPointsInPlace(absTransforms[iEntry], posArray);
10601068

10611069
// Getting the view properly relies on having the appropriate type of the
10621070
// loaded data
1063-
// const auto idxView = meshData->indices<std::uint32_t>();
1064-
const auto idxAra = meshData->indicesAsArray();
1071+
// const auto idxView = newMeshData->indices<std::uint32_t>();
1072+
const auto idxAra = newMeshData->indicesAsArray();
10651073
// # of indices
1066-
uint32_t numIdxs = meshData->indexCount();
1074+
uint32_t numIdxs = newMeshData->indexCount();
10671075
// Assuming no duplicate vertices with different idxs
10681076
// Determine that all edges have exactly 2 sides ->
10691077
// idxAra describes exactly 2 pairs of the same idxs, a->b and b->a

0 commit comments

Comments
 (0)