Closes https://github.com/assimp/assimp/issues/777: fix invalid skipping
of line during face defintion parsing.pull/790/head
parent
2466ae6c2e
commit
1550191256
|
@ -114,35 +114,34 @@ const aiImporterDesc* ObjFileImporter::GetInfo () const
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Obj-file import implementation
|
// 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
|
// Read file into memory
|
||||||
const std::string mode = "rb";
|
static const std::string mode = "rb";
|
||||||
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile, mode));
|
boost::scoped_ptr<IOStream> fileStream( pIOHandler->Open( file, mode));
|
||||||
if( !file.get() ) {
|
if( !fileStream.get() ) {
|
||||||
throw DeadlyImportError( "Failed to open file " + pFile + "." );
|
throw DeadlyImportError( "Failed to open file " + file + "." );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the file-size and validate it, throwing an exception when fails
|
// 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 ) {
|
if( fileSize < ObjMinSize ) {
|
||||||
throw DeadlyImportError( "OBJ-file is too small.");
|
throw DeadlyImportError( "OBJ-file is too small.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate buffer and read file into it
|
// Allocate buffer and read file into it
|
||||||
TextFileToBuffer(file.get(),m_Buffer);
|
TextFileToBuffer( fileStream.get(),m_Buffer);
|
||||||
|
|
||||||
// Get the model name
|
// Get the model name
|
||||||
std::string modelName, folderName;
|
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 ) {
|
if ( pos != std::string::npos ) {
|
||||||
modelName = pFile.substr(pos+1, pFile.size() - pos - 1);
|
modelName = file.substr(pos+1, file.size() - pos - 1);
|
||||||
folderName = pFile.substr( 0, pos );
|
folderName = file.substr( 0, pos );
|
||||||
if ( !folderName.empty() ) {
|
if ( !folderName.empty() ) {
|
||||||
pIOHandler->PushDirectory( folderName );
|
pIOHandler->PushDirectory( folderName );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
modelName = pFile;
|
modelName = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This next stage takes ~ 1/3th of the total readFile task
|
// This next stage takes ~ 1/3th of the total readFile task
|
||||||
|
|
|
@ -293,7 +293,7 @@ void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Get values for a new 3D vector instance
|
// Get values for a new 3D vector instance
|
||||||
void ObjFileParser::getVector3(std::vector<aiVector3D> &point3d_array) {
|
void ObjFileParser::getVector3( std::vector<aiVector3D> &point3d_array ) {
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
copyNextWord(m_buffer, Buffersize);
|
copyNextWord(m_buffer, Buffersize);
|
||||||
x = (float) fast_atof(m_buffer);
|
x = (float) fast_atof(m_buffer);
|
||||||
|
@ -328,8 +328,8 @@ void ObjFileParser::getVector2( std::vector<aiVector2D> &point2d_array ) {
|
||||||
void ObjFileParser::getFace(aiPrimitiveType type)
|
void ObjFileParser::getFace(aiPrimitiveType type)
|
||||||
{
|
{
|
||||||
copyNextLine(m_buffer, Buffersize);
|
copyNextLine(m_buffer, Buffersize);
|
||||||
if (m_DataIt == m_DataItEnd)
|
/*if (m_DataIt == m_DataItEnd)
|
||||||
return;
|
return;*/
|
||||||
|
|
||||||
char *pPtr = m_buffer;
|
char *pPtr = m_buffer;
|
||||||
char *pEnd = &pPtr[Buffersize];
|
char *pEnd = &pPtr[Buffersize];
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue