Browse Source

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.

Alexander Gessler 11 years ago
parent
commit
75fd29ac19
2 changed files with 47 additions and 0 deletions
  1. 46 0
      code/SceneCombiner.cpp
  2. 1 0
      code/SceneCombiner.h

+ 46 - 0
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<bool*>(in.mData));
+			break;
+		case AI_INT:
+			out.mData = new int(*static_cast<int*>(in.mData));
+			break;
+		case AI_UINT64:
+			out.mData = new uint64_t(*static_cast<uint64_t*>(in.mData));
+			break;
+		case AI_FLOAT:
+			out.mData = new float(*static_cast<float*>(in.mData));
+			break;
+		case AI_AISTRING:
+			out.mData = new aiString(*static_cast<aiString*>(in.mData));
+			break;
+		case AI_AIVECTOR3D:
+			out.mData = new aiVector3D(*static_cast<aiVector3D*>(in.mData));
+			break;
+		default:
+			ai_assert(false);
+		}
+	}
+}
 
 }

+ 1 - 0
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);