diff --git a/Gems/MotionMatching/Code/Source/FeatureMatrix.h b/Gems/MotionMatching/Code/Source/FeatureMatrix.h index 645dcaf34a..4f1f69a5e5 100644 --- a/Gems/MotionMatching/Code/Source/FeatureMatrix.h +++ b/Gems/MotionMatching/Code/Source/FeatureMatrix.h @@ -17,7 +17,7 @@ //! Enable in case you want to use the Eigen SDK Eigen::Matrix as base for the feature matrix (https://eigen.tuxfamily.org/) //! In case Eigen is disabled, a small simple NxM wrapper class is provided by default. -#define O3DE_USE_EIGEN +//#define O3DE_USE_EIGEN #define O3DE_MM_FLOATTYPE float #ifdef O3DE_USE_EIGEN diff --git a/Gems/MotionMatching/Code/Source/KdTree.cpp b/Gems/MotionMatching/Code/Source/KdTree.cpp index e496f0b63e..e2de897946 100644 --- a/Gems/MotionMatching/Code/Source/KdTree.cpp +++ b/Gems/MotionMatching/Code/Source/KdTree.cpp @@ -48,11 +48,13 @@ namespace EMotionFX::MotionMatching Clear(); // Verify the dimensions. - // Going above a 20 dimensional tree would start eating up too much memory. m_numDimensions = CalcNumDimensions(features); - if (m_numDimensions == 0 || m_numDimensions > 20) + + // Going above a 48 dimensional tree would start eating up too much memory. + const size_t maxNumDimensions = 48; + if (m_numDimensions == 0 || m_numDimensions > maxNumDimensions) { - AZ_Error("Motion Matching", false, "Cannot initialize KD-tree. KD-tree dimension (%d) has to be between 1 and 20. Please use Feature::SetIncludeInKdTree(false) on some features.", m_numDimensions); + AZ_Error("Motion Matching", false, "Cannot initialize KD-tree. KD-tree dimension (%d) has to be between 1 and %zu. Please use Feature::SetIncludeInKdTree(false) on some features.", m_numDimensions, maxNumDimensions); return false; } @@ -203,6 +205,12 @@ namespace EMotionFX::MotionMatching void KdTree::MergeSmallLeafNodesToParents() { + // If the tree is empty or only has a single node, there is nothing to merge. + if (m_nodes.size() < 2) + { + return; + } + AZStd::vector nodesToRemove; for (Node* node : m_nodes) { @@ -410,7 +418,7 @@ namespace EMotionFX::MotionMatching } else { - // We have both a left and right node, so we're not at a leaf yet. + // We have either a left and right node, so we're not at a leaf yet. if (curNode->m_leftNode) { if (frameFloats[d] <= curNode->m_median) diff --git a/Gems/MotionMatching/Code/Source/KdTree.h b/Gems/MotionMatching/Code/Source/KdTree.h index 8b62788c32..70b8652645 100644 --- a/Gems/MotionMatching/Code/Source/KdTree.h +++ b/Gems/MotionMatching/Code/Source/KdTree.h @@ -34,12 +34,10 @@ namespace EMotionFX::MotionMatching size_t maxDepth=10, size_t minFramesPerLeaf=1000); - /** - * Calculate the number of dimensions or values for the given feature set. - * Each feature might store one or multiple values inside the feature matrix and the number of - * values each feature holds varies with the feature type. This calculates the sum of the number of - * values of the given feature set. - */ + //! Calculate the number of dimensions or values for the given feature set. + //! Each feature might store one or multiple values inside the feature matrix and the number of + //! values each feature holds varies with the feature type. This calculates the sum of the number of + //! values of the given feature set. static size_t CalcNumDimensions(const AZStd::vector& features); void Clear();