MeshBinary.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. // WARNING: This file is auto generated.
  6. #pragma once
  7. #include <AnKi/Resource/Common.h>
  8. #include <AnKi/Math.h>
  9. #include <AnKi/Gr/Common.h>
  10. namespace anki {
  11. /// @addtogroup resource
  12. /// @{
  13. inline constexpr const char* kMeshMagic = "ANKIMES7";
  14. enum class MeshBinaryFlag : U32
  15. {
  16. kNone = 0,
  17. kQuad = 1 << 0,
  18. kConvex = 1 << 1,
  19. kAll = kQuad | kConvex,
  20. };
  21. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(MeshBinaryFlag)
  22. /// Vertex buffer info.
  23. class MeshBinaryVertexBuffer
  24. {
  25. public:
  26. /// The size of the vertex. It's zero if the buffer is not present.
  27. U32 m_vertexStride;
  28. template<typename TSerializer, typename TClass>
  29. static void serializeCommon(TSerializer& s, TClass self)
  30. {
  31. s.doValue("m_vertexStride", offsetof(MeshBinaryVertexBuffer, m_vertexStride), self.m_vertexStride);
  32. }
  33. template<typename TDeserializer>
  34. void deserialize(TDeserializer& deserializer)
  35. {
  36. serializeCommon<TDeserializer, MeshBinaryVertexBuffer&>(deserializer, *this);
  37. }
  38. template<typename TSerializer>
  39. void serialize(TSerializer& serializer) const
  40. {
  41. serializeCommon<TSerializer, const MeshBinaryVertexBuffer&>(serializer, *this);
  42. }
  43. };
  44. /// Vertex attribute.
  45. class MeshBinaryVertexAttribute
  46. {
  47. public:
  48. U32 m_bufferIndex;
  49. /// If the format is kNone then the attribute is not present.
  50. Format m_format;
  51. U32 m_relativeOffset;
  52. /// Attribute is compressed and needs to be scaled.
  53. Array<F32, 4> m_scale;
  54. /// Attribute is compressed and needs to be translated.
  55. Array<F32, 4> m_translation;
  56. template<typename TSerializer, typename TClass>
  57. static void serializeCommon(TSerializer& s, TClass self)
  58. {
  59. s.doValue("m_bufferIndex", offsetof(MeshBinaryVertexAttribute, m_bufferIndex), self.m_bufferIndex);
  60. s.doValue("m_format", offsetof(MeshBinaryVertexAttribute, m_format), self.m_format);
  61. s.doValue("m_relativeOffset", offsetof(MeshBinaryVertexAttribute, m_relativeOffset), self.m_relativeOffset);
  62. s.doArray("m_scale", offsetof(MeshBinaryVertexAttribute, m_scale), &self.m_scale[0], self.m_scale.getSize());
  63. s.doArray("m_translation", offsetof(MeshBinaryVertexAttribute, m_translation), &self.m_translation[0],
  64. self.m_translation.getSize());
  65. }
  66. template<typename TDeserializer>
  67. void deserialize(TDeserializer& deserializer)
  68. {
  69. serializeCommon<TDeserializer, MeshBinaryVertexAttribute&>(deserializer, *this);
  70. }
  71. template<typename TSerializer>
  72. void serialize(TSerializer& serializer) const
  73. {
  74. serializeCommon<TSerializer, const MeshBinaryVertexAttribute&>(serializer, *this);
  75. }
  76. };
  77. /// MeshBinarySubMesh class.
  78. class MeshBinarySubMesh
  79. {
  80. public:
  81. Array<U32, kMaxLodCount> m_firstIndices;
  82. Array<U32, kMaxLodCount> m_indexCounts;
  83. /// Bounding box min.
  84. Vec3 m_aabbMin;
  85. /// Bounding box max.
  86. Vec3 m_aabbMax;
  87. template<typename TSerializer, typename TClass>
  88. static void serializeCommon(TSerializer& s, TClass self)
  89. {
  90. s.doArray("m_firstIndices", offsetof(MeshBinarySubMesh, m_firstIndices), &self.m_firstIndices[0],
  91. self.m_firstIndices.getSize());
  92. s.doArray("m_indexCounts", offsetof(MeshBinarySubMesh, m_indexCounts), &self.m_indexCounts[0],
  93. self.m_indexCounts.getSize());
  94. s.doValue("m_aabbMin", offsetof(MeshBinarySubMesh, m_aabbMin), self.m_aabbMin);
  95. s.doValue("m_aabbMax", offsetof(MeshBinarySubMesh, m_aabbMax), self.m_aabbMax);
  96. }
  97. template<typename TDeserializer>
  98. void deserialize(TDeserializer& deserializer)
  99. {
  100. serializeCommon<TDeserializer, MeshBinarySubMesh&>(deserializer, *this);
  101. }
  102. template<typename TSerializer>
  103. void serialize(TSerializer& serializer) const
  104. {
  105. serializeCommon<TSerializer, const MeshBinarySubMesh&>(serializer, *this);
  106. }
  107. };
  108. /// The 1st things that appears in a mesh binary.
  109. class MeshBinaryHeader
  110. {
  111. public:
  112. Array<U8, 8> m_magic;
  113. MeshBinaryFlag m_flags;
  114. Array<MeshBinaryVertexBuffer, kMaxVertexAttributes> m_vertexBuffers;
  115. Array<MeshBinaryVertexAttribute, kMaxVertexAttributes> m_vertexAttributes;
  116. IndexType m_indexType;
  117. Array<U8, 3> m_padding;
  118. Array<U32, kMaxLodCount> m_totalIndexCounts;
  119. Array<U32, kMaxLodCount> m_totalVertexCounts;
  120. U32 m_subMeshCount;
  121. U32 m_lodCount;
  122. /// Bounding box min.
  123. Vec3 m_aabbMin;
  124. /// Bounding box max.
  125. Vec3 m_aabbMax;
  126. template<typename TSerializer, typename TClass>
  127. static void serializeCommon(TSerializer& s, TClass self)
  128. {
  129. s.doArray("m_magic", offsetof(MeshBinaryHeader, m_magic), &self.m_magic[0], self.m_magic.getSize());
  130. s.doValue("m_flags", offsetof(MeshBinaryHeader, m_flags), self.m_flags);
  131. s.doArray("m_vertexBuffers", offsetof(MeshBinaryHeader, m_vertexBuffers), &self.m_vertexBuffers[0],
  132. self.m_vertexBuffers.getSize());
  133. s.doArray("m_vertexAttributes", offsetof(MeshBinaryHeader, m_vertexAttributes), &self.m_vertexAttributes[0],
  134. self.m_vertexAttributes.getSize());
  135. s.doValue("m_indexType", offsetof(MeshBinaryHeader, m_indexType), self.m_indexType);
  136. s.doArray("m_padding", offsetof(MeshBinaryHeader, m_padding), &self.m_padding[0], self.m_padding.getSize());
  137. s.doArray("m_totalIndexCounts", offsetof(MeshBinaryHeader, m_totalIndexCounts), &self.m_totalIndexCounts[0],
  138. self.m_totalIndexCounts.getSize());
  139. s.doArray("m_totalVertexCounts", offsetof(MeshBinaryHeader, m_totalVertexCounts), &self.m_totalVertexCounts[0],
  140. self.m_totalVertexCounts.getSize());
  141. s.doValue("m_subMeshCount", offsetof(MeshBinaryHeader, m_subMeshCount), self.m_subMeshCount);
  142. s.doValue("m_lodCount", offsetof(MeshBinaryHeader, m_lodCount), self.m_lodCount);
  143. s.doValue("m_aabbMin", offsetof(MeshBinaryHeader, m_aabbMin), self.m_aabbMin);
  144. s.doValue("m_aabbMax", offsetof(MeshBinaryHeader, m_aabbMax), self.m_aabbMax);
  145. }
  146. template<typename TDeserializer>
  147. void deserialize(TDeserializer& deserializer)
  148. {
  149. serializeCommon<TDeserializer, MeshBinaryHeader&>(deserializer, *this);
  150. }
  151. template<typename TSerializer>
  152. void serialize(TSerializer& serializer) const
  153. {
  154. serializeCommon<TSerializer, const MeshBinaryHeader&>(serializer, *this);
  155. }
  156. };
  157. /// @}
  158. } // end namespace anki