diff --git a/code/M3Importer.cpp b/code/M3Importer.cpp index b256b2dce..df7c3c026 100644 --- a/code/M3Importer.cpp +++ b/code/M3Importer.cpp @@ -81,7 +81,7 @@ bool M3Importer::CanRead( const std::string &rFile, IOSystem* /*pIOHandler*/, bo // ------------------------------------------------------------------------------------------------ void M3Importer::GetExtensionList(std::set& extensions) { - extensions.insert( "m3" ); + extensions.insert( M3Extension ); } // ------------------------------------------------------------------------------------------------ @@ -157,6 +157,11 @@ void M3Importer::InternReadFile( const std::string& pFile, aiScene* pScene, IOSy ok = false; break; } + + // Everything ok, if not throw an exception + if ( !ok ) { + throw DeadlyImportError( "Failed to open file " + pFile + "."); + } // Get all region data regions = GetEntries( pViews->regions ); @@ -165,11 +170,6 @@ void M3Importer::InternReadFile( const std::string& pFile, aiScene* pScene, IOSy faces = GetEntries( pViews->faces ); nFaces = pViews->faces.nEntries; - // Everything ok, if not throw an exception - if ( !ok ) { - throw DeadlyImportError( "Failed to open file " + pFile + "."); - } - // Convert the vertices std::vector vertices; vertices.resize( nVertices ); @@ -186,21 +186,21 @@ void M3Importer::InternReadFile( const std::string& pFile, aiScene* pScene, IOSy } } - // Write UV coords + // Write the UV coordinates offset = 0; std::vector uvCoords; uvCoords.resize( nVertices ); for( unsigned int i = 0; i < nVertices; ++i ) { if( pVerts1 ) { - float u = (float) pVerts1[i].uv[0] / 2048; - float v = (float) pVerts1[i].uv[1] / 2048; + float u = (float) pVerts1[ i ].uv[ 0 ] / 2048; + float v = (float) pVerts1[ i ].uv[ 1 ] / 2048; uvCoords[ offset ].Set( u, v, 0.0f ); ++offset; } if( pVerts2 ) { - float u = (float) pVerts2[i].uv[0] / 2048; - float v = (float) pVerts2[i].uv[1] / 2048; + float u = (float) pVerts2[ i ].uv[ 0 ] / 2048; + float v = (float) pVerts2[ i ].uv[ 1 ] / 2048; uvCoords[ offset ].Set( u, v, 0.0f ); ++offset; } @@ -267,7 +267,7 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV pRootNode->mChildren = new aiNode*[ pRootNode->mNumChildren ]; } - for ( unsigned int i=0; iregions.nEntries; ++i ) { + for ( unsigned int i=0; imNumChildren; ++i ) { // Create a new node pCurrentNode = createNode( pRootNode ); std::stringstream stream; @@ -276,10 +276,10 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV pRootNode->mChildren[ i ] = pCurrentNode; // Loop over the faces of the nodes - unsigned int numFaces = ( pRegions[ i ].ofsIndices + pRegions[ i ].nIndices ) - pRegions[ i ].ofsIndices; + unsigned int numFaces = ( ( pRegions[ i ].ofsIndices + pRegions[ i ].nIndices ) - pRegions[ i ].ofsIndices ) / 3; aiMesh *pMesh = new aiMesh; MeshArray.push_back( pMesh ); - //pMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; + pMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; pMesh->mNumFaces = numFaces; pMesh->mFaces = new aiFace[ pMesh->mNumFaces ]; @@ -303,7 +303,7 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV pCurrentNode->mMeshes = new unsigned int[ 1 ]; const unsigned int meshIdx = MeshArray.size() - 1; pCurrentNode->mMeshes[ 0 ] = meshIdx; - createVertexData( pMesh, vertices, normals ); + createVertexData( pMesh, vertices, uvCoords, normals ); } // Copy the meshes into the scene @@ -319,12 +319,14 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV // ------------------------------------------------------------------------------------------------ // void M3Importer::createVertexData( aiMesh *pMesh, const std::vector &vertices, + const std::vector &uvCoords, const std::vector &normals ) { unsigned int numIndices = 0; pMesh->mNumVertices = pMesh->mNumFaces * 3; pMesh->mVertices = new aiVector3D[ pMesh->mNumVertices ]; +// pMesh->mNumUVComponents pMesh->mNormals = new aiVector3D[ pMesh->mNumVertices ]; unsigned int pos = 0; for ( unsigned int currentFace = 0; currentFace < pMesh->mNumFaces; currentFace++ ) { diff --git a/code/M3Importer.h b/code/M3Importer.h index 87f5c3a9e..3780f6598 100644 --- a/code/M3Importer.h +++ b/code/M3Importer.h @@ -698,7 +698,8 @@ private: void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler ); void convertToAssimp( const std::string& pFile, aiScene* pScene, DIV *pViews, Region *pRegions, uint16 *pFaces, const std::vector &vertices, const std::vector &uvCoords, const std::vector &normals ); - void createVertexData( aiMesh *pMesh, const std::vector &vertices, const std::vector &normals ); + void createVertexData( aiMesh *pMesh, const std::vector &vertices, const std::vector &uvCoords, + const std::vector &normals ); aiNode *createNode( aiNode *pParent ); template T* GetEntries( Reference ref ); diff --git a/contrib/poly2tri/poly2tri/sweep/sweep.cc b/contrib/poly2tri/poly2tri/sweep/sweep.cc index 573ca372d..883cde619 100644 --- a/contrib/poly2tri/poly2tri/sweep/sweep.cc +++ b/contrib/poly2tri/poly2tri/sweep/sweep.cc @@ -192,7 +192,7 @@ Node& Sweep::NewFrontTriangle(SweepContext& tcx, Point& point, Node& node) new_node->next = node.next; new_node->prev = &node; node.next->prev = new_node; - node.next = new_node; + node.next = new_node; if (!Legalize(tcx, *triangle)) { tcx.MapTriangleToNodes(*triangle); @@ -214,7 +214,7 @@ void Sweep::Fill(SweepContext& tcx, Node& node) // Update the advancing front node.prev->next = node.next; - node.next->prev = node.prev; + node.next->prev = node.prev; // If it was legalized the triangle has already been mapped if (!Legalize(tcx, *triangle)) { @@ -224,7 +224,7 @@ void Sweep::Fill(SweepContext& tcx, Node& node) } void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n) -{ +{ // Fill right holes Node* node = n.next; @@ -467,7 +467,7 @@ void Sweep::FillBasinReq(SweepContext& tcx, Node* node) return; } - Fill(tcx, *node); + Fill(tcx, *node); if (node->prev == tcx.basin.left_node && node->next == tcx.basin.right_node) { return; @@ -562,7 +562,7 @@ void Sweep::FillRightConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node) // Next is convex } } - } + } } @@ -749,15 +749,15 @@ void Sweep::FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& Point& newP = NextFlipPoint(ep, eq, ot, op); FlipScanEdgeEvent(tcx, ep, eq, flip_triangle, ot, newP); } -} - -Sweep::~Sweep() { - - // Clean up memory - for(int i = 0; i < nodes_.size(); i++) { - delete nodes_[i]; - } - +} + +Sweep::~Sweep() { + + // Clean up memory + for(int i = 0; i < nodes_.size(); i++) { + delete nodes_[i]; + } + } } diff --git a/test/models-nonbsd/M3/Bunker.m3 b/test/models-nonbsd/M3/Bunker.m3 new file mode 100644 index 000000000..88c2ab95c Binary files /dev/null and b/test/models-nonbsd/M3/Bunker.m3 differ