fix all unittests.
parent
255758e6ff
commit
0357333c81
|
@ -49,8 +49,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "AssbinFileWriter.h"
|
||||
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
|
|
|
@ -48,10 +48,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "Common/assbin_chunks.h"
|
||||
#include "PostProcessing/ProcessHelper.h"
|
||||
|
||||
#include <assimp/version.h>
|
||||
#include <assimp/IOStream.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/Exceptional.h>
|
||||
#include <assimp/version.h>
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/IOStream.hpp>
|
||||
|
||||
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
|
||||
#include <zlib.h>
|
||||
|
@ -74,8 +74,7 @@ size_t Write(IOStream * stream, const T& v) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize an aiString
|
||||
template <>
|
||||
inline
|
||||
size_t Write<aiString>(IOStream * stream, const aiString& s) {
|
||||
inline size_t Write<aiString>(IOStream *stream, const aiString &s) {
|
||||
const size_t s2 = (uint32_t)s.length;
|
||||
stream->Write(&s, 4, 1);
|
||||
stream->Write(s.data, s2, 1);
|
||||
|
@ -86,8 +85,7 @@ size_t Write<aiString>(IOStream * stream, const aiString& s) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize an unsigned int as uint32_t
|
||||
template <>
|
||||
inline
|
||||
size_t Write<unsigned int>(IOStream * stream, const unsigned int& w) {
|
||||
inline size_t Write<unsigned int>(IOStream *stream, const unsigned int &w) {
|
||||
const uint32_t t = (uint32_t)w;
|
||||
if (w > t) {
|
||||
// this shouldn't happen, integers in Assimp data structures never exceed 2^32
|
||||
|
@ -102,8 +100,7 @@ size_t Write<unsigned int>(IOStream * stream, const unsigned int& w) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize an unsigned int as uint16_t
|
||||
template <>
|
||||
inline
|
||||
size_t Write<uint16_t>(IOStream * stream, const uint16_t& w) {
|
||||
inline size_t Write<uint16_t>(IOStream *stream, const uint16_t &w) {
|
||||
static_assert(sizeof(uint16_t) == 2, "sizeof(uint16_t)==2");
|
||||
stream->Write(&w, 2, 1);
|
||||
|
||||
|
@ -113,8 +110,7 @@ size_t Write<uint16_t>(IOStream * stream, const uint16_t& w) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize a float
|
||||
template <>
|
||||
inline
|
||||
size_t Write<float>(IOStream * stream, const float& f) {
|
||||
inline size_t Write<float>(IOStream *stream, const float &f) {
|
||||
static_assert(sizeof(float) == 4, "sizeof(float)==4");
|
||||
stream->Write(&f, 4, 1);
|
||||
|
||||
|
@ -124,8 +120,7 @@ size_t Write<float>(IOStream * stream, const float& f) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize a double
|
||||
template <>
|
||||
inline
|
||||
size_t Write<double>(IOStream * stream, const double& f) {
|
||||
inline size_t Write<double>(IOStream *stream, const double &f) {
|
||||
static_assert(sizeof(double) == 8, "sizeof(double)==8");
|
||||
stream->Write(&f, 8, 1);
|
||||
|
||||
|
@ -135,8 +130,7 @@ size_t Write<double>(IOStream * stream, const double& f) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize a vec3
|
||||
template <>
|
||||
inline
|
||||
size_t Write<aiVector3D>(IOStream * stream, const aiVector3D& v) {
|
||||
inline size_t Write<aiVector3D>(IOStream *stream, const aiVector3D &v) {
|
||||
size_t t = Write<float>(stream, v.x);
|
||||
t += Write<float>(stream, v.y);
|
||||
t += Write<float>(stream, v.z);
|
||||
|
@ -147,8 +141,7 @@ size_t Write<aiVector3D>(IOStream * stream, const aiVector3D& v) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize a color value
|
||||
template <>
|
||||
inline
|
||||
size_t Write<aiColor3D>(IOStream * stream, const aiColor3D& v) {
|
||||
inline size_t Write<aiColor3D>(IOStream *stream, const aiColor3D &v) {
|
||||
size_t t = Write<float>(stream, v.r);
|
||||
t += Write<float>(stream, v.g);
|
||||
t += Write<float>(stream, v.b);
|
||||
|
@ -159,8 +152,7 @@ size_t Write<aiColor3D>(IOStream * stream, const aiColor3D& v) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize a color value
|
||||
template <>
|
||||
inline
|
||||
size_t Write<aiColor4D>(IOStream * stream, const aiColor4D& v) {
|
||||
inline size_t Write<aiColor4D>(IOStream *stream, const aiColor4D &v) {
|
||||
size_t t = Write<float>(stream, v.r);
|
||||
t += Write<float>(stream, v.g);
|
||||
t += Write<float>(stream, v.b);
|
||||
|
@ -172,8 +164,7 @@ size_t Write<aiColor4D>(IOStream * stream, const aiColor4D& v) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize a quaternion
|
||||
template <>
|
||||
inline
|
||||
size_t Write<aiQuaternion>(IOStream * stream, const aiQuaternion& v) {
|
||||
inline size_t Write<aiQuaternion>(IOStream *stream, const aiQuaternion &v) {
|
||||
size_t t = Write<float>(stream, v.w);
|
||||
t += Write<float>(stream, v.x);
|
||||
t += Write<float>(stream, v.y);
|
||||
|
@ -186,8 +177,7 @@ size_t Write<aiQuaternion>(IOStream * stream, const aiQuaternion& v) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize a vertex weight
|
||||
template <>
|
||||
inline
|
||||
size_t Write<aiVertexWeight>(IOStream * stream, const aiVertexWeight& v) {
|
||||
inline size_t Write<aiVertexWeight>(IOStream *stream, const aiVertexWeight &v) {
|
||||
size_t t = Write<unsigned int>(stream, v.mVertexId);
|
||||
|
||||
return t + Write<float>(stream, v.mWeight);
|
||||
|
@ -196,8 +186,7 @@ size_t Write<aiVertexWeight>(IOStream * stream, const aiVertexWeight& v) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize a mat4x4
|
||||
template <>
|
||||
inline
|
||||
size_t Write<aiMatrix4x4>(IOStream * stream, const aiMatrix4x4& m) {
|
||||
inline size_t Write<aiMatrix4x4>(IOStream *stream, const aiMatrix4x4 &m) {
|
||||
for (unsigned int i = 0; i < 4; ++i) {
|
||||
for (unsigned int i2 = 0; i2 < 4; ++i2) {
|
||||
Write<float>(stream, m[i][i2]);
|
||||
|
@ -210,8 +199,7 @@ size_t Write<aiMatrix4x4>(IOStream * stream, const aiMatrix4x4& m) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize an aiVectorKey
|
||||
template <>
|
||||
inline
|
||||
size_t Write<aiVectorKey>(IOStream * stream, const aiVectorKey& v) {
|
||||
inline size_t Write<aiVectorKey>(IOStream *stream, const aiVectorKey &v) {
|
||||
const size_t t = Write<double>(stream, v.mTime);
|
||||
return t + Write<aiVector3D>(stream, v.mValue);
|
||||
}
|
||||
|
@ -219,15 +207,13 @@ size_t Write<aiVectorKey>(IOStream * stream, const aiVectorKey& v) {
|
|||
// -----------------------------------------------------------------------------------
|
||||
// Serialize an aiQuatKey
|
||||
template <>
|
||||
inline
|
||||
size_t Write<aiQuatKey>(IOStream * stream, const aiQuatKey& v) {
|
||||
inline size_t Write<aiQuatKey>(IOStream *stream, const aiQuatKey &v) {
|
||||
const size_t t = Write<double>(stream, v.mTime);
|
||||
return t + Write<aiQuaternion>(stream, v.mValue);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
size_t WriteBounds(IOStream * stream, const T* in, unsigned int size) {
|
||||
inline size_t WriteBounds(IOStream *stream, const T *in, unsigned int size) {
|
||||
T minc, maxc;
|
||||
ArrayBounds(in, size, minc, maxc);
|
||||
|
||||
|
@ -238,10 +224,10 @@ size_t WriteBounds(IOStream * stream, const T* in, unsigned int size) {
|
|||
// We use this to write out non-byte arrays so that we write using the specializations.
|
||||
// This way we avoid writing out extra bytes that potentially come from struct alignment.
|
||||
template <typename T>
|
||||
inline
|
||||
size_t WriteArray(IOStream * stream, const T* in, unsigned int size) {
|
||||
inline size_t WriteArray(IOStream *stream, const T *in, unsigned int size) {
|
||||
size_t n = 0;
|
||||
for (unsigned int i=0; i<size; i++) n += Write<T>(stream,in[i]);
|
||||
for (unsigned int i = 0; i < size; i++)
|
||||
n += Write<T>(stream, in[i]);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
@ -256,10 +242,8 @@ size_t WriteArray(IOStream * stream, const T* in, unsigned int size) {
|
|||
* and the chunk contents to the container stream. This allows relatively easy chunk
|
||||
* chunk construction, even recursively.
|
||||
*/
|
||||
class AssbinChunkWriter : public IOStream
|
||||
{
|
||||
class AssbinChunkWriter : public IOStream {
|
||||
private:
|
||||
|
||||
uint8_t *buffer;
|
||||
uint32_t magic;
|
||||
IOStream *container;
|
||||
|
@ -267,8 +251,7 @@ private:
|
|||
|
||||
private:
|
||||
// -------------------------------------------------------------------
|
||||
void Grow(size_t need = 0)
|
||||
{
|
||||
void Grow(size_t need = 0) {
|
||||
size_t new_size = std::max(initial, std::max(need, cur_size + (cur_size >> 1)));
|
||||
|
||||
const uint8_t *const old = buffer;
|
||||
|
@ -283,14 +266,17 @@ private:
|
|||
}
|
||||
|
||||
public:
|
||||
|
||||
AssbinChunkWriter( IOStream * container, uint32_t magic, size_t initial = 4096)
|
||||
: buffer(NULL), magic(magic), container(container), cur_size(0), cursor(0), initial(initial)
|
||||
{
|
||||
AssbinChunkWriter(IOStream *container, uint32_t magic, size_t initial = 4096) :
|
||||
buffer(NULL),
|
||||
magic(magic),
|
||||
container(container),
|
||||
cur_size(0),
|
||||
cursor(0),
|
||||
initial(initial) {
|
||||
// empty
|
||||
}
|
||||
|
||||
virtual ~AssbinChunkWriter()
|
||||
{
|
||||
virtual ~AssbinChunkWriter() {
|
||||
if (container) {
|
||||
container->Write(&magic, sizeof(uint32_t), 1);
|
||||
container->Write(&cursor, sizeof(uint32_t), 1);
|
||||
|
@ -331,7 +317,6 @@ public:
|
|||
|
||||
return pCount;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
@ -340,16 +325,14 @@ public:
|
|||
*
|
||||
* This class writes an .assbin file, and is responsible for the file layout.
|
||||
*/
|
||||
class AssbinFileWriter
|
||||
{
|
||||
class AssbinFileWriter {
|
||||
private:
|
||||
bool shortened;
|
||||
bool compressed;
|
||||
|
||||
protected:
|
||||
// -----------------------------------------------------------------------------------
|
||||
void WriteBinaryNode( IOStream * container, const aiNode* node)
|
||||
{
|
||||
void WriteBinaryNode(IOStream *container, const aiNode *node) {
|
||||
AssbinChunkWriter chunk(container, ASSBIN_CHUNK_AINODE);
|
||||
|
||||
unsigned int nb_metadata = (node->mMetaData != NULL ? node->mMetaData->mNumProperties : 0);
|
||||
|
@ -408,8 +391,7 @@ protected:
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void WriteBinaryTexture(IOStream * container, const aiTexture* tex)
|
||||
{
|
||||
void WriteBinaryTexture(IOStream *container, const aiTexture *tex) {
|
||||
AssbinChunkWriter chunk(container, ASSBIN_CHUNK_AITEXTURE);
|
||||
|
||||
Write<unsigned int>(&chunk, tex->mWidth);
|
||||
|
@ -420,17 +402,14 @@ protected:
|
|||
if (!shortened) {
|
||||
if (!tex->mHeight) {
|
||||
chunk.Write(tex->pcData, 1, tex->mWidth);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
chunk.Write(tex->pcData, 1, tex->mWidth * tex->mHeight * 4);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void WriteBinaryBone(IOStream * container, const aiBone* b)
|
||||
{
|
||||
void WriteBinaryBone(IOStream *container, const aiBone *b) {
|
||||
AssbinChunkWriter chunk(container, ASSBIN_CHUNK_AIBONE);
|
||||
|
||||
Write<aiString>(&chunk, b->mName);
|
||||
|
@ -442,12 +421,12 @@ protected:
|
|||
if (shortened) {
|
||||
WriteBounds(&chunk, b->mWeights, b->mNumWeights);
|
||||
} // else write as usual
|
||||
else WriteArray<aiVertexWeight>(&chunk,b->mWeights,b->mNumWeights);
|
||||
else
|
||||
WriteArray<aiVertexWeight>(&chunk, b->mWeights, b->mNumWeights);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void WriteBinaryMesh(IOStream * container, const aiMesh* mesh)
|
||||
{
|
||||
void WriteBinaryMesh(IOStream *container, const aiMesh *mesh) {
|
||||
AssbinChunkWriter chunk(container, ASSBIN_CHUNK_AIMESH);
|
||||
|
||||
Write<unsigned int>(&chunk, mesh->mPrimitiveTypes);
|
||||
|
@ -486,13 +465,15 @@ protected:
|
|||
if (shortened) {
|
||||
WriteBounds(&chunk, mesh->mVertices, mesh->mNumVertices);
|
||||
} // else write as usual
|
||||
else WriteArray<aiVector3D>(&chunk,mesh->mVertices,mesh->mNumVertices);
|
||||
else
|
||||
WriteArray<aiVector3D>(&chunk, mesh->mVertices, mesh->mNumVertices);
|
||||
}
|
||||
if (mesh->mNormals) {
|
||||
if (shortened) {
|
||||
WriteBounds(&chunk, mesh->mNormals, mesh->mNumVertices);
|
||||
} // else write as usual
|
||||
else WriteArray<aiVector3D>(&chunk,mesh->mNormals,mesh->mNumVertices);
|
||||
else
|
||||
WriteArray<aiVector3D>(&chunk, mesh->mNormals, mesh->mNumVertices);
|
||||
}
|
||||
if (mesh->mTangents && mesh->mBitangents) {
|
||||
if (shortened) {
|
||||
|
@ -511,7 +492,8 @@ protected:
|
|||
if (shortened) {
|
||||
WriteBounds(&chunk, mesh->mColors[n], mesh->mNumVertices);
|
||||
} // else write as usual
|
||||
else WriteArray<aiColor4D>(&chunk,mesh->mColors[n],mesh->mNumVertices);
|
||||
else
|
||||
WriteArray<aiColor4D>(&chunk, mesh->mColors[n], mesh->mNumVertices);
|
||||
}
|
||||
for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++n) {
|
||||
if (!mesh->mTextureCoords[n])
|
||||
|
@ -523,7 +505,8 @@ protected:
|
|||
if (shortened) {
|
||||
WriteBounds(&chunk, mesh->mTextureCoords[n], mesh->mNumVertices);
|
||||
} // else write as usual
|
||||
else WriteArray<aiVector3D>(&chunk,mesh->mTextureCoords[n],mesh->mNumVertices);
|
||||
else
|
||||
WriteArray<aiVector3D>(&chunk, mesh->mTextureCoords[n], mesh->mNumVertices);
|
||||
}
|
||||
|
||||
// write faces. There are no floating-point calculations involved
|
||||
|
@ -547,19 +530,18 @@ protected:
|
|||
}
|
||||
Write<unsigned int>(&chunk, hash);
|
||||
}
|
||||
}
|
||||
else // else write as usual
|
||||
} else // else write as usual
|
||||
{
|
||||
// if there are less than 2^16 vertices, we can simply use 16 bit integers ...
|
||||
for (unsigned int i = 0; i < mesh->mNumFaces; ++i) {
|
||||
const aiFace &f = mesh->mFaces[i];
|
||||
|
||||
static_assert(AI_MAX_FACE_INDICES <= 0xffff, "AI_MAX_FACE_INDICES <= 0xffff");
|
||||
Write<uint32_t>(&chunk,f.mNumIndices);
|
||||
Write<uint16_t>(&chunk, static_cast<uint16_t>(f.mNumIndices));
|
||||
|
||||
for (unsigned int a = 0; a < f.mNumIndices; ++a) {
|
||||
if (mesh->mNumVertices < (1u << 16)) {
|
||||
Write<uint32_t>(&chunk,f.mIndices[a]);
|
||||
Write<uint16_t>(&chunk, static_cast<uint16_t>(f.mIndices[a]));
|
||||
} else {
|
||||
Write<unsigned int>(&chunk, f.mIndices[a]);
|
||||
}
|
||||
|
@ -577,8 +559,7 @@ protected:
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void WriteBinaryMaterialProperty(IOStream * container, const aiMaterialProperty* prop)
|
||||
{
|
||||
void WriteBinaryMaterialProperty(IOStream *container, const aiMaterialProperty *prop) {
|
||||
AssbinChunkWriter chunk(container, ASSBIN_CHUNK_AIMATERIALPROPERTY);
|
||||
|
||||
Write<aiString>(&chunk, prop->mKey);
|
||||
|
@ -591,8 +572,7 @@ protected:
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void WriteBinaryMaterial(IOStream * container, const aiMaterial* mat)
|
||||
{
|
||||
void WriteBinaryMaterial(IOStream *container, const aiMaterial *mat) {
|
||||
AssbinChunkWriter chunk(container, ASSBIN_CHUNK_AIMATERIAL);
|
||||
|
||||
Write<unsigned int>(&chunk, mat->mNumProperties);
|
||||
|
@ -602,8 +582,7 @@ protected:
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void WriteBinaryNodeAnim(IOStream * container, const aiNodeAnim* nd)
|
||||
{
|
||||
void WriteBinaryNodeAnim(IOStream *container, const aiNodeAnim *nd) {
|
||||
AssbinChunkWriter chunk(container, ASSBIN_CHUNK_AINODEANIM);
|
||||
|
||||
Write<aiString>(&chunk, nd->mNodeName);
|
||||
|
@ -618,28 +597,29 @@ protected:
|
|||
WriteBounds(&chunk, nd->mPositionKeys, nd->mNumPositionKeys);
|
||||
|
||||
} // else write as usual
|
||||
else WriteArray<aiVectorKey>(&chunk,nd->mPositionKeys,nd->mNumPositionKeys);
|
||||
else
|
||||
WriteArray<aiVectorKey>(&chunk, nd->mPositionKeys, nd->mNumPositionKeys);
|
||||
}
|
||||
if (nd->mRotationKeys) {
|
||||
if (shortened) {
|
||||
WriteBounds(&chunk, nd->mRotationKeys, nd->mNumRotationKeys);
|
||||
|
||||
} // else write as usual
|
||||
else WriteArray<aiQuatKey>(&chunk,nd->mRotationKeys,nd->mNumRotationKeys);
|
||||
else
|
||||
WriteArray<aiQuatKey>(&chunk, nd->mRotationKeys, nd->mNumRotationKeys);
|
||||
}
|
||||
if (nd->mScalingKeys) {
|
||||
if (shortened) {
|
||||
WriteBounds(&chunk, nd->mScalingKeys, nd->mNumScalingKeys);
|
||||
|
||||
} // else write as usual
|
||||
else WriteArray<aiVectorKey>(&chunk,nd->mScalingKeys,nd->mNumScalingKeys);
|
||||
else
|
||||
WriteArray<aiVectorKey>(&chunk, nd->mScalingKeys, nd->mNumScalingKeys);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void WriteBinaryAnim( IOStream * container, const aiAnimation* anim )
|
||||
{
|
||||
void WriteBinaryAnim(IOStream *container, const aiAnimation *anim) {
|
||||
AssbinChunkWriter chunk(container, ASSBIN_CHUNK_AIANIMATION);
|
||||
|
||||
Write<aiString>(&chunk, anim->mName);
|
||||
|
@ -654,8 +634,7 @@ protected:
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void WriteBinaryLight( IOStream * container, const aiLight* l )
|
||||
{
|
||||
void WriteBinaryLight(IOStream *container, const aiLight *l) {
|
||||
AssbinChunkWriter chunk(container, ASSBIN_CHUNK_AILIGHT);
|
||||
|
||||
Write<aiString>(&chunk, l->mName);
|
||||
|
@ -675,12 +654,10 @@ protected:
|
|||
Write<float>(&chunk, l->mAngleInnerCone);
|
||||
Write<float>(&chunk, l->mAngleOuterCone);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void WriteBinaryCamera( IOStream * container, const aiCamera* cam )
|
||||
{
|
||||
void WriteBinaryCamera(IOStream *container, const aiCamera *cam) {
|
||||
AssbinChunkWriter chunk(container, ASSBIN_CHUNK_AICAMERA);
|
||||
|
||||
Write<aiString>(&chunk, cam->mName);
|
||||
|
@ -694,8 +671,7 @@ protected:
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void WriteBinaryScene( IOStream * container, const aiScene* scene)
|
||||
{
|
||||
void WriteBinaryScene(IOStream *container, const aiScene *scene) {
|
||||
AssbinChunkWriter chunk(container, ASSBIN_CHUNK_AISCENE);
|
||||
|
||||
// basic scene information
|
||||
|
@ -728,7 +704,6 @@ protected:
|
|||
WriteBinaryAnim(&chunk, anim);
|
||||
}
|
||||
|
||||
|
||||
// write all textures
|
||||
for (unsigned int i = 0; i < scene->mNumTextures; ++i) {
|
||||
const aiTexture *mesh = scene->mTextures[i];
|
||||
|
@ -746,19 +721,16 @@ protected:
|
|||
const aiCamera *cam = scene->mCameras[i];
|
||||
WriteBinaryCamera(&chunk, cam);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
AssbinFileWriter(bool shortened, bool compressed)
|
||||
: shortened(shortened), compressed(compressed)
|
||||
{
|
||||
AssbinFileWriter(bool shortened, bool compressed) :
|
||||
shortened(shortened), compressed(compressed) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
// Write a binary model dump
|
||||
void WriteBinaryDump(const char* pFile, const char* cmd, IOSystem* pIOSystem, const aiScene* pScene)
|
||||
{
|
||||
void WriteBinaryDump(const char *pFile, const char *cmd, IOSystem *pIOSystem, const aiScene *pScene) {
|
||||
IOStream *out = pIOSystem->Open(pFile, "wb");
|
||||
if (!out)
|
||||
throw std::runtime_error("Unable to open output file " + std::string(pFile) + '\n');
|
||||
|
@ -816,8 +788,7 @@ public:
|
|||
|
||||
// Up to here the data is uncompressed. For compressed files, the rest
|
||||
// is compressed using standard DEFLATE from zlib.
|
||||
if (compressed)
|
||||
{
|
||||
if (compressed) {
|
||||
AssbinChunkWriter uncompressedStream(NULL, 0);
|
||||
WriteBinaryScene(&uncompressedStream, pScene);
|
||||
|
||||
|
@ -826,8 +797,7 @@ public:
|
|||
uint8_t *compressedBuffer = new uint8_t[compressedSize];
|
||||
|
||||
int res = compress2(compressedBuffer, &compressedSize, (const Bytef *)uncompressedStream.GetBufferPointer(), uncompressedSize, 9);
|
||||
if (res != Z_OK)
|
||||
{
|
||||
if (res != Z_OK) {
|
||||
delete[] compressedBuffer;
|
||||
throw DeadlyExportError("Compression failed.");
|
||||
}
|
||||
|
@ -836,15 +806,12 @@ public:
|
|||
out->Write(compressedBuffer, sizeof(char), compressedSize);
|
||||
|
||||
delete[] compressedBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
WriteBinaryScene(out, pScene);
|
||||
}
|
||||
|
||||
CloseIOStream();
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
CloseIOStream();
|
||||
throw;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
@ -105,8 +103,9 @@ template <typename T>
|
|||
T Read(IOStream *stream) {
|
||||
T t;
|
||||
size_t res = stream->Read(&t, sizeof(T), 1);
|
||||
if (res != 1)
|
||||
if (res != 1) {
|
||||
throw DeadlyImportError("Unexpected EOF");
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
|
@ -313,6 +312,7 @@ void AssbinImporter::ReadBinaryBone(IOStream *stream, aiBone *b) {
|
|||
static bool fitsIntoUI16(unsigned int mNumVertices) {
|
||||
return (mNumVertices < (1u << 16));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryMesh(IOStream *stream, aiMesh *mesh) {
|
||||
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AIMESH)
|
||||
|
|
|
@ -1272,13 +1272,9 @@ inline void Asset::ReadBinaryHeader(IOStream &stream) {
|
|||
inline void Asset::Load(const std::string &pFile, bool isBinary) {
|
||||
mCurrentAssetDir.clear();
|
||||
|
||||
int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
|
||||
if (pos != int(std::string::npos)) mCurrentAssetDir = pFile.substr(0, pos + 1);
|
||||
|
||||
/* std::string::size_type pos = std::max(pFile.rfind('/'), pFile.rfind('\\'));
|
||||
if (pos != std::string::npos) {
|
||||
mCurrentAssetDir = pFile.substr(0, pos + 1);
|
||||
}*/
|
||||
/*int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
|
||||
if (pos != int(std::string::npos)) mCurrentAssetDir = pFile.substr(0, pos + 1);*/
|
||||
mCurrentAssetDir = getCurrentAssetDir(pFile);
|
||||
|
||||
shared_ptr<IOStream> stream(OpenFile(pFile.c_str(), "rb", true));
|
||||
if (!stream) {
|
||||
|
|
|
@ -110,13 +110,11 @@ void EncodeBase64(const uint8_t* in, size_t inLength, std::string& out) {
|
|||
|
||||
b = in[i + 2] & 0x3F;
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
out[j++] = '=';
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
out[j++] = '=';
|
||||
out[j++] = '=';
|
||||
|
@ -159,16 +157,14 @@ bool ParseDataURI(const char* const_uri, size_t uriLen, DataURI& out) {
|
|||
|
||||
if (strncmp(uri + j, "charset=", 8) == 0) {
|
||||
uri[2] = char(j + 8);
|
||||
}
|
||||
else if (strncmp(uri + j, "base64", 6) == 0) {
|
||||
} else if (strncmp(uri + j, "base64", 6) == 0) {
|
||||
uri[3] = char(j);
|
||||
}
|
||||
}
|
||||
if (i < uriLen) {
|
||||
uri[i++] = '\0';
|
||||
uri[4] = char(i);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
uri[1] = uri[2] = uri[3] = 0;
|
||||
uri[4] = 5;
|
||||
}
|
||||
|
@ -189,5 +185,5 @@ bool ParseDataURI(const char* const_uri, size_t uriLen, DataURI& out) {
|
|||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace Util
|
||||
} // namespace glTFCommon
|
||||
|
|
|
@ -45,29 +45,28 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <assimp/Exceptional.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define RAPIDJSON_HAS_STDSTRING 1
|
||||
#include <rapidjson/rapidjson.h>
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/error/en.h>
|
||||
#include <rapidjson/rapidjson.h>
|
||||
|
||||
#ifdef ASSIMP_API
|
||||
# include <memory>
|
||||
# include <assimp/DefaultIOSystem.h>
|
||||
#include <assimp/ByteSwapper.h>
|
||||
#include <assimp/DefaultIOSystem.h>
|
||||
#include <memory>
|
||||
#else
|
||||
#include <memory>
|
||||
#define AI_SWAP4(p)
|
||||
#define ai_assert
|
||||
#endif
|
||||
|
||||
|
||||
#if _MSC_VER > 1500 || (defined __GNUC___)
|
||||
#define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
|
||||
#else
|
||||
|
@ -105,8 +104,12 @@ namespace glTFCommon {
|
|||
|
||||
class IOStream {
|
||||
public:
|
||||
IOStream(FILE* file) : f(file) {}
|
||||
~IOStream() { fclose(f); f = 0; }
|
||||
IOStream(FILE *file) :
|
||||
f(file) {}
|
||||
~IOStream() {
|
||||
fclose(f);
|
||||
f = 0;
|
||||
}
|
||||
|
||||
size_t Read(void *b, size_t sz, size_t n) { return fread(b, sz, n, f); }
|
||||
size_t Write(const void *b, size_t sz, size_t n) { return fwrite(b, sz, n, f); }
|
||||
|
@ -128,67 +131,84 @@ namespace glTFCommon {
|
|||
typedef float(vec4)[4];
|
||||
typedef float(mat4)[16];
|
||||
|
||||
inline
|
||||
void CopyValue(const glTFCommon::vec3& v, aiColor4D& out) {
|
||||
inline void CopyValue(const glTFCommon::vec3 &v, aiColor4D &out) {
|
||||
out.r = v[0];
|
||||
out.g = v[1];
|
||||
out.b = v[2];
|
||||
out.a = 1.0;
|
||||
}
|
||||
|
||||
inline
|
||||
void CopyValue(const glTFCommon::vec4& v, aiColor4D& out) {
|
||||
inline void CopyValue(const glTFCommon::vec4 &v, aiColor4D &out) {
|
||||
out.r = v[0];
|
||||
out.g = v[1];
|
||||
out.b = v[2];
|
||||
out.a = v[3];
|
||||
}
|
||||
|
||||
inline
|
||||
void CopyValue(const glTFCommon::vec4& v, aiColor3D& out) {
|
||||
inline void CopyValue(const glTFCommon::vec4 &v, aiColor3D &out) {
|
||||
out.r = v[0];
|
||||
out.g = v[1];
|
||||
out.b = v[2];
|
||||
}
|
||||
|
||||
inline
|
||||
void CopyValue(const glTFCommon::vec3& v, aiColor3D& out) {
|
||||
inline void CopyValue(const glTFCommon::vec3 &v, aiColor3D &out) {
|
||||
out.r = v[0];
|
||||
out.g = v[1];
|
||||
out.b = v[2];
|
||||
}
|
||||
|
||||
inline
|
||||
void CopyValue(const glTFCommon::vec3& v, aiVector3D& out) {
|
||||
inline void CopyValue(const glTFCommon::vec3 &v, aiVector3D &out) {
|
||||
out.x = v[0];
|
||||
out.y = v[1];
|
||||
out.z = v[2];
|
||||
}
|
||||
|
||||
inline
|
||||
void CopyValue(const glTFCommon::vec4& v, aiQuaternion& out) {
|
||||
inline void CopyValue(const glTFCommon::vec4 &v, aiQuaternion &out) {
|
||||
out.x = v[0];
|
||||
out.y = v[1];
|
||||
out.z = v[2];
|
||||
out.w = v[3];
|
||||
}
|
||||
|
||||
inline
|
||||
void CopyValue(const glTFCommon::mat4& v, aiMatrix4x4& o) {
|
||||
o.a1 = v[0]; o.b1 = v[1]; o.c1 = v[2]; o.d1 = v[3];
|
||||
o.a2 = v[4]; o.b2 = v[5]; o.c2 = v[6]; o.d2 = v[7];
|
||||
o.a3 = v[8]; o.b3 = v[9]; o.c3 = v[10]; o.d3 = v[11];
|
||||
o.a4 = v[12]; o.b4 = v[13]; o.c4 = v[14]; o.d4 = v[15];
|
||||
inline void CopyValue(const glTFCommon::mat4 &v, aiMatrix4x4 &o) {
|
||||
o.a1 = v[0];
|
||||
o.b1 = v[1];
|
||||
o.c1 = v[2];
|
||||
o.d1 = v[3];
|
||||
o.a2 = v[4];
|
||||
o.b2 = v[5];
|
||||
o.c2 = v[6];
|
||||
o.d2 = v[7];
|
||||
o.a3 = v[8];
|
||||
o.b3 = v[9];
|
||||
o.c3 = v[10];
|
||||
o.d3 = v[11];
|
||||
o.a4 = v[12];
|
||||
o.b4 = v[13];
|
||||
o.c4 = v[14];
|
||||
o.d4 = v[15];
|
||||
}
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4310)
|
||||
inline std::string getCurrentAssetDir(const std::string &pFile) {
|
||||
std::string path = pFile;
|
||||
int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
|
||||
if (pos != int(std::string::npos)) {
|
||||
path = pFile.substr(0, pos + 1);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
namespace Util {
|
||||
|
||||
void EncodeBase64(const uint8_t *in, size_t inLength, std::string &out);
|
||||
|
||||
size_t DecodeBase64(const char *in, size_t inLength, uint8_t *&out);
|
||||
|
||||
inline
|
||||
size_t DecodeBase64(const char* in, uint8_t*& out) {
|
||||
inline size_t DecodeBase64(const char *in, uint8_t *&out) {
|
||||
return DecodeBase64(in, strlen(in), out);
|
||||
}
|
||||
|
||||
|
@ -220,13 +240,11 @@ namespace glTFCommon {
|
|||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
inline
|
||||
char EncodeCharBase64(uint8_t b) {
|
||||
inline char EncodeCharBase64(uint8_t b) {
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="[size_t(b)];
|
||||
}
|
||||
|
||||
inline
|
||||
uint8_t DecodeCharBase64(char c) {
|
||||
inline uint8_t DecodeCharBase64(char c) {
|
||||
return DATA<true>::tableDecodeBase64[size_t(c)]; // TODO faster with lookup table or ifs?
|
||||
}
|
||||
|
||||
|
@ -238,7 +256,7 @@ namespace glTFCommon {
|
|||
#define CHECK_EXT(EXT) \
|
||||
if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true;
|
||||
|
||||
}
|
||||
} // namespace glTFCommon
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER
|
||||
|
||||
|
|
|
@ -55,29 +55,28 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <assimp/Exceptional.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define RAPIDJSON_HAS_STDSTRING 1
|
||||
#include <rapidjson/rapidjson.h>
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/error/en.h>
|
||||
#include <rapidjson/rapidjson.h>
|
||||
|
||||
#ifdef ASSIMP_API
|
||||
# include <memory>
|
||||
# include <assimp/DefaultIOSystem.h>
|
||||
#include <assimp/ByteSwapper.h>
|
||||
#include <assimp/DefaultIOSystem.h>
|
||||
#include <memory>
|
||||
#else
|
||||
#include <memory>
|
||||
#define AI_SWAP4(p)
|
||||
#define ai_assert
|
||||
#endif
|
||||
|
||||
|
||||
#if _MSC_VER > 1500 || (defined __GNUC___)
|
||||
#define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
|
||||
#else
|
||||
|
@ -97,14 +96,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "glTF/glTFCommon.h"
|
||||
|
||||
namespace glTF2
|
||||
{
|
||||
using glTFCommon::shared_ptr;
|
||||
using glTFCommon::IOSystem;
|
||||
namespace glTF2 {
|
||||
using glTFCommon::IOStream;
|
||||
using glTFCommon::IOSystem;
|
||||
using glTFCommon::shared_ptr;
|
||||
|
||||
using rapidjson::Value;
|
||||
using rapidjson::Document;
|
||||
using rapidjson::Value;
|
||||
|
||||
class Asset;
|
||||
class AssetWriter;
|
||||
|
@ -113,9 +111,9 @@ namespace glTF2
|
|||
struct Texture;
|
||||
struct Skin;
|
||||
|
||||
using glTFCommon::mat4;
|
||||
using glTFCommon::vec3;
|
||||
using glTFCommon::vec4;
|
||||
using glTFCommon::mat4;
|
||||
|
||||
//! Magic number for GLB files
|
||||
#define AI_GLB_MAGIC_NUMBER "glTF"
|
||||
|
@ -127,15 +125,13 @@ namespace glTF2
|
|||
|
||||
//! For binary .glb files
|
||||
//! 12-byte header (+ the JSON + a "body" data section)
|
||||
struct GLB_Header
|
||||
{
|
||||
struct GLB_Header {
|
||||
uint8_t magic[4]; //!< Magic number: "glTF"
|
||||
uint32_t version; //!< Version number (always 2 as of the last update)
|
||||
uint32_t length; //!< Total length of the Binary glTF, including header, scene, and body, in bytes
|
||||
} PACK_STRUCT;
|
||||
|
||||
struct GLB_Chunk
|
||||
{
|
||||
struct GLB_Chunk {
|
||||
uint32_t chunkLength;
|
||||
uint32_t chunkType;
|
||||
} PACK_STRUCT;
|
||||
|
@ -144,17 +140,14 @@ namespace glTF2
|
|||
#include <assimp/Compiler/poppack1.h>
|
||||
#endif
|
||||
|
||||
|
||||
//! Values for the GLB_Chunk::chunkType field
|
||||
enum ChunkType
|
||||
{
|
||||
enum ChunkType {
|
||||
ChunkType_JSON = 0x4E4F534A,
|
||||
ChunkType_BIN = 0x004E4942
|
||||
};
|
||||
|
||||
//! Values for the mesh primitive modes
|
||||
enum PrimitiveMode
|
||||
{
|
||||
enum PrimitiveMode {
|
||||
PrimitiveMode_POINTS = 0,
|
||||
PrimitiveMode_LINES = 1,
|
||||
PrimitiveMode_LINE_LOOP = 2,
|
||||
|
@ -165,8 +158,7 @@ namespace glTF2
|
|||
};
|
||||
|
||||
//! Values for the Accessor::componentType field
|
||||
enum ComponentType
|
||||
{
|
||||
enum ComponentType {
|
||||
ComponentType_BYTE = 5120,
|
||||
ComponentType_UNSIGNED_BYTE = 5121,
|
||||
ComponentType_SHORT = 5122,
|
||||
|
@ -175,9 +167,7 @@ namespace glTF2
|
|||
ComponentType_FLOAT = 5126
|
||||
};
|
||||
|
||||
inline
|
||||
unsigned int ComponentTypeSize(ComponentType t)
|
||||
{
|
||||
inline unsigned int ComponentTypeSize(ComponentType t) {
|
||||
switch (t) {
|
||||
case ComponentType_SHORT:
|
||||
case ComponentType_UNSIGNED_SHORT:
|
||||
|
@ -196,24 +186,21 @@ namespace glTF2
|
|||
}
|
||||
|
||||
//! Values for the BufferView::target field
|
||||
enum BufferViewTarget
|
||||
{
|
||||
enum BufferViewTarget {
|
||||
BufferViewTarget_NONE = 0,
|
||||
BufferViewTarget_ARRAY_BUFFER = 34962,
|
||||
BufferViewTarget_ELEMENT_ARRAY_BUFFER = 34963
|
||||
};
|
||||
|
||||
//! Values for the Sampler::magFilter field
|
||||
enum class SamplerMagFilter : unsigned int
|
||||
{
|
||||
enum class SamplerMagFilter : unsigned int {
|
||||
UNSET = 0,
|
||||
SamplerMagFilter_Nearest = 9728,
|
||||
SamplerMagFilter_Linear = 9729
|
||||
};
|
||||
|
||||
//! Values for the Sampler::minFilter field
|
||||
enum class SamplerMinFilter : unsigned int
|
||||
{
|
||||
enum class SamplerMinFilter : unsigned int {
|
||||
UNSET = 0,
|
||||
SamplerMinFilter_Nearest = 9728,
|
||||
SamplerMinFilter_Linear = 9729,
|
||||
|
@ -224,8 +211,7 @@ namespace glTF2
|
|||
};
|
||||
|
||||
//! Values for the Sampler::wrapS and Sampler::wrapT field
|
||||
enum class SamplerWrap: unsigned int
|
||||
{
|
||||
enum class SamplerWrap : unsigned int {
|
||||
UNSET = 0,
|
||||
Clamp_To_Edge = 33071,
|
||||
Mirrored_Repeat = 33648,
|
||||
|
@ -233,8 +219,7 @@ namespace glTF2
|
|||
};
|
||||
|
||||
//! Values for the Texture::format and Texture::internalFormat fields
|
||||
enum TextureFormat
|
||||
{
|
||||
enum TextureFormat {
|
||||
TextureFormat_ALPHA = 6406,
|
||||
TextureFormat_RGB = 6407,
|
||||
TextureFormat_RGBA = 6408,
|
||||
|
@ -243,14 +228,12 @@ namespace glTF2
|
|||
};
|
||||
|
||||
//! Values for the Texture::target field
|
||||
enum TextureTarget
|
||||
{
|
||||
enum TextureTarget {
|
||||
TextureTarget_TEXTURE_2D = 3553
|
||||
};
|
||||
|
||||
//! Values for the Texture::type field
|
||||
enum TextureType
|
||||
{
|
||||
enum TextureType {
|
||||
TextureType_UNSIGNED_BYTE = 5121,
|
||||
TextureType_UNSIGNED_SHORT_5_6_5 = 33635,
|
||||
TextureType_UNSIGNED_SHORT_4_4_4_4 = 32819,
|
||||
|
@ -273,24 +256,29 @@ namespace glTF2
|
|||
};
|
||||
|
||||
//! Values for the Accessor::type field (helper class)
|
||||
class AttribType
|
||||
{
|
||||
class AttribType {
|
||||
public:
|
||||
enum Value
|
||||
{ SCALAR, VEC2, VEC3, VEC4, MAT2, MAT3, MAT4 };
|
||||
enum Value { SCALAR,
|
||||
VEC2,
|
||||
VEC3,
|
||||
VEC4,
|
||||
MAT2,
|
||||
MAT3,
|
||||
MAT4 };
|
||||
|
||||
private:
|
||||
static const size_t NUM_VALUES = static_cast<size_t>(MAT4) + 1;
|
||||
|
||||
struct Info
|
||||
{ const char* name; unsigned int numComponents; };
|
||||
struct Info {
|
||||
const char *name;
|
||||
unsigned int numComponents;
|
||||
};
|
||||
|
||||
template<int N> struct data
|
||||
{ static const Info infos[NUM_VALUES]; };
|
||||
template <int N>
|
||||
struct data { static const Info infos[NUM_VALUES]; };
|
||||
|
||||
public:
|
||||
inline static Value FromString(const char* str)
|
||||
{
|
||||
inline static Value FromString(const char *str) {
|
||||
for (size_t i = 0; i < NUM_VALUES; ++i) {
|
||||
if (strcmp(data<0>::infos[i].name, str) == 0) {
|
||||
return static_cast<Value>(i);
|
||||
|
@ -299,79 +287,70 @@ namespace glTF2
|
|||
return SCALAR;
|
||||
}
|
||||
|
||||
inline static const char* ToString(Value type)
|
||||
{
|
||||
inline static const char *ToString(Value type) {
|
||||
return data<0>::infos[static_cast<size_t>(type)].name;
|
||||
}
|
||||
|
||||
inline static unsigned int GetNumComponents(Value type)
|
||||
{
|
||||
inline static unsigned int GetNumComponents(Value type) {
|
||||
return data<0>::infos[static_cast<size_t>(type)].numComponents;
|
||||
}
|
||||
};
|
||||
|
||||
// must match the order of the AttribTypeTraits::Value enum!
|
||||
template<int N> const AttribType::Info
|
||||
template <int N>
|
||||
const AttribType::Info
|
||||
AttribType::data<N>::infos[AttribType::NUM_VALUES] = {
|
||||
{ "SCALAR", 1 }, { "VEC2", 2 }, { "VEC3", 3 }, { "VEC4", 4 }, { "MAT2", 4 }, { "MAT3", 9 }, { "MAT4", 16 }
|
||||
};
|
||||
|
||||
|
||||
|
||||
//! A reference to one top-level object, which is valid
|
||||
//! until the Asset instance is destroyed
|
||||
template <class T>
|
||||
class Ref
|
||||
{
|
||||
class Ref {
|
||||
std::vector<T *> *vector;
|
||||
unsigned int index;
|
||||
|
||||
public:
|
||||
Ref() : vector(0), index(0) {}
|
||||
Ref(std::vector<T*>& vec, unsigned int idx) : vector(&vec), index(idx) {}
|
||||
Ref() :
|
||||
vector(0), index(0) {}
|
||||
Ref(std::vector<T *> &vec, unsigned int idx) :
|
||||
vector(&vec), index(idx) {}
|
||||
|
||||
inline unsigned int GetIndex() const
|
||||
{ return index; }
|
||||
inline unsigned int GetIndex() const { return index; }
|
||||
|
||||
operator bool() const
|
||||
{ return vector != 0; }
|
||||
operator bool() const { return vector != 0; }
|
||||
|
||||
T* operator->()
|
||||
{ return (*vector)[index]; }
|
||||
T *operator->() { return (*vector)[index]; }
|
||||
|
||||
T& operator*()
|
||||
{ return *((*vector)[index]); }
|
||||
T &operator*() { return *((*vector)[index]); }
|
||||
};
|
||||
|
||||
//! Helper struct to represent values that might not be present
|
||||
template <class T>
|
||||
struct Nullable
|
||||
{
|
||||
struct Nullable {
|
||||
T value;
|
||||
bool isPresent;
|
||||
|
||||
Nullable() : isPresent(false) {}
|
||||
Nullable(T& val) : value(val), isPresent(true) {}
|
||||
Nullable() :
|
||||
isPresent(false) {}
|
||||
Nullable(T &val) :
|
||||
value(val), isPresent(true) {}
|
||||
};
|
||||
|
||||
|
||||
//! Base class for all glTF top-level objects
|
||||
struct Object
|
||||
{
|
||||
struct Object {
|
||||
int index; //!< The index of this object within its property container
|
||||
int oIndex; //!< The original index of this object defined in the JSON
|
||||
std::string id; //!< The globally unique ID used to reference this object
|
||||
std::string name; //!< The user-defined name of this object
|
||||
|
||||
//! Objects marked as special are not exported (used to emulate the binary body buffer)
|
||||
virtual bool IsSpecial() const
|
||||
{ return false; }
|
||||
virtual bool IsSpecial() const { return false; }
|
||||
|
||||
virtual ~Object() {}
|
||||
|
||||
//! Maps special IDs to another ID, where needed. Subclasses may override it (statically)
|
||||
static const char* TranslateId(Asset& /*r*/, const char* id)
|
||||
{ return id; }
|
||||
static const char *TranslateId(Asset & /*r*/, const char *id) { return id; }
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -381,8 +360,7 @@ namespace glTF2
|
|||
//! A typed view into a BufferView. A BufferView contains raw binary data.
|
||||
//! An accessor provides a typed view into a BufferView or a subset of a BufferView
|
||||
//! similar to how WebGL's vertexAttribPointer() defines an attribute in a buffer.
|
||||
struct Accessor : public Object
|
||||
{
|
||||
struct Accessor : public Object {
|
||||
Ref<BufferView> bufferView; //!< The ID of the bufferView. (required)
|
||||
size_t byteOffset; //!< The offset relative to the start of the bufferView in bytes. (required)
|
||||
ComponentType componentType; //!< The datatype of components in the attribute. (required)
|
||||
|
@ -403,8 +381,7 @@ namespace glTF2
|
|||
void WriteData(size_t count, const void *src_buffer, size_t src_stride);
|
||||
|
||||
//! Helper class to iterate the data
|
||||
class Indexer
|
||||
{
|
||||
class Indexer {
|
||||
friend struct Accessor;
|
||||
|
||||
Accessor &accessor;
|
||||
|
@ -414,25 +391,21 @@ namespace glTF2
|
|||
Indexer(Accessor &acc);
|
||||
|
||||
public:
|
||||
|
||||
//! Accesses the i-th value as defined by the accessor
|
||||
template <class T>
|
||||
T GetValue(int i);
|
||||
|
||||
//! Accesses the i-th value as defined by the accessor
|
||||
inline unsigned int GetUInt(int i)
|
||||
{
|
||||
inline unsigned int GetUInt(int i) {
|
||||
return GetValue<unsigned int>(i);
|
||||
}
|
||||
|
||||
inline bool IsValid() const
|
||||
{
|
||||
inline bool IsValid() const {
|
||||
return data != 0;
|
||||
}
|
||||
};
|
||||
|
||||
inline Indexer GetIndexer()
|
||||
{
|
||||
inline Indexer GetIndexer() {
|
||||
return Indexer(*this);
|
||||
}
|
||||
|
||||
|
@ -441,21 +414,17 @@ namespace glTF2
|
|||
};
|
||||
|
||||
//! A buffer points to binary geometry, animation, or skins.
|
||||
struct Buffer : public Object
|
||||
{
|
||||
struct Buffer : public Object {
|
||||
/********************* Types *********************/
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
enum Type {
|
||||
Type_arraybuffer,
|
||||
Type_text
|
||||
};
|
||||
|
||||
/// \struct SEncodedRegion
|
||||
/// Descriptor of encoded region in "bufferView".
|
||||
struct SEncodedRegion
|
||||
{
|
||||
struct SEncodedRegion {
|
||||
const size_t Offset; ///< Offset from begin of "bufferView" to encoded region, in bytes.
|
||||
const size_t EncodedData_Length; ///< Size of encoded region, in bytes.
|
||||
uint8_t *const DecodedData; ///< Cached encoded data.
|
||||
|
@ -469,9 +438,8 @@ namespace glTF2
|
|||
/// \param [in] pDecodedData - pointer to decoded data array.
|
||||
/// \param [in] pDecodedData_Length - size of encoded region, in bytes.
|
||||
/// \param [in] pID - ID of the region.
|
||||
SEncodedRegion(const size_t pOffset, const size_t pEncodedData_Length, uint8_t* pDecodedData, const size_t pDecodedData_Length, const std::string pID)
|
||||
: Offset(pOffset), EncodedData_Length(pEncodedData_Length), DecodedData(pDecodedData), DecodedData_Length(pDecodedData_Length), ID(pID)
|
||||
{}
|
||||
SEncodedRegion(const size_t pOffset, const size_t pEncodedData_Length, uint8_t *pDecodedData, const size_t pDecodedData_Length, const std::string pID) :
|
||||
Offset(pOffset), EncodedData_Length(pEncodedData_Length), DecodedData(pDecodedData), DecodedData_Length(pDecodedData_Length), ID(pID) {}
|
||||
|
||||
/// \fn ~SEncodedRegion()
|
||||
/// Destructor.
|
||||
|
@ -510,7 +478,6 @@ namespace glTF2
|
|||
SEncodedRegion *EncodedRegion_Current;
|
||||
|
||||
private:
|
||||
|
||||
shared_ptr<uint8_t> mData; //!< Pointer to the data
|
||||
bool mIsSpecial; //!< Set to true for special cases (e.g. the body buffer)
|
||||
|
||||
|
@ -521,7 +488,6 @@ namespace glTF2
|
|||
/******************* Functions *******************/
|
||||
|
||||
public:
|
||||
|
||||
Buffer();
|
||||
~Buffer();
|
||||
|
||||
|
@ -556,24 +522,19 @@ namespace glTF2
|
|||
size_t AppendData(uint8_t *data, size_t length);
|
||||
void Grow(size_t amount);
|
||||
|
||||
uint8_t* GetPointer()
|
||||
{ return mData.get(); }
|
||||
uint8_t *GetPointer() { return mData.get(); }
|
||||
|
||||
void MarkAsSpecial()
|
||||
{ mIsSpecial = true; }
|
||||
void MarkAsSpecial() { mIsSpecial = true; }
|
||||
|
||||
bool IsSpecial() const
|
||||
{ return mIsSpecial; }
|
||||
bool IsSpecial() const { return mIsSpecial; }
|
||||
|
||||
std::string GetURI()
|
||||
{ return std::string(this->id) + ".bin"; }
|
||||
std::string GetURI() { return std::string(this->id) + ".bin"; }
|
||||
|
||||
static const char *TranslateId(Asset &r, const char *id);
|
||||
};
|
||||
|
||||
//! A view into a buffer generally representing a subset of the buffer.
|
||||
struct BufferView : public Object
|
||||
{
|
||||
struct BufferView : public Object {
|
||||
Ref<Buffer> buffer; //! The ID of the buffer. (required)
|
||||
size_t byteOffset; //! The offset into the buffer in bytes. (required)
|
||||
size_t byteLength; //! The length of the bufferView in bytes. (default: 0)
|
||||
|
@ -584,18 +545,15 @@ namespace glTF2
|
|||
void Read(Value &obj, Asset &r);
|
||||
};
|
||||
|
||||
struct Camera : public Object
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
struct Camera : public Object {
|
||||
enum Type {
|
||||
Perspective,
|
||||
Orthographic
|
||||
};
|
||||
|
||||
Type type;
|
||||
|
||||
union
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
float aspectRatio; //!<The floating - point aspect ratio of the field of view. (0 = undefined = use the canvas one)
|
||||
float yfov; //!<The floating - point vertical field of view in radians. (required)
|
||||
|
@ -611,19 +569,16 @@ namespace glTF2
|
|||
} ortographic;
|
||||
} cameraProperties;
|
||||
|
||||
Camera()
|
||||
: type(Perspective)
|
||||
, cameraProperties() {
|
||||
Camera() :
|
||||
type(Perspective), cameraProperties() {
|
||||
// empty
|
||||
}
|
||||
void Read(Value &obj, Asset &r);
|
||||
};
|
||||
|
||||
//! A light (from KHR_lights_punctual extension)
|
||||
struct Light : public Object
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
struct Light : public Object {
|
||||
enum Type {
|
||||
Directional,
|
||||
Point,
|
||||
Spot
|
||||
|
@ -643,8 +598,7 @@ namespace glTF2
|
|||
};
|
||||
|
||||
//! Image data used to create a texture.
|
||||
struct Image : public Object
|
||||
{
|
||||
struct Image : public Object {
|
||||
std::string uri; //! The uri of the image, that can be a file path, a data URI, etc.. (required)
|
||||
|
||||
Ref<BufferView> bufferView;
|
||||
|
@ -658,18 +612,14 @@ namespace glTF2
|
|||
size_t mDataLength;
|
||||
|
||||
public:
|
||||
|
||||
Image();
|
||||
void Read(Value &obj, Asset &r);
|
||||
|
||||
inline bool HasData() const
|
||||
{ return mDataLength > 0; }
|
||||
inline bool HasData() const { return mDataLength > 0; }
|
||||
|
||||
inline size_t GetDataLength() const
|
||||
{ return mDataLength; }
|
||||
inline size_t GetDataLength() const { return mDataLength; }
|
||||
|
||||
inline const uint8_t* GetData() const
|
||||
{ return mData.get(); }
|
||||
inline const uint8_t *GetData() const { return mData.get(); }
|
||||
|
||||
inline uint8_t *StealData();
|
||||
|
||||
|
@ -681,8 +631,7 @@ namespace glTF2
|
|||
const vec4 defaultDiffuseFactor = { 1, 1, 1, 1 };
|
||||
const vec3 defaultSpecularFactor = { 1, 1, 1 };
|
||||
|
||||
struct TextureInfo
|
||||
{
|
||||
struct TextureInfo {
|
||||
Ref<Texture> texture;
|
||||
unsigned int index;
|
||||
unsigned int texCoord = 0;
|
||||
|
@ -695,18 +644,15 @@ namespace glTF2
|
|||
} TextureTransformExt_t;
|
||||
};
|
||||
|
||||
struct NormalTextureInfo : TextureInfo
|
||||
{
|
||||
struct NormalTextureInfo : TextureInfo {
|
||||
float scale = 1;
|
||||
};
|
||||
|
||||
struct OcclusionTextureInfo : TextureInfo
|
||||
{
|
||||
struct OcclusionTextureInfo : TextureInfo {
|
||||
float strength = 1;
|
||||
};
|
||||
|
||||
struct PbrMetallicRoughness
|
||||
{
|
||||
struct PbrMetallicRoughness {
|
||||
vec4 baseColorFactor;
|
||||
TextureInfo baseColorTexture;
|
||||
TextureInfo metallicRoughnessTexture;
|
||||
|
@ -714,8 +660,7 @@ namespace glTF2
|
|||
float roughnessFactor;
|
||||
};
|
||||
|
||||
struct PbrSpecularGlossiness
|
||||
{
|
||||
struct PbrSpecularGlossiness {
|
||||
vec4 diffuseFactor;
|
||||
vec3 specularFactor;
|
||||
float glossinessFactor;
|
||||
|
@ -727,8 +672,7 @@ namespace glTF2
|
|||
};
|
||||
|
||||
//! The material appearance of a primitive.
|
||||
struct Material : public Object
|
||||
{
|
||||
struct Material : public Object {
|
||||
//PBR metallic roughness properties
|
||||
PbrMetallicRoughness pbrMetallicRoughness;
|
||||
|
||||
|
@ -753,12 +697,10 @@ namespace glTF2
|
|||
};
|
||||
|
||||
//! A set of primitives to be rendered. A node can contain one or more meshes. A node's transform places the mesh in the scene.
|
||||
struct Mesh : public Object
|
||||
{
|
||||
struct Mesh : public Object {
|
||||
typedef std::vector<Ref<Accessor>> AccessorList;
|
||||
|
||||
struct Primitive
|
||||
{
|
||||
struct Primitive {
|
||||
PrimitiveMode mode;
|
||||
|
||||
struct Attributes {
|
||||
|
@ -788,8 +730,7 @@ namespace glTF2
|
|||
void Read(Value &pJSON_Object, Asset &pAsset_Root);
|
||||
};
|
||||
|
||||
struct Node : public Object
|
||||
{
|
||||
struct Node : public Object {
|
||||
std::vector<Ref<Node>> children;
|
||||
std::vector<Ref<Mesh>> meshes;
|
||||
|
||||
|
@ -811,15 +752,12 @@ namespace glTF2
|
|||
void Read(Value &obj, Asset &r);
|
||||
};
|
||||
|
||||
struct Program : public Object
|
||||
{
|
||||
struct Program : public Object {
|
||||
Program() {}
|
||||
void Read(Value &obj, Asset &r);
|
||||
};
|
||||
|
||||
|
||||
struct Sampler : public Object
|
||||
{
|
||||
struct Sampler : public Object {
|
||||
SamplerMagFilter magFilter; //!< The texture magnification filter.
|
||||
SamplerMinFilter minFilter; //!< The texture minification filter.
|
||||
SamplerWrap wrapS; //!< The texture wrapping in the S direction.
|
||||
|
@ -830,22 +768,19 @@ namespace glTF2
|
|||
void SetDefaults();
|
||||
};
|
||||
|
||||
struct Scene : public Object
|
||||
{
|
||||
struct Scene : public Object {
|
||||
std::vector<Ref<Node>> nodes;
|
||||
|
||||
Scene() {}
|
||||
void Read(Value &obj, Asset &r);
|
||||
};
|
||||
|
||||
struct Shader : public Object
|
||||
{
|
||||
struct Shader : public Object {
|
||||
Shader() {}
|
||||
void Read(Value &obj, Asset &r);
|
||||
};
|
||||
|
||||
struct Skin : public Object
|
||||
{
|
||||
struct Skin : public Object {
|
||||
Nullable<mat4> bindShapeMatrix; //!< Floating-point 4x4 transformation matrix stored in column-major order.
|
||||
Ref<Accessor> inverseBindMatrices; //!< The ID of the accessor containing the floating-point 4x4 inverse-bind matrices.
|
||||
std::vector<Ref<Node>> jointNames; //!< Joint names of the joints (nodes with a jointName property) in this skin.
|
||||
|
@ -856,8 +791,7 @@ namespace glTF2
|
|||
};
|
||||
|
||||
//! A texture and its sampler.
|
||||
struct Texture : public Object
|
||||
{
|
||||
struct Texture : public Object {
|
||||
Ref<Sampler> sampler; //!< The ID of the sampler used by this texture. (required)
|
||||
Ref<Image> source; //!< The ID of the image used by this texture. (required)
|
||||
|
||||
|
@ -871,10 +805,10 @@ namespace glTF2
|
|||
void Read(Value &obj, Asset &r);
|
||||
};
|
||||
|
||||
struct Animation : public Object
|
||||
{
|
||||
struct Animation : public Object {
|
||||
struct Sampler {
|
||||
Sampler() : interpolation(Interpolation_LINEAR) {}
|
||||
Sampler() :
|
||||
interpolation(Interpolation_LINEAR) {}
|
||||
|
||||
Ref<Accessor> input; //!< Accessor reference to the buffer storing the key-frame times.
|
||||
Ref<Accessor> output; //!< Accessor reference to the buffer storing the key-frame values.
|
||||
|
@ -882,14 +816,16 @@ namespace glTF2
|
|||
};
|
||||
|
||||
struct Target {
|
||||
Target() : path(AnimationPath_TRANSLATION) {}
|
||||
Target() :
|
||||
path(AnimationPath_TRANSLATION) {}
|
||||
|
||||
Ref<Node> node; //!< The node to animate.
|
||||
AnimationPath path; //!< The property of the node to animate.
|
||||
};
|
||||
|
||||
struct Channel {
|
||||
Channel() : sampler(-1) {}
|
||||
Channel() :
|
||||
sampler(-1) {}
|
||||
|
||||
int sampler; //!< The sampler index containing the animation data.
|
||||
Target target; //!< The node and property to animate.
|
||||
|
@ -903,8 +839,7 @@ namespace glTF2
|
|||
};
|
||||
|
||||
//! Base class for LazyDict that acts as an interface
|
||||
class LazyDictBase
|
||||
{
|
||||
class LazyDictBase {
|
||||
public:
|
||||
virtual ~LazyDictBase() {}
|
||||
|
||||
|
@ -914,7 +849,6 @@ namespace glTF2
|
|||
virtual void WriteObjects(AssetWriter &writer) = 0;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class LazyDict;
|
||||
|
||||
|
@ -922,12 +856,10 @@ namespace glTF2
|
|||
template <class T>
|
||||
void WriteLazyDict(LazyDict<T> &d, AssetWriter &w);
|
||||
|
||||
|
||||
//! Manages lazy loading of the glTF top-level objects, and keeps a reference to them by ID
|
||||
//! It is the owner the loaded objects, so when it is destroyed it also deletes them
|
||||
template <class T>
|
||||
class LazyDict : public LazyDictBase
|
||||
{
|
||||
class LazyDict : public LazyDictBase {
|
||||
friend class Asset;
|
||||
friend class AssetWriter;
|
||||
|
||||
|
@ -945,8 +877,7 @@ namespace glTF2
|
|||
void AttachToDocument(Document &doc);
|
||||
void DetachFromDocument();
|
||||
|
||||
void WriteObjects(AssetWriter& writer)
|
||||
{ WriteLazyDict<T>(*this, writer); }
|
||||
void WriteObjects(AssetWriter &writer) { WriteLazyDict<T>(*this, writer); }
|
||||
|
||||
Ref<T> Add(T *obj);
|
||||
|
||||
|
@ -960,22 +891,16 @@ namespace glTF2
|
|||
Ref<T> Get(const char *id);
|
||||
|
||||
Ref<T> Create(const char *id);
|
||||
Ref<T> Create(const std::string& id)
|
||||
{ return Create(id.c_str()); }
|
||||
Ref<T> Create(const std::string &id) { return Create(id.c_str()); }
|
||||
|
||||
unsigned int Remove(const char *id);
|
||||
|
||||
inline unsigned int Size() const
|
||||
{ return unsigned(mObjs.size()); }
|
||||
|
||||
inline T& operator[](size_t i)
|
||||
{ return *mObjs[i]; }
|
||||
inline unsigned int Size() const { return unsigned(mObjs.size()); }
|
||||
|
||||
inline T &operator[](size_t i) { return *mObjs[i]; }
|
||||
};
|
||||
|
||||
|
||||
struct AssetMetadata
|
||||
{
|
||||
struct AssetMetadata {
|
||||
std::string copyright; //!< A copyright message suitable for display to credit the content creator.
|
||||
std::string generator; //!< Tool that generated this glTF model.Useful for debugging.
|
||||
|
||||
|
@ -988,7 +913,8 @@ namespace glTF2
|
|||
|
||||
void Read(Document &doc);
|
||||
|
||||
AssetMetadata() : version("") {}
|
||||
AssetMetadata() :
|
||||
version("") {}
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -996,8 +922,7 @@ namespace glTF2
|
|||
//
|
||||
|
||||
//! Root object for a glTF asset
|
||||
class Asset
|
||||
{
|
||||
class Asset {
|
||||
typedef std::gltf_unordered_map<std::string, int> IdMap;
|
||||
|
||||
template <class T>
|
||||
|
@ -1025,10 +950,8 @@ namespace glTF2
|
|||
Asset &operator=(const Asset &);
|
||||
|
||||
public:
|
||||
|
||||
//! Keeps info about the enabled extensions
|
||||
struct Extensions
|
||||
{
|
||||
struct Extensions {
|
||||
bool KHR_materials_pbrSpecularGlossiness;
|
||||
bool KHR_materials_unlit;
|
||||
bool KHR_lights_punctual;
|
||||
|
@ -1036,14 +959,12 @@ namespace glTF2
|
|||
} extensionsUsed;
|
||||
|
||||
//! Keeps info about the required extensions
|
||||
struct RequiredExtensions
|
||||
{
|
||||
struct RequiredExtensions {
|
||||
bool KHR_draco_mesh_compression;
|
||||
} extensionsRequired;
|
||||
|
||||
AssetMetadata asset;
|
||||
|
||||
|
||||
// Dictionaries for each type of object
|
||||
|
||||
LazyDict<Accessor> accessors;
|
||||
|
@ -1064,24 +985,8 @@ namespace glTF2
|
|||
Ref<Scene> scene;
|
||||
|
||||
public:
|
||||
Asset(IOSystem* io = 0)
|
||||
: mIOSystem(io)
|
||||
, asset()
|
||||
, accessors (*this, "accessors")
|
||||
, animations (*this, "animations")
|
||||
, buffers (*this, "buffers")
|
||||
, bufferViews (*this, "bufferViews")
|
||||
, cameras (*this, "cameras")
|
||||
, lights (*this, "lights", "KHR_lights_punctual")
|
||||
, images (*this, "images")
|
||||
, materials (*this, "materials")
|
||||
, meshes (*this, "meshes")
|
||||
, nodes (*this, "nodes")
|
||||
, samplers (*this, "samplers")
|
||||
, scenes (*this, "scenes")
|
||||
, skins (*this, "skins")
|
||||
, textures (*this, "textures")
|
||||
{
|
||||
Asset(IOSystem *io = 0) :
|
||||
mIOSystem(io), asset(), accessors(*this, "accessors"), animations(*this, "animations"), buffers(*this, "buffers"), bufferViews(*this, "bufferViews"), cameras(*this, "cameras"), lights(*this, "lights", "KHR_lights_punctual"), images(*this, "images"), materials(*this, "materials"), meshes(*this, "meshes"), nodes(*this, "nodes"), samplers(*this, "samplers"), scenes(*this, "scenes"), skins(*this, "skins"), textures(*this, "textures") {
|
||||
memset(&extensionsUsed, 0, sizeof(extensionsUsed));
|
||||
memset(&extensionsRequired, 0, sizeof(extensionsRequired));
|
||||
}
|
||||
|
@ -1095,8 +1000,7 @@ namespace glTF2
|
|||
//! Search for an available name, starting from the given strings
|
||||
std::string FindUniqueID(const std::string &str, const char *suffix);
|
||||
|
||||
Ref<Buffer> GetBodyBuffer()
|
||||
{ return mBodyBuffer; }
|
||||
Ref<Buffer> GetBodyBuffer() { return mBodyBuffer; }
|
||||
|
||||
private:
|
||||
void ReadBinaryHeader(IOStream &stream, std::vector<char> &sceneData);
|
||||
|
@ -1107,7 +1011,7 @@ namespace glTF2
|
|||
IOStream *OpenFile(std::string path, const char *mode, bool absolute = false);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace glTF2
|
||||
|
||||
// Include the implementation of the methods
|
||||
#include "glTF2Asset.inl"
|
||||
|
|
|
@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "glTF/glTFCommon.h"
|
||||
#include <assimp/StringUtils.h>
|
||||
|
||||
// Header files, Assimp
|
||||
|
@ -1328,8 +1329,10 @@ inline void Asset::ReadBinaryHeader(IOStream &stream, std::vector<char> &sceneDa
|
|||
|
||||
inline void Asset::Load(const std::string &pFile, bool isBinary) {
|
||||
mCurrentAssetDir.clear();
|
||||
int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
|
||||
if (pos != int(std::string::npos)) mCurrentAssetDir = pFile.substr(0, pos + 1);
|
||||
/*int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
|
||||
if (pos != int(std::string::npos)) */
|
||||
|
||||
mCurrentAssetDir = glTFCommon::getCurrentAssetDir(pFile);
|
||||
|
||||
shared_ptr<IOStream> stream(OpenFile(pFile.c_str(), "rb", true));
|
||||
if (!stream) {
|
||||
|
|
|
@ -110,8 +110,9 @@ const aiImporterDesc *glTF2Importer::GetInfo() const {
|
|||
bool glTF2Importer::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /* checkSig */) const {
|
||||
const std::string &extension = GetExtension(pFile);
|
||||
|
||||
if (extension != "gltf" && extension != "glb")
|
||||
if (extension != "gltf" && extension != "glb") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pIOHandler) {
|
||||
glTF2::Asset asset(pIOHandler);
|
||||
|
|
Loading…
Reference in New Issue