Mesh.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifndef ANKI_RESOURCE_MESH_H
  2. #define ANKI_RESOURCE_MESH_H
  3. #include "anki/Math.h"
  4. #include "anki/gl/BufferObject.h"
  5. #include "anki/collision/Obb.h"
  6. #include "anki/util/Vector.h"
  7. namespace anki {
  8. class MeshLoader;
  9. /// Mesh Resource. It contains the geometry packed in VBOs
  10. class Mesh
  11. {
  12. public:
  13. enum VertexAttribute
  14. {
  15. VA_POSITION,
  16. VA_NORMAL,
  17. VA_TANGENT,
  18. VA_TEXTURE_COORD,
  19. VA_TEXTURE_COORD_1,
  20. VA_BONE_COUNT,
  21. VA_BONE_IDS,
  22. VA_BONE_WEIGHTS,
  23. VA_INDICES,
  24. VA_COUNT
  25. };
  26. /// Default constructor. Do nothing
  27. Mesh()
  28. {}
  29. /// Does nothing
  30. ~Mesh()
  31. {}
  32. U32 getTextureChannelsCount() const
  33. {
  34. return texChannelsCount;
  35. }
  36. Bool hasWeights() const
  37. {
  38. return weights;
  39. }
  40. /// Used only to clone the VBO
  41. U32 getVerticesCount() const
  42. {
  43. return vertsCount;
  44. }
  45. U32 getIndicesCount() const
  46. {
  47. return indicesCount;
  48. }
  49. const Obb& getBoundingShape() const
  50. {
  51. return obb;
  52. }
  53. /// Get indices count and offset of submesh
  54. U32 getIndicesCountSub(U subMeshId, U32& offset) const
  55. {
  56. ANKI_ASSERT(subMeshId < subMeshes.size());
  57. const SubMesh& sm = subMeshes[subMeshId];
  58. offset = sm.indicesOffset;
  59. return sm.indicesCount;
  60. }
  61. const Obb& getBoundingShapeSub(U subMeshId) const
  62. {
  63. ANKI_ASSERT(subMeshId < subMeshes.size());
  64. return subMeshes[subMeshId].obb;
  65. }
  66. /// If returns zero then the mesh is a single uniform mesh
  67. U32 getSubMeshesCount() const
  68. {
  69. return subMeshes.size();
  70. }
  71. /// Get info on how to attach a VBO to a VAO
  72. void getVboInfo(
  73. const VertexAttribute attrib, const Vbo*& vbo,
  74. U32& size, GLenum& type, U32& stride, U32& offset) const;
  75. /// Helper function for correct loading
  76. Bool isCompatible(const Mesh& other) const;
  77. /// Load from a .mesh file
  78. void load(const char* filename);
  79. protected:
  80. /// Per sub mesh data
  81. struct SubMesh
  82. {
  83. U32 indicesCount;
  84. U32 indicesOffset;
  85. Obb obb;
  86. };
  87. Vector<SubMesh> subMeshes;
  88. U32 indicesCount;
  89. U32 vertsCount;
  90. Obb obb;
  91. U8 texChannelsCount;
  92. Bool8 weights;
  93. Vbo vbo;
  94. Vbo indicesVbo;
  95. /// Create the VBOs using the mesh data
  96. void createVbos(const MeshLoader& loader);
  97. U32 calcVertexSize() const;
  98. };
  99. /// A mesh that behaves as a mesh and as a collection of separate meshes
  100. class BucketMesh: public Mesh
  101. {
  102. public:
  103. /// Default constructor. Do nothing
  104. BucketMesh()
  105. {}
  106. /// Load file
  107. BucketMesh(const char* filename)
  108. {
  109. load(filename);
  110. }
  111. /// @}
  112. /// Does nothing
  113. ~BucketMesh()
  114. {}
  115. /// Load from a .mmesh file
  116. void load(const char* filename);
  117. };
  118. } // end namespace anki
  119. #endif