| 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;	}}//OpenB3dmFileextern "C" DLLEXPORT b3dm_loader* OpenB3dmFile(const char* file){	b3dm_loader* loader = b3dm_loader::LoadB3dmFromFile(file);	return loader;}//CloseOsgbFileextern "C" DLLEXPORT void CloseB3dmFile(b3dm_loader * visitor){	delete visitor;	visitor = nullptr;}//GetMeshCountextern "C" DLLEXPORT int GetMeshCount(b3dm_loader * visitor){	return visitor->mMeshInfos.size();}//GetVertexCountextern "C" DLLEXPORT int GetVertexCount(b3dm_loader * visitor, int meshIndex){	return visitor->mMeshInfos[meshIndex]->mVertexCount;}//Ö±½Ó¿½±´ÄÚ´æ GetVertexsextern "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);}//GetVertexPointerextern "C" DLLEXPORT float* GetVertexPointer(b3dm_loader * visitor, int meshIndex, int vertexIndex){	return visitor->mMeshInfos[meshIndex]->mVertexs + vertexIndex * 3;}//GetTriangleCountextern "C" DLLEXPORT int GetTriangleCount(b3dm_loader * visitor, int meshIndex){	return visitor->mMeshInfos[meshIndex]->mTriangleCount;}//Ö±½Ó¿½±´ÄÚ´æ GetTrianglesextern "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);}//GetTrianglePointerextern "C" DLLEXPORT unsigned int* GetTrianglePointer(b3dm_loader * visitor, int meshIndex){	return visitor->mMeshInfos[meshIndex]->mTriangles;}//GetImageSizeextern "C" DLLEXPORT unsigned int GetImageSize(b3dm_loader * visitor, int meshIndex){	return visitor->mMeshInfos[meshIndex]->mImageSize;}//GetImageResolutionSextern "C" DLLEXPORT int GetImageResolutionS(b3dm_loader * visitor, int meshIndex){	return visitor->mMeshInfos[meshIndex]->mImageResolutionS;}//GetImageResolutionTextern "C" DLLEXPORT int GetImageResolutionT(b3dm_loader * visitor, int meshIndex){	return visitor->mMeshInfos[meshIndex]->mImageResolutionT;}//GetImageFormatextern "C" DLLEXPORT int GetImageFormat(b3dm_loader * visitor, int meshIndex){	return visitor->mMeshInfos[meshIndex]->mTextureFormat;}//GetImagePointerextern "C" DLLEXPORT unsigned char* GetImagePointer(b3dm_loader * visitor, int meshIndex){	return visitor->mMeshInfos[meshIndex]->mImageData;}//Ö±½Ó¿½±´ÄÚ´æ GetImageDataextern "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);}//GetTexCoordCountextern "C" DLLEXPORT int GetTexCoordCount(b3dm_loader * visitor, int meshIndex){	return visitor->mMeshInfos[meshIndex]->mTexCoordCount;}//Ö±½Ó¿½±´ÄÚ´æ GetTexCoordsextern "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);}//GetTexCoordPointerextern "C" DLLEXPORT float* GetTexCoordPointer(b3dm_loader * visitor, int meshIndex, int texCoordIndex){	return visitor->mMeshInfos[meshIndex]->mTexCoords + texCoordIndex * 2;}
 |