Merge pull request #1337 from terziman/master
Added support for metadata in assbin formatpull/1345/head
commit
c9912fd481
|
@ -325,10 +325,13 @@ inline size_t WriteArray(IOStream * stream, const T* in, unsigned int size)
|
|||
{
|
||||
AssbinChunkWriter chunk( container, ASSBIN_CHUNK_AINODE );
|
||||
|
||||
size_t nb_metadata = (node->mMetaData != NULL ? node->mMetaData->mNumProperties : 0);
|
||||
|
||||
Write<aiString>(&chunk,node->mName);
|
||||
Write<aiMatrix4x4>(&chunk,node->mTransformation);
|
||||
Write<unsigned int>(&chunk,node->mNumChildren);
|
||||
Write<unsigned int>(&chunk,node->mNumMeshes);
|
||||
Write<unsigned int>(&chunk,nb_metadata);
|
||||
|
||||
for (unsigned int i = 0; i < node->mNumMeshes;++i) {
|
||||
Write<unsigned int>(&chunk,node->mMeshes[i]);
|
||||
|
@ -337,6 +340,39 @@ inline size_t WriteArray(IOStream * stream, const T* in, unsigned int size)
|
|||
for (unsigned int i = 0; i < node->mNumChildren;++i) {
|
||||
WriteBinaryNode( &chunk, node->mChildren[i] );
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < nb_metadata; ++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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
|
|
@ -210,6 +210,8 @@ void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** node, aiNode* p
|
|||
(*node)->mTransformation = Read<aiMatrix4x4>(stream);
|
||||
(*node)->mNumChildren = Read<unsigned int>(stream);
|
||||
(*node)->mNumMeshes = Read<unsigned int>(stream);
|
||||
unsigned int nb_metadata = Read<unsigned int>(stream);
|
||||
|
||||
if(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue