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