Fix review findings.

pull/1061/head
Kim Kulling 2016-11-09 20:16:45 +01:00
parent ae956044aa
commit 568b459e24
1 changed files with 27 additions and 68 deletions

View File

@ -54,7 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Assimp { namespace Assimp {
const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; static const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Constructor with loaded data and directories. // Constructor with loaded data and directories.
@ -87,16 +87,14 @@ ObjFileParser::ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::str
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Destructor // Destructor
ObjFileParser::~ObjFileParser() ObjFileParser::~ObjFileParser() {
{
delete m_pModel; delete m_pModel;
m_pModel = NULL; m_pModel = NULL;
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Returns a pointer to the model instance. // Returns a pointer to the model instance.
ObjFile::Model *ObjFileParser::GetModel() const ObjFile::Model *ObjFileParser::GetModel() const {
{
return m_pModel; return m_pModel;
} }
@ -413,9 +411,6 @@ void ObjFileParser::getFace( aiPrimitiveType type ) {
} }
ObjFile::Face *face = new ObjFile::Face( type ); 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>;*/
bool hasNormal = false; bool hasNormal = false;
const int vSize = m_pModel->m_Vertices.size(); const int vSize = m_pModel->m_Vertices.size();
@ -459,51 +454,28 @@ void ObjFileParser::getFace( aiPrimitiveType type ) {
++iStep; ++iStep;
} }
if ( iVal > 0 ) if ( iVal > 0 ) {
{
// Store parsed index // Store parsed index
if ( 0 == iPos ) if ( 0 == iPos ) {
{
face->m_vertices.push_back( iVal - 1 ); face->m_vertices.push_back( iVal - 1 );
//pIndices->push_back( iVal-1 ); } else if ( 1 == iPos ) {
}
else if ( 1 == iPos )
{
face->m_texturCoords.push_back( iVal - 1 ); face->m_texturCoords.push_back( iVal - 1 );
//pTexID->push_back( iVal-1 ); } else if ( 2 == iPos ) {
}
else if ( 2 == iPos )
{
face->m_normals.push_back( iVal - 1 ); face->m_normals.push_back( iVal - 1 );
//pNormalID->push_back( iVal-1 );
hasNormal = true; hasNormal = true;
} } else {
else
{
reportErrorTokenInFace(); reportErrorTokenInFace();
} }
} } else if ( iVal < 0 ) {
else if ( iVal < 0 )
{
// Store relatively index // Store relatively index
if ( 0 == iPos ) if ( 0 == iPos ) {
{
face->m_vertices.push_back( vSize + iVal ); face->m_vertices.push_back( vSize + iVal );
//pIndices->push_back( vSize + iVal ); } else if ( 1 == iPos ) {
}
else if ( 1 == iPos )
{
face->m_texturCoords.push_back( vtSize + iVal ); face->m_texturCoords.push_back( vtSize + iVal );
//pTexID->push_back( vtSize + iVal ); } else if ( 2 == iPos ) {
}
else if ( 2 == iPos )
{
face->m_normals.push_back( vnSize + iVal ); face->m_normals.push_back( vnSize + iVal );
//pNormalID->push_back( vnSize + iVal );
hasNormal = true; hasNormal = true;
} } else {
else
{
reportErrorTokenInFace(); reportErrorTokenInFace();
} }
} }
@ -515,10 +487,6 @@ void ObjFileParser::getFace( aiPrimitiveType type ) {
DefaultLogger::get()->error("Obj: Ignoring empty face"); DefaultLogger::get()->error("Obj: Ignoring empty face");
// skip line and clean up // skip line and clean up
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine ); m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
/*delete pNormalID;
delete pTexID;
delete pIndices;*/
return; return;
} }
@ -552,8 +520,7 @@ void ObjFileParser::getFace( aiPrimitiveType type ) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Get values for a new material description // Get values for a new material description
void ObjFileParser::getMaterialDesc() void ObjFileParser::getMaterialDesc() {
{
// Get next data for material data // Get next data for material data
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
if (m_DataIt == m_DataItEnd) { if (m_DataIt == m_DataItEnd) {
@ -576,28 +543,26 @@ void ObjFileParser::getMaterialDesc()
// If the current mesh has the same material, we simply ignore that 'usemtl' command // If the current mesh has the same material, we simply ignore that 'usemtl' command
// There is no need to create another object or even mesh here // There is no need to create another object or even mesh here
if (m_pModel->m_pCurrentMaterial && m_pModel->m_pCurrentMaterial->MaterialName == aiString(strName)) if ( m_pModel->m_pCurrentMaterial && m_pModel->m_pCurrentMaterial->MaterialName == aiString( strName ) ) {
skip = true; skip = true;
}
if (!skip) if (!skip) {
{
// Search for material // Search for material
std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find(strName); std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find(strName);
if (it == m_pModel->m_MaterialMap.end()) if (it == m_pModel->m_MaterialMap.end()) {
{
// Not found, use default material // Not found, use default material
m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial; m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial;
DefaultLogger::get()->error("OBJ: failed to locate material " + strName + ", skipping"); DefaultLogger::get()->error("OBJ: failed to locate material " + strName + ", skipping");
strName = m_pModel->m_pDefaultMaterial->MaterialName.C_Str(); strName = m_pModel->m_pDefaultMaterial->MaterialName.C_Str();
} } else {
else
{
// Found, using detected material // Found, using detected material
m_pModel->m_pCurrentMaterial = (*it).second; m_pModel->m_pCurrentMaterial = (*it).second;
} }
if (needsNewMesh(strName)) if ( needsNewMesh( strName ) ) {
createMesh(strName); createMesh( strName );
}
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strName); m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strName);
} }
@ -608,17 +573,12 @@ void ObjFileParser::getMaterialDesc()
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Get a comment, values will be skipped // Get a comment, values will be skipped
void ObjFileParser::getComment() void ObjFileParser::getComment() {
{ while (m_DataIt != m_DataItEnd) {
while (m_DataIt != m_DataItEnd) if ( '\n' == (*m_DataIt)) {
{
if ( '\n' == (*m_DataIt))
{
++m_DataIt; ++m_DataIt;
break; break;
} } else {
else
{
++m_DataIt; ++m_DataIt;
} }
} }
@ -626,8 +586,7 @@ void ObjFileParser::getComment()
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Get material library from file. // Get material library from file.
void ObjFileParser::getMaterialLib() void ObjFileParser::getMaterialLib() {
{
// Translate tuple // Translate tuple
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
if( m_DataIt == m_DataItEnd ) { if( m_DataIt == m_DataItEnd ) {