123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- #pragma once
- #include <iostream>
- #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<char> buf(gltfSize);
- ::memcpy(&buf.at(0), totalData + len_b3dm, gltfSize);
- unsigned char* data = reinterpret_cast<unsigned char*>(&buf.at(0));
- int length = static_cast<unsigned int>(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;
- }
|