Selaa lähdekoodia

- Bugfix: ColladaLoader failed on <extra> tags in geometry elements
- Bugfix: ColladaLoader reads and filters mesh subgroups without faces now. Who the fuck writes them anyways? I'm looking at you, Maya export!
- Made the VC9 workspace load again. Thanks to Aramis for the hints.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@302 67173fc5-114c-0410-ac8e-9d2fd5bffc1f

ulfjorensen 16 vuotta sitten
vanhempi
commit
244e2468c6

+ 6 - 3
code/ColladaLoader.cpp

@@ -155,7 +155,7 @@ void ColladaLoader::BuildMeshesForNode( const ColladaParser& pParser, const Coll
 	// accumulated mesh references by this node
 	std::vector<size_t> newMeshRefs;
 
-	// for the moment we simply ignore all material tags and transfer the meshes one by one
+	// add a mesh for each subgroup in each collada mesh
 	BOOST_FOREACH( const Collada::MeshInstance& mid, pNode->mMeshes)
 	{
 		// find the referred mesh
@@ -172,6 +172,9 @@ void ColladaLoader::BuildMeshesForNode( const ColladaParser& pParser, const Coll
 		for( size_t sm = 0; sm < srcMesh->mSubMeshes.size(); ++sm)
 		{
 			const Collada::SubMesh& submesh = srcMesh->mSubMeshes[sm];
+      if( submesh.mNumFaces == 0)
+        continue;
+
 			// find material assigned to this submesh
 			std::map<std::string, std::string>::const_iterator meshMatIt = mid.mMaterials.find( submesh.mMaterial);
 			std::string meshMaterial;
@@ -216,8 +219,8 @@ void ColladaLoader::BuildMeshesForNode( const ColladaParser& pParser, const Coll
 					if( srcMesh->mTexCoords[a].size() == srcMesh->mPositions.size())
 					{
 						dstMesh->mTextureCoords[a] = new aiVector3D[numVertices];
-						for( size_t b = vertexStart; b < vertexStart + numVertices; ++b)
-							dstMesh->mTextureCoords[a][b].Set( srcMesh->mTexCoords[a][b].x, srcMesh->mTexCoords[a][b].y, 0.0f);
+						for( size_t b = 0; b < numVertices; ++b)
+							dstMesh->mTextureCoords[a][b].Set( srcMesh->mTexCoords[a][vertexStart+b].x, srcMesh->mTexCoords[a][vertexStart+b].y, 0.0f);
 						dstMesh->mNumUVComponents[a] = 2;
 					}
 				}

+ 53 - 24
code/ColladaParser.cpp

@@ -554,17 +554,12 @@ void ColladaParser::ReadGeometryLibrary()
 				// TODO: (thom) support SIDs
 				assert( TestAttribute( "sid") == -1);
 
-				// a <geometry> always contains a single <mesh> element inside, so we just skip that element in advance
-				TestOpening( "mesh");
-
 				// create a mesh and store it in the library under its ID
 				Mesh* mesh = new Mesh;
-				mMeshLibrary[id] = mesh;
-				// read on from there
-				ReadMesh( mesh);
+ 				mMeshLibrary[id] = mesh;
 
-				// check for the closing tag of the outer <geometry> element, the inner closing of <mesh> has been consumed by ReadMesh()
-				TestClosing( "geometry");
+				// read on from there
+        ReadGeometry( mesh);
 			} else
 			{
 				// ignore the rest
@@ -581,6 +576,34 @@ void ColladaParser::ReadGeometryLibrary()
 	}
 }
 
+// ------------------------------------------------------------------------------------------------
+// Reads a geometry from the geometry library.
+void ColladaParser::ReadGeometry( Collada::Mesh* pMesh)
+{
+	while( mReader->read())
+	{
+		if( mReader->getNodeType() == irr::io::EXN_ELEMENT)
+		{
+			if( IsElement( "mesh"))
+			{
+        // read on from there
+				ReadMesh( pMesh);
+			} else
+			{
+				// ignore the rest
+				SkipElement();
+			}
+		}
+		else if( mReader->getNodeType() == irr::io::EXN_ELEMENT_END)
+		{
+			if( strcmp( mReader->getNodeName(), "geometry") != 0)
+				ThrowException( "Expected end of \"geometry\" element.");
+
+			break;
+		}
+	}
+}
+
 // ------------------------------------------------------------------------------------------------
 // Reads a mesh from the geometry library
 void ColladaParser::ReadMesh( Mesh* pMesh)
@@ -840,25 +863,31 @@ void ColladaParser::ReadIndexData( Mesh* pMesh)
 			} 
 			else if( IsElement( "vcount"))
 			{
-				// case <polylist> - specifies the number of indices for each polygon
-				const char* content = GetTextContent();
-				vcount.reserve( numPrimitives);
-				for( unsigned int a = 0; a < numPrimitives; a++)
-				{
-					if( *content == 0)
-						ThrowException( "Expected more values while reading vcount contents.");
-					// read a number
-					vcount.push_back( (size_t) strtol10( content, &content));
-					// skip whitespace after it
-					SkipSpacesAndLineEnd( &content);
-				}
-				
-				TestClosing( "vcount");
+        if( !mReader->isEmptyElement())
+        {
+				  // case <polylist> - specifies the number of indices for each polygon
+				  const char* content = GetTextContent();
+				  vcount.reserve( numPrimitives);
+				  for( unsigned int a = 0; a < numPrimitives; a++)
+				  {
+					  if( *content == 0)
+						  ThrowException( "Expected more values while reading vcount contents.");
+					  // read a number
+					  vcount.push_back( (size_t) strtol10( content, &content));
+					  // skip whitespace after it
+					  SkipSpacesAndLineEnd( &content);
+				  }
+  				
+				  TestClosing( "vcount");
+        }
 			}
 			else if( IsElement( "p"))
 			{
-				// now here the actual fun starts - these are the indices to construct the mesh data from
-				ReadPrimitives( pMesh, perIndexData, numPrimitives, vcount, primType);
+        if( !mReader->isEmptyElement())
+        {
+				  // now here the actual fun starts - these are the indices to construct the mesh data from
+				  ReadPrimitives( pMesh, perIndexData, numPrimitives, vcount, primType);
+        }
 			} else
 			{
 				ThrowException( "Unexpected sub element in tag \"vertices\".");

+ 3 - 0
code/ColladaParser.h

@@ -101,6 +101,9 @@ protected:
 	/** Reads the geometry library contents */
 	void ReadGeometryLibrary();
 
+  /** Reads a geometry from the geometry library. */
+  void ReadGeometry( Collada::Mesh* pMesh);
+
 	/** Reads a mesh from the geometry library */
 	void ReadMesh( Collada::Mesh* pMesh);
 

+ 0 - 1
workspaces/vc9/assimp.sln

@@ -100,7 +100,6 @@ Global
 		{5691E159-2D9B-407F-971F-EA5C592DC524}.release-st|x64.ActiveCfg = release-st|x64
 		{5691E159-2D9B-407F-971F-EA5C592DC524}.release-st|x64.Build.0 = release-st|x64
 		{9B9D1C90-8A03-409A-B547-AE7B48B90F1A}.debug|Win32.ActiveCfg = debug|Win32
-		{9B9D1C90-8A03-409A-B547-AE7B48B90F1A}.debug|Win32.Build.0 = debug|Win32
 		{9B9D1C90-8A03-409A-B547-AE7B48B90F1A}.debug|x64.ActiveCfg = debug|x64
 		{9B9D1C90-8A03-409A-B547-AE7B48B90F1A}.debug|x64.Build.0 = debug|x64
 		{9B9D1C90-8A03-409A-B547-AE7B48B90F1A}.debug-dll|Win32.ActiveCfg = debug-dll|Win32

+ 17 - 0
workspaces/vc9/shared/DllShared.vsprops

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="DllShared"
+	OutputDirectory="./../../bin/$(ProjectName)_$(ConfigurationName)_$(PlatformName)"
+	IntermediateDirectory="./../../obj/$(ProjectName)_$(ConfigurationName)_$(PlatformName)"
+	>
+	<Tool
+		Name="VCCLCompilerTool"
+		PreprocessorDefinitions="ASSIMP_BUILD_DLL_EXPORT"
+	/>
+	<Tool
+		Name="VCPostBuildEventTool"
+		CommandLine=""
+	/>
+</VisualStudioPropertySheet>

+ 9 - 0
workspaces/vc9/shared/LibShared.vsprops

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="LibShared"
+	OutputDirectory="./../../lib/$(ProjectName)_$(ConfigurationName)_$(PlatformName)"
+	IntermediateDirectory="./../../obj/$(ProjectName)_$(ConfigurationName)_$(PlatformName)"
+	>
+</VisualStudioPropertySheet>

+ 11 - 0
workspaces/vc9/shared/NoBoostShared.vsprops

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="NoBoostShared"
+	>
+	<Tool
+		Name="VCCLCompilerTool"
+		PreprocessorDefinitions="ASSIMP_BUILD_BOOST_WORKAROUND;ASSIMP_BUILD_SINGLETHREADED"
+	/>
+</VisualStudioPropertySheet>

+ 11 - 0
workspaces/vc9/shared/SingleThreadedShared.vsprops

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="SingleThreadedShared"
+	>
+	<Tool
+		Name="VCCLCompilerTool"
+		PreprocessorDefinitions="ASSIMP_BUILD_SINGLETHREADED"
+	/>
+</VisualStudioPropertySheet>

+ 17 - 0
workspaces/vc9/shared/UnitTest.vsprops

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="UnitTest"
+	OutputDirectory="./../../lib/$(ProjectName)_$(ConfigurationName)_$(PlatformName)"
+	>
+	<Tool
+		Name="VCCLCompilerTool"
+		AdditionalIncludeDirectories="&quot;..\..\contrib\cppunit-1.12.1\include&quot;"
+		PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS"
+	/>
+	<Tool
+		Name="VCLinkerTool"
+		AdditionalLibraryDirectories="&quot;..\..\contrib\cppunit-1.12.1\lib&quot;"
+	/>
+</VisualStudioPropertySheet>