MeshGroup.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <algorithm>
  9. #include <AzCore/RTTI/ReflectContext.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <SceneAPI/SceneData/Groups/MeshGroup.h>
  13. #include <SceneAPI/SceneCore/DataTypes/GraphData/IMeshData.h>
  14. #include <SceneAPI/SceneCore/DataTypes/Rules/IRule.h>
  15. #include <SceneAPI/SceneUI/RowWidgets/ManifestVectorHandler.h>
  16. namespace AZ
  17. {
  18. namespace SceneAPI
  19. {
  20. namespace SceneData
  21. {
  22. MeshGroup::MeshGroup()
  23. : m_id(Uuid::CreateRandom())
  24. {
  25. }
  26. const AZStd::string& MeshGroup::GetName() const
  27. {
  28. return m_name;
  29. }
  30. void MeshGroup::SetName(const AZStd::string& name)
  31. {
  32. m_name = name;
  33. }
  34. void MeshGroup::SetName(AZStd::string&& name)
  35. {
  36. m_name = AZStd::move(name);
  37. }
  38. const Uuid& MeshGroup::GetId() const
  39. {
  40. return m_id;
  41. }
  42. void MeshGroup::OverrideId(const Uuid& id)
  43. {
  44. m_id = id;
  45. }
  46. Containers::RuleContainer& MeshGroup::GetRuleContainer()
  47. {
  48. return m_rules;
  49. }
  50. const Containers::RuleContainer& MeshGroup::GetRuleContainerConst() const
  51. {
  52. return m_rules;
  53. }
  54. DataTypes::ISceneNodeSelectionList& MeshGroup::GetSceneNodeSelectionList()
  55. {
  56. return m_nodeSelectionList;
  57. }
  58. const DataTypes::ISceneNodeSelectionList& MeshGroup::GetSceneNodeSelectionList() const
  59. {
  60. return m_nodeSelectionList;
  61. }
  62. void MeshGroup::Reflect(ReflectContext* context)
  63. {
  64. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  65. if (!serializeContext)
  66. {
  67. return;
  68. }
  69. serializeContext->Class<MeshGroup, DataTypes::IMeshGroup>()
  70. ->Version(3, VersionConverter)
  71. ->Field("name", &MeshGroup::m_name)
  72. ->Field("nodeSelectionList", &MeshGroup::m_nodeSelectionList)
  73. ->Field("rules", &MeshGroup::m_rules)
  74. ->Field("id", &MeshGroup::m_id);
  75. EditContext* editContext = serializeContext->GetEditContext();
  76. if (editContext)
  77. {
  78. editContext->Class<MeshGroup>("Mesh group", "Name and configure 1 or more meshes from your source file.")
  79. ->ClassElement(Edit::ClassElements::EditorData, "")
  80. ->Attribute("AutoExpand", true)
  81. ->Attribute(Edit::Attributes::NameLabelOverride, "")
  82. ->Attribute(AZ::Edit::Attributes::CategoryStyle, "display divider")
  83. ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://www.o3de.org/docs/user-guide/assets/scene-settings/meshes-tab/")
  84. ->DataElement(AZ_CRC_CE("ManifestName"), &MeshGroup::m_name, "Name mesh",
  85. "Name the mesh as you want it to appear in the Open 3D Engine Asset Browser.")
  86. ->Attribute("FilterType", DataTypes::IMeshGroup::TYPEINFO_Uuid())
  87. ->DataElement(Edit::UIHandlers::Default, &MeshGroup::m_nodeSelectionList, "Select meshes", "Select 1 or more meshes to add to this asset in the Open 3D Engine Asset Browser.")
  88. ->Attribute("FilterName", "meshes")
  89. ->Attribute("FilterType", DataTypes::IMeshData::TYPEINFO_Uuid())
  90. ->DataElement(Edit::UIHandlers::Default, &MeshGroup::m_rules, "", "Add or remove rules to fine-tune the export process.")
  91. ->Attribute(AZ::Edit::Attributes::Visibility, AZ_CRC_CE("PropertyVisibility_ShowChildrenOnly"));
  92. }
  93. }
  94. bool MeshGroup::VersionConverter(SerializeContext& context, SerializeContext::DataElementNode& classElement)
  95. {
  96. const unsigned int version = classElement.GetVersion();
  97. // Replaced vector<IRule> with RuleContainer.
  98. bool result = true;
  99. if (version == 1)
  100. {
  101. result = result && Containers::RuleContainer::VectorToRuleContainerConverter(context, classElement);
  102. }
  103. // Added a uuid "id" as the unique identifier to replace the file name.
  104. // Setting it to null by default and expecting a behavior to patch this when additional information is available.
  105. if (version <= 2)
  106. {
  107. result = result && classElement.AddElementWithData<AZ::Uuid>(context, "id", AZ::Uuid::CreateNull()) != -1;
  108. }
  109. return result;
  110. }
  111. } // namespace SceneData
  112. } // namespace SceneAPI
  113. } // namespace AZ