Browse Source

Merge pull request #513 from assimp/xgl-fixes

XGL fixes
Alexander Gessler 10 years ago
parent
commit
2be44365dd
2 changed files with 17 additions and 0 deletions
  1. 6 0
      code/XGLLoader.cpp
  2. 11 0
      code/XGLLoader.h

+ 6 - 0
code/XGLLoader.cpp

@@ -431,6 +431,12 @@ aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* cl
 		throw;
 	}
 
+	// FIX: since we used std::multimap<> to keep meshes by id, mesh order now depends on the behaviour
+	// of the multimap implementation with respect to the ordering of entries with same values.
+	// C++11 gives the guarantee that it uses insertion order, before it is implementation-specific.
+	// Sort by material id to always guarantee a deterministic result.
+	std::sort(meshes.begin(), meshes.end(), SortMeshByMaterialId(scope));
+
 	// link meshes to node
 	nd->mNumMeshes = static_cast<unsigned int>(meshes.size());
 	if (nd->mNumMeshes) {

+ 11 - 0
code/XGLLoader.h

@@ -86,6 +86,7 @@ protected:
 
 private:
 
+	
 	struct TempScope
 	{
 		TempScope()
@@ -122,6 +123,16 @@ private:
 		aiLight* light;
 	};
 
+
+	struct SortMeshByMaterialId {
+		SortMeshByMaterialId(const TempScope& scope) : scope(scope) {}
+		bool operator()(unsigned int a, unsigned int b) const {
+			return scope.meshes_linear[a]->mMaterialIndex < scope.meshes_linear[b]->mMaterialIndex;
+		};
+
+		const TempScope& scope;
+	};
+
 	struct TempMesh
 	{
 		std::map<unsigned int, aiVector3D> points;