From 6c6a8fe671b927bf7ff37157436e803931b8ca68 Mon Sep 17 00:00:00 2001 From: Leo Terziman Date: Tue, 11 Jul 2017 17:39:36 +0200 Subject: [PATCH] Added support for metadata in assbin format --- code/AssbinExporter.cpp | 34 ++++++++++++++++++++++++++++++++++ code/AssbinLoader.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/code/AssbinExporter.cpp b/code/AssbinExporter.cpp index b03a45309..5735c92cd 100644 --- a/code/AssbinExporter.cpp +++ b/code/AssbinExporter.cpp @@ -329,6 +329,7 @@ inline size_t WriteArray(IOStream * stream, const T* in, unsigned int size) Write(&chunk,node->mTransformation); Write(&chunk,node->mNumChildren); Write(&chunk,node->mNumMeshes); + Write(&chunk,node->mMetaData->mNumProperties); for (unsigned int i = 0; i < node->mNumMeshes;++i) { Write(&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(&chunk, key); + Write(&chunk, type); + + switch (type) { + case AI_BOOL: + Write(&chunk, *((bool*) value)); + break; + case AI_INT32: + Write(&chunk, *((int32_t*) value)); + break; + case AI_UINT64: + Write(&chunk, *((uint64_t*) value)); + break; + case AI_FLOAT: + Write(&chunk, *((float*) value)); + break; + case AI_DOUBLE: + Write(&chunk, *((double*) value)); + break; + case AI_AISTRING: + Write(&chunk, *((aiString*) value)); + break; + case AI_AIVECTOR3D: + Write(&chunk, *((aiVector3D*) value)); + break; + } + } } // ----------------------------------------------------------------------------------- diff --git a/code/AssbinLoader.cpp b/code/AssbinLoader.cpp index 3ed58297c..218d8f53a 100644 --- a/code/AssbinLoader.cpp +++ b/code/AssbinLoader.cpp @@ -210,6 +210,8 @@ void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** node, aiNode* p (*node)->mTransformation = Read(stream); (*node)->mNumChildren = Read(stream); (*node)->mNumMeshes = Read(stream); + unsigned int nb_metadata = Read(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(stream); + (*node)->mMetaData->mValues[i].mType = (aiMetadataType) Read(stream); + void* data = NULL; + + switch ((*node)->mMetaData->mValues[i].mType) { + case AI_BOOL: + data = new bool(Read(stream)); + break; + case AI_INT32: + data = new int32_t(Read(stream)); + break; + case AI_UINT64: + data = new uint64_t(Read(stream)); + break; + case AI_FLOAT: + data = new float(Read(stream)); + break; + case AI_DOUBLE: + data = new double(Read(stream)); + break; + case AI_AISTRING: + data = new aiString(Read(stream)); + break; + case AI_AIVECTOR3D: + data = new aiVector3D(Read(stream)); + break; + } + + (*node)->mMetaData->mValues[i].mData = data; + } + } } // -----------------------------------------------------------------------------------