AnimationData.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #include <SceneAPI/SceneData/GraphData/AnimationData.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/RTTI/BehaviorContext.h>
  11. namespace AZ
  12. {
  13. namespace SceneData
  14. {
  15. namespace GraphData
  16. {
  17. void AnimationData::Reflect(ReflectContext* context)
  18. {
  19. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  20. if (serializeContext)
  21. {
  22. serializeContext->Class<AnimationData, SceneAPI::DataTypes::IAnimationData>()
  23. ->Version(1);
  24. }
  25. BehaviorContext* behaviorContext = azrtti_cast<BehaviorContext*>(context);
  26. if (behaviorContext)
  27. {
  28. behaviorContext->Class<SceneAPI::DataTypes::IAnimationData>()
  29. ->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::ListOnly)
  30. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  31. ->Attribute(AZ::Script::Attributes::Module, "scene")
  32. ->Method("GetKeyFrameCount", &SceneAPI::DataTypes::IAnimationData::GetKeyFrameCount)
  33. ->Method("GetKeyFrame", &SceneAPI::DataTypes::IAnimationData::GetKeyFrame)
  34. ->Method("GetTimeStepBetweenFrames", &SceneAPI::DataTypes::IAnimationData::GetTimeStepBetweenFrames);
  35. behaviorContext->Class<AnimationData>()
  36. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  37. ->Attribute(AZ::Script::Attributes::Module, "scene");
  38. }
  39. }
  40. AnimationData::AnimationData()
  41. : m_timeStepBetweenFrames(1.0/30.0) // default value
  42. {
  43. }
  44. void AnimationData::AddKeyFrame(const SceneAPI::DataTypes::MatrixType& keyFrameTransform)
  45. {
  46. m_keyFrames.push_back(keyFrameTransform);
  47. }
  48. void AnimationData::ReserveKeyFrames(size_t count)
  49. {
  50. m_keyFrames.reserve(count);
  51. }
  52. void AnimationData::SetTimeStepBetweenFrames(double timeStep)
  53. {
  54. m_timeStepBetweenFrames = timeStep;
  55. }
  56. size_t AnimationData::GetKeyFrameCount() const
  57. {
  58. return m_keyFrames.size();
  59. }
  60. const SceneAPI::DataTypes::MatrixType& AnimationData::GetKeyFrame(size_t index) const
  61. {
  62. AZ_Assert(index < m_keyFrames.size(), "GetTranslationKeyFrame index %i is out of range for frame size %i", index, m_keyFrames.size());
  63. return m_keyFrames[index];
  64. }
  65. double AnimationData::GetTimeStepBetweenFrames() const
  66. {
  67. return m_timeStepBetweenFrames;
  68. }
  69. void AnimationData::GetDebugOutput(SceneAPI::Utilities::DebugOutput& output) const
  70. {
  71. output.Write("KeyFrames", m_keyFrames);
  72. output.Write("TimeStepBetweenFrames", m_timeStepBetweenFrames);
  73. }
  74. void BlendShapeAnimationData::Reflect(ReflectContext* context)
  75. {
  76. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  77. if (serializeContext)
  78. {
  79. serializeContext->Class<BlendShapeAnimationData, SceneAPI::DataTypes::IBlendShapeAnimationData>()
  80. ->Version(1);
  81. }
  82. BehaviorContext* behaviorContext = azrtti_cast<BehaviorContext*>(context);
  83. if (behaviorContext)
  84. {
  85. behaviorContext->Class<SceneAPI::DataTypes::IBlendShapeAnimationData>()
  86. ->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::ListOnly)
  87. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  88. ->Attribute(AZ::Script::Attributes::Module, "scene")
  89. ->Method("GetBlendShapeName", &SceneAPI::DataTypes::IBlendShapeAnimationData::GetBlendShapeName)
  90. ->Method("GetKeyFrameCount", &SceneAPI::DataTypes::IBlendShapeAnimationData::GetKeyFrameCount)
  91. ->Method("GetKeyFrame", &SceneAPI::DataTypes::IBlendShapeAnimationData::GetKeyFrame)
  92. ->Method("GetTimeStepBetweenFrames", &SceneAPI::DataTypes::IBlendShapeAnimationData::GetTimeStepBetweenFrames);
  93. behaviorContext->Class<BlendShapeAnimationData>()
  94. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  95. ->Attribute(AZ::Script::Attributes::Module, "scene");
  96. }
  97. }
  98. BlendShapeAnimationData::BlendShapeAnimationData()
  99. : m_timeStepBetweenFrames(1 / 30.0) // default value
  100. {
  101. }
  102. void BlendShapeAnimationData::CloneAttributesFrom(const IGraphObject* sourceObject)
  103. {
  104. IBlendShapeAnimationData::CloneAttributesFrom(sourceObject);
  105. if (const auto* typedSource = azrtti_cast<const BlendShapeAnimationData*>(sourceObject))
  106. {
  107. SetBlendShapeName(typedSource->GetBlendShapeName());
  108. }
  109. }
  110. void BlendShapeAnimationData::SetBlendShapeName(const char* blendShapeName)
  111. {
  112. m_blendShapeName = blendShapeName;
  113. }
  114. void BlendShapeAnimationData::AddKeyFrame(double keyFrameValue)
  115. {
  116. m_keyFrames.push_back(keyFrameValue);
  117. }
  118. void BlendShapeAnimationData::ReserveKeyFrames(size_t count)
  119. {
  120. m_keyFrames.reserve(count);
  121. }
  122. void BlendShapeAnimationData::SetTimeStepBetweenFrames(double timeStep)
  123. {
  124. m_timeStepBetweenFrames = timeStep;
  125. }
  126. const char* BlendShapeAnimationData::GetBlendShapeName() const
  127. {
  128. return m_blendShapeName.c_str();
  129. }
  130. size_t BlendShapeAnimationData::GetKeyFrameCount() const
  131. {
  132. return m_keyFrames.size();
  133. }
  134. double BlendShapeAnimationData::GetKeyFrame(size_t index) const
  135. {
  136. AZ_Assert(index < m_keyFrames.size(), "BlendShapeAnimationData::GetKeyFrame index %i is out of range for frame count %i", index, m_keyFrames.size());
  137. return m_keyFrames[index];
  138. }
  139. double BlendShapeAnimationData::GetTimeStepBetweenFrames() const
  140. {
  141. return m_timeStepBetweenFrames;
  142. }
  143. void BlendShapeAnimationData::GetDebugOutput(SceneAPI::Utilities::DebugOutput& output) const
  144. {
  145. output.Write("BlendShapeName", m_blendShapeName);
  146. output.Write("KeyFrames", m_keyFrames);
  147. output.Write("TimeStepBetweenFrames", m_timeStepBetweenFrames);
  148. }
  149. }
  150. }
  151. }