Added support for metadata in assbin format

pull/1337/head
Leo Terziman 2017-07-11 17:39:36 +02:00
parent e66dc5c9ad
commit 6c6a8fe671
2 changed files with 71 additions and 0 deletions

View File

@ -329,6 +329,7 @@ inline size_t WriteArray(IOStream * stream, const T* in, unsigned int size)
Write<aiMatrix4x4>(&chunk,node->mTransformation); Write<aiMatrix4x4>(&chunk,node->mTransformation);
Write<unsigned int>(&chunk,node->mNumChildren); Write<unsigned int>(&chunk,node->mNumChildren);
Write<unsigned int>(&chunk,node->mNumMeshes); Write<unsigned int>(&chunk,node->mNumMeshes);
Write<unsigned int>(&chunk,node->mMetaData->mNumProperties);
for (unsigned int i = 0; i < node->mNumMeshes;++i) { for (unsigned int i = 0; i < node->mNumMeshes;++i) {
Write<unsigned int>(&chunk,node->mMeshes[i]); Write<unsigned int>(&chunk,node->mMeshes[i]);
@ -337,6 +338,39 @@ inline size_t WriteArray(IOStream * stream, const T* in, unsigned int size)
for (unsigned int i = 0; i < node->mNumChildren;++i) { for (unsigned int i = 0; i < node->mNumChildren;++i) {
WriteBinaryNode( &chunk, node->mChildren[i] ); WriteBinaryNode( &chunk, node->mChildren[i] );
} }
for (unsigned int i = 0; i < node->mMetaData->mNumProperties; ++i) {
const aiString& key = node->mMetaData->mKeys[i];
aiMetadataType type = node->mMetaData->mValues[i].mType;
void* value = node->mMetaData->mValues[i].mData;
Write<aiString>(&chunk, key);
Write<uint16_t>(&chunk, type);
switch (type) {
case AI_BOOL:
Write<bool>(&chunk, *((bool*) value));
break;
case AI_INT32:
Write<int32_t>(&chunk, *((int32_t*) value));
break;
case AI_UINT64:
Write<uint64_t>(&chunk, *((uint64_t*) value));
break;
case AI_FLOAT:
Write<float>(&chunk, *((float*) value));
break;
case AI_DOUBLE:
Write<double>(&chunk, *((double*) value));
break;
case AI_AISTRING:
Write<aiString>(&chunk, *((aiString*) value));
break;
case AI_AIVECTOR3D:
Write<aiVector3D>(&chunk, *((aiVector3D*) value));
break;
}
}
} }
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------

View File

@ -210,6 +210,8 @@ void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** node, aiNode* p
(*node)->mTransformation = Read<aiMatrix4x4>(stream); (*node)->mTransformation = Read<aiMatrix4x4>(stream);
(*node)->mNumChildren = Read<unsigned int>(stream); (*node)->mNumChildren = Read<unsigned int>(stream);
(*node)->mNumMeshes = Read<unsigned int>(stream); (*node)->mNumMeshes = Read<unsigned int>(stream);
unsigned int nb_metadata = Read<unsigned int>(stream);
if(parent) if(parent)
{ {
(*node)->mParent = parent; (*node)->mParent = parent;
@ -231,6 +233,41 @@ void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** node, aiNode* p
} }
} }
if (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 = NULL;
switch ((*node)->mMetaData->mValues[i].mType) {
case AI_BOOL:
data = new bool(Read<bool>(stream));
break;
case AI_INT32:
data = new int32_t(Read<int32_t>(stream));
break;
case AI_UINT64:
data = new uint64_t(Read<uint64_t>(stream));
break;
case AI_FLOAT:
data = new float(Read<float>(stream));
break;
case AI_DOUBLE:
data = new double(Read<double>(stream));
break;
case AI_AISTRING:
data = new aiString(Read<aiString>(stream));
break;
case AI_AIVECTOR3D:
data = new aiVector3D(Read<aiVector3D>(stream));
break;
}
(*node)->mMetaData->mValues[i].mData = data;
}
}
} }
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------