mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-19 06:33:49 +00:00
Updated assimp to latest
This commit is contained in:
parent
25ce4477ce
commit
161bf7f83b
461 changed files with 34662 additions and 30165 deletions
|
|
@ -3,7 +3,8 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2017, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -51,11 +52,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
// internal headers
|
||||
#include "AssbinLoader.h"
|
||||
#include "assbin_chunks.h"
|
||||
#include "MemoryIOWrapper.h"
|
||||
#include <assimp/MemoryIOWrapper.h>
|
||||
#include <assimp/mesh.h>
|
||||
#include <assimp/anim.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include <memory>
|
||||
|
||||
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
|
||||
# include <zlib.h>
|
||||
|
|
@ -78,16 +80,17 @@ static const aiImporterDesc desc = {
|
|||
"assbin"
|
||||
};
|
||||
|
||||
const aiImporterDesc* AssbinImporter::GetInfo() const
|
||||
{
|
||||
// -----------------------------------------------------------------------------------
|
||||
const aiImporterDesc* AssbinImporter::GetInfo() const {
|
||||
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);
|
||||
if (!in)
|
||||
if (nullptr == in) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char s[32];
|
||||
in->Read( s, sizeof(char), 32 );
|
||||
|
|
@ -97,17 +100,19 @@ bool AssbinImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bo
|
|||
return strncmp( s, "ASSIMP.binary-dump.", 19 ) == 0;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T Read(IOStream * stream)
|
||||
{
|
||||
T Read(IOStream * stream) {
|
||||
T t;
|
||||
stream->Read( &t, sizeof(T), 1 );
|
||||
size_t res = stream->Read( &t, sizeof(T), 1 );
|
||||
if(res != 1)
|
||||
throw DeadlyImportError("Unexpected EOF");
|
||||
return t;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
template <>
|
||||
aiVector3D Read<aiVector3D>(IOStream * stream)
|
||||
{
|
||||
aiVector3D Read<aiVector3D>(IOStream * stream) {
|
||||
aiVector3D v;
|
||||
v.x = Read<float>(stream);
|
||||
v.y = Read<float>(stream);
|
||||
|
|
@ -115,9 +120,9 @@ aiVector3D Read<aiVector3D>(IOStream * stream)
|
|||
return v;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
template <>
|
||||
aiColor4D Read<aiColor4D>(IOStream * stream)
|
||||
{
|
||||
aiColor4D Read<aiColor4D>(IOStream * stream) {
|
||||
aiColor4D c;
|
||||
c.r = Read<float>(stream);
|
||||
c.g = Read<float>(stream);
|
||||
|
|
@ -126,9 +131,9 @@ aiColor4D Read<aiColor4D>(IOStream * stream)
|
|||
return c;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
template <>
|
||||
aiQuaternion Read<aiQuaternion>(IOStream * stream)
|
||||
{
|
||||
aiQuaternion Read<aiQuaternion>(IOStream * stream) {
|
||||
aiQuaternion v;
|
||||
v.w = Read<float>(stream);
|
||||
v.x = Read<float>(stream);
|
||||
|
|
@ -137,28 +142,29 @@ aiQuaternion Read<aiQuaternion>(IOStream * stream)
|
|||
return v;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
template <>
|
||||
aiString Read<aiString>(IOStream * stream)
|
||||
{
|
||||
aiString Read<aiString>(IOStream * stream) {
|
||||
aiString s;
|
||||
stream->Read(&s.length,4,1);
|
||||
stream->Read(s.data,s.length,1);
|
||||
if(s.length)
|
||||
stream->Read(s.data,s.length,1);
|
||||
s.data[s.length] = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
template <>
|
||||
aiVertexWeight Read<aiVertexWeight>(IOStream * stream)
|
||||
{
|
||||
aiVertexWeight Read<aiVertexWeight>(IOStream * stream) {
|
||||
aiVertexWeight w;
|
||||
w.mVertexId = Read<unsigned int>(stream);
|
||||
w.mWeight = Read<float>(stream);
|
||||
return w;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
template <>
|
||||
aiMatrix4x4 Read<aiMatrix4x4>(IOStream * stream)
|
||||
{
|
||||
aiMatrix4x4 Read<aiMatrix4x4>(IOStream * stream) {
|
||||
aiMatrix4x4 m;
|
||||
for (unsigned int i = 0; i < 4;++i) {
|
||||
for (unsigned int i2 = 0; i2 < 4;++i2) {
|
||||
|
|
@ -168,76 +174,85 @@ aiMatrix4x4 Read<aiMatrix4x4>(IOStream * stream)
|
|||
return m;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
template <>
|
||||
aiVectorKey Read<aiVectorKey>(IOStream * stream)
|
||||
{
|
||||
aiVectorKey Read<aiVectorKey>(IOStream * stream) {
|
||||
aiVectorKey v;
|
||||
v.mTime = Read<double>(stream);
|
||||
v.mValue = Read<aiVector3D>(stream);
|
||||
return v;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
template <>
|
||||
aiQuatKey Read<aiQuatKey>(IOStream * stream)
|
||||
{
|
||||
aiQuatKey Read<aiQuatKey>(IOStream * stream) {
|
||||
aiQuatKey v;
|
||||
v.mTime = Read<double>(stream);
|
||||
v.mValue = Read<aiQuaternion>(stream);
|
||||
return v;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void ReadArray(IOStream * stream, T * out, unsigned int size)
|
||||
{
|
||||
for (unsigned int i=0; i<size; i++) out[i] = Read<T>(stream);
|
||||
void ReadArray( IOStream *stream, T * out, unsigned int size) {
|
||||
ai_assert( nullptr != stream );
|
||||
ai_assert( nullptr != out );
|
||||
|
||||
for (unsigned int i=0; i<size; i++) {
|
||||
out[i] = Read<T>(stream);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> void ReadBounds( IOStream * stream, T* /*p*/, unsigned int n )
|
||||
{
|
||||
// -----------------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void ReadBounds( IOStream * stream, T* /*p*/, unsigned int n ) {
|
||||
// not sure what to do here, the data isn't really useful.
|
||||
stream->Seek( sizeof(T) * n, aiOrigin_CUR );
|
||||
}
|
||||
|
||||
void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** node, aiNode* parent ) {
|
||||
uint32_t chunkID = Read<uint32_t>(stream);
|
||||
(void)(chunkID);
|
||||
ai_assert(chunkID == ASSBIN_CHUNK_AINODE);
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** onode, aiNode* parent ) {
|
||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AINODE)
|
||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
||||
|
||||
*node = new aiNode();
|
||||
std::unique_ptr<aiNode> node(new aiNode());
|
||||
|
||||
(*node)->mName = Read<aiString>(stream);
|
||||
(*node)->mTransformation = Read<aiMatrix4x4>(stream);
|
||||
(*node)->mNumChildren = Read<unsigned int>(stream);
|
||||
(*node)->mNumMeshes = Read<unsigned int>(stream);
|
||||
node->mName = Read<aiString>(stream);
|
||||
node->mTransformation = Read<aiMatrix4x4>(stream);
|
||||
unsigned numChildren = Read<unsigned int>(stream);
|
||||
unsigned numMeshes = Read<unsigned int>(stream);
|
||||
unsigned int nb_metadata = Read<unsigned int>(stream);
|
||||
|
||||
if(parent) {
|
||||
(*node)->mParent = parent;
|
||||
node->mParent = parent;
|
||||
}
|
||||
|
||||
if ((*node)->mNumMeshes) {
|
||||
(*node)->mMeshes = new unsigned int[(*node)->mNumMeshes];
|
||||
for (unsigned int i = 0; i < (*node)->mNumMeshes; ++i) {
|
||||
(*node)->mMeshes[i] = Read<unsigned int>(stream);
|
||||
if (numMeshes)
|
||||
{
|
||||
node->mMeshes = new unsigned int[numMeshes];
|
||||
for (unsigned int i = 0; i < numMeshes; ++i) {
|
||||
node->mMeshes[i] = Read<unsigned int>(stream);
|
||||
node->mNumMeshes++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((*node)->mNumChildren) {
|
||||
(*node)->mChildren = new aiNode*[(*node)->mNumChildren];
|
||||
for (unsigned int i = 0; i < (*node)->mNumChildren; ++i) {
|
||||
ReadBinaryNode( stream, &(*node)->mChildren[i], *node );
|
||||
if (numChildren) {
|
||||
node->mChildren = new aiNode*[numChildren];
|
||||
for (unsigned int i = 0; i < numChildren; ++i) {
|
||||
ReadBinaryNode( stream, &node->mChildren[i], node.get() );
|
||||
node->mNumChildren++;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
(*node)->mMetaData->mKeys[i] = Read<aiString>(stream);
|
||||
(*node)->mMetaData->mValues[i].mType = (aiMetadataType) Read<uint16_t>(stream);
|
||||
void* data( nullptr );
|
||||
node->mMetaData->mKeys[i] = Read<aiString>(stream);
|
||||
node->mMetaData->mValues[i].mType = (aiMetadataType) Read<uint16_t>(stream);
|
||||
void* data = nullptr;
|
||||
|
||||
switch ((*node)->mMetaData->mValues[i].mType) {
|
||||
switch (node->mMetaData->mValues[i].mType) {
|
||||
case AI_BOOL:
|
||||
data = new bool(Read<bool>(stream));
|
||||
break;
|
||||
|
|
@ -266,17 +281,16 @@ void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** node, aiNode* p
|
|||
break;
|
||||
}
|
||||
|
||||
(*node)->mMetaData->mValues[i].mData = data;
|
||||
node->mMetaData->mValues[i].mData = data;
|
||||
}
|
||||
}
|
||||
*onode = node.release();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryBone( IOStream * stream, aiBone* b )
|
||||
{
|
||||
uint32_t chunkID = Read<uint32_t>(stream);
|
||||
(void)(chunkID);
|
||||
ai_assert(chunkID == ASSBIN_CHUNK_AIBONE);
|
||||
void AssbinImporter::ReadBinaryBone( IOStream * stream, aiBone* b ) {
|
||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AIBONE)
|
||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
||||
|
||||
b->mName = Read<aiString>(stream);
|
||||
|
|
@ -285,23 +299,23 @@ void AssbinImporter::ReadBinaryBone( IOStream * stream, aiBone* b )
|
|||
|
||||
// for the moment we write dumb min/max values for the bones, too.
|
||||
// maybe I'll add a better, hash-like solution later
|
||||
if (shortened)
|
||||
{
|
||||
if (shortened) {
|
||||
ReadBounds(stream,b->mWeights,b->mNumWeights);
|
||||
} // else write as usual
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// else write as usual
|
||||
b->mWeights = new aiVertexWeight[b->mNumWeights];
|
||||
ReadArray<aiVertexWeight>(stream,b->mWeights,b->mNumWeights);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh )
|
||||
{
|
||||
uint32_t chunkID = Read<uint32_t>(stream);
|
||||
(void)(chunkID);
|
||||
ai_assert(chunkID == ASSBIN_CHUNK_AIMESH);
|
||||
// -----------------------------------------------------------------------------------
|
||||
static bool fitsIntoUI16(unsigned int mNumVertices) {
|
||||
return ( mNumVertices < (1u<<16) );
|
||||
}
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh ) {
|
||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AIMESH)
|
||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
||||
|
||||
mesh->mPrimitiveTypes = Read<unsigned int>(stream);
|
||||
|
|
@ -313,70 +327,61 @@ void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh )
|
|||
// first of all, write bits for all existent vertex components
|
||||
unsigned int c = Read<unsigned int>(stream);
|
||||
|
||||
if (c & ASSBIN_MESH_HAS_POSITIONS)
|
||||
{
|
||||
if (c & ASSBIN_MESH_HAS_POSITIONS) {
|
||||
if (shortened) {
|
||||
ReadBounds(stream,mesh->mVertices,mesh->mNumVertices);
|
||||
} // else write as usual
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// else write as usual
|
||||
mesh->mVertices = new aiVector3D[mesh->mNumVertices];
|
||||
ReadArray<aiVector3D>(stream,mesh->mVertices,mesh->mNumVertices);
|
||||
}
|
||||
}
|
||||
if (c & ASSBIN_MESH_HAS_NORMALS)
|
||||
{
|
||||
if (c & ASSBIN_MESH_HAS_NORMALS) {
|
||||
if (shortened) {
|
||||
ReadBounds(stream,mesh->mNormals,mesh->mNumVertices);
|
||||
} // else write as usual
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// else write as usual
|
||||
mesh->mNormals = new aiVector3D[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) {
|
||||
ReadBounds(stream,mesh->mTangents,mesh->mNumVertices);
|
||||
ReadBounds(stream,mesh->mBitangents,mesh->mNumVertices);
|
||||
} // else write as usual
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// else write as usual
|
||||
mesh->mTangents = new aiVector3D[mesh->mNumVertices];
|
||||
ReadArray<aiVector3D>(stream,mesh->mTangents,mesh->mNumVertices);
|
||||
mesh->mBitangents = new aiVector3D[mesh->mNumVertices];
|
||||
ReadArray<aiVector3D>(stream,mesh->mBitangents,mesh->mNumVertices);
|
||||
}
|
||||
}
|
||||
for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_COLOR_SETS;++n)
|
||||
{
|
||||
if (!(c & ASSBIN_MESH_HAS_COLOR(n)))
|
||||
for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_COLOR_SETS;++n) {
|
||||
if (!(c & ASSBIN_MESH_HAS_COLOR(n))) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (shortened)
|
||||
{
|
||||
if (shortened) {
|
||||
ReadBounds(stream,mesh->mColors[n],mesh->mNumVertices);
|
||||
} // else write as usual
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// else write as usual
|
||||
mesh->mColors[n] = new aiColor4D[mesh->mNumVertices];
|
||||
ReadArray<aiColor4D>(stream,mesh->mColors[n],mesh->mNumVertices);
|
||||
}
|
||||
}
|
||||
for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_TEXTURECOORDS;++n)
|
||||
{
|
||||
if (!(c & ASSBIN_MESH_HAS_TEXCOORD(n)))
|
||||
for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_TEXTURECOORDS;++n) {
|
||||
if (!(c & ASSBIN_MESH_HAS_TEXCOORD(n))) {
|
||||
break;
|
||||
}
|
||||
|
||||
// write number of UV components
|
||||
mesh->mNumUVComponents[n] = Read<unsigned int>(stream);
|
||||
|
||||
if (shortened) {
|
||||
ReadBounds(stream,mesh->mTextureCoords[n],mesh->mNumVertices);
|
||||
} // else write as usual
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// else write as usual
|
||||
mesh->mTextureCoords[n] = new aiVector3D[mesh->mNumVertices];
|
||||
ReadArray<aiVector3D>(stream,mesh->mTextureCoords[n],mesh->mNumVertices);
|
||||
}
|
||||
|
|
@ -388,9 +393,8 @@ void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh )
|
|||
// using Assimp's standard hashing function.
|
||||
if (shortened) {
|
||||
Read<unsigned int>(stream);
|
||||
}
|
||||
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 ...
|
||||
mesh->mFaces = new aiFace[mesh->mNumFaces];
|
||||
for (unsigned int i = 0; i < mesh->mNumFaces;++i) {
|
||||
|
|
@ -401,12 +405,10 @@ void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh )
|
|||
f.mIndices = new unsigned int[f.mNumIndices];
|
||||
|
||||
for (unsigned int a = 0; a < f.mNumIndices;++a) {
|
||||
if (mesh->mNumVertices < (1u<<16))
|
||||
{
|
||||
// Check if unsigned short ( 16 bit ) are big enought for the indices
|
||||
if ( fitsIntoUI16( mesh->mNumVertices ) ) {
|
||||
f.mIndices[a] = Read<uint16_t>(stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
f.mIndices[a] = Read<unsigned int>(stream);
|
||||
}
|
||||
}
|
||||
|
|
@ -423,11 +425,10 @@ void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh )
|
|||
}
|
||||
}
|
||||
|
||||
void AssbinImporter::ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop)
|
||||
{
|
||||
uint32_t chunkID = Read<uint32_t>(stream);
|
||||
(void)(chunkID);
|
||||
ai_assert(chunkID == ASSBIN_CHUNK_AIMATERIALPROPERTY);
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop) {
|
||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AIMATERIALPROPERTY)
|
||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
||||
|
||||
prop->mKey = Read<aiString>(stream);
|
||||
|
|
@ -441,11 +442,9 @@ void AssbinImporter::ReadBinaryMaterialProperty(IOStream * stream, aiMaterialPro
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat)
|
||||
{
|
||||
uint32_t chunkID = Read<uint32_t>(stream);
|
||||
(void)(chunkID);
|
||||
ai_assert(chunkID == ASSBIN_CHUNK_AIMATERIAL);
|
||||
void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat) {
|
||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AIMATERIAL)
|
||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
||||
|
||||
mat->mNumAllocated = mat->mNumProperties = Read<unsigned int>(stream);
|
||||
|
|
@ -464,11 +463,9 @@ void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat)
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd)
|
||||
{
|
||||
uint32_t chunkID = Read<uint32_t>(stream);
|
||||
(void)(chunkID);
|
||||
ai_assert(chunkID == ASSBIN_CHUNK_AINODEANIM);
|
||||
void AssbinImporter::ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd) {
|
||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AINODEANIM)
|
||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
||||
|
||||
nd->mNodeName = Read<aiString>(stream);
|
||||
|
|
@ -492,9 +489,8 @@ void AssbinImporter::ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd)
|
|||
if (shortened) {
|
||||
ReadBounds(stream,nd->mRotationKeys,nd->mNumRotationKeys);
|
||||
|
||||
} // else write as usual
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// else write as usual
|
||||
nd->mRotationKeys = new aiQuatKey[nd->mNumRotationKeys];
|
||||
ReadArray<aiQuatKey>(stream,nd->mRotationKeys,nd->mNumRotationKeys);
|
||||
}
|
||||
|
|
@ -503,22 +499,18 @@ void AssbinImporter::ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd)
|
|||
if (shortened) {
|
||||
ReadBounds(stream,nd->mScalingKeys,nd->mNumScalingKeys);
|
||||
|
||||
} // else write as usual
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// else write as usual
|
||||
nd->mScalingKeys = new aiVectorKey[nd->mNumScalingKeys];
|
||||
ReadArray<aiVectorKey>(stream,nd->mScalingKeys,nd->mNumScalingKeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryAnim( IOStream * stream, aiAnimation* anim )
|
||||
{
|
||||
uint32_t chunkID = Read<uint32_t>(stream);
|
||||
(void)(chunkID);
|
||||
ai_assert(chunkID == ASSBIN_CHUNK_AIANIMATION);
|
||||
void AssbinImporter::ReadBinaryAnim( IOStream * stream, aiAnimation* anim ) {
|
||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AIANIMATION)
|
||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
||||
|
||||
anim->mName = Read<aiString> (stream);
|
||||
|
|
@ -526,8 +518,7 @@ void AssbinImporter::ReadBinaryAnim( IOStream * stream, aiAnimation* anim )
|
|||
anim->mTicksPerSecond = Read<double> (stream);
|
||||
anim->mNumChannels = Read<unsigned int>(stream);
|
||||
|
||||
if (anim->mNumChannels)
|
||||
{
|
||||
if (anim->mNumChannels) {
|
||||
anim->mChannels = new aiNodeAnim*[ anim->mNumChannels ];
|
||||
for (unsigned int a = 0; a < anim->mNumChannels;++a) {
|
||||
anim->mChannels[a] = new aiNodeAnim();
|
||||
|
|
@ -536,11 +527,10 @@ void AssbinImporter::ReadBinaryAnim( IOStream * stream, aiAnimation* anim )
|
|||
}
|
||||
}
|
||||
|
||||
void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex)
|
||||
{
|
||||
uint32_t chunkID = Read<uint32_t>(stream);
|
||||
(void)(chunkID);
|
||||
ai_assert(chunkID == ASSBIN_CHUNK_AITEXTURE);
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex) {
|
||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AITEXTURE)
|
||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
||||
|
||||
tex->mWidth = Read<unsigned int>(stream);
|
||||
|
|
@ -551,21 +541,17 @@ void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex)
|
|||
if (!tex->mHeight) {
|
||||
tex->pcData = new aiTexel[ tex->mWidth ];
|
||||
stream->Read(tex->pcData,1,tex->mWidth);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
tex->pcData = new aiTexel[ tex->mWidth*tex->mHeight ];
|
||||
stream->Read(tex->pcData,1,tex->mWidth*tex->mHeight*4);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryLight( IOStream * stream, aiLight* l )
|
||||
{
|
||||
uint32_t chunkID = Read<uint32_t>(stream);
|
||||
(void)(chunkID);
|
||||
ai_assert(chunkID == ASSBIN_CHUNK_AILIGHT);
|
||||
void AssbinImporter::ReadBinaryLight( IOStream * stream, aiLight* l ) {
|
||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AILIGHT)
|
||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
||||
|
||||
l->mName = Read<aiString>(stream);
|
||||
|
|
@ -585,15 +571,12 @@ void AssbinImporter::ReadBinaryLight( IOStream * stream, aiLight* l )
|
|||
l->mAngleInnerCone = Read<float>(stream);
|
||||
l->mAngleOuterCone = Read<float>(stream);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryCamera( IOStream * stream, aiCamera* cam )
|
||||
{
|
||||
uint32_t chunkID = Read<uint32_t>(stream);
|
||||
(void)(chunkID);
|
||||
ai_assert(chunkID == ASSBIN_CHUNK_AICAMERA);
|
||||
void AssbinImporter::ReadBinaryCamera( IOStream * stream, aiCamera* cam ) {
|
||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AICAMERA)
|
||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
||||
|
||||
cam->mName = Read<aiString>(stream);
|
||||
|
|
@ -606,11 +589,10 @@ void AssbinImporter::ReadBinaryCamera( IOStream * stream, aiCamera* cam )
|
|||
cam->mAspect = Read<float>(stream);
|
||||
}
|
||||
|
||||
void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
|
||||
{
|
||||
uint32_t chunkID = Read<uint32_t>(stream);
|
||||
(void)(chunkID);
|
||||
ai_assert(chunkID == ASSBIN_CHUNK_AISCENE);
|
||||
// -----------------------------------------------------------------------------------
|
||||
void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene ) {
|
||||
if(Read<uint32_t>(stream) != ASSBIN_CHUNK_AISCENE)
|
||||
throw DeadlyImportError("Magic chunk identifiers are wrong!");
|
||||
/*uint32_t size =*/ Read<uint32_t>(stream);
|
||||
|
||||
scene->mFlags = Read<unsigned int>(stream);
|
||||
|
|
@ -622,13 +604,13 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
|
|||
scene->mNumCameras = Read<unsigned int>(stream);
|
||||
|
||||
// Read node graph
|
||||
scene->mRootNode = new aiNode[1];
|
||||
//scene->mRootNode = new aiNode[1];
|
||||
ReadBinaryNode( stream, &scene->mRootNode, (aiNode*)NULL );
|
||||
|
||||
// Read all meshes
|
||||
if (scene->mNumMeshes)
|
||||
{
|
||||
if (scene->mNumMeshes) {
|
||||
scene->mMeshes = new aiMesh*[scene->mNumMeshes];
|
||||
memset(scene->mMeshes, 0, scene->mNumMeshes*sizeof(aiMesh*));
|
||||
for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
|
||||
scene->mMeshes[i] = new aiMesh();
|
||||
ReadBinaryMesh( stream,scene->mMeshes[i]);
|
||||
|
|
@ -636,9 +618,9 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
|
|||
}
|
||||
|
||||
// Read materials
|
||||
if (scene->mNumMaterials)
|
||||
{
|
||||
if (scene->mNumMaterials) {
|
||||
scene->mMaterials = new aiMaterial*[scene->mNumMaterials];
|
||||
memset(scene->mMaterials, 0, scene->mNumMaterials*sizeof(aiMaterial*));
|
||||
for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
|
||||
scene->mMaterials[i] = new aiMaterial();
|
||||
ReadBinaryMaterial(stream,scene->mMaterials[i]);
|
||||
|
|
@ -646,9 +628,9 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
|
|||
}
|
||||
|
||||
// Read all animations
|
||||
if (scene->mNumAnimations)
|
||||
{
|
||||
if (scene->mNumAnimations) {
|
||||
scene->mAnimations = new aiAnimation*[scene->mNumAnimations];
|
||||
memset(scene->mAnimations, 0, scene->mNumAnimations*sizeof(aiAnimation*));
|
||||
for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
|
||||
scene->mAnimations[i] = new aiAnimation();
|
||||
ReadBinaryAnim(stream,scene->mAnimations[i]);
|
||||
|
|
@ -656,9 +638,9 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
|
|||
}
|
||||
|
||||
// Read all textures
|
||||
if (scene->mNumTextures)
|
||||
{
|
||||
if (scene->mNumTextures) {
|
||||
scene->mTextures = new aiTexture*[scene->mNumTextures];
|
||||
memset(scene->mTextures, 0, scene->mNumTextures*sizeof(aiTexture*));
|
||||
for (unsigned int i = 0; i < scene->mNumTextures;++i) {
|
||||
scene->mTextures[i] = new aiTexture();
|
||||
ReadBinaryTexture(stream,scene->mTextures[i]);
|
||||
|
|
@ -666,9 +648,9 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
|
|||
}
|
||||
|
||||
// Read lights
|
||||
if (scene->mNumLights)
|
||||
{
|
||||
if (scene->mNumLights) {
|
||||
scene->mLights = new aiLight*[scene->mNumLights];
|
||||
memset(scene->mLights, 0, scene->mNumLights*sizeof(aiLight*));
|
||||
for (unsigned int i = 0; i < scene->mNumLights;++i) {
|
||||
scene->mLights[i] = new aiLight();
|
||||
ReadBinaryLight(stream,scene->mLights[i]);
|
||||
|
|
@ -676,9 +658,9 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
|
|||
}
|
||||
|
||||
// Read cameras
|
||||
if (scene->mNumCameras)
|
||||
{
|
||||
if (scene->mNumCameras) {
|
||||
scene->mCameras = new aiCamera*[scene->mNumCameras];
|
||||
memset(scene->mCameras, 0, scene->mNumCameras*sizeof(aiCamera*));
|
||||
for (unsigned int i = 0; i < scene->mNumCameras;++i) {
|
||||
scene->mCameras[i] = new aiCamera();
|
||||
ReadBinaryCamera(stream,scene->mCameras[i]);
|
||||
|
|
@ -687,16 +669,22 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
|
|||
|
||||
}
|
||||
|
||||
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");
|
||||
if (!stream)
|
||||
if (nullptr == stream) {
|
||||
return;
|
||||
}
|
||||
|
||||
stream->Seek( 44, aiOrigin_CUR ); // signature
|
||||
// signature
|
||||
stream->Seek( 44, aiOrigin_CUR );
|
||||
|
||||
unsigned int versionMajor = Read<unsigned int>(stream);
|
||||
unsigned int versionMinor = Read<unsigned int>(stream);
|
||||
if (versionMinor != ASSBIN_VERSION_MINOR || versionMajor != ASSBIN_VERSION_MAJOR) {
|
||||
throw DeadlyImportError( "Invalid version, data format not compatible!" );
|
||||
}
|
||||
|
||||
/*unsigned int versionMajor =*/ Read<unsigned int>(stream);
|
||||
/*unsigned int versionMinor =*/ Read<unsigned int>(stream);
|
||||
/*unsigned int versionRevision =*/ Read<unsigned int>(stream);
|
||||
/*unsigned int compileFlags =*/ Read<unsigned int>(stream);
|
||||
|
||||
|
|
@ -710,17 +698,24 @@ void AssbinImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
|
|||
stream->Seek( 128, aiOrigin_CUR ); // options
|
||||
stream->Seek( 64, aiOrigin_CUR ); // padding
|
||||
|
||||
if (compressed)
|
||||
{
|
||||
if (compressed) {
|
||||
uLongf uncompressedSize = Read<uint32_t>(stream);
|
||||
uLongf compressedSize = static_cast<uLongf>(stream->FileSize() - stream->Tell());
|
||||
|
||||
unsigned char * compressedData = new unsigned char[ compressedSize ];
|
||||
stream->Read( compressedData, 1, compressedSize );
|
||||
size_t len = stream->Read( compressedData, 1, compressedSize );
|
||||
ai_assert(len == compressedSize);
|
||||
|
||||
unsigned char * uncompressedData = new unsigned char[ uncompressedSize ];
|
||||
|
||||
uncompress( uncompressedData, &uncompressedSize, compressedData, compressedSize );
|
||||
int res = uncompress( uncompressedData, &uncompressedSize, compressedData, len );
|
||||
if(res != Z_OK)
|
||||
{
|
||||
delete [] uncompressedData;
|
||||
delete [] compressedData;
|
||||
pIOHandler->Close(stream);
|
||||
throw DeadlyImportError("Zlib decompression failed.");
|
||||
}
|
||||
|
||||
MemoryIOStream io( uncompressedData, uncompressedSize );
|
||||
|
||||
|
|
@ -728,9 +723,7 @@ void AssbinImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
|
|||
|
||||
delete[] uncompressedData;
|
||||
delete[] compressedData;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ReadBinaryScene(stream,pScene);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue