GNMeshData.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #pragma once
  2. #include <Editor/Common/GNConstants.h>
  3. #include <Editor/Math/MathHelper.h>
  4. #include <AzCore/Math/Aabb.h>
  5. #include <AZCore/std/string/string.h>
  6. namespace GeomNodes
  7. {
  8. using MaterialList = AZStd::vector<AZStd::string>;
  9. class GNMeshData
  10. {
  11. public:
  12. struct DataRange
  13. {
  14. AZ::u32 offset = 0;
  15. AZ::u32 count = 0;
  16. };
  17. GNMeshData();
  18. explicit GNMeshData(
  19. const Vert3Vector& positions
  20. , const Vert3Vector& normals
  21. , const S32Vector& indices
  22. , const S32Vector& triangleLoops
  23. , const S32Vector& loops
  24. , const Vert2Vector& uvs
  25. , const Vert4Vector& colors
  26. , const S32Vector& materialIndices
  27. , const MaterialList& materials
  28. , AZ::u64 hash
  29. , bool isIndexedUVs
  30. , bool isIndexedColors);
  31. ~GNMeshData() = default;
  32. AZ::u32 GetIndexCount() const;
  33. AZ::u32 GetIndexOffset() const;
  34. void SetIndexOffset(AZ::u32 offset);
  35. void SetIndexOffset(AZ::u64 offset);
  36. void SetIndexCount(AZ::u32 count);
  37. void SetIndexCount(AZ::u64 count);
  38. template<AttributeType AttributeTypeT>
  39. AZ::u32 GetCount() const;
  40. template<AttributeType AttributeTypeT>
  41. AZ::u32 GetOffset() const;
  42. template<AttributeType AttributeTypeT>
  43. void SetCount(AZ::u32 count);
  44. template<AttributeType AttributeTypeT>
  45. void SetCount(AZ::u64 count);
  46. template<AttributeType AttributeTypeT>
  47. void SetOffset(AZ::u32 offset);
  48. template<AttributeType AttributeTypeT>
  49. void SetOffset(AZ::u64 offset);
  50. const U32Vector& GetIndices() const;
  51. void SetIndices(const U32Vector& indices);
  52. template<AttributeType AttributeTypeT>
  53. const auto& GetDataBuffer() const;
  54. const Mat4Vector& GetInstances() const;
  55. const MaterialList& GetMaterials() const;
  56. void ClearMaterialList();
  57. void SetMaterialIndex(AZ::u32 materialIndex);
  58. AZ::u32 GetMaterialIndex() const;
  59. void AddInstance(const AZ::Matrix4x4& mat4);
  60. U32Vector GetIndicesByMaterialIndex(int materialIndex);
  61. AZ::Aabb GetAabb() const;
  62. AZ::s64 GetHash() const;
  63. void CalculateTangents();
  64. void CalculateAABB();
  65. GNMeshData& operator+=(const GNMeshData& rhs);
  66. void ClearBuffers();
  67. private:
  68. U32Vector m_indices;
  69. S32Vector m_loops;
  70. S32Vector m_materialIndices;
  71. Vert3Vector m_positions;
  72. Vert3Vector m_normals;
  73. Vert4Vector m_tangents;
  74. Vert3Vector m_bitangents;
  75. Vert2Vector m_uvs;
  76. Vert4Vector m_colors;
  77. DataRange m_indicesRange;
  78. DataRange m_positionsRange;
  79. DataRange m_normalsRange;
  80. DataRange m_tangentsRange;
  81. DataRange m_bitangentsRange;
  82. DataRange m_uvsRange;
  83. DataRange m_colorsRange;
  84. MaterialList m_materialNames;
  85. AZ::u32 m_materialIndex = 0;
  86. AZ::Aabb m_aabb = AZ::Aabb::CreateNull();
  87. AZ::s64 m_hash = 0;
  88. Mat4Vector m_instances;
  89. };
  90. }