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++ )
|
for ( unsigned int i=0; i< pObject->m_Meshes.size(); i++ )
|
||||||
{
|
{
|
||||||
unsigned int meshId = pObject->m_Meshes[ i ];
|
unsigned int meshId = pObject->m_Meshes[ i ];
|
||||||
aiMesh *pMesh = new aiMesh;
|
aiMesh *pMesh = createTopology( pModel, pObject, meshId );
|
||||||
createTopology( pModel, pObject, meshId, pMesh );
|
if( pMesh && pMesh->mNumFaces > 0 ) {
|
||||||
if ( pMesh->mNumVertices > 0 )
|
|
||||||
{
|
|
||||||
MeshArray.push_back( pMesh );
|
MeshArray.push_back( pMesh );
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
delete pMesh;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create all nodes from the sub-objects stored in the current object
|
// 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
|
// Create topology data
|
||||||
void ObjFileImporter::createTopology(const ObjFile::Model* pModel,
|
aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||||
const ObjFile::Object* pData,
|
unsigned int uiMeshIndex )
|
||||||
unsigned int uiMeshIndex,
|
|
||||||
aiMesh* pMesh )
|
|
||||||
{
|
{
|
||||||
// Checking preconditions
|
// Checking preconditions
|
||||||
ai_assert( NULL != pModel );
|
ai_assert( NULL != pModel );
|
||||||
if( NULL == pData ) {
|
if( NULL == pData ) {
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create faces
|
// Create faces
|
||||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[ uiMeshIndex ];
|
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[ uiMeshIndex ];
|
||||||
ai_assert( NULL != pObjMesh );
|
if( !pObjMesh ) {
|
||||||
|
return NULL;
|
||||||
pMesh->mNumFaces = 0;
|
}
|
||||||
|
ai_assert( NULL != pObjMesh );
|
||||||
|
aiMesh* pMesh = new aiMesh;
|
||||||
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++)
|
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++)
|
||||||
{
|
{
|
||||||
ObjFile::Face* const inp = pObjMesh->m_Faces[ 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) {
|
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
|
||||||
pMesh->mNumFaces += inp->m_pVertices->size() - 1;
|
pMesh->mNumFaces += inp->m_pVertices->size() - 1;
|
||||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_LINE;
|
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->mNumFaces += inp->m_pVertices->size();
|
||||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_POINT;
|
pMesh->mPrimitiveTypes |= aiPrimitiveType_POINT;
|
||||||
} else {
|
} else {
|
||||||
++pMesh->mNumFaces;
|
++pMesh->mNumFaces;
|
||||||
if (inp->m_pVertices->size() > 3) {
|
if (inp->m_pVertices->size() > 3) {
|
||||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_POLYGON;
|
pMesh->mPrimitiveTypes |= aiPrimitiveType_POLYGON;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
|
pMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,6 +345,8 @@ void ObjFileImporter::createTopology(const ObjFile::Model* pModel,
|
||||||
|
|
||||||
// Create mesh vertices
|
// Create mesh vertices
|
||||||
createVertexArray(pModel, pData, uiMeshIndex, pMesh, uiIdxCount);
|
createVertexArray(pModel, pData, uiMeshIndex, pMesh, uiIdxCount);
|
||||||
|
|
||||||
|
return pMesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -91,8 +91,8 @@ private:
|
||||||
aiNode *pParent, aiScene* pScene, std::vector<aiMesh*> &MeshArray);
|
aiNode *pParent, aiScene* pScene, std::vector<aiMesh*> &MeshArray);
|
||||||
|
|
||||||
//! \brief Creates topology data like faces and meshes for the geometry.
|
//! \brief Creates topology data like faces and meshes for the geometry.
|
||||||
void createTopology(const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
aiMesh *createTopology( const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||||
unsigned int uiMeshIndex, aiMesh* pMesh);
|
unsigned int uiMeshIndex );
|
||||||
|
|
||||||
//! \brief Creates vertices from model.
|
//! \brief Creates vertices from model.
|
||||||
void createVertexArray(const ObjFile::Model* pModel, const ObjFile::Object* pCurrentObject,
|
void createVertexArray(const ObjFile::Model* pModel, const ObjFile::Object* pCurrentObject,
|
||||||
|
|
Loading…
Reference in New Issue