From 244e2468c6f44527be82feb5bb27bcf107bc8425 Mon Sep 17 00:00:00 2001 From: ulfjorensen Date: Sun, 18 Jan 2009 00:52:20 +0000 Subject: [PATCH] - Bugfix: ColladaLoader failed on 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 --- code/ColladaLoader.cpp | 9 ++- code/ColladaParser.cpp | 77 +++++++++++++------ code/ColladaParser.h | 3 + workspaces/vc9/assimp.sln | 1 - workspaces/vc9/shared/DllShared.vsprops | 17 ++++ workspaces/vc9/shared/LibShared.vsprops | 9 +++ workspaces/vc9/shared/NoBoostShared.vsprops | 11 +++ .../vc9/shared/SingleThreadedShared.vsprops | 11 +++ workspaces/vc9/shared/UnitTest.vsprops | 17 ++++ 9 files changed, 127 insertions(+), 28 deletions(-) create mode 100644 workspaces/vc9/shared/DllShared.vsprops create mode 100644 workspaces/vc9/shared/LibShared.vsprops create mode 100644 workspaces/vc9/shared/NoBoostShared.vsprops create mode 100644 workspaces/vc9/shared/SingleThreadedShared.vsprops create mode 100644 workspaces/vc9/shared/UnitTest.vsprops diff --git a/code/ColladaLoader.cpp b/code/ColladaLoader.cpp index 2e630cebb..2f2045943 100644 --- a/code/ColladaLoader.cpp +++ b/code/ColladaLoader.cpp @@ -155,7 +155,7 @@ void ColladaLoader::BuildMeshesForNode( const ColladaParser& pParser, const Coll // accumulated mesh references by this node std::vector 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::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; } } diff --git a/code/ColladaParser.cpp b/code/ColladaParser.cpp index e65a1c144..eecb8a8f1 100644 --- a/code/ColladaParser.cpp +++ b/code/ColladaParser.cpp @@ -554,17 +554,12 @@ void ColladaParser::ReadGeometryLibrary() // TODO: (thom) support SIDs assert( TestAttribute( "sid") == -1); - // a always contains a single 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 element, the inner closing of 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 - 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 - 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\"."); diff --git a/code/ColladaParser.h b/code/ColladaParser.h index e80485e0f..e3b2f3784 100644 --- a/code/ColladaParser.h +++ b/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); diff --git a/workspaces/vc9/assimp.sln b/workspaces/vc9/assimp.sln index bafa8268b..c500d4ff6 100644 --- a/workspaces/vc9/assimp.sln +++ b/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 diff --git a/workspaces/vc9/shared/DllShared.vsprops b/workspaces/vc9/shared/DllShared.vsprops new file mode 100644 index 000000000..b19c45e7d --- /dev/null +++ b/workspaces/vc9/shared/DllShared.vsprops @@ -0,0 +1,17 @@ + + + + + diff --git a/workspaces/vc9/shared/LibShared.vsprops b/workspaces/vc9/shared/LibShared.vsprops new file mode 100644 index 000000000..f5ac51231 --- /dev/null +++ b/workspaces/vc9/shared/LibShared.vsprops @@ -0,0 +1,9 @@ + + + diff --git a/workspaces/vc9/shared/NoBoostShared.vsprops b/workspaces/vc9/shared/NoBoostShared.vsprops new file mode 100644 index 000000000..637faa281 --- /dev/null +++ b/workspaces/vc9/shared/NoBoostShared.vsprops @@ -0,0 +1,11 @@ + + + + diff --git a/workspaces/vc9/shared/SingleThreadedShared.vsprops b/workspaces/vc9/shared/SingleThreadedShared.vsprops new file mode 100644 index 000000000..efbb6515f --- /dev/null +++ b/workspaces/vc9/shared/SingleThreadedShared.vsprops @@ -0,0 +1,11 @@ + + + + diff --git a/workspaces/vc9/shared/UnitTest.vsprops b/workspaces/vc9/shared/UnitTest.vsprops new file mode 100644 index 000000000..1f93b380d --- /dev/null +++ b/workspaces/vc9/shared/UnitTest.vsprops @@ -0,0 +1,17 @@ + + + + +