b3dm_loader.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef B3DM_LOADER_H_
  2. #define B3DM_LOADER_H_
  3. #include <iostream>
  4. #include "tiny_gltf.h"
  5. using namespace tinygltf;
  6. class MeshInfo
  7. {
  8. public:
  9. float* mVertexs = nullptr;
  10. int mVertexCount = 0;
  11. unsigned int* mTriangles = nullptr;
  12. int mTriangleCount = 0;
  13. unsigned char* mImageData;
  14. unsigned int mImageSize = 0;
  15. float* mTexCoords = nullptr;
  16. int mTexCoordCount = 0;
  17. int mImageResolutionS = 0;
  18. int mImageResolutionT = 0;
  19. int mTextureFormat = 0;
  20. void ReleaseMeshInfo()
  21. {
  22. delete[] mVertexs;
  23. delete[] mTriangles;
  24. delete[] mImageData;
  25. delete[] mTexCoords;
  26. mVertexs = nullptr;
  27. mTriangles = nullptr;
  28. mImageData = nullptr;
  29. mTexCoords = nullptr;
  30. }
  31. };
  32. class b3dm_loader
  33. {
  34. public:
  35. ~b3dm_loader()
  36. {
  37. ReleaseMeshInfo();
  38. }
  39. static b3dm_loader* LoadB3dmFromFile(const std::string& filename);
  40. void VisitorModel(const tinygltf::Model& model);
  41. std::vector<MeshInfo*> mMeshInfos;
  42. private:
  43. MeshInfo* VisitorPrimitive(const tinygltf::Model& model, const Primitive& primitive);
  44. void ReleaseMeshInfo()
  45. {
  46. auto itor = mMeshInfos.begin();
  47. while (itor != mMeshInfos.end())
  48. {
  49. (*itor)->ReleaseMeshInfo();
  50. itor++;
  51. }
  52. }
  53. };
  54. #endif