@@ -1044,26 +1044,40 @@ void ResourceManager::computeGeneralMeshAreaAndVolume(
1044
1044
" transforms does not match number of drawables." , );
1045
1045
1046
1046
for (uint32_t iEntry = 0 ; iEntry < staticDrawableInfo.size (); ++iEntry) {
1047
+ // Current drawable's meshID
1047
1048
const int meshID = staticDrawableInfo[iEntry].meshID ;
1049
+ // Current drawable's scene node
1050
+ scene::SceneNode& node = staticDrawableInfo[iEntry].node ;
1048
1051
1049
1052
Cr::Containers::Optional<Mn::Trade::MeshData>& meshData =
1050
1053
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
+ }
1051
1061
CORRADE_ASSERT (
1052
1062
meshData,
1053
1063
" ::computeGeneralMeshAreaAndVolume: The mesh data specified at ID:"
1054
1064
<< 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}));
1055
1069
1056
1070
// Precalc all transformed verts - only use first position array for this
1057
1071
Cr::Containers::Array<Mn::Vector3> posArray =
1058
- meshData ->positions3DAsArray (0 );
1072
+ newMeshData ->positions3DAsArray (0 );
1059
1073
Mn::MeshTools::transformPointsInPlace (absTransforms[iEntry], posArray);
1060
1074
1061
1075
// Getting the view properly relies on having the appropriate type of the
1062
1076
// 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 ();
1065
1079
// # of indices
1066
- uint32_t numIdxs = meshData ->indexCount ();
1080
+ uint32_t numIdxs = newMeshData ->indexCount ();
1067
1081
// Assuming no duplicate vertices with different idxs
1068
1082
// Determine that all edges have exactly 2 sides ->
1069
1083
// idxAra describes exactly 2 pairs of the same idxs, a->b and b->a
@@ -1100,8 +1114,6 @@ void ResourceManager::computeGeneralMeshAreaAndVolume(
1100
1114
}
1101
1115
}
1102
1116
1103
- // locate the scene node which contains the current drawable
1104
- scene::SceneNode& node = staticDrawableInfo[iEntry].node ;
1105
1117
// Surface area of the mesh : .5 * ba.cross(bc)
1106
1118
double ttlSurfaceArea = 0.0 ;
1107
1119
// Volume of the mesh : 1/6 * (OA.dot(ba.cross(bc)))
0 commit comments