AnimationGroup.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 <AzCore/RTTI/ReflectContext.h>
  9. #include <AzCore/Memory/SystemAllocator.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <SceneAPI/SceneCore/DataTypes/Rules/IRule.h>
  13. #include <SceneAPI/SceneData/Groups/AnimationGroup.h>
  14. #include <SceneAPI/SceneData/GraphData/RootBoneData.h>
  15. namespace AZ
  16. {
  17. namespace SceneAPI
  18. {
  19. void DataTypes::IAnimationGroup::PerBoneCompression::Reflect(ReflectContext* context)
  20. {
  21. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  22. serializeContext->Class<IAnimationGroup::PerBoneCompression>()->Version(1)
  23. ->Field("boneNamePattern", &IAnimationGroup::PerBoneCompression::m_boneNamePattern)
  24. ->Field("compressionStrength", &IAnimationGroup::PerBoneCompression::m_compressionStrength)
  25. ;
  26. EditContext* editContext = serializeContext->GetEditContext();
  27. if (editContext)
  28. {
  29. editContext->Class<IAnimationGroup::PerBoneCompression>("Compression Override", "Compression settings for an individual bone.")
  30. ->ClassElement(Edit::ClassElements::EditorData, "")
  31. ->Attribute("AutoExpand", true)
  32. ->DataElement("NodeListSelection", &IAnimationGroup::PerBoneCompression::m_boneNamePattern, "Bone name/pattern", "Bone name or pattern with wildcards, e.g. \"*arm*\".")
  33. ->Attribute("ClassTypeIdFilter", AZ::SceneAPI::DataTypes::IBoneData::TYPEINFO_Uuid())
  34. ->Attribute(AZ::Edit::Attributes::ComboBoxEditable, true)
  35. ->DataElement(Edit::UIHandlers::Slider, &IAnimationGroup::PerBoneCompression::m_compressionStrength, "Strength", "Compression strength to use for the specified bone.")
  36. ->Attribute(AZ::Edit::Attributes::Min, 0.f)
  37. ->Attribute(AZ::Edit::Attributes::Max, 1.f)
  38. ;
  39. }
  40. }
  41. namespace SceneData
  42. {
  43. AZ_CLASS_ALLOCATOR_IMPL(AnimationGroup, SystemAllocator);
  44. AnimationGroup::AnimationGroup()
  45. : m_id(Uuid::CreateRandom())
  46. , m_startFrame(0)
  47. , m_endFrame(0)
  48. , m_defaultCompressionStrength(0.1f)
  49. {
  50. }
  51. const AZStd::string& AnimationGroup::GetName() const
  52. {
  53. return m_name;
  54. }
  55. void AnimationGroup::SetName(const AZStd::string& name)
  56. {
  57. m_name = name;
  58. }
  59. void AnimationGroup::SetName(AZStd::string&& name)
  60. {
  61. m_name = AZStd::move(name);
  62. }
  63. const Uuid& AnimationGroup::GetId() const
  64. {
  65. return m_id;
  66. }
  67. void AnimationGroup::OverrideId(const Uuid& id)
  68. {
  69. m_id = id;
  70. }
  71. Containers::RuleContainer& AnimationGroup::GetRuleContainer()
  72. {
  73. return m_rules;
  74. }
  75. const Containers::RuleContainer& AnimationGroup::GetRuleContainerConst() const
  76. {
  77. return m_rules;
  78. }
  79. const AZStd::string& AnimationGroup::GetSelectedRootBone() const
  80. {
  81. return m_selectedRootBone;
  82. }
  83. uint32_t AnimationGroup::GetStartFrame() const
  84. {
  85. return m_startFrame;
  86. }
  87. uint32_t AnimationGroup::GetEndFrame() const
  88. {
  89. return m_endFrame;
  90. }
  91. const float AnimationGroup::GetDefaultCompressionStrength() const
  92. {
  93. return m_defaultCompressionStrength;
  94. }
  95. const DataTypes::IAnimationGroup::PerBoneCompressionList& AnimationGroup::GetPerBoneCompression() const
  96. {
  97. return m_perBoneCompression;
  98. }
  99. void AnimationGroup::SetSelectedRootBone(const AZStd::string& selectedRootBone)
  100. {
  101. m_selectedRootBone = selectedRootBone;
  102. }
  103. void AnimationGroup::SetStartFrame(uint32_t frame)
  104. {
  105. m_startFrame = frame;
  106. }
  107. void AnimationGroup::SetEndFrame(uint32_t frame)
  108. {
  109. m_endFrame = frame;
  110. }
  111. void AnimationGroup::Reflect(ReflectContext* context)
  112. {
  113. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  114. if (!serializeContext)
  115. {
  116. return;
  117. }
  118. DataTypes::IAnimationGroup::PerBoneCompression::Reflect(context);
  119. serializeContext->Class<AnimationGroup, DataTypes::IAnimationGroup>()->Version(3, VersionConverter)
  120. ->Field("name", &AnimationGroup::m_name)
  121. ->Field("id", &AnimationGroup::m_id)
  122. ->Field("selectedRootBone", &AnimationGroup::m_selectedRootBone)
  123. ->Field("startFrame", &AnimationGroup::m_startFrame)
  124. ->Field("endFrame", &AnimationGroup::m_endFrame)
  125. ->Field("defaultCompressionStrength", &AnimationGroup::m_defaultCompressionStrength)
  126. ->Field("perBoneCompression", &AnimationGroup::m_perBoneCompression)
  127. ->Field("rules", &AnimationGroup::m_rules)
  128. ;
  129. EditContext* editContext = serializeContext->GetEditContext();
  130. if (editContext)
  131. {
  132. editContext->Class<AnimationGroup>("Animation group", "Configure animation data exporting.")
  133. ->ClassElement(Edit::ClassElements::EditorData, "")
  134. ->Attribute("AutoExpand", true)
  135. ->Attribute(Edit::Attributes::NameLabelOverride, "")
  136. ->Attribute(AZ::Edit::Attributes::CategoryStyle, "display divider")
  137. ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://www.o3de.org/docs/user-guide/assets/scene-settings/motions-tab/")
  138. ->DataElement(AZ_CRC_CE("ManifestName"), &AnimationGroup::m_name, "Group name",
  139. "Name for the group. This name will also be used as the name for the generated file.")
  140. ->Attribute("FilterType", DataTypes::IAnimationGroup::TYPEINFO_Uuid())
  141. ->DataElement("NodeListSelection", &AnimationGroup::m_selectedRootBone, "Select root bone", "The root bone of the animation that will be exported.")
  142. ->Attribute("ClassTypeIdFilter", AZ::SceneAPI::DataTypes::IBoneData::TYPEINFO_Uuid())
  143. ->DataElement(Edit::UIHandlers::Default, &AnimationGroup::m_startFrame, "Start frame", "The start frame of the animation that will be exported.")
  144. ->DataElement(Edit::UIHandlers::Default, &AnimationGroup::m_endFrame, "End frame", "The end frame of the animation that will be exported.")
  145. ->DataElement(Edit::UIHandlers::Default, &AnimationGroup::m_rules, "", "Add or remove rules to fine-tune the export process.")
  146. ->Attribute(AZ::Edit::Attributes::Visibility, AZ_CRC_CE("PropertyVisibility_ShowChildrenOnly"))
  147. ->ClassElement(Edit::ClassElements::Group, "Compression")
  148. ->DataElement(Edit::UIHandlers::Slider, &AnimationGroup::m_defaultCompressionStrength, "Default strength", "Default compression strength to use by default for all bones.")
  149. ->Attribute(AZ::Edit::Attributes::Min, 0.f)
  150. ->Attribute(AZ::Edit::Attributes::Max, 1.f)
  151. ->DataElement(Edit::UIHandlers::Default, &AnimationGroup::m_perBoneCompression, "Bone/group overrides", "Compression strength overrides for specific bones, or bone groups (using wildcards).")
  152. ;
  153. }
  154. }
  155. bool AnimationGroup::VersionConverter(SerializeContext& context, SerializeContext::DataElementNode& classElement)
  156. {
  157. const unsigned int version = classElement.GetVersion();
  158. bool result = true;
  159. // Replaced vector<IRule> with RuleContainer.
  160. if (version == 1)
  161. {
  162. result = result && Containers::RuleContainer::VectorToRuleContainerConverter(context, classElement);
  163. }
  164. // Added a uuid "id" as the unique identifier to replace the file name.
  165. // Setting it to null by default and expecting a behavior to patch this when additional information is available.
  166. if (version <= 2)
  167. {
  168. result = result && classElement.AddElementWithData<AZ::Uuid>(context, "id", AZ::Uuid::CreateNull()) != -1;
  169. }
  170. return result;
  171. }
  172. } // namespace SceneData
  173. } // namespace SceneAPI
  174. } // namespace AZ