- REFACTORING : Removing deprecated code from obj-loader.

- BUGFIX      : Fix memory leak in obj-loader, when an empty mesh was detected and ignored.
- BUGFIX      : Fix invalid material assignment in obj-loader, when groups are used instead of objects. 


git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@534 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
kimmi 2010-01-31 16:53:08 +00:00
parent c55be8ada3
commit 5c0432057a
3 changed files with 23 additions and 46 deletions

View File

@ -110,10 +110,11 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
// Allocate buffer and read file into it // Allocate buffer and read file into it
TextFileToBuffer(file.get(),m_Buffer); TextFileToBuffer(file.get(),m_Buffer);
// // Get the model name
std::string strModelName; std::string strModelName;
std::string::size_type pos = pFile.find_last_of( "\\/" ); std::string::size_type pos = pFile.find_last_of( "\\/" );
if ( pos != std::string::npos ) { if ( pos != std::string::npos )
{
strModelName = pFile.substr(pos+1, pFile.size() - pos - 1); strModelName = pFile.substr(pos+1, pFile.size() - pos - 1);
} }
else else
@ -169,10 +170,7 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
} }
// Create all materials // Create all materials
for (size_t index = 0; index < pModel->m_Objects.size(); index++) createMaterials( pModel, pScene );
{
createMaterial( pModel, pModel->m_Objects[ index ], pScene );
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -182,49 +180,35 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile
aiNode *pParent, aiScene* pScene, aiNode *pParent, aiScene* pScene,
std::vector<aiMesh*> &MeshArray) std::vector<aiMesh*> &MeshArray)
{ {
ai_assert( NULL != pModel );
if (NULL == pData) if (NULL == pData)
return NULL; return NULL;
// Store older mesh size to be able to computate mesh offsets for new mesh instances // Store older mesh size to be able to computate mesh offsets for new mesh instances
size_t oldMeshSize = MeshArray.size(); const size_t oldMeshSize = MeshArray.size();
aiNode *pNode = new aiNode(); aiNode *pNode = new aiNode();
if (pParent != NULL) if (pParent != NULL)
this->appendChildToParentNode(pParent, pNode); this->appendChildToParentNode(pParent, pNode);
aiMesh *pMesh = NULL; aiMesh *pMesh = new aiMesh;
//for (unsigned int meshIndex = 0; meshIndex < pModel->m_Meshes.size(); meshIndex++) createTopology( pModel, pData, uiMeshIndex, pMesh );
if ( pMesh->mNumVertices > 0 )
{ {
pMesh = new aiMesh(); MeshArray.push_back( pMesh );
createTopology( pModel, pData, uiMeshIndex, pMesh ); }
if (pMesh->mNumVertices > 0) { else
MeshArray.push_back( pMesh ); {
} delete pMesh;
} }
// Create all nodes from the subobjects stored in the current object // Create all nodes from the subobjects stored in the current object
if (!pData->m_SubObjects.empty()) if ( !pData->m_SubObjects.empty() )
{ {
pNode->mNumChildren = (unsigned int)pData->m_SubObjects.size(); pNode->mNumChildren = (unsigned int)pData->m_SubObjects.size();
pNode->mChildren = new aiNode*[pData->m_SubObjects.size()]; pNode->mChildren = new aiNode*[pData->m_SubObjects.size()];
pNode->mNumMeshes = 1; pNode->mNumMeshes = 1;
pNode->mMeshes = new unsigned int[1]; pNode->mMeshes = new unsigned int[1];
// Loop over all child objects, TODO
/*for (size_t index = 0; index < pData->m_SubObjects.size(); index++)
{
// Create all child nodes
pNode->mChildren[ index ] = createNodes( pModel, pData, pNode, pScene, MeshArray );
for (unsigned int meshIndex = 0; meshIndex < pData->m_SubObjects[ index ]->m_Meshes.size(); meshIndex++)
{
pMesh = new aiMesh();
MeshArray.push_back( pMesh );
createTopology( pModel, pData, meshIndex, pMesh );
}
// Create material of this object
createMaterial(pModel, pData->m_SubObjects[ index ], pScene);
}*/
} }
// Set mesh instances into scene- and node-instances // Set mesh instances into scene- and node-instances
@ -399,11 +383,10 @@ void ObjFileImporter::countObjects(const std::vector<ObjFile::Object*> &rObjects
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Creates the material // Creates the material
void ObjFileImporter::createMaterial(const ObjFile::Model* pModel, const ObjFile::Object* pData, void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pScene )
aiScene* pScene)
{ {
ai_assert (NULL != pScene); ai_assert( NULL != pScene );
if (NULL == pData) if ( NULL == pScene )
return; return;
const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size(); const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size();

View File

@ -105,8 +105,7 @@ private:
void countObjects(const std::vector<ObjFile::Object*> &rObjects, int &iNumMeshes); void countObjects(const std::vector<ObjFile::Object*> &rObjects, int &iNumMeshes);
//! \brief Material creation. //! \brief Material creation.
void createMaterial(const ObjFile::Model* pModel, const ObjFile::Object* pData, void createMaterials(const ObjFile::Model* pModel, aiScene* pScene);
aiScene* pScene);
//! \brief Appends a child node to a parentnode and updates the datastructures. //! \brief Appends a child node to a parentnode and updates the datastructures.
void appendChildToParentNode(aiNode *pParent, aiNode *pChild); void appendChildToParentNode(aiNode *pParent, aiNode *pChild);

View File

@ -385,19 +385,11 @@ void ObjFileParser::getMaterialDesc()
{ {
// Not found, use default material // Not found, use default material
m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial; m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial;
//m_pModel->m_pCurrentMesh = new ObjFile::Mesh();
//m_pModel->m_Meshes.push_back( m_pModel->m_pCurrentMesh );
//m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( DEFAULT_MATERIAL );
} }
else else
{ {
// Found, using detected material // Found, using detected material
m_pModel->m_pCurrentMaterial = (*it).second; m_pModel->m_pCurrentMaterial = (*it).second;
// Create a new mesh for a new material
//m_pModel->m_pCurrentMesh = new ObjFile::Mesh();
//m_pModel->m_Meshes.push_back( m_pModel->m_pCurrentMesh );
//m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strName );
} }
// Skip rest of line // Skip rest of line
@ -525,8 +517,11 @@ void ObjFileParser::getGroupName()
// Search for already existing entry // Search for already existing entry
ObjFile::Model::ConstGroupMapIt it = m_pModel->m_Groups.find(&strGroupName); ObjFile::Model::ConstGroupMapIt it = m_pModel->m_Groups.find(&strGroupName);
// We are mapping groups into the object structure
/// TODO: Is this the right way to do it????
createObject( strGroupName );
// New group name, creating a new entry // New group name, creating a new entry
//ObjFile::Object *pObject = m_pModel->m_pCurrent;
if (it == m_pModel->m_Groups.end()) if (it == m_pModel->m_Groups.end())
{ {
std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>; std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>;