From 97c9ce1d5b1e8fd76677c38e9759c3b182ee82e0 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Wed, 6 Aug 2014 14:44:06 +0200 Subject: [PATCH] add animations and textures --- code/AssbinLoader.cpp | 118 ++++++++++++++++++++++++++++++++++++++---- code/AssbinLoader.h | 3 ++ 2 files changed, 111 insertions(+), 10 deletions(-) diff --git a/code/AssbinLoader.cpp b/code/AssbinLoader.cpp index ee970cd2e..c0777a87b 100644 --- a/code/AssbinLoader.cpp +++ b/code/AssbinLoader.cpp @@ -334,6 +334,97 @@ void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat) } } +// ----------------------------------------------------------------------------------- +void AssbinImporter::ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd) +{ + ai_assert( Read(stream) == ASSBIN_CHUNK_AINODEANIM); + uint32_t size = Read(stream); + + nd->mNodeName = Read(stream); + nd->mNumPositionKeys = Read(stream); + nd->mNumRotationKeys = Read(stream); + nd->mNumScalingKeys = Read(stream); + nd->mPreState = (aiAnimBehaviour)Read(stream); + nd->mPostState = (aiAnimBehaviour)Read(stream); + + if (nd->mNumPositionKeys) { + if (shortened) { + ReadBounds(stream,nd->mPositionKeys,nd->mNumPositionKeys); + + } // else write as usual + else { + nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys]; + stream->Read(nd->mPositionKeys,1,nd->mNumPositionKeys*sizeof(aiVectorKey)); + } + } + if (nd->mNumRotationKeys) { + if (shortened) { + ReadBounds(stream,nd->mRotationKeys,nd->mNumRotationKeys); + + } // else write as usual + else + { + nd->mRotationKeys = new aiQuatKey[nd->mNumRotationKeys]; + stream->Read(nd->mRotationKeys,1,nd->mNumRotationKeys*sizeof(aiQuatKey)); + } + } + if (nd->mNumScalingKeys) { + if (shortened) { + ReadBounds(stream,nd->mScalingKeys,nd->mNumScalingKeys); + + } // else write as usual + else + { + nd->mScalingKeys = new aiVectorKey[nd->mNumScalingKeys]; + stream->Read(nd->mScalingKeys,1,nd->mNumScalingKeys*sizeof(aiVectorKey)); + } + } +} + + +// ----------------------------------------------------------------------------------- +void AssbinImporter::ReadBinaryAnim( IOStream * stream, aiAnimation* anim ) +{ + ai_assert( Read(stream) == ASSBIN_CHUNK_AIANIMATION); + uint32_t size = 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[a] = new aiNodeAnim(); + ReadBinaryNodeAnim(stream,anim->mChannels[a]); + } + } +} + +void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex) +{ + ai_assert( Read(stream) == ASSBIN_CHUNK_AITEXTURE); + uint32_t size = Read(stream); + + tex->mWidth = Read(stream); + tex->mHeight = Read(stream); + stream->Read( tex->achFormatHint, sizeof(char), 4 ); + + if(!shortened) { + if (!tex->mHeight) { + 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); + } + } + +} + void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene ) { ai_assert( Read(stream) == ASSBIN_CHUNK_AISCENE); @@ -370,21 +461,28 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene ) ReadBinaryMaterial(stream,scene->mMaterials[i]); } } -/* // Read all animations - for (unsigned int i = 0; i < scene->mNumAnimations;++i) { - const aiAnimation* anim = scene->mAnimations[i]; - ReadBinaryAnim(stream,anim); - } - + if (scene->mNumAnimations) + { + scene->mAnimations = new aiAnimation*[scene->mNumAnimations]; + for (unsigned int i = 0; i < scene->mNumAnimations;++i) { + scene->mAnimations[i] = new aiAnimation(); + ReadBinaryAnim(stream,scene->mAnimations[i]); + } + } // Read all textures - for (unsigned int i = 0; i < scene->mNumTextures;++i) { - const aiTexture* mesh = scene->mTextures[i]; - ReadBinaryTexture(stream,mesh); - } + if (scene->mNumTextures) + { + scene->mTextures = new aiTexture*[scene->mNumTextures]; + for (unsigned int i = 0; i < scene->mNumTextures;++i) { + scene->mTextures[i] = new aiTexture(); + ReadBinaryTexture(stream,scene->mTextures[i]); + } + } +/* // Read lights for (unsigned int i = 0; i < scene->mNumLights;++i) { const aiLight* l = scene->mLights[i]; diff --git a/code/AssbinLoader.h b/code/AssbinLoader.h index 7b99860b4..a1b2a71d6 100644 --- a/code/AssbinLoader.h +++ b/code/AssbinLoader.h @@ -80,6 +80,9 @@ public: void ReadBinaryBone( IOStream * stream, aiBone* bone ); void ReadBinaryMaterial(IOStream * stream, aiMaterial* mat); void ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop); + void ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd); + void ReadBinaryAnim( IOStream * stream, aiAnimation* anim ); + void ReadBinaryTexture(IOStream * stream, aiTexture* tex); }; } // end of namespace Assimp