12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #ifndef B3DM_LOADER_H_
- #define B3DM_LOADER_H_
- #include <iostream>
- #include "tiny_gltf.h"
- using namespace tinygltf;
- class MeshInfo
- {
- public:
- float* mVertexs = nullptr;
- int mVertexCount = 0;
- unsigned int* mTriangles = nullptr;
- int mTriangleCount = 0;
- unsigned char* mImageData;
- unsigned int mImageSize = 0;
- float* mTexCoords = nullptr;
- int mTexCoordCount = 0;
- int mImageResolutionS = 0;
- int mImageResolutionT = 0;
- int mTextureFormat = 0;
- void ReleaseMeshInfo()
- {
- delete[] mVertexs;
- delete[] mTriangles;
- delete[] mImageData;
- delete[] mTexCoords;
- mVertexs = nullptr;
- mTriangles = nullptr;
- mImageData = nullptr;
- mTexCoords = nullptr;
- }
- };
- class b3dm_loader
- {
- public:
- ~b3dm_loader()
- {
- ReleaseMeshInfo();
- }
- static b3dm_loader* LoadB3dmFromFile(const std::string& filename);
- void VisitorModel(const tinygltf::Model& model);
- std::vector<MeshInfo*> mMeshInfos;
- private:
- MeshInfo* VisitorPrimitive(const tinygltf::Model& model, const Primitive& primitive);
- void ReleaseMeshInfo()
- {
- auto itor = mMeshInfos.begin();
- while (itor != mMeshInfos.end())
- {
- (*itor)->ReleaseMeshInfo();
- itor++;
- }
- }
- };
- #endif
|