Fix for ATOM-15923 : Editor Spends Several Minutes Entering/Ending Play Game Mode (#1846)

* Cut off kd-tree generation if more than 10 percent of triangles straddle split axis

Signed-off-by: amzn-tommy <waltont@amazon.com>

* Switched to aznumeric_cast and added a comment with a JIRA to follow up on

Signed-off-by: amzn-tommy <waltont@amazon.com>
This commit is contained in:
Tommy Walton
2021-07-07 15:08:57 -07:00
committed by GitHub
parent 1b474afdb0
commit 5b9647c11b
2 changed files with 7 additions and 2 deletions
@@ -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<ModelKdTreeNode> m_pRootNode;
struct MeshData
@@ -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<float>(outInfo.m_aboveIndices.size() + outInfo.m_belowIndices.size()) / aznumeric_cast<float>(indices.size()) < s_MaximumSplitAxisStraddlingTriangles;
}
bool ModelKdTree::Build(const ModelAsset* model)