Procházet zdrojové kódy

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 před 11 roky
rodič
revize
75fd29ac19
2 změnil soubory, kde provedl 47 přidání a 0 odebrání
  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
 /** @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
 	// get a flat copy
 	::memcpy(dest,src,sizeof(aiNode));
 	::memcpy(dest,src,sizeof(aiNode));
 
 
+	if (src->mMetaData) {
+		Copy(&dest->mMetaData, src->mMetaData);
+	}
+
 	// and reallocate all arrays
 	// and reallocate all arrays
 	GetArrayCopy( dest->mMeshes, dest->mNumMeshes );
 	GetArrayCopy( dest->mMeshes, dest->mNumMeshes );
 	CopyPtrArray( dest->mChildren, src->mChildren,dest->mNumChildren);
 	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  (aiBone** dest, const aiBone* src);
 	static void Copy  (aiLight** dest, const aiLight* src);
 	static void Copy  (aiLight** dest, const aiLight* src);
 	static void Copy  (aiNodeAnim** dest, const aiNodeAnim* src);
 	static void Copy  (aiNodeAnim** dest, const aiNodeAnim* src);
+	static void Copy  (aiMetadata** dest, const aiMetadata* src);
 
 
 	// recursive, of course
 	// recursive, of course
 	static void Copy     (aiNode** dest, const aiNode* src);
 	static void Copy     (aiNode** dest, const aiNode* src);