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