From 648e8fe924f6cbc38b52a2f8540a84e6438e50bd Mon Sep 17 00:00:00 2001 From: kimmi Date: Sun, 26 Feb 2012 13:36:29 +0000 Subject: [PATCH] - Bugfix: Fix two possible reasons for bug ID 3039342 : On skipping an invalid material description in obj-loader avoid creating aiMaterial instance. Release obj-specific material instances. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1186 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/M3Importer.cpp | 12 ++++++------ code/ObjFileData.h | 17 +++++++---------- code/ObjFileImporter.cpp | 6 +++--- code/ObjFileParser.cpp | 4 ++-- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/code/M3Importer.cpp b/code/M3Importer.cpp index df7c3c026..e02248250 100644 --- a/code/M3Importer.cpp +++ b/code/M3Importer.cpp @@ -268,6 +268,7 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV } for ( unsigned int i=0; imNumChildren; ++i ) { + //pRegions[ i ]. // Create a new node pCurrentNode = createNode( pRootNode ); std::stringstream stream; @@ -294,10 +295,6 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV pCurrentFace->mIndices[ 1 ] = pFaces[ j+1 ]; pCurrentFace->mIndices[ 2 ] = pFaces[ j+2 ]; } -/* fprintf_s(f, "f %d/%d/%d %d/%d/%d %d/%d/%d\n", faces[j]+1, faces[j]+1, faces[j]+1, - faces[j+1]+1, faces[j+1]+1, faces[j+1]+1, - faces[j+2]+1, faces[j+2]+1, faces[j+2]+1);*/ - // Now we can create the vertex data itself pCurrentNode->mNumMeshes = 1; pCurrentNode->mMeshes = new unsigned int[ 1 ]; @@ -312,7 +309,7 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV unsigned int pos = 0; for ( std::vector::iterator it = MeshArray.begin(); it != MeshArray.end(); ++it ) { pScene->mMeshes[ pos ] = *it; - pos++; + ++pos; } } @@ -326,7 +323,8 @@ void M3Importer::createVertexData( aiMesh *pMesh, const std::vector pMesh->mNumVertices = pMesh->mNumFaces * 3; pMesh->mVertices = new aiVector3D[ pMesh->mNumVertices ]; -// pMesh->mNumUVComponents + pMesh->mNumUVComponents[ 0 ] = 2; + pMesh->mTextureCoords[ 0 ] = new aiVector3D[ pMesh->mNumVertices ]; pMesh->mNormals = new aiVector3D[ pMesh->mNumVertices ]; unsigned int pos = 0; for ( unsigned int currentFace = 0; currentFace < pMesh->mNumFaces; currentFace++ ) { @@ -336,6 +334,8 @@ void M3Importer::createVertexData( aiMesh *pMesh, const std::vector if ( vertices.size() > idx ) { pMesh->mVertices[ pos ] = vertices[ idx ]; pMesh->mNormals[ pos ] = normals[ idx ]; + pMesh->mTextureCoords[ 0 ]->x = uvCoords[ idx ].x; + pMesh->mTextureCoords[ 0 ]->y = uvCoords[ idx ].y; pFace->mIndices[ currentIdx ] = pos; pos++; } diff --git a/code/ObjFileData.h b/code/ObjFileData.h index 5bfbadad4..c2c092cee 100644 --- a/code/ObjFileData.h +++ b/code/ObjFileData.h @@ -274,7 +274,6 @@ struct Model //! Material map std::map m_MaterialMap; - //! \brief Default constructor Model() : m_ModelName(""), @@ -292,28 +291,26 @@ struct Model { // Clear all stored object instances for (std::vector::iterator it = m_Objects.begin(); - it != m_Objects.end(); ++it) - { + it != m_Objects.end(); ++it) { delete *it; } m_Objects.clear(); // Clear all stored mesh instances for (std::vector::iterator it = m_Meshes.begin(); - it != m_Meshes.end(); ++it) - { + it != m_Meshes.end(); ++it) { delete *it; } - m_Meshes.clear(); - for(GroupMapIt it = m_Groups.begin(); - it != m_Groups.end(); ++it) - { + for(GroupMapIt it = m_Groups.begin(); it != m_Groups.end(); ++it) { delete it->second; } - m_Groups.clear(); + + for ( std::map::iterator it = m_MaterialMap.begin(); it != m_MaterialMap.end(); ++it ) { + delete it->second; + } } }; diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 7e348ea8a..155c11cc5 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -477,9 +477,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc pScene->mMaterials = new aiMaterial*[ numMaterials ]; for ( unsigned int matIndex = 0; matIndex < numMaterials; matIndex++ ) - { - aiMaterial* mat = new aiMaterial; - + { // Store material name std::map::const_iterator it; it = pModel->m_MaterialMap.find( pModel->m_MaterialLib[ matIndex ] ); @@ -488,6 +486,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc if ( pModel->m_MaterialMap.end() == it ) continue; + aiMaterial* mat = new aiMaterial; ObjFile::Material *pCurrentMaterial = (*it).second; mat->AddProperty( &pCurrentMaterial->MaterialName, AI_MATKEY_NAME ); @@ -508,6 +507,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc sm = aiShadingMode_Gouraud; DefaultLogger::get()->error("OBJ: unexpected illumination model (0-2 recognized)"); } + mat->AddProperty( &sm, 1, AI_MATKEY_SHADING_MODEL); // multiplying the specular exponent with 2 seems to yield better results diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 970bd7d69..5dcdf4b9a 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -84,8 +84,8 @@ ObjFileParser::ObjFileParser(std::vector &Data,const std::string &strModel // Destructor ObjFileParser::~ObjFileParser() { - delete m_pModel->m_pDefaultMaterial; - m_pModel->m_pDefaultMaterial = NULL; + /*delete m_pModel->m_pDefaultMaterial; + m_pModel->m_pDefaultMaterial = NULL;*/ delete m_pModel; m_pModel = NULL;