diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 1c279cbc7..40f68cac1 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -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,49 +180,35 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile aiNode *pParent, aiScene* pScene, std::vector &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++) + aiMesh *pMesh = new aiMesh; + createTopology( pModel, pData, uiMeshIndex, pMesh ); + if ( pMesh->mNumVertices > 0 ) { - pMesh = new aiMesh(); - createTopology( pModel, pData, uiMeshIndex, pMesh ); - if (pMesh->mNumVertices > 0) { - MeshArray.push_back( pMesh ); - } + MeshArray.push_back( pMesh ); + } + else + { + delete pMesh; } // 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->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 &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) + ai_assert( NULL != pScene ); + if ( NULL == pScene ) return; const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size(); diff --git a/code/ObjFileImporter.h b/code/ObjFileImporter.h index 996c73a83..a2ca52baa 100644 --- a/code/ObjFileImporter.h +++ b/code/ObjFileImporter.h @@ -105,8 +105,7 @@ private: void countObjects(const std::vector &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); diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index b515d24a3..1519e4456 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -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 *pFaceIDArray = new std::vector;