Skip to content

Commit

Permalink
--exit calc if not strictly triangle-based mesh; make temp dedup copy
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner65 committed Aug 9, 2024
1 parent 8cead38 commit e86bf5e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/esp/assets/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mn::Trade::MeshData>& 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<Mn::Trade::MeshData> 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<Mn::Vector3> 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<std::uint32_t>();
const auto idxAra = meshData->indicesAsArray();
// const auto idxView = newMeshData->indices<std::uint32_t>();
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
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit e86bf5e

Please sign in to comment.