fix read for precision-depending data.
parent
dc04759492
commit
255758e6ff
|
@ -53,16 +53,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "Assbin/AssbinLoader.h"
|
#include "Assbin/AssbinLoader.h"
|
||||||
#include "Common/assbin_chunks.h"
|
#include "Common/assbin_chunks.h"
|
||||||
#include <assimp/MemoryIOWrapper.h>
|
#include <assimp/MemoryIOWrapper.h>
|
||||||
#include <assimp/mesh.h>
|
|
||||||
#include <assimp/anim.h>
|
#include <assimp/anim.h>
|
||||||
#include <assimp/scene.h>
|
|
||||||
#include <assimp/importerdesc.h>
|
#include <assimp/importerdesc.h>
|
||||||
|
#include <assimp/mesh.h>
|
||||||
|
#include <assimp/scene.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
|
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
|
||||||
# include <zlib.h>
|
#include <zlib.h>
|
||||||
#else
|
#else
|
||||||
# include <contrib/zlib/zlib.h>
|
#include <contrib/zlib/zlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
@ -81,94 +81,96 @@ static const aiImporterDesc desc = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
const aiImporterDesc* AssbinImporter::GetInfo() const {
|
const aiImporterDesc *AssbinImporter::GetInfo() const {
|
||||||
return &desc;
|
return &desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
bool AssbinImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/ ) const {
|
bool AssbinImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
|
||||||
IOStream * in = pIOHandler->Open(pFile);
|
IOStream *in = pIOHandler->Open(pFile);
|
||||||
if (nullptr == in) {
|
if (nullptr == in) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char s[32];
|
char s[32];
|
||||||
in->Read( s, sizeof(char), 32 );
|
in->Read(s, sizeof(char), 32);
|
||||||
|
|
||||||
pIOHandler->Close(in);
|
pIOHandler->Close(in);
|
||||||
|
|
||||||
return strncmp( s, "ASSIMP.binary-dump.", 19 ) == 0;
|
return strncmp(s, "ASSIMP.binary-dump.", 19) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
template <typename T>
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
template <>
|
template <>
|
||||||
aiVector3D Read<aiVector3D>(IOStream * stream) {
|
aiVector3D Read<aiVector3D>(IOStream *stream) {
|
||||||
aiVector3D v;
|
aiVector3D v;
|
||||||
v.x = Read<float>(stream);
|
v.x = Read<ai_real>(stream);
|
||||||
v.y = Read<float>(stream);
|
v.y = Read<ai_real>(stream);
|
||||||
v.z = Read<float>(stream);
|
v.z = Read<ai_real>(stream);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
template <>
|
template <>
|
||||||
aiColor4D Read<aiColor4D>(IOStream * stream) {
|
aiColor4D Read<aiColor4D>(IOStream *stream) {
|
||||||
aiColor4D c;
|
aiColor4D c;
|
||||||
c.r = Read<float>(stream);
|
c.r = Read<ai_real>(stream);
|
||||||
c.g = Read<float>(stream);
|
c.g = Read<ai_real>(stream);
|
||||||
c.b = Read<float>(stream);
|
c.b = Read<ai_real>(stream);
|
||||||
c.a = Read<float>(stream);
|
c.a = Read<ai_real>(stream);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
template <>
|
template <>
|
||||||
aiQuaternion Read<aiQuaternion>(IOStream * stream) {
|
aiQuaternion Read<aiQuaternion>(IOStream *stream) {
|
||||||
aiQuaternion v;
|
aiQuaternion v;
|
||||||
v.w = Read<float>(stream);
|
v.w = Read<ai_real>(stream);
|
||||||
v.x = Read<float>(stream);
|
v.x = Read<ai_real>(stream);
|
||||||
v.y = Read<float>(stream);
|
v.y = Read<ai_real>(stream);
|
||||||
v.z = Read<float>(stream);
|
v.z = Read<ai_real>(stream);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
template <>
|
template <>
|
||||||
aiString Read<aiString>(IOStream * stream) {
|
aiString Read<aiString>(IOStream *stream) {
|
||||||
aiString s;
|
aiString s;
|
||||||
stream->Read(&s.length,4,1);
|
stream->Read(&s.length, 4, 1);
|
||||||
if(s.length)
|
if (s.length) {
|
||||||
stream->Read(s.data,s.length,1);
|
stream->Read(s.data, s.length, 1);
|
||||||
|
}
|
||||||
s.data[s.length] = 0;
|
s.data[s.length] = 0;
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
template <>
|
template <>
|
||||||
aiVertexWeight Read<aiVertexWeight>(IOStream * stream) {
|
aiVertexWeight Read<aiVertexWeight>(IOStream *stream) {
|
||||||
aiVertexWeight w;
|
aiVertexWeight w;
|
||||||
w.mVertexId = Read<unsigned int>(stream);
|
w.mVertexId = Read<unsigned int>(stream);
|
||||||
w.mWeight = Read<float>(stream);
|
w.mWeight = Read<ai_real>(stream);
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
template <>
|
template <>
|
||||||
aiMatrix4x4 Read<aiMatrix4x4>(IOStream * stream) {
|
aiMatrix4x4 Read<aiMatrix4x4>(IOStream *stream) {
|
||||||
aiMatrix4x4 m;
|
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) {
|
||||||
m[i][i2] = Read<float>(stream);
|
m[i][i2] = Read<ai_real>(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m;
|
return m;
|
||||||
|
@ -176,7 +178,7 @@ aiMatrix4x4 Read<aiMatrix4x4>(IOStream * stream) {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
template <>
|
template <>
|
||||||
aiVectorKey Read<aiVectorKey>(IOStream * stream) {
|
aiVectorKey Read<aiVectorKey>(IOStream *stream) {
|
||||||
aiVectorKey v;
|
aiVectorKey v;
|
||||||
v.mTime = Read<double>(stream);
|
v.mTime = Read<double>(stream);
|
||||||
v.mValue = Read<aiVector3D>(stream);
|
v.mValue = Read<aiVector3D>(stream);
|
||||||
|
@ -185,7 +187,7 @@ aiVectorKey Read<aiVectorKey>(IOStream * stream) {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
template <>
|
template <>
|
||||||
aiQuatKey Read<aiQuatKey>(IOStream * stream) {
|
aiQuatKey Read<aiQuatKey>(IOStream *stream) {
|
||||||
aiQuatKey v;
|
aiQuatKey v;
|
||||||
v.mTime = Read<double>(stream);
|
v.mTime = Read<double>(stream);
|
||||||
v.mValue = Read<aiQuaternion>(stream);
|
v.mValue = Read<aiQuaternion>(stream);
|
||||||
|
@ -194,27 +196,27 @@ aiQuatKey Read<aiQuatKey>(IOStream * stream) {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void ReadArray( IOStream *stream, T * out, unsigned int size) {
|
void ReadArray(IOStream *stream, T *out, unsigned int size) {
|
||||||
ai_assert( nullptr != stream );
|
ai_assert(nullptr != stream);
|
||||||
ai_assert( nullptr != out );
|
ai_assert(nullptr != out);
|
||||||
|
|
||||||
for (unsigned int i=0; i<size; i++) {
|
for (unsigned int i = 0; i < size; i++) {
|
||||||
out[i] = Read<T>(stream);
|
out[i] = Read<T>(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void ReadBounds( IOStream * stream, T* /*p*/, unsigned int n ) {
|
void ReadBounds(IOStream *stream, T * /*p*/, unsigned int n) {
|
||||||
// not sure what to do here, the data isn't really useful.
|
// not sure what to do here, the data isn't really useful.
|
||||||
stream->Seek( sizeof(T) * n, aiOrigin_CUR );
|
stream->Seek(sizeof(T) * n, aiOrigin_CUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** onode, aiNode* parent ) {
|
void AssbinImporter::ReadBinaryNode(IOStream *stream, aiNode **onode, aiNode *parent) {
|
||||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AINODE)
|
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AINODE)
|
||||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
/*uint32_t size =*/Read<uint32_t>(stream);
|
||||||
|
|
||||||
std::unique_ptr<aiNode> node(new aiNode());
|
std::unique_ptr<aiNode> node(new aiNode());
|
||||||
|
|
||||||
|
@ -222,14 +224,13 @@ void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** onode, aiNode*
|
||||||
node->mTransformation = Read<aiMatrix4x4>(stream);
|
node->mTransformation = Read<aiMatrix4x4>(stream);
|
||||||
unsigned numChildren = Read<unsigned int>(stream);
|
unsigned numChildren = Read<unsigned int>(stream);
|
||||||
unsigned numMeshes = Read<unsigned int>(stream);
|
unsigned numMeshes = Read<unsigned int>(stream);
|
||||||
unsigned int nb_metadata = Read<unsigned int>(stream);
|
unsigned int nb_metadata = Read<unsigned int>(stream);
|
||||||
|
|
||||||
if(parent) {
|
if (parent) {
|
||||||
node->mParent = parent;
|
node->mParent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numMeshes)
|
if (numMeshes) {
|
||||||
{
|
|
||||||
node->mMeshes = new unsigned int[numMeshes];
|
node->mMeshes = new unsigned int[numMeshes];
|
||||||
for (unsigned int i = 0; i < numMeshes; ++i) {
|
for (unsigned int i = 0; i < numMeshes; ++i) {
|
||||||
node->mMeshes[i] = Read<unsigned int>(stream);
|
node->mMeshes[i] = Read<unsigned int>(stream);
|
||||||
|
@ -238,19 +239,19 @@ void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** onode, aiNode*
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numChildren) {
|
if (numChildren) {
|
||||||
node->mChildren = new aiNode*[numChildren];
|
node->mChildren = new aiNode *[numChildren];
|
||||||
for (unsigned int i = 0; i < numChildren; ++i) {
|
for (unsigned int i = 0; i < numChildren; ++i) {
|
||||||
ReadBinaryNode( stream, &node->mChildren[i], node.get() );
|
ReadBinaryNode(stream, &node->mChildren[i], node.get());
|
||||||
node->mNumChildren++;
|
node->mNumChildren++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( nb_metadata > 0 ) {
|
if (nb_metadata > 0) {
|
||||||
node->mMetaData = aiMetadata::Alloc(nb_metadata);
|
node->mMetaData = aiMetadata::Alloc(nb_metadata);
|
||||||
for (unsigned int i = 0; i < nb_metadata; ++i) {
|
for (unsigned int i = 0; i < nb_metadata; ++i) {
|
||||||
node->mMetaData->mKeys[i] = Read<aiString>(stream);
|
node->mMetaData->mKeys[i] = Read<aiString>(stream);
|
||||||
node->mMetaData->mValues[i].mType = (aiMetadataType) Read<uint16_t>(stream);
|
node->mMetaData->mValues[i].mType = (aiMetadataType)Read<uint16_t>(stream);
|
||||||
void* data = nullptr;
|
void *data = nullptr;
|
||||||
|
|
||||||
switch (node->mMetaData->mValues[i].mType) {
|
switch (node->mMetaData->mValues[i].mType) {
|
||||||
case AI_BOOL:
|
case AI_BOOL:
|
||||||
|
@ -263,7 +264,7 @@ void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** onode, aiNode*
|
||||||
data = new uint64_t(Read<uint64_t>(stream));
|
data = new uint64_t(Read<uint64_t>(stream));
|
||||||
break;
|
break;
|
||||||
case AI_FLOAT:
|
case AI_FLOAT:
|
||||||
data = new float(Read<float>(stream));
|
data = new ai_real(Read<ai_real>(stream));
|
||||||
break;
|
break;
|
||||||
case AI_DOUBLE:
|
case AI_DOUBLE:
|
||||||
data = new double(Read<double>(stream));
|
data = new double(Read<double>(stream));
|
||||||
|
@ -281,17 +282,17 @@ void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** onode, aiNode*
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
node->mMetaData->mValues[i].mData = data;
|
node->mMetaData->mValues[i].mData = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*onode = node.release();
|
*onode = node.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void AssbinImporter::ReadBinaryBone( IOStream * stream, aiBone* b ) {
|
void AssbinImporter::ReadBinaryBone(IOStream *stream, aiBone *b) {
|
||||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AIBONE)
|
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AIBONE)
|
||||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
/*uint32_t size =*/Read<uint32_t>(stream);
|
||||||
|
|
||||||
b->mName = Read<aiString>(stream);
|
b->mName = Read<aiString>(stream);
|
||||||
b->mNumWeights = Read<unsigned int>(stream);
|
b->mNumWeights = Read<unsigned int>(stream);
|
||||||
|
@ -300,23 +301,23 @@ void AssbinImporter::ReadBinaryBone( IOStream * stream, aiBone* b ) {
|
||||||
// for the moment we write dumb min/max values for the bones, too.
|
// for the moment we write dumb min/max values for the bones, too.
|
||||||
// maybe I'll add a better, hash-like solution later
|
// maybe I'll add a better, hash-like solution later
|
||||||
if (shortened) {
|
if (shortened) {
|
||||||
ReadBounds(stream,b->mWeights,b->mNumWeights);
|
ReadBounds(stream, b->mWeights, b->mNumWeights);
|
||||||
} else {
|
} else {
|
||||||
// else write as usual
|
// else write as usual
|
||||||
b->mWeights = new aiVertexWeight[b->mNumWeights];
|
b->mWeights = new aiVertexWeight[b->mNumWeights];
|
||||||
ReadArray<aiVertexWeight>(stream,b->mWeights,b->mNumWeights);
|
ReadArray<aiVertexWeight>(stream, b->mWeights, b->mNumWeights);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
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)
|
||||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
/*uint32_t size =*/Read<uint32_t>(stream);
|
||||||
|
|
||||||
mesh->mPrimitiveTypes = Read<unsigned int>(stream);
|
mesh->mPrimitiveTypes = Read<unsigned int>(stream);
|
||||||
mesh->mNumVertices = Read<unsigned int>(stream);
|
mesh->mNumVertices = Read<unsigned int>(stream);
|
||||||
|
@ -329,48 +330,48 @@ void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh ) {
|
||||||
|
|
||||||
if (c & ASSBIN_MESH_HAS_POSITIONS) {
|
if (c & ASSBIN_MESH_HAS_POSITIONS) {
|
||||||
if (shortened) {
|
if (shortened) {
|
||||||
ReadBounds(stream,mesh->mVertices,mesh->mNumVertices);
|
ReadBounds(stream, mesh->mVertices, mesh->mNumVertices);
|
||||||
} else {
|
} else {
|
||||||
// else write as usual
|
// else write as usual
|
||||||
mesh->mVertices = new aiVector3D[mesh->mNumVertices];
|
mesh->mVertices = new aiVector3D[mesh->mNumVertices];
|
||||||
ReadArray<aiVector3D>(stream,mesh->mVertices,mesh->mNumVertices);
|
ReadArray<aiVector3D>(stream, mesh->mVertices, mesh->mNumVertices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c & ASSBIN_MESH_HAS_NORMALS) {
|
if (c & ASSBIN_MESH_HAS_NORMALS) {
|
||||||
if (shortened) {
|
if (shortened) {
|
||||||
ReadBounds(stream,mesh->mNormals,mesh->mNumVertices);
|
ReadBounds(stream, mesh->mNormals, mesh->mNumVertices);
|
||||||
} else {
|
} else {
|
||||||
// else write as usual
|
// else write as usual
|
||||||
mesh->mNormals = new aiVector3D[mesh->mNumVertices];
|
mesh->mNormals = new aiVector3D[mesh->mNumVertices];
|
||||||
ReadArray<aiVector3D>(stream,mesh->mNormals,mesh->mNumVertices);
|
ReadArray<aiVector3D>(stream, mesh->mNormals, mesh->mNumVertices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c & ASSBIN_MESH_HAS_TANGENTS_AND_BITANGENTS) {
|
if (c & ASSBIN_MESH_HAS_TANGENTS_AND_BITANGENTS) {
|
||||||
if (shortened) {
|
if (shortened) {
|
||||||
ReadBounds(stream,mesh->mTangents,mesh->mNumVertices);
|
ReadBounds(stream, mesh->mTangents, mesh->mNumVertices);
|
||||||
ReadBounds(stream,mesh->mBitangents,mesh->mNumVertices);
|
ReadBounds(stream, mesh->mBitangents, mesh->mNumVertices);
|
||||||
} else {
|
} else {
|
||||||
// else write as usual
|
// else write as usual
|
||||||
mesh->mTangents = new aiVector3D[mesh->mNumVertices];
|
mesh->mTangents = new aiVector3D[mesh->mNumVertices];
|
||||||
ReadArray<aiVector3D>(stream,mesh->mTangents,mesh->mNumVertices);
|
ReadArray<aiVector3D>(stream, mesh->mTangents, mesh->mNumVertices);
|
||||||
mesh->mBitangents = new aiVector3D[mesh->mNumVertices];
|
mesh->mBitangents = new aiVector3D[mesh->mNumVertices];
|
||||||
ReadArray<aiVector3D>(stream,mesh->mBitangents,mesh->mNumVertices);
|
ReadArray<aiVector3D>(stream, mesh->mBitangents, mesh->mNumVertices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_COLOR_SETS;++n) {
|
for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_COLOR_SETS; ++n) {
|
||||||
if (!(c & ASSBIN_MESH_HAS_COLOR(n))) {
|
if (!(c & ASSBIN_MESH_HAS_COLOR(n))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shortened) {
|
if (shortened) {
|
||||||
ReadBounds(stream,mesh->mColors[n],mesh->mNumVertices);
|
ReadBounds(stream, mesh->mColors[n], mesh->mNumVertices);
|
||||||
} else {
|
} else {
|
||||||
// else write as usual
|
// else write as usual
|
||||||
mesh->mColors[n] = new aiColor4D[mesh->mNumVertices];
|
mesh->mColors[n] = new aiColor4D[mesh->mNumVertices];
|
||||||
ReadArray<aiColor4D>(stream,mesh->mColors[n],mesh->mNumVertices);
|
ReadArray<aiColor4D>(stream, 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 (!(c & ASSBIN_MESH_HAS_TEXCOORD(n))) {
|
if (!(c & ASSBIN_MESH_HAS_TEXCOORD(n))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -379,11 +380,11 @@ void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh ) {
|
||||||
mesh->mNumUVComponents[n] = Read<unsigned int>(stream);
|
mesh->mNumUVComponents[n] = Read<unsigned int>(stream);
|
||||||
|
|
||||||
if (shortened) {
|
if (shortened) {
|
||||||
ReadBounds(stream,mesh->mTextureCoords[n],mesh->mNumVertices);
|
ReadBounds(stream, mesh->mTextureCoords[n], mesh->mNumVertices);
|
||||||
} else {
|
} else {
|
||||||
// else write as usual
|
// else write as usual
|
||||||
mesh->mTextureCoords[n] = new aiVector3D[mesh->mNumVertices];
|
mesh->mTextureCoords[n] = new aiVector3D[mesh->mNumVertices];
|
||||||
ReadArray<aiVector3D>(stream,mesh->mTextureCoords[n],mesh->mNumVertices);
|
ReadArray<aiVector3D>(stream, mesh->mTextureCoords[n], mesh->mNumVertices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,20 +394,20 @@ void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh ) {
|
||||||
// using Assimp's standard hashing function.
|
// using Assimp's standard hashing function.
|
||||||
if (shortened) {
|
if (shortened) {
|
||||||
Read<unsigned int>(stream);
|
Read<unsigned int>(stream);
|
||||||
} else {
|
} else {
|
||||||
// else write as usual
|
// 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 ...
|
||||||
mesh->mFaces = new aiFace[mesh->mNumFaces];
|
mesh->mFaces = new aiFace[mesh->mNumFaces];
|
||||||
for (unsigned int i = 0; i < mesh->mNumFaces;++i) {
|
for (unsigned int i = 0; i < mesh->mNumFaces; ++i) {
|
||||||
aiFace& f = mesh->mFaces[i];
|
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");
|
||||||
f.mNumIndices = Read<uint16_t>(stream);
|
f.mNumIndices = Read<uint16_t>(stream);
|
||||||
f.mIndices = new unsigned int[f.mNumIndices];
|
f.mIndices = new unsigned int[f.mNumIndices];
|
||||||
|
|
||||||
for (unsigned int a = 0; a < f.mNumIndices;++a) {
|
for (unsigned int a = 0; a < f.mNumIndices; ++a) {
|
||||||
// Check if unsigned short ( 16 bit ) are big enought for the indices
|
// Check if unsigned short ( 16 bit ) are big enought for the indices
|
||||||
if ( fitsIntoUI16( mesh->mNumVertices ) ) {
|
if (fitsIntoUI16(mesh->mNumVertices)) {
|
||||||
f.mIndices[a] = Read<uint16_t>(stream);
|
f.mIndices[a] = Read<uint16_t>(stream);
|
||||||
} else {
|
} else {
|
||||||
f.mIndices[a] = Read<unsigned int>(stream);
|
f.mIndices[a] = Read<unsigned int>(stream);
|
||||||
|
@ -417,19 +418,19 @@ void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh ) {
|
||||||
|
|
||||||
// write bones
|
// write bones
|
||||||
if (mesh->mNumBones) {
|
if (mesh->mNumBones) {
|
||||||
mesh->mBones = new C_STRUCT aiBone*[mesh->mNumBones];
|
mesh->mBones = new C_STRUCT aiBone *[mesh->mNumBones];
|
||||||
for (unsigned int a = 0; a < mesh->mNumBones;++a) {
|
for (unsigned int a = 0; a < mesh->mNumBones; ++a) {
|
||||||
mesh->mBones[a] = new aiBone();
|
mesh->mBones[a] = new aiBone();
|
||||||
ReadBinaryBone(stream,mesh->mBones[a]);
|
ReadBinaryBone(stream, mesh->mBones[a]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void AssbinImporter::ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop) {
|
void AssbinImporter::ReadBinaryMaterialProperty(IOStream *stream, aiMaterialProperty *prop) {
|
||||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AIMATERIALPROPERTY)
|
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AIMATERIALPROPERTY)
|
||||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
/*uint32_t size =*/Read<uint32_t>(stream);
|
||||||
|
|
||||||
prop->mKey = Read<aiString>(stream);
|
prop->mKey = Read<aiString>(stream);
|
||||||
prop->mSemantic = Read<unsigned int>(stream);
|
prop->mSemantic = Read<unsigned int>(stream);
|
||||||
|
@ -437,36 +438,34 @@ void AssbinImporter::ReadBinaryMaterialProperty(IOStream * stream, aiMaterialPro
|
||||||
|
|
||||||
prop->mDataLength = Read<unsigned int>(stream);
|
prop->mDataLength = Read<unsigned int>(stream);
|
||||||
prop->mType = (aiPropertyTypeInfo)Read<unsigned int>(stream);
|
prop->mType = (aiPropertyTypeInfo)Read<unsigned int>(stream);
|
||||||
prop->mData = new char [ prop->mDataLength ];
|
prop->mData = new char[prop->mDataLength];
|
||||||
stream->Read(prop->mData,1,prop->mDataLength);
|
stream->Read(prop->mData, 1, prop->mDataLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat) {
|
void AssbinImporter::ReadBinaryMaterial(IOStream *stream, aiMaterial *mat) {
|
||||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AIMATERIAL)
|
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AIMATERIAL)
|
||||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
/*uint32_t size =*/Read<uint32_t>(stream);
|
||||||
|
|
||||||
mat->mNumAllocated = mat->mNumProperties = Read<unsigned int>(stream);
|
mat->mNumAllocated = mat->mNumProperties = Read<unsigned int>(stream);
|
||||||
if (mat->mNumProperties)
|
if (mat->mNumProperties) {
|
||||||
{
|
if (mat->mProperties) {
|
||||||
if (mat->mProperties)
|
|
||||||
{
|
|
||||||
delete[] mat->mProperties;
|
delete[] mat->mProperties;
|
||||||
}
|
}
|
||||||
mat->mProperties = new aiMaterialProperty*[mat->mNumProperties];
|
mat->mProperties = new aiMaterialProperty *[mat->mNumProperties];
|
||||||
for (unsigned int i = 0; i < mat->mNumProperties;++i) {
|
for (unsigned int i = 0; i < mat->mNumProperties; ++i) {
|
||||||
mat->mProperties[i] = new aiMaterialProperty();
|
mat->mProperties[i] = new aiMaterialProperty();
|
||||||
ReadBinaryMaterialProperty( stream, mat->mProperties[i]);
|
ReadBinaryMaterialProperty(stream, mat->mProperties[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void AssbinImporter::ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd) {
|
void AssbinImporter::ReadBinaryNodeAnim(IOStream *stream, aiNodeAnim *nd) {
|
||||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AINODEANIM)
|
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AINODEANIM)
|
||||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
/*uint32_t size =*/Read<uint32_t>(stream);
|
||||||
|
|
||||||
nd->mNodeName = Read<aiString>(stream);
|
nd->mNodeName = Read<aiString>(stream);
|
||||||
nd->mNumPositionKeys = Read<unsigned int>(stream);
|
nd->mNumPositionKeys = Read<unsigned int>(stream);
|
||||||
|
@ -477,82 +476,82 @@ void AssbinImporter::ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd) {
|
||||||
|
|
||||||
if (nd->mNumPositionKeys) {
|
if (nd->mNumPositionKeys) {
|
||||||
if (shortened) {
|
if (shortened) {
|
||||||
ReadBounds(stream,nd->mPositionKeys,nd->mNumPositionKeys);
|
ReadBounds(stream, nd->mPositionKeys, nd->mNumPositionKeys);
|
||||||
|
|
||||||
} // else write as usual
|
} // else write as usual
|
||||||
else {
|
else {
|
||||||
nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys];
|
nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys];
|
||||||
ReadArray<aiVectorKey>(stream,nd->mPositionKeys,nd->mNumPositionKeys);
|
ReadArray<aiVectorKey>(stream, nd->mPositionKeys, nd->mNumPositionKeys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nd->mNumRotationKeys) {
|
if (nd->mNumRotationKeys) {
|
||||||
if (shortened) {
|
if (shortened) {
|
||||||
ReadBounds(stream,nd->mRotationKeys,nd->mNumRotationKeys);
|
ReadBounds(stream, nd->mRotationKeys, nd->mNumRotationKeys);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// else write as usual
|
// else write as usual
|
||||||
nd->mRotationKeys = new aiQuatKey[nd->mNumRotationKeys];
|
nd->mRotationKeys = new aiQuatKey[nd->mNumRotationKeys];
|
||||||
ReadArray<aiQuatKey>(stream,nd->mRotationKeys,nd->mNumRotationKeys);
|
ReadArray<aiQuatKey>(stream, nd->mRotationKeys, nd->mNumRotationKeys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nd->mNumScalingKeys) {
|
if (nd->mNumScalingKeys) {
|
||||||
if (shortened) {
|
if (shortened) {
|
||||||
ReadBounds(stream,nd->mScalingKeys,nd->mNumScalingKeys);
|
ReadBounds(stream, nd->mScalingKeys, nd->mNumScalingKeys);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// else write as usual
|
// else write as usual
|
||||||
nd->mScalingKeys = new aiVectorKey[nd->mNumScalingKeys];
|
nd->mScalingKeys = new aiVectorKey[nd->mNumScalingKeys];
|
||||||
ReadArray<aiVectorKey>(stream,nd->mScalingKeys,nd->mNumScalingKeys);
|
ReadArray<aiVectorKey>(stream, nd->mScalingKeys, nd->mNumScalingKeys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void AssbinImporter::ReadBinaryAnim( IOStream * stream, aiAnimation* anim ) {
|
void AssbinImporter::ReadBinaryAnim(IOStream *stream, aiAnimation *anim) {
|
||||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AIANIMATION)
|
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AIANIMATION)
|
||||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
/*uint32_t size =*/Read<uint32_t>(stream);
|
||||||
|
|
||||||
anim->mName = Read<aiString> (stream);
|
anim->mName = Read<aiString>(stream);
|
||||||
anim->mDuration = Read<double> (stream);
|
anim->mDuration = Read<double>(stream);
|
||||||
anim->mTicksPerSecond = Read<double> (stream);
|
anim->mTicksPerSecond = Read<double>(stream);
|
||||||
anim->mNumChannels = Read<unsigned int>(stream);
|
anim->mNumChannels = Read<unsigned int>(stream);
|
||||||
|
|
||||||
if (anim->mNumChannels) {
|
if (anim->mNumChannels) {
|
||||||
anim->mChannels = new aiNodeAnim*[ anim->mNumChannels ];
|
anim->mChannels = new aiNodeAnim *[anim->mNumChannels];
|
||||||
for (unsigned int a = 0; a < anim->mNumChannels;++a) {
|
for (unsigned int a = 0; a < anim->mNumChannels; ++a) {
|
||||||
anim->mChannels[a] = new aiNodeAnim();
|
anim->mChannels[a] = new aiNodeAnim();
|
||||||
ReadBinaryNodeAnim(stream,anim->mChannels[a]);
|
ReadBinaryNodeAnim(stream, anim->mChannels[a]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex) {
|
void AssbinImporter::ReadBinaryTexture(IOStream *stream, aiTexture *tex) {
|
||||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AITEXTURE)
|
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AITEXTURE)
|
||||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
/*uint32_t size =*/Read<uint32_t>(stream);
|
||||||
|
|
||||||
tex->mWidth = Read<unsigned int>(stream);
|
tex->mWidth = Read<unsigned int>(stream);
|
||||||
tex->mHeight = Read<unsigned int>(stream);
|
tex->mHeight = Read<unsigned int>(stream);
|
||||||
stream->Read( tex->achFormatHint, sizeof(char), HINTMAXTEXTURELEN - 1 );
|
stream->Read(tex->achFormatHint, sizeof(char), HINTMAXTEXTURELEN - 1);
|
||||||
|
|
||||||
if(!shortened) {
|
if (!shortened) {
|
||||||
if (!tex->mHeight) {
|
if (!tex->mHeight) {
|
||||||
tex->pcData = new aiTexel[ tex->mWidth ];
|
tex->pcData = new aiTexel[tex->mWidth];
|
||||||
stream->Read(tex->pcData,1,tex->mWidth);
|
stream->Read(tex->pcData, 1, tex->mWidth);
|
||||||
} else {
|
} else {
|
||||||
tex->pcData = new aiTexel[ tex->mWidth*tex->mHeight ];
|
tex->pcData = new aiTexel[tex->mWidth * tex->mHeight];
|
||||||
stream->Read(tex->pcData,1,tex->mWidth*tex->mHeight*4);
|
stream->Read(tex->pcData, 1, tex->mWidth * tex->mHeight * 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void AssbinImporter::ReadBinaryLight( IOStream * stream, aiLight* l ) {
|
void AssbinImporter::ReadBinaryLight(IOStream *stream, aiLight *l) {
|
||||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AILIGHT)
|
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AILIGHT)
|
||||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
/*uint32_t size =*/Read<uint32_t>(stream);
|
||||||
|
|
||||||
l->mName = Read<aiString>(stream);
|
l->mName = Read<aiString>(stream);
|
||||||
l->mType = (aiLightSourceType)Read<unsigned int>(stream);
|
l->mType = (aiLightSourceType)Read<unsigned int>(stream);
|
||||||
|
@ -574,10 +573,10 @@ void AssbinImporter::ReadBinaryLight( IOStream * stream, aiLight* l ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void AssbinImporter::ReadBinaryCamera( IOStream * stream, aiCamera* cam ) {
|
void AssbinImporter::ReadBinaryCamera(IOStream *stream, aiCamera *cam) {
|
||||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AICAMERA)
|
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AICAMERA)
|
||||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
/*uint32_t size =*/Read<uint32_t>(stream);
|
||||||
|
|
||||||
cam->mName = Read<aiString>(stream);
|
cam->mName = Read<aiString>(stream);
|
||||||
cam->mPosition = Read<aiVector3D>(stream);
|
cam->mPosition = Read<aiVector3D>(stream);
|
||||||
|
@ -590,141 +589,139 @@ void AssbinImporter::ReadBinaryCamera( IOStream * stream, aiCamera* cam ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene ) {
|
void AssbinImporter::ReadBinaryScene(IOStream *stream, aiScene *scene) {
|
||||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AISCENE)
|
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AISCENE)
|
||||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
/*uint32_t size =*/Read<uint32_t>(stream);
|
||||||
|
|
||||||
scene->mFlags = Read<unsigned int>(stream);
|
scene->mFlags = Read<unsigned int>(stream);
|
||||||
scene->mNumMeshes = Read<unsigned int>(stream);
|
scene->mNumMeshes = Read<unsigned int>(stream);
|
||||||
scene->mNumMaterials = Read<unsigned int>(stream);
|
scene->mNumMaterials = Read<unsigned int>(stream);
|
||||||
scene->mNumAnimations = Read<unsigned int>(stream);
|
scene->mNumAnimations = Read<unsigned int>(stream);
|
||||||
scene->mNumTextures = Read<unsigned int>(stream);
|
scene->mNumTextures = Read<unsigned int>(stream);
|
||||||
scene->mNumLights = Read<unsigned int>(stream);
|
scene->mNumLights = Read<unsigned int>(stream);
|
||||||
scene->mNumCameras = Read<unsigned int>(stream);
|
scene->mNumCameras = Read<unsigned int>(stream);
|
||||||
|
|
||||||
// Read node graph
|
// Read node graph
|
||||||
//scene->mRootNode = new aiNode[1];
|
//scene->mRootNode = new aiNode[1];
|
||||||
ReadBinaryNode( stream, &scene->mRootNode, (aiNode*)NULL );
|
ReadBinaryNode(stream, &scene->mRootNode, (aiNode *)NULL);
|
||||||
|
|
||||||
// Read all meshes
|
// Read all meshes
|
||||||
if (scene->mNumMeshes) {
|
if (scene->mNumMeshes) {
|
||||||
scene->mMeshes = new aiMesh*[scene->mNumMeshes];
|
scene->mMeshes = new aiMesh *[scene->mNumMeshes];
|
||||||
memset(scene->mMeshes, 0, scene->mNumMeshes*sizeof(aiMesh*));
|
memset(scene->mMeshes, 0, scene->mNumMeshes * sizeof(aiMesh *));
|
||||||
for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
|
for (unsigned int i = 0; i < scene->mNumMeshes; ++i) {
|
||||||
scene->mMeshes[i] = new aiMesh();
|
scene->mMeshes[i] = new aiMesh();
|
||||||
ReadBinaryMesh( stream,scene->mMeshes[i]);
|
ReadBinaryMesh(stream, scene->mMeshes[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read materials
|
// Read materials
|
||||||
if (scene->mNumMaterials) {
|
if (scene->mNumMaterials) {
|
||||||
scene->mMaterials = new aiMaterial*[scene->mNumMaterials];
|
scene->mMaterials = new aiMaterial *[scene->mNumMaterials];
|
||||||
memset(scene->mMaterials, 0, scene->mNumMaterials*sizeof(aiMaterial*));
|
memset(scene->mMaterials, 0, scene->mNumMaterials * sizeof(aiMaterial *));
|
||||||
for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
|
for (unsigned int i = 0; i < scene->mNumMaterials; ++i) {
|
||||||
scene->mMaterials[i] = new aiMaterial();
|
scene->mMaterials[i] = new aiMaterial();
|
||||||
ReadBinaryMaterial(stream,scene->mMaterials[i]);
|
ReadBinaryMaterial(stream, scene->mMaterials[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read all animations
|
// Read all animations
|
||||||
if (scene->mNumAnimations) {
|
if (scene->mNumAnimations) {
|
||||||
scene->mAnimations = new aiAnimation*[scene->mNumAnimations];
|
scene->mAnimations = new aiAnimation *[scene->mNumAnimations];
|
||||||
memset(scene->mAnimations, 0, scene->mNumAnimations*sizeof(aiAnimation*));
|
memset(scene->mAnimations, 0, scene->mNumAnimations * sizeof(aiAnimation *));
|
||||||
for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
|
for (unsigned int i = 0; i < scene->mNumAnimations; ++i) {
|
||||||
scene->mAnimations[i] = new aiAnimation();
|
scene->mAnimations[i] = new aiAnimation();
|
||||||
ReadBinaryAnim(stream,scene->mAnimations[i]);
|
ReadBinaryAnim(stream, scene->mAnimations[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read all textures
|
// Read all textures
|
||||||
if (scene->mNumTextures) {
|
if (scene->mNumTextures) {
|
||||||
scene->mTextures = new aiTexture*[scene->mNumTextures];
|
scene->mTextures = new aiTexture *[scene->mNumTextures];
|
||||||
memset(scene->mTextures, 0, scene->mNumTextures*sizeof(aiTexture*));
|
memset(scene->mTextures, 0, scene->mNumTextures * sizeof(aiTexture *));
|
||||||
for (unsigned int i = 0; i < scene->mNumTextures;++i) {
|
for (unsigned int i = 0; i < scene->mNumTextures; ++i) {
|
||||||
scene->mTextures[i] = new aiTexture();
|
scene->mTextures[i] = new aiTexture();
|
||||||
ReadBinaryTexture(stream,scene->mTextures[i]);
|
ReadBinaryTexture(stream, scene->mTextures[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read lights
|
// Read lights
|
||||||
if (scene->mNumLights) {
|
if (scene->mNumLights) {
|
||||||
scene->mLights = new aiLight*[scene->mNumLights];
|
scene->mLights = new aiLight *[scene->mNumLights];
|
||||||
memset(scene->mLights, 0, scene->mNumLights*sizeof(aiLight*));
|
memset(scene->mLights, 0, scene->mNumLights * sizeof(aiLight *));
|
||||||
for (unsigned int i = 0; i < scene->mNumLights;++i) {
|
for (unsigned int i = 0; i < scene->mNumLights; ++i) {
|
||||||
scene->mLights[i] = new aiLight();
|
scene->mLights[i] = new aiLight();
|
||||||
ReadBinaryLight(stream,scene->mLights[i]);
|
ReadBinaryLight(stream, scene->mLights[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read cameras
|
// Read cameras
|
||||||
if (scene->mNumCameras) {
|
if (scene->mNumCameras) {
|
||||||
scene->mCameras = new aiCamera*[scene->mNumCameras];
|
scene->mCameras = new aiCamera *[scene->mNumCameras];
|
||||||
memset(scene->mCameras, 0, scene->mNumCameras*sizeof(aiCamera*));
|
memset(scene->mCameras, 0, scene->mNumCameras * sizeof(aiCamera *));
|
||||||
for (unsigned int i = 0; i < scene->mNumCameras;++i) {
|
for (unsigned int i = 0; i < scene->mNumCameras; ++i) {
|
||||||
scene->mCameras[i] = new aiCamera();
|
scene->mCameras[i] = new aiCamera();
|
||||||
ReadBinaryCamera(stream,scene->mCameras[i]);
|
ReadBinaryCamera(stream, scene->mCameras[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void AssbinImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler ) {
|
void AssbinImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
|
||||||
IOStream * stream = pIOHandler->Open(pFile,"rb");
|
IOStream *stream = pIOHandler->Open(pFile, "rb");
|
||||||
if (nullptr == stream) {
|
if (nullptr == stream) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// signature
|
// signature
|
||||||
stream->Seek( 44, aiOrigin_CUR );
|
stream->Seek(44, aiOrigin_CUR);
|
||||||
|
|
||||||
unsigned int versionMajor = Read<unsigned int>(stream);
|
unsigned int versionMajor = Read<unsigned int>(stream);
|
||||||
unsigned int versionMinor = Read<unsigned int>(stream);
|
unsigned int versionMinor = Read<unsigned int>(stream);
|
||||||
if (versionMinor != ASSBIN_VERSION_MINOR || versionMajor != ASSBIN_VERSION_MAJOR) {
|
if (versionMinor != ASSBIN_VERSION_MINOR || versionMajor != ASSBIN_VERSION_MAJOR) {
|
||||||
throw DeadlyImportError( "Invalid version, data format not compatible!" );
|
throw DeadlyImportError("Invalid version, data format not compatible!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*unsigned int versionRevision =*/ Read<unsigned int>(stream);
|
/*unsigned int versionRevision =*/Read<unsigned int>(stream);
|
||||||
/*unsigned int compileFlags =*/ Read<unsigned int>(stream);
|
/*unsigned int compileFlags =*/Read<unsigned int>(stream);
|
||||||
|
|
||||||
shortened = Read<uint16_t>(stream) > 0;
|
shortened = Read<uint16_t>(stream) > 0;
|
||||||
compressed = Read<uint16_t>(stream) > 0;
|
compressed = Read<uint16_t>(stream) > 0;
|
||||||
|
|
||||||
if (shortened)
|
if (shortened)
|
||||||
throw DeadlyImportError( "Shortened binaries are not supported!" );
|
throw DeadlyImportError("Shortened binaries are not supported!");
|
||||||
|
|
||||||
stream->Seek( 256, aiOrigin_CUR ); // original filename
|
stream->Seek(256, aiOrigin_CUR); // original filename
|
||||||
stream->Seek( 128, aiOrigin_CUR ); // options
|
stream->Seek(128, aiOrigin_CUR); // options
|
||||||
stream->Seek( 64, aiOrigin_CUR ); // padding
|
stream->Seek(64, aiOrigin_CUR); // padding
|
||||||
|
|
||||||
if (compressed) {
|
if (compressed) {
|
||||||
uLongf uncompressedSize = Read<uint32_t>(stream);
|
uLongf uncompressedSize = Read<uint32_t>(stream);
|
||||||
uLongf compressedSize = static_cast<uLongf>(stream->FileSize() - stream->Tell());
|
uLongf compressedSize = static_cast<uLongf>(stream->FileSize() - stream->Tell());
|
||||||
|
|
||||||
unsigned char * compressedData = new unsigned char[ compressedSize ];
|
unsigned char *compressedData = new unsigned char[compressedSize];
|
||||||
size_t len = stream->Read( compressedData, 1, compressedSize );
|
size_t len = stream->Read(compressedData, 1, compressedSize);
|
||||||
ai_assert(len == compressedSize);
|
ai_assert(len == compressedSize);
|
||||||
|
|
||||||
unsigned char * uncompressedData = new unsigned char[ uncompressedSize ];
|
unsigned char *uncompressedData = new unsigned char[uncompressedSize];
|
||||||
|
|
||||||
int res = uncompress( uncompressedData, &uncompressedSize, compressedData, (uLong) len );
|
int res = uncompress(uncompressedData, &uncompressedSize, compressedData, (uLong)len);
|
||||||
if(res != Z_OK)
|
if (res != Z_OK) {
|
||||||
{
|
delete[] uncompressedData;
|
||||||
delete [] uncompressedData;
|
delete[] compressedData;
|
||||||
delete [] compressedData;
|
|
||||||
pIOHandler->Close(stream);
|
pIOHandler->Close(stream);
|
||||||
throw DeadlyImportError("Zlib decompression failed.");
|
throw DeadlyImportError("Zlib decompression failed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryIOStream io( uncompressedData, uncompressedSize );
|
MemoryIOStream io(uncompressedData, uncompressedSize);
|
||||||
|
|
||||||
ReadBinaryScene(&io,pScene);
|
ReadBinaryScene(&io, pScene);
|
||||||
|
|
||||||
delete[] uncompressedData;
|
delete[] uncompressedData;
|
||||||
delete[] compressedData;
|
delete[] compressedData;
|
||||||
} else {
|
} else {
|
||||||
ReadBinaryScene(stream,pScene);
|
ReadBinaryScene(stream, pScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
pIOHandler->Close(stream);
|
pIOHandler->Close(stream);
|
||||||
|
|
|
@ -220,7 +220,7 @@ struct aiVertexWeight {
|
||||||
|
|
||||||
//! The strength of the influence in the range (0...1).
|
//! The strength of the influence in the range (0...1).
|
||||||
//! The influence from all bones at one vertex amounts to 1.
|
//! The influence from all bones at one vertex amounts to 1.
|
||||||
float mWeight;
|
ai_real mWeight;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue