ObjImporter: remove unnecessary allocations of std::vector in obj-specific

face.
This commit is contained in:
Kim Kulling
2016-11-09 20:09:45 +01:00
parent d4223d1fce
commit ae956044aa
4 changed files with 91 additions and 125 deletions

View File

@@ -403,7 +403,7 @@ static const std::string DefaultObjName = "defaultobject";
// -------------------------------------------------------------------
// Get values for a new face instance
void ObjFileParser::getFace(aiPrimitiveType type) {
void ObjFileParser::getFace( aiPrimitiveType type ) {
copyNextLine(m_buffer, Buffersize);
char *pPtr = m_buffer;
char *pEnd = &pPtr[Buffersize];
@@ -412,9 +412,10 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
return;
}
std::vector<unsigned int> *pIndices = new std::vector<unsigned int>;
ObjFile::Face *face = new ObjFile::Face( type );
/*std::vector<unsigned int> *pIndices = new std::vector<unsigned int>;
std::vector<unsigned int> *pTexID = new std::vector<unsigned int>;
std::vector<unsigned int> *pNormalID = new std::vector<unsigned int>;
std::vector<unsigned int> *pNormalID = new std::vector<unsigned int>;*/
bool hasNormal = false;
const int vSize = m_pModel->m_Vertices.size();
@@ -463,15 +464,18 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
// Store parsed index
if ( 0 == iPos )
{
pIndices->push_back( iVal-1 );
face->m_vertices.push_back( iVal - 1 );
//pIndices->push_back( iVal-1 );
}
else if ( 1 == iPos )
{
pTexID->push_back( iVal-1 );
face->m_texturCoords.push_back( iVal - 1 );
//pTexID->push_back( iVal-1 );
}
else if ( 2 == iPos )
{
pNormalID->push_back( iVal-1 );
face->m_normals.push_back( iVal - 1 );
//pNormalID->push_back( iVal-1 );
hasNormal = true;
}
else
@@ -484,15 +488,18 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
// Store relatively index
if ( 0 == iPos )
{
pIndices->push_back( vSize + iVal );
face->m_vertices.push_back( vSize + iVal );
//pIndices->push_back( vSize + iVal );
}
else if ( 1 == iPos )
{
pTexID->push_back( vtSize + iVal );
face->m_texturCoords.push_back( vtSize + iVal );
//pTexID->push_back( vtSize + iVal );
}
else if ( 2 == iPos )
{
pNormalID->push_back( vnSize + iVal );
face->m_normals.push_back( vnSize + iVal );
//pNormalID->push_back( vnSize + iVal );
hasNormal = true;
}
else
@@ -504,19 +511,17 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
pPtr += iStep;
}
if ( pIndices->empty() ) {
if ( face->m_vertices.empty() ) {
DefaultLogger::get()->error("Obj: Ignoring empty face");
// skip line and clean up
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
delete pNormalID;
/*delete pNormalID;
delete pTexID;
delete pIndices;
delete pIndices;*/
return;
}
ObjFile::Face *face = new ObjFile::Face( pIndices, pNormalID, pTexID, type );
// Set active material, if one set
if( NULL != m_pModel->m_pCurrentMaterial ) {
face->m_pMaterial = m_pModel->m_pCurrentMaterial;
@@ -536,8 +541,8 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
// Store the face
m_pModel->m_pCurrentMesh->m_Faces.push_back( face );
m_pModel->m_pCurrentMesh->m_uiNumIndices += (unsigned int)face->m_pVertices->size();
m_pModel->m_pCurrentMesh->m_uiUVCoordinates[ 0 ] += (unsigned int)face->m_pTexturCoords[0].size();
m_pModel->m_pCurrentMesh->m_uiNumIndices += (unsigned int) face->m_vertices.size();
m_pModel->m_pCurrentMesh->m_uiUVCoordinates[ 0 ] += (unsigned int) face->m_texturCoords.size();
if( !m_pModel->m_pCurrentMesh->m_hasNormals && hasNormal ) {
m_pModel->m_pCurrentMesh->m_hasNormals = true;
}