StaticMeshAdvancedRule.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/SceneData/Rules/StaticMeshAdvancedRule.h>
  13. #include <SceneAPI/SceneCore/DataTypes/GraphData/IMeshVertexUVData.h>
  14. #include <SceneAPI/SceneCore/DataTypes/GraphData/IMeshVertexColorData.h>
  15. #include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
  16. namespace AZ
  17. {
  18. namespace SceneAPI
  19. {
  20. namespace SceneData
  21. {
  22. AZ_CLASS_ALLOCATOR_IMPL(StaticMeshAdvancedRule, SystemAllocator);
  23. StaticMeshAdvancedRule::StaticMeshAdvancedRule()
  24. : m_use32bitVertices(false)
  25. , m_mergeMeshes(true)
  26. , m_useCustomNormals(true)
  27. {
  28. AZ::SceneAPI::Events::AssetImportRequestBus::Broadcast(&AZ::SceneAPI::Events::AssetImportRequestBus::Events::AreCustomNormalsUsed, m_useCustomNormals);
  29. }
  30. void StaticMeshAdvancedRule::SetUse32bitVertices(bool value)
  31. {
  32. m_use32bitVertices = value;
  33. }
  34. bool StaticMeshAdvancedRule::Use32bitVertices() const
  35. {
  36. return m_use32bitVertices;
  37. }
  38. void StaticMeshAdvancedRule::SetMergeMeshes(bool value)
  39. {
  40. m_mergeMeshes = value;
  41. }
  42. bool StaticMeshAdvancedRule::MergeMeshes() const
  43. {
  44. return m_mergeMeshes;
  45. }
  46. void StaticMeshAdvancedRule::SetUseCustomNormals(bool value)
  47. {
  48. m_useCustomNormals = value;
  49. }
  50. bool StaticMeshAdvancedRule::UseCustomNormals() const
  51. {
  52. return m_useCustomNormals;
  53. }
  54. void StaticMeshAdvancedRule::SetVertexColorStreamName(const AZStd::string& name)
  55. {
  56. m_vertexColorStreamName = name;
  57. }
  58. void StaticMeshAdvancedRule::SetVertexColorStreamName(AZStd::string&& name)
  59. {
  60. m_vertexColorStreamName = AZStd::move(name);
  61. }
  62. const AZStd::string& StaticMeshAdvancedRule::GetVertexColorStreamName() const
  63. {
  64. return m_vertexColorStreamName;
  65. }
  66. bool StaticMeshAdvancedRule::IsVertexColorStreamDisabled() const
  67. {
  68. return m_vertexColorStreamName == DataTypes::s_advancedDisabledString;
  69. }
  70. void StaticMeshAdvancedRule::Reflect(ReflectContext* context)
  71. {
  72. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  73. if (!serializeContext)
  74. {
  75. return;
  76. }
  77. serializeContext->Class<StaticMeshAdvancedRule, DataTypes::IMeshAdvancedRule>()->Version(6)
  78. ->Field("use32bitVertices", &StaticMeshAdvancedRule::m_use32bitVertices)
  79. ->Field("mergeMeshes", &StaticMeshAdvancedRule::m_mergeMeshes)
  80. ->Field("useCustomNormals", &StaticMeshAdvancedRule::m_useCustomNormals)
  81. ->Field("vertexColorStreamName", &StaticMeshAdvancedRule::m_vertexColorStreamName);
  82. EditContext* editContext = serializeContext->GetEditContext();
  83. if (editContext)
  84. {
  85. editContext->Class<StaticMeshAdvancedRule>("Mesh (Advanced)", "Configure advanced properties for this mesh group.")
  86. ->ClassElement(Edit::ClassElements::EditorData, "")
  87. ->Attribute("AutoExpand", true)
  88. ->Attribute(AZ::Edit::Attributes::NameLabelOverride, "")
  89. ->DataElement(AZ::Edit::UIHandlers::RadioButton, &StaticMeshAdvancedRule::m_use32bitVertices, "Vertex Precision",
  90. "Selecting 32-bits of precision increases the accuracy of the position of each vertex which can be useful when the mesh is located far from its pivot.\n\n"
  91. "Please note that not all platforms support 32-bit vertices. For more details please see documentation."
  92. )
  93. ->Attribute(AZ::Edit::Attributes::FalseText, "16-bit")
  94. ->Attribute(AZ::Edit::Attributes::TrueText, "32-bit")
  95. ->DataElement(Edit::UIHandlers::Default, &StaticMeshAdvancedRule::m_mergeMeshes, "Merge Meshes", "Merge all meshes into one single mesh.")
  96. ->DataElement(Edit::UIHandlers::Default, &StaticMeshAdvancedRule::m_useCustomNormals, "Use Custom Normals", "Use custom normals from DCC data or average them.")
  97. ->DataElement("NodeListSelection", &StaticMeshAdvancedRule::m_vertexColorStreamName, "Vertex Color Stream",
  98. "Select a vertex color stream to enable Vertex Coloring or 'Disable' to turn Vertex Coloring off.\n\n"
  99. "Vertex Coloring works in conjunction with materials. If a material was previously generated,\n"
  100. "changing vertex coloring will require the material to be reset or the material editor to be used\n"
  101. "to enable 'Vertex Coloring'.")
  102. ->Attribute("ClassTypeIdFilter", DataTypes::IMeshVertexColorData::TYPEINFO_Uuid())
  103. ->Attribute("DisabledOption", DataTypes::s_advancedDisabledString)
  104. ->Attribute("UseShortNames", true);
  105. }
  106. }
  107. } // SceneData
  108. } // SceneAPI
  109. } // AZ