MotionMatchingData.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Memory/Memory.h>
  10. #include <AzCore/RTTI/RTTI.h>
  11. #include <AzCore/std/containers/vector.h>
  12. #include <EMotionFX/Source/EMotionFXConfig.h>
  13. #include <Feature.h>
  14. #include <FeatureSchema.h>
  15. #include <FrameDatabase.h>
  16. #include <FeatureMatrixTransformer.h>
  17. #include <KdTree.h>
  18. namespace AZ
  19. {
  20. class ReflectContext;
  21. }
  22. namespace EMotionFX
  23. {
  24. class ActorInstance;
  25. }
  26. namespace EMotionFX::MotionMatching
  27. {
  28. class EMFX_API MotionMatchingData
  29. {
  30. public:
  31. AZ_RTTI(MotionMatchingData, "{7BC3DFF5-8864-4518-B6F0-0553ADFAB5C1}")
  32. AZ_CLASS_ALLOCATOR_DECL
  33. MotionMatchingData(const FeatureSchema& featureSchema);
  34. virtual ~MotionMatchingData();
  35. enum FeatureScalerType
  36. {
  37. StandardScalerType = 0,
  38. MinMaxScalerType = 1
  39. };
  40. struct EMFX_API InitSettings
  41. {
  42. ActorInstance* m_actorInstance = nullptr;
  43. AZStd::vector<Motion*> m_motionList;
  44. FrameDatabase::FrameImportSettings m_frameImportSettings;
  45. size_t m_maxKdTreeDepth = 20;
  46. size_t m_minFramesPerKdTreeNode = 1000;
  47. bool m_importMirrored = false;
  48. bool m_normalizeData = false;
  49. FeatureScalerType m_featureScalerType = StandardScalerType;
  50. FeatureMatrixTransformer::Settings m_featureTansformerSettings = {};
  51. };
  52. bool Init(const InitSettings& settings);
  53. void Clear();
  54. const FrameDatabase& GetFrameDatabase() const { return m_frameDatabase; }
  55. FrameDatabase& GetFrameDatabase() { return m_frameDatabase; }
  56. const FeatureSchema& GetFeatureSchema() const { return m_featureSchema; }
  57. const FeatureMatrix& GetFeatureMatrix() const { return m_featureMatrix; }
  58. FeatureMatrixTransformer* GetFeatureTransformer() { return m_featureTransformer.get(); }
  59. const KdTree& GetKdTree() const { return *m_kdTree.get(); }
  60. const AZStd::vector<Feature*>& GetFeaturesInKdTree() const { return m_featuresInKdTree; }
  61. protected:
  62. //! Extract features from the motion database (multi-threaded).
  63. bool ExtractFeatures(ActorInstance* actorInstance, FrameDatabase* frameDatabase);
  64. //! Extract features for a given range of frames and store the values in the feature matrix.
  65. static void ExtractFeatureValuesRange(ActorInstance* actorInstance, FrameDatabase& frameDatabase, const FeatureSchema& featureSchema, FeatureMatrix& featureMatrix, size_t startFrame, size_t endFrame);
  66. const size_t s_numFramesPerBatch = 1000; //!< Number of frames per task in the multi-threaded feature extraction routine.
  67. FrameDatabase m_frameDatabase; //< The animation database with all the keyframes and joint transform data.
  68. const FeatureSchema& m_featureSchema;
  69. FeatureMatrix m_featureMatrix;
  70. AZStd::unique_ptr<FeatureMatrixTransformer> m_featureTransformer;
  71. AZStd::unique_ptr<KdTree> m_kdTree; //< The acceleration structure to speed up the search for lowest cost frames.
  72. AZStd::vector<Feature*> m_featuresInKdTree;
  73. };
  74. } // namespace EMotionFX::MotionMatching