- 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
pull/5/head
kimmi 2012-02-26 13:36:29 +00:00
parent 8fc1d1c529
commit 648e8fe924
4 changed files with 18 additions and 21 deletions

View File

@ -268,6 +268,7 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV
} }
for ( unsigned int i=0; i<pRootNode->mNumChildren; ++i ) { for ( unsigned int i=0; i<pRootNode->mNumChildren; ++i ) {
//pRegions[ i ].
// Create a new node // Create a new node
pCurrentNode = createNode( pRootNode ); pCurrentNode = createNode( pRootNode );
std::stringstream stream; 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[ 1 ] = pFaces[ j+1 ];
pCurrentFace->mIndices[ 2 ] = pFaces[ j+2 ]; 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 // Now we can create the vertex data itself
pCurrentNode->mNumMeshes = 1; pCurrentNode->mNumMeshes = 1;
pCurrentNode->mMeshes = new unsigned int[ 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; unsigned int pos = 0;
for ( std::vector<aiMesh*>::iterator it = MeshArray.begin(); it != MeshArray.end(); ++it ) { for ( std::vector<aiMesh*>::iterator it = MeshArray.begin(); it != MeshArray.end(); ++it ) {
pScene->mMeshes[ pos ] = *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->mNumVertices = pMesh->mNumFaces * 3;
pMesh->mVertices = new aiVector3D[ pMesh->mNumVertices ]; 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 ]; pMesh->mNormals = new aiVector3D[ pMesh->mNumVertices ];
unsigned int pos = 0; unsigned int pos = 0;
for ( unsigned int currentFace = 0; currentFace < pMesh->mNumFaces; currentFace++ ) { 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 ) { if ( vertices.size() > idx ) {
pMesh->mVertices[ pos ] = vertices[ idx ]; pMesh->mVertices[ pos ] = vertices[ idx ];
pMesh->mNormals[ pos ] = normals[ idx ]; pMesh->mNormals[ pos ] = normals[ idx ];
pMesh->mTextureCoords[ 0 ]->x = uvCoords[ idx ].x;
pMesh->mTextureCoords[ 0 ]->y = uvCoords[ idx ].y;
pFace->mIndices[ currentIdx ] = pos; pFace->mIndices[ currentIdx ] = pos;
pos++; pos++;
} }

View File

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

View File

@ -477,9 +477,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
pScene->mMaterials = new aiMaterial*[ numMaterials ]; pScene->mMaterials = new aiMaterial*[ numMaterials ];
for ( unsigned int matIndex = 0; matIndex < numMaterials; matIndex++ ) for ( unsigned int matIndex = 0; matIndex < numMaterials; matIndex++ )
{ {
aiMaterial* mat = new aiMaterial;
// Store material name // Store material name
std::map<std::string, ObjFile::Material*>::const_iterator it; std::map<std::string, ObjFile::Material*>::const_iterator it;
it = pModel->m_MaterialMap.find( pModel->m_MaterialLib[ matIndex ] ); 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 ) if ( pModel->m_MaterialMap.end() == it )
continue; continue;
aiMaterial* mat = new aiMaterial;
ObjFile::Material *pCurrentMaterial = (*it).second; ObjFile::Material *pCurrentMaterial = (*it).second;
mat->AddProperty( &pCurrentMaterial->MaterialName, AI_MATKEY_NAME ); mat->AddProperty( &pCurrentMaterial->MaterialName, AI_MATKEY_NAME );
@ -508,6 +507,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
sm = aiShadingMode_Gouraud; sm = aiShadingMode_Gouraud;
DefaultLogger::get()->error("OBJ: unexpected illumination model (0-2 recognized)"); DefaultLogger::get()->error("OBJ: unexpected illumination model (0-2 recognized)");
} }
mat->AddProperty<int>( &sm, 1, AI_MATKEY_SHADING_MODEL); mat->AddProperty<int>( &sm, 1, AI_MATKEY_SHADING_MODEL);
// multiplying the specular exponent with 2 seems to yield better results // multiplying the specular exponent with 2 seems to yield better results

View File

@ -84,8 +84,8 @@ ObjFileParser::ObjFileParser(std::vector<char> &Data,const std::string &strModel
// Destructor // Destructor
ObjFileParser::~ObjFileParser() ObjFileParser::~ObjFileParser()
{ {
delete m_pModel->m_pDefaultMaterial; /*delete m_pModel->m_pDefaultMaterial;
m_pModel->m_pDefaultMaterial = NULL; m_pModel->m_pDefaultMaterial = NULL;*/
delete m_pModel; delete m_pModel;
m_pModel = NULL; m_pModel = NULL;