diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Model/ModelKdTree.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Model/ModelKdTree.h index cd3f1968bf..fc915bcd07 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Model/ModelKdTree.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Model/ModelKdTree.h @@ -67,7 +67,8 @@ namespace AZ void ConstructMeshList(const ModelAsset* model, const AZ::Transform& matParent); static const int s_MinimumVertexSizeInLeafNode = 3 * 10; - + // Stop splitting the tree if more than 10% of the triangles are straddling the split axis + static constexpr float s_MaximumSplitAxisStraddlingTriangles = 1.1; AZStd::unique_ptr m_pRootNode; struct MeshData diff --git a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Model/ModelKdTree.cpp b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Model/ModelKdTree.cpp index 54ec002893..ace4df5c0b 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Model/ModelKdTree.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Model/ModelKdTree.cpp @@ -84,7 +84,11 @@ namespace AZ // If either the top or bottom contain all the input indices, the triangles are too close to cut any // further and the split failed - return indices.size() != outInfo.m_aboveIndices.size() && indices.size() != outInfo.m_belowIndices.size(); + // Additionally, if too many triangles straddle the split-axis, + // the triangles are too close and the split failed + // [ATOM-15944] - Use a more sophisticated method to terminate KdTree generation + return indices.size() != outInfo.m_aboveIndices.size() && indices.size() != outInfo.m_belowIndices.size() + && aznumeric_cast(outInfo.m_aboveIndices.size() + outInfo.m_belowIndices.size()) / aznumeric_cast(indices.size()) < s_MaximumSplitAxisStraddlingTriangles; } bool ModelKdTree::Build(const ModelAsset* model)