diff --git a/code/AssbinLoader.cpp b/code/AssbinLoader.cpp index 24924ade5..ee970cd2e 100644 --- a/code/AssbinLoader.cpp +++ b/code/AssbinLoader.cpp @@ -298,6 +298,42 @@ void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh ) } } +void AssbinImporter::ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop) +{ + ai_assert( Read(stream) == ASSBIN_CHUNK_AIMATERIALPROPERTY); + uint32_t size = Read(stream); + + prop->mKey = Read(stream); + prop->mSemantic = Read(stream); + prop->mIndex = Read(stream); + + prop->mDataLength = Read(stream); + prop->mType = (aiPropertyTypeInfo)Read(stream); + prop->mData = new char [ prop->mDataLength ]; + stream->Read(prop->mData,1,prop->mDataLength); +} + +// ----------------------------------------------------------------------------------- +void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat) +{ + ai_assert( Read(stream) == ASSBIN_CHUNK_AIMATERIAL); + uint32_t size = Read(stream); + + mat->mNumAllocated = mat->mNumProperties = Read(stream); + 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[i] = new aiMaterialProperty(); + ReadBinaryMaterialProperty( stream, mat->mProperties[i]); + } + } +} + void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene ) { ai_assert( Read(stream) == ASSBIN_CHUNK_AISCENE); @@ -325,12 +361,16 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene ) } } -/* // Read materials - for (unsigned int i = 0; i< scene->mNumMaterials; ++i) { - const aiMaterial* mat = scene->mMaterials[i]; - ReadBinaryMaterial(stream,mat); - } + if (scene->mNumMaterials) + { + scene->mMaterials = new aiMaterial*[scene->mNumMaterials]; + for (unsigned int i = 0; i< scene->mNumMaterials; ++i) { + scene->mMaterials[i] = new aiMaterial(); + ReadBinaryMaterial(stream,scene->mMaterials[i]); + } + } +/* // Read all animations for (unsigned int i = 0; i < scene->mNumAnimations;++i) { diff --git a/code/AssbinLoader.h b/code/AssbinLoader.h index 64fb7056e..7b99860b4 100644 --- a/code/AssbinLoader.h +++ b/code/AssbinLoader.h @@ -78,6 +78,8 @@ public: void ReadBinaryNode( IOStream * stream, aiNode** mRootNode ); void ReadBinaryMesh( IOStream * stream, aiMesh* mesh ); void ReadBinaryBone( IOStream * stream, aiBone* bone ); + void ReadBinaryMaterial(IOStream * stream, aiMaterial* mat); + void ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop); }; } // end of namespace Assimp