- 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-9d2fd5bffc1fpull/1/head
parent
c55be8ada3
commit
5c0432057a
|
@ -110,10 +110,11 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
|
|||
// Allocate buffer and read file into it
|
||||
TextFileToBuffer(file.get(),m_Buffer);
|
||||
|
||||
//
|
||||
// Get the model name
|
||||
std::string strModelName;
|
||||
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);
|
||||
}
|
||||
else
|
||||
|
@ -169,10 +170,7 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
|
|||
}
|
||||
|
||||
// Create all materials
|
||||
for (size_t index = 0; index < pModel->m_Objects.size(); index++)
|
||||
{
|
||||
createMaterial( pModel, pModel->m_Objects[ index ], pScene );
|
||||
}
|
||||
createMaterials( pModel, pScene );
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -182,24 +180,26 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile
|
|||
aiNode *pParent, aiScene* pScene,
|
||||
std::vector<aiMesh*> &MeshArray)
|
||||
{
|
||||
ai_assert( NULL != pModel );
|
||||
if (NULL == pData)
|
||||
return NULL;
|
||||
|
||||
// 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();
|
||||
|
||||
if (pParent != NULL)
|
||||
this->appendChildToParentNode(pParent, pNode);
|
||||
|
||||
aiMesh *pMesh = NULL;
|
||||
//for (unsigned int meshIndex = 0; meshIndex < pModel->m_Meshes.size(); meshIndex++)
|
||||
{
|
||||
pMesh = new aiMesh();
|
||||
aiMesh *pMesh = new aiMesh;
|
||||
createTopology( pModel, pData, uiMeshIndex, pMesh );
|
||||
if (pMesh->mNumVertices > 0) {
|
||||
if ( pMesh->mNumVertices > 0 )
|
||||
{
|
||||
MeshArray.push_back( pMesh );
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pMesh;
|
||||
}
|
||||
|
||||
// Create all nodes from the subobjects stored in the current object
|
||||
|
@ -209,22 +209,6 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile
|
|||
pNode->mChildren = new aiNode*[pData->m_SubObjects.size()];
|
||||
pNode->mNumMeshes = 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
|
||||
|
@ -399,11 +383,10 @@ void ObjFileImporter::countObjects(const std::vector<ObjFile::Object*> &rObjects
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Creates the material
|
||||
void ObjFileImporter::createMaterial(const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||
aiScene* pScene)
|
||||
void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pScene )
|
||||
{
|
||||
ai_assert( NULL != pScene );
|
||||
if (NULL == pData)
|
||||
if ( NULL == pScene )
|
||||
return;
|
||||
|
||||
const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size();
|
||||
|
|
|
@ -105,8 +105,7 @@ private:
|
|||
void countObjects(const std::vector<ObjFile::Object*> &rObjects, int &iNumMeshes);
|
||||
|
||||
//! \brief Material creation.
|
||||
void createMaterial(const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||
aiScene* pScene);
|
||||
void createMaterials(const ObjFile::Model* pModel, aiScene* pScene);
|
||||
|
||||
//! \brief Appends a child node to a parentnode and updates the datastructures.
|
||||
void appendChildToParentNode(aiNode *pParent, aiNode *pChild);
|
||||
|
|
|
@ -385,19 +385,11 @@ void ObjFileParser::getMaterialDesc()
|
|||
{
|
||||
// Not found, use default material
|
||||
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
|
||||
{
|
||||
// Found, using detected material
|
||||
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
|
||||
|
@ -525,8 +517,11 @@ void ObjFileParser::getGroupName()
|
|||
// Search for already existing entry
|
||||
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
|
||||
//ObjFile::Object *pObject = m_pModel->m_pCurrent;
|
||||
if (it == m_pModel->m_Groups.end())
|
||||
{
|
||||
std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>;
|
||||
|
|
Loading…
Reference in New Issue