add material import

pull/327/head
Gargaj 2014-08-06 14:21:53 +02:00
parent f38dd8e6e2
commit 5048793096
2 changed files with 47 additions and 5 deletions

View File

@ -298,6 +298,42 @@ void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh )
} }
} }
void AssbinImporter::ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop)
{
ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIMATERIALPROPERTY);
uint32_t size = Read<uint32_t>(stream);
prop->mKey = Read<aiString>(stream);
prop->mSemantic = Read<unsigned int>(stream);
prop->mIndex = Read<unsigned int>(stream);
prop->mDataLength = Read<unsigned int>(stream);
prop->mType = (aiPropertyTypeInfo)Read<unsigned int>(stream);
prop->mData = new char [ prop->mDataLength ];
stream->Read(prop->mData,1,prop->mDataLength);
}
// -----------------------------------------------------------------------------------
void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat)
{
ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIMATERIAL);
uint32_t size = Read<uint32_t>(stream);
mat->mNumAllocated = mat->mNumProperties = Read<unsigned int>(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 ) void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
{ {
ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AISCENE); ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AISCENE);
@ -325,12 +361,16 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
} }
} }
/*
// Read materials // Read materials
for (unsigned int i = 0; i< scene->mNumMaterials; ++i) { if (scene->mNumMaterials)
const aiMaterial* mat = scene->mMaterials[i]; {
ReadBinaryMaterial(stream,mat); 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 // Read all animations
for (unsigned int i = 0; i < scene->mNumAnimations;++i) { for (unsigned int i = 0; i < scene->mNumAnimations;++i) {

View File

@ -78,6 +78,8 @@ public:
void ReadBinaryNode( IOStream * stream, aiNode** mRootNode ); void ReadBinaryNode( IOStream * stream, aiNode** mRootNode );
void ReadBinaryMesh( IOStream * stream, aiMesh* mesh ); void ReadBinaryMesh( IOStream * stream, aiMesh* mesh );
void ReadBinaryBone( IOStream * stream, aiBone* bone ); void ReadBinaryBone( IOStream * stream, aiBone* bone );
void ReadBinaryMaterial(IOStream * stream, aiMaterial* mat);
void ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop);
}; };
} // end of namespace Assimp } // end of namespace Assimp