SkeletonGroup.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/SkeletonGroup.h>
  14. #include <SceneAPI/SceneData/GraphData/RootBoneData.h>
  15. namespace AZ
  16. {
  17. namespace SceneAPI
  18. {
  19. namespace SceneData
  20. {
  21. AZ_CLASS_ALLOCATOR_IMPL(SkeletonGroup, SystemAllocator);
  22. SkeletonGroup::SkeletonGroup()
  23. : m_id(Uuid::CreateRandom())
  24. {
  25. }
  26. const AZStd::string& SkeletonGroup::GetName() const
  27. {
  28. return m_name;
  29. }
  30. void SkeletonGroup::SetName(const AZStd::string& name)
  31. {
  32. m_name = name;
  33. }
  34. void SkeletonGroup::SetName(AZStd::string&& name)
  35. {
  36. m_name = AZStd::move(name);
  37. }
  38. const Uuid& SkeletonGroup::GetId() const
  39. {
  40. return m_id;
  41. }
  42. void SkeletonGroup::OverrideId(const Uuid& id)
  43. {
  44. m_id = id;
  45. }
  46. Containers::RuleContainer& SkeletonGroup::GetRuleContainer()
  47. {
  48. return m_rules;
  49. }
  50. const Containers::RuleContainer& SkeletonGroup::GetRuleContainerConst() const
  51. {
  52. return m_rules;
  53. }
  54. const AZStd::string& SkeletonGroup::GetSelectedRootBone() const
  55. {
  56. return m_selectedRootBone;
  57. }
  58. void SkeletonGroup::SetSelectedRootBone(const AZStd::string& selectedRootBone)
  59. {
  60. m_selectedRootBone = selectedRootBone;
  61. }
  62. void SkeletonGroup::Reflect(ReflectContext* context)
  63. {
  64. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  65. if (!serializeContext)
  66. {
  67. return;
  68. }
  69. serializeContext->Class<SkeletonGroup, DataTypes::ISkeletonGroup>()->Version(3, VersionConverter)
  70. ->Field("name", &SkeletonGroup::m_name)
  71. ->Field("selectedRootBone", &SkeletonGroup::m_selectedRootBone)
  72. ->Field("rules", &SkeletonGroup::m_rules)
  73. ->Field("id", &SkeletonGroup::m_id);
  74. EditContext* editContext = serializeContext->GetEditContext();
  75. if (editContext)
  76. {
  77. editContext->Class<SkeletonGroup>("Skeleton group", "Name and configure a skeleton from your source file.")
  78. ->ClassElement(Edit::ClassElements::EditorData, "")
  79. ->Attribute("AutoExpand", true)
  80. ->Attribute(Edit::Attributes::NameLabelOverride, "")
  81. ->DataElement(AZ_CRC_CE("ManifestName"), &SkeletonGroup::m_name, "Name skeleton",
  82. "Name the skeleton as you want it to appear in the Open 3D Engine Asset Browser.")
  83. ->Attribute("FilterType", DataTypes::ISkeletonGroup::TYPEINFO_Uuid())
  84. ->DataElement("NodeListSelection", &SkeletonGroup::m_selectedRootBone, "Select root bone", "Select the root bone of the skeleton.")
  85. ->Attribute("ClassTypeIdFilter", AZ::SceneData::GraphData::RootBoneData::TYPEINFO_Uuid())
  86. ->DataElement(Edit::UIHandlers::Default, &SkeletonGroup::m_rules, "", "Add or remove rules to fine-tune the export process.")
  87. ->Attribute(AZ::Edit::Attributes::Visibility, AZ_CRC_CE("PropertyVisibility_ShowChildrenOnly"));
  88. }
  89. }
  90. bool SkeletonGroup::VersionConverter(SerializeContext& context, SerializeContext::DataElementNode& classElement)
  91. {
  92. const unsigned int version = classElement.GetVersion();
  93. bool result = true;
  94. // Replaced vector<IRule> with RuleContainer.
  95. if (version == 1)
  96. {
  97. result = result && Containers::RuleContainer::VectorToRuleContainerConverter(context, classElement);
  98. }
  99. // Added a uuid "id" as the unique identifier to replace the file name.
  100. // Setting it to null by default and expecting a behavior to patch this when additional information is available.
  101. if (version <= 2)
  102. {
  103. result = result && classElement.AddElementWithData<AZ::Uuid>(context, "id", AZ::Uuid::CreateNull()) != -1;
  104. }
  105. return result;
  106. }
  107. } // namespace SceneData
  108. } // namespace SceneAPI
  109. } // namespace AZ