diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 9ea93c93c..c812baf23 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -114,35 +114,34 @@ const aiImporterDesc* ObjFileImporter::GetInfo () const // ------------------------------------------------------------------------------------------------ // Obj-file import implementation -void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) -{ +void ObjFileImporter::InternReadFile( const std::string &file, aiScene* pScene, IOSystem* pIOHandler) { // Read file into memory - const std::string mode = "rb"; - boost::scoped_ptr file( pIOHandler->Open( pFile, mode)); - if( !file.get() ) { - throw DeadlyImportError( "Failed to open file " + pFile + "." ); + static const std::string mode = "rb"; + boost::scoped_ptr fileStream( pIOHandler->Open( file, mode)); + if( !fileStream.get() ) { + throw DeadlyImportError( "Failed to open file " + file + "." ); } // Get the file-size and validate it, throwing an exception when fails - size_t fileSize = file->FileSize(); + size_t fileSize = fileStream->FileSize(); if( fileSize < ObjMinSize ) { throw DeadlyImportError( "OBJ-file is too small."); } // Allocate buffer and read file into it - TextFileToBuffer(file.get(),m_Buffer); + TextFileToBuffer( fileStream.get(),m_Buffer); // Get the model name std::string modelName, folderName; - std::string::size_type pos = pFile.find_last_of( "\\/" ); + std::string::size_type pos = file.find_last_of( "\\/" ); if ( pos != std::string::npos ) { - modelName = pFile.substr(pos+1, pFile.size() - pos - 1); - folderName = pFile.substr( 0, pos ); + modelName = file.substr(pos+1, file.size() - pos - 1); + folderName = file.substr( 0, pos ); if ( !folderName.empty() ) { pIOHandler->PushDirectory( folderName ); } } else { - modelName = pFile; + modelName = file; } // This next stage takes ~ 1/3th of the total readFile task diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 29cca5952..3f6748106 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -293,7 +293,7 @@ void ObjFileParser::getVector( std::vector &point3d_array ) { // ------------------------------------------------------------------- // Get values for a new 3D vector instance -void ObjFileParser::getVector3(std::vector &point3d_array) { +void ObjFileParser::getVector3( std::vector &point3d_array ) { float x, y, z; copyNextWord(m_buffer, Buffersize); x = (float) fast_atof(m_buffer); @@ -328,8 +328,8 @@ void ObjFileParser::getVector2( std::vector &point2d_array ) { void ObjFileParser::getFace(aiPrimitiveType type) { copyNextLine(m_buffer, Buffersize); - if (m_DataIt == m_DataItEnd) - return; + /*if (m_DataIt == m_DataItEnd) + return;*/ char *pPtr = m_buffer; char *pEnd = &pPtr[Buffersize]; diff --git a/test/models/OBJ/box_without_lineending.obj b/test/models/OBJ/box_without_lineending.obj new file mode 100644 index 000000000..80a201495 --- /dev/null +++ b/test/models/OBJ/box_without_lineending.obj @@ -0,0 +1,28 @@ +# Vertices: 8 +# Points: 0 +# Lines: 0 +# Faces: 6 +# Materials: 1 + +o 1 + +# Vertex list + +v -0.5 -0.5 0.5 +v -0.5 -0.5 -0.5 +v -0.5 0.5 -0.5 +v -0.5 0.5 0.5 +v 0.5 -0.5 0.5 +v 0.5 -0.5 -0.5 +v 0.5 0.5 -0.5 +v 0.5 0.5 0.5 + +# Point/Line/Face list + +usemtl Default +f 4 3 2 1 +f 2 6 5 1 +f 3 7 6 2 +f 8 7 3 4 +f 5 8 4 1 +f 6 7 8 5 \ No newline at end of file