#pragma once #include #include "b3dm_loader.h" #define DLLEXPORT extern "C" DLLEXPORT b3dm_loader* LoadB3dmFromData(unsigned char* totalData, int totalLength) { Model model; TinyGLTF loader; std::string err; std::string warn; std::string basedir; int header[7]; ::memcpy(header, totalData, 7 * sizeof(int)); int len_b3dm = 7 * sizeof(int) + header[3] + header[4] + header[5] + header[6]; int gltfSize = totalLength - len_b3dm; std::vector buf(gltfSize); ::memcpy(&buf.at(0), totalData + len_b3dm, gltfSize); unsigned char* data = reinterpret_cast(&buf.at(0)); int length = static_cast(buf.size()); bool ret = loader.LoadBinaryFromMemory(&model, &err, &warn, data, length, basedir); if (!ret) { return nullptr; } else { b3dm_loader* loader = new b3dm_loader(); loader->VisitorModel(model); return loader; } } //OpenB3dmFile extern "C" DLLEXPORT b3dm_loader* OpenB3dmFile(const char* file) { b3dm_loader* loader = b3dm_loader::LoadB3dmFromFile(file); return loader; } //CloseOsgbFile extern "C" DLLEXPORT void CloseB3dmFile(b3dm_loader * visitor) { delete visitor; visitor = nullptr; } //GetMeshCount extern "C" DLLEXPORT int GetMeshCount(b3dm_loader * visitor) { return visitor->mMeshInfos.size(); } //GetVertexCount extern "C" DLLEXPORT int GetVertexCount(b3dm_loader * visitor, int meshIndex) { return visitor->mMeshInfos[meshIndex]->mVertexCount; } //直接拷贝内存 GetVertexs extern "C" DLLEXPORT void GetVertexs(b3dm_loader * visitor, int meshIndex, float* destVertexs) { int count = visitor->mMeshInfos[meshIndex]->mVertexCount; float* srcVertexs = visitor->mMeshInfos[meshIndex]->mVertexs; memcpy(destVertexs, srcVertexs, sizeof(float) * count * 3); } //GetVertexPointer extern "C" DLLEXPORT float* GetVertexPointer(b3dm_loader * visitor, int meshIndex, int vertexIndex) { return visitor->mMeshInfos[meshIndex]->mVertexs + vertexIndex * 3; } //GetTriangleCount extern "C" DLLEXPORT int GetTriangleCount(b3dm_loader * visitor, int meshIndex) { return visitor->mMeshInfos[meshIndex]->mTriangleCount; } //直接拷贝内存 GetTriangles extern "C" DLLEXPORT void GetTriangles(b3dm_loader * visitor, int meshIndex, unsigned int* destTriangles) { int count = visitor->mMeshInfos[meshIndex]->mTriangleCount; unsigned int* srcTriangles = visitor->mMeshInfos[meshIndex]->mTriangles; memcpy(destTriangles, srcTriangles, sizeof(int) * count); } //GetTrianglePointer extern "C" DLLEXPORT unsigned int* GetTrianglePointer(b3dm_loader * visitor, int meshIndex) { return visitor->mMeshInfos[meshIndex]->mTriangles; } //GetImageSize extern "C" DLLEXPORT unsigned int GetImageSize(b3dm_loader * visitor, int meshIndex) { return visitor->mMeshInfos[meshIndex]->mImageSize; } //GetImageResolutionS extern "C" DLLEXPORT int GetImageResolutionS(b3dm_loader * visitor, int meshIndex) { return visitor->mMeshInfos[meshIndex]->mImageResolutionS; } //GetImageResolutionT extern "C" DLLEXPORT int GetImageResolutionT(b3dm_loader * visitor, int meshIndex) { return visitor->mMeshInfos[meshIndex]->mImageResolutionT; } //GetImageFormat extern "C" DLLEXPORT int GetImageFormat(b3dm_loader * visitor, int meshIndex) { return visitor->mMeshInfos[meshIndex]->mTextureFormat; } //GetImagePointer extern "C" DLLEXPORT unsigned char* GetImagePointer(b3dm_loader * visitor, int meshIndex) { return visitor->mMeshInfos[meshIndex]->mImageData; } //直接拷贝内存 GetImageData extern "C" DLLEXPORT void GetImageData(b3dm_loader * visitor, int meshIndex, unsigned char* destData) { unsigned char* srcData = visitor->mMeshInfos[meshIndex]->mImageData; memcpy(destData, srcData, visitor->mMeshInfos[meshIndex]->mImageSize); } //GetTexCoordCount extern "C" DLLEXPORT int GetTexCoordCount(b3dm_loader * visitor, int meshIndex) { return visitor->mMeshInfos[meshIndex]->mTexCoordCount; } //直接拷贝内存 GetTexCoords extern "C" DLLEXPORT void GetTexCoords(b3dm_loader * visitor, int meshIndex, float* destVertexs) { int count = visitor->mMeshInfos[meshIndex]->mTexCoordCount; float* srcVertexs = visitor->mMeshInfos[meshIndex]->mTexCoords; memcpy(destVertexs, srcVertexs, sizeof(float) * count * 2); } //GetTexCoordPointer extern "C" DLLEXPORT float* GetTexCoordPointer(b3dm_loader * visitor, int meshIndex, int texCoordIndex) { return visitor->mMeshInfos[meshIndex]->mTexCoords + texCoordIndex * 2; }