From 75fd29ac19563de2e235a20c4b3b15143d15f0c4 Mon Sep 17 00:00:00 2001 From: Alexander Gessler Date: Tue, 17 Jun 2014 15:18:10 +0200 Subject: [PATCH] SceneCombiner: implement proper copying of meta data. This entire module will need to be revamped in future as it is highly likely to cause further regressions as assimp data structures are modified. --- code/SceneCombiner.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++ code/SceneCombiner.h | 1 + 2 files changed, 47 insertions(+) diff --git a/code/SceneCombiner.cpp b/code/SceneCombiner.cpp index d6b138d74..f9face9b1 100644 --- a/code/SceneCombiner.cpp +++ b/code/SceneCombiner.cpp @@ -38,6 +38,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ +// TODO: refactor entire file to get rid of the "flat-copy" first approach +// to copying structures. This easily breaks in the most unintuitive way +// possible as new fields are added to assimp structures. // ---------------------------------------------------------------------------- /** @file Implements Assimp::SceneCombiner. This is a smart utility @@ -1194,10 +1197,53 @@ void SceneCombiner::Copy (aiNode** _dest, const aiNode* src) // get a flat copy ::memcpy(dest,src,sizeof(aiNode)); + if (src->mMetaData) { + Copy(&dest->mMetaData, src->mMetaData); + } + // and reallocate all arrays GetArrayCopy( dest->mMeshes, dest->mNumMeshes ); CopyPtrArray( dest->mChildren, src->mChildren,dest->mNumChildren); } +// ------------------------------------------------------------------------------------------------ +void SceneCombiner::Copy (aiMetadata** _dest, const aiMetadata* src) +{ + ai_assert(NULL != _dest && NULL != src); + + aiMetadata* dest = *_dest = new aiMetadata(); + dest->mNumProperties = src->mNumProperties; + dest->mKeys = new aiString[src->mNumProperties]; + std::copy(src->mKeys, src->mKeys + src->mNumProperties, dest->mKeys); + + dest->mValues = new aiMetadataEntry[src->mNumProperties]; + for (unsigned int i = 0; i < src->mNumProperties; ++i) { + aiMetadataEntry& in = src->mValues[i]; + aiMetadataEntry& out = dest->mValues[i]; + out.mType = in.mType; + switch (dest->mValues[i].mType) { + case AI_BOOL: + out.mData = new bool(*static_cast(in.mData)); + break; + case AI_INT: + out.mData = new int(*static_cast(in.mData)); + break; + case AI_UINT64: + out.mData = new uint64_t(*static_cast(in.mData)); + break; + case AI_FLOAT: + out.mData = new float(*static_cast(in.mData)); + break; + case AI_AISTRING: + out.mData = new aiString(*static_cast(in.mData)); + break; + case AI_AIVECTOR3D: + out.mData = new aiVector3D(*static_cast(in.mData)); + break; + default: + ai_assert(false); + } + } +} } diff --git a/code/SceneCombiner.h b/code/SceneCombiner.h index e7dd242fd..0c4cfc2ee 100644 --- a/code/SceneCombiner.h +++ b/code/SceneCombiner.h @@ -349,6 +349,7 @@ public: static void Copy (aiBone** dest, const aiBone* src); static void Copy (aiLight** dest, const aiLight* src); static void Copy (aiNodeAnim** dest, const aiNodeAnim* src); + static void Copy (aiMetadata** dest, const aiMetadata* src); // recursive, of course static void Copy (aiNode** dest, const aiNode* src);