Skip to content

Commit e86bf5e

Browse files
committed
--exit calc if not strictly triangle-based mesh; make temp dedup copy
1 parent 8cead38 commit e86bf5e

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Diff for: src/esp/assets/ResourceManager.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -1044,26 +1044,40 @@ void ResourceManager::computeGeneralMeshAreaAndVolume(
10441044
"transforms does not match number of drawables.", );
10451045

10461046
for (uint32_t iEntry = 0; iEntry < staticDrawableInfo.size(); ++iEntry) {
1047+
// Current drawable's meshID
10471048
const int meshID = staticDrawableInfo[iEntry].meshID;
1049+
// Current drawable's scene node
1050+
scene::SceneNode& node = staticDrawableInfo[iEntry].node;
10481051

10491052
Cr::Containers::Optional<Mn::Trade::MeshData>& meshData =
10501053
meshes_.at(meshID)->getMeshData();
1054+
if (meshData->primitive() != Mn::MeshPrimitive::Triangles) {
1055+
// These calculations rely on this mesh being purely triangle-based
1056+
// Make sure mesh's topology is set to unknown so area/volume values are
1057+
// not trusted
1058+
node.setMeshTopology(scene::DrawableMeshTopology::Unknown);
1059+
continue;
1060+
}
10511061
CORRADE_ASSERT(
10521062
meshData,
10531063
"::computeGeneralMeshAreaAndVolume: The mesh data specified at ID:"
10541064
<< meshID << "is empty/undefined. Aborting", );
1065+
// Make temp copy that removes dupes for volume calc
1066+
Cr::Containers::Optional<Mn::Trade::MeshData> newMeshData =
1067+
Mn::MeshTools::removeDuplicates(Mn::MeshTools::filterOnlyAttributes(
1068+
*meshData, {Mn::Trade::MeshAttribute::Position}));
10551069

10561070
// Precalc all transformed verts - only use first position array for this
10571071
Cr::Containers::Array<Mn::Vector3> posArray =
1058-
meshData->positions3DAsArray(0);
1072+
newMeshData->positions3DAsArray(0);
10591073
Mn::MeshTools::transformPointsInPlace(absTransforms[iEntry], posArray);
10601074

10611075
// Getting the view properly relies on having the appropriate type of the
10621076
// loaded data
1063-
// const auto idxView = meshData->indices<std::uint32_t>();
1064-
const auto idxAra = meshData->indicesAsArray();
1077+
// const auto idxView = newMeshData->indices<std::uint32_t>();
1078+
const auto idxAra = newMeshData->indicesAsArray();
10651079
// # of indices
1066-
uint32_t numIdxs = meshData->indexCount();
1080+
uint32_t numIdxs = newMeshData->indexCount();
10671081
// Assuming no duplicate vertices with different idxs
10681082
// Determine that all edges have exactly 2 sides ->
10691083
// idxAra describes exactly 2 pairs of the same idxs, a->b and b->a
@@ -1100,8 +1114,6 @@ void ResourceManager::computeGeneralMeshAreaAndVolume(
11001114
}
11011115
}
11021116

1103-
// locate the scene node which contains the current drawable
1104-
scene::SceneNode& node = staticDrawableInfo[iEntry].node;
11051117
// Surface area of the mesh : .5 * ba.cross(bc)
11061118
double ttlSurfaceArea = 0.0;
11071119
// Volume of the mesh : 1/6 * (OA.dot(ba.cross(bc)))

0 commit comments

Comments
 (0)