浏览代码

- 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
kimmi 13 年之前
父节点
当前提交
648e8fe924
共有 4 个文件被更改,包括 18 次插入21 次删除
  1. 6 6
      code/M3Importer.cpp
  2. 7 10
      code/ObjFileData.h
  3. 3 3
      code/ObjFileImporter.cpp
  4. 2 2
      code/ObjFileParser.cpp

+ 6 - 6
code/M3Importer.cpp

@@ -268,6 +268,7 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV
 	}
 
 	for ( unsigned int i=0; i<pRootNode->mNumChildren; ++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<aiMesh*>::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<aiVector3D>
 
 	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<aiVector3D>
 			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++;
 			}

+ 7 - 10
code/ObjFileData.h

@@ -274,7 +274,6 @@ struct Model
 	//!	Material map
 	std::map<std::string, Material*> m_MaterialMap;
 
-
 	//!	\brief	Default constructor
 	Model() :
 		m_ModelName(""),
@@ -292,28 +291,26 @@ struct Model
 	{
 		// Clear all stored object instances
 		for (std::vector<Object*>::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<Mesh*>::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<std::string, Material*>::iterator it = m_MaterialMap.begin(); it != m_MaterialMap.end(); ++it ) {
+			delete it->second;
+		}
 	}
 };
 

+ 3 - 3
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<std::string, ObjFile::Material*>::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<int>( &sm, 1, AI_MATKEY_SHADING_MODEL);
 
 		// multiplying the specular exponent with 2 seems to yield better results

+ 2 - 2
code/ObjFileParser.cpp

@@ -84,8 +84,8 @@ ObjFileParser::ObjFileParser(std::vector<char> &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;