update: avoid mesh generation on heap, when the mesh will be empty ( obj-loader ).
Signed-off-by: Kim Kulling <kim.kulling@googlemail.com>pull/379/merge
parent
7dff0c6d52
commit
49c9786b0a
|
@ -230,16 +230,10 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile
|
|||
for ( unsigned int i=0; i< pObject->m_Meshes.size(); i++ )
|
||||
{
|
||||
unsigned int meshId = pObject->m_Meshes[ i ];
|
||||
aiMesh *pMesh = new aiMesh;
|
||||
createTopology( pModel, pObject, meshId, pMesh );
|
||||
if ( pMesh->mNumVertices > 0 )
|
||||
{
|
||||
aiMesh *pMesh = createTopology( pModel, pObject, meshId );
|
||||
if( pMesh && pMesh->mNumFaces > 0 ) {
|
||||
MeshArray.push_back( pMesh );
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pMesh;
|
||||
}
|
||||
}
|
||||
|
||||
// Create all nodes from the sub-objects stored in the current object
|
||||
|
@ -272,22 +266,22 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Create topology data
|
||||
void ObjFileImporter::createTopology(const ObjFile::Model* pModel,
|
||||
const ObjFile::Object* pData,
|
||||
unsigned int uiMeshIndex,
|
||||
aiMesh* pMesh )
|
||||
aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||
unsigned int uiMeshIndex )
|
||||
{
|
||||
// Checking preconditions
|
||||
ai_assert( NULL != pModel );
|
||||
if( NULL == pData ) {
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create faces
|
||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[ uiMeshIndex ];
|
||||
if( !pObjMesh ) {
|
||||
return NULL;
|
||||
}
|
||||
ai_assert( NULL != pObjMesh );
|
||||
|
||||
pMesh->mNumFaces = 0;
|
||||
aiMesh* pMesh = new aiMesh;
|
||||
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++)
|
||||
{
|
||||
ObjFile::Face* const inp = pObjMesh->m_Faces[ index ];
|
||||
|
@ -295,16 +289,14 @@ void ObjFileImporter::createTopology(const ObjFile::Model* pModel,
|
|||
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
|
||||
pMesh->mNumFaces += inp->m_pVertices->size() - 1;
|
||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_LINE;
|
||||
}
|
||||
else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
|
||||
} else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
|
||||
pMesh->mNumFaces += inp->m_pVertices->size();
|
||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_POINT;
|
||||
} else {
|
||||
++pMesh->mNumFaces;
|
||||
if (inp->m_pVertices->size() > 3) {
|
||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_POLYGON;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
|
||||
}
|
||||
}
|
||||
|
@ -353,6 +345,8 @@ void ObjFileImporter::createTopology(const ObjFile::Model* pModel,
|
|||
|
||||
// Create mesh vertices
|
||||
createVertexArray(pModel, pData, uiMeshIndex, pMesh, uiIdxCount);
|
||||
|
||||
return pMesh;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -91,8 +91,8 @@ private:
|
|||
aiNode *pParent, aiScene* pScene, std::vector<aiMesh*> &MeshArray);
|
||||
|
||||
//! \brief Creates topology data like faces and meshes for the geometry.
|
||||
void createTopology(const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||
unsigned int uiMeshIndex, aiMesh* pMesh);
|
||||
aiMesh *createTopology( const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||
unsigned int uiMeshIndex );
|
||||
|
||||
//! \brief Creates vertices from model.
|
||||
void createVertexArray(const ObjFile::Model* pModel, const ObjFile::Object* pCurrentObject,
|
||||
|
|
Loading…
Reference in New Issue