2
0

MeshVertexUVData.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/MeshVertexUVData.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 MeshVertexUVData::Reflect(ReflectContext* context)
  18. {
  19. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  20. if (serializeContext)
  21. {
  22. serializeContext->Class<MeshVertexUVData>()->Version(1);
  23. }
  24. BehaviorContext* behaviorContext = azrtti_cast<BehaviorContext*>(context);
  25. if (behaviorContext)
  26. {
  27. behaviorContext->Class<MeshVertexUVData>()
  28. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  29. ->Attribute(AZ::Script::Attributes::Module, "scene")
  30. ->Method("GetCustomName",[](const MeshVertexUVData& self) { return self.GetCustomName().GetCStr(); })
  31. ->Method("GetCount", &MeshVertexUVData::GetCount)
  32. ->Method("GetUV", &MeshVertexUVData::GetUV);
  33. }
  34. }
  35. void MeshVertexUVData::CloneAttributesFrom(const IGraphObject* sourceObject)
  36. {
  37. IMeshVertexUVData::CloneAttributesFrom(sourceObject);
  38. if (const auto* typedSource = azrtti_cast<const MeshVertexUVData*>(sourceObject))
  39. {
  40. SetCustomName(typedSource->GetCustomName());
  41. }
  42. }
  43. const AZ::Name& MeshVertexUVData::GetCustomName() const
  44. {
  45. return m_customName;
  46. }
  47. void MeshVertexUVData::SetCustomName(const char* name)
  48. {
  49. m_customName = name;
  50. }
  51. void MeshVertexUVData::SetCustomName(const AZ::Name& name)
  52. {
  53. m_customName = name;
  54. }
  55. size_t MeshVertexUVData::GetCount() const
  56. {
  57. return m_uvs.size();
  58. }
  59. const AZ::Vector2& MeshVertexUVData::GetUV(size_t index) const
  60. {
  61. AZ_Assert(index < m_uvs.size(), "Invalid index %i for mesh vertex UVs.", index);
  62. return m_uvs[index];
  63. }
  64. void MeshVertexUVData::ReserveContainerSpace(size_t size)
  65. {
  66. m_uvs.reserve(size);
  67. }
  68. void MeshVertexUVData::Clear()
  69. {
  70. m_uvs.clear();
  71. }
  72. void MeshVertexUVData::AppendUV(const AZ::Vector2& uv)
  73. {
  74. m_uvs.push_back(uv);
  75. }
  76. void MeshVertexUVData::GetDebugOutput(AZ::SceneAPI::Utilities::DebugOutput& output) const
  77. {
  78. output.Write("UVs", m_uvs);
  79. output.Write("UVCustomName", m_customName.GetCStr());
  80. }
  81. } // GraphData
  82. } // SceneData
  83. } // AZ