Added support for metadata in assbin format
authorLeo Terziman <leo.terziman@clarte.asso.fr>
Tue, 11 Jul 2017 15:39:36 +0000 (17:39 +0200)
committerLeo Terziman <leo.terziman@clarte.asso.fr>
Tue, 11 Jul 2017 15:39:36 +0000 (17:39 +0200)
code/AssbinExporter.cpp
code/AssbinLoader.cpp

index b03a453..5735c92 100644 (file)
@@ -329,6 +329,7 @@ inline size_t WriteArray(IOStream * stream, const T* in, unsigned int size)
             Write<aiMatrix4x4>(&chunk,node->mTransformation);
             Write<unsigned int>(&chunk,node->mNumChildren);
             Write<unsigned int>(&chunk,node->mNumMeshes);
+                       Write<unsigned int>(&chunk,node->mMetaData->mNumProperties);
 
             for (unsigned int i = 0; i < node->mNumMeshes;++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) {
                 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;
+                               }
+                       }
         }
 
         // -----------------------------------------------------------------------------------
index 3ed5829..218d8f5 100644 (file)
@@ -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;
+               }
+       }
 }
 
 // -----------------------------------------------------------------------------------