Skip to content

Commit

Permalink
Merge pull request #2550 from merwaaan/fix-obj-line-continuation
Browse files Browse the repository at this point in the history
Fix line continuations in OBJ files
  • Loading branch information
kimkulling committed Jul 20, 2019
2 parents 4bd8ae8 + ff7ec7e commit 5b6fe80
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/Obj/ObjFileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
size_t lastFilePos( 0 );

std::vector<char> buffer;
while ( streamBuffer.getNextDataLine( buffer, '\0' ) ) {
while ( streamBuffer.getNextDataLine( buffer, '\\' ) ) {
m_DataIt = buffer.begin();
m_DataItEnd = buffer.end();

Expand Down
34 changes: 34 additions & 0 deletions test/unit/utObjImportExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,37 @@ TEST_F(utObjImportExport, import_without_linend) {
const aiScene *scene = myImporter.ReadFile(ASSIMP_TEST_MODELS_DIR "/OBJ/box_without_lineending.obj", 0);
ASSERT_NE(nullptr, scene);
}

TEST_F(utObjImportExport, import_with_line_continuations) {
static const char *ObjModel =
"v -0.5 -0.5 0.5\n"
"v -0.5 \\\n"
" -0.5 -0.5\n"
"v -0.5 \\\n"
" 0.5 \\\n"
" -0.5\n"
"f 1 2 3\n";

Assimp::Importer myImporter;
const aiScene *scene = myImporter.ReadFileFromMemory(ObjModel, strlen(ObjModel), 0);
EXPECT_NE(nullptr, scene);

EXPECT_EQ(scene->mNumMeshes, 1U);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 3U);
EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 1U);

auto vertices = scene->mMeshes[0]->mVertices;
const float threshold = 0.0001f;

EXPECT_NEAR(vertices[0].x, -0.5f, threshold);
EXPECT_NEAR(vertices[0].y, -0.5f, threshold);
EXPECT_NEAR(vertices[0].z, 0.5f, threshold);

EXPECT_NEAR(vertices[1].x, -0.5f, threshold);
EXPECT_NEAR(vertices[1].y, -0.5f, threshold);
EXPECT_NEAR(vertices[1].z, -0.5f, threshold);

EXPECT_NEAR(vertices[2].x, -0.5f, threshold);
EXPECT_NEAR(vertices[2].y, 0.5f, threshold);
EXPECT_NEAR(vertices[2].z, -0.5f, threshold);
}

0 comments on commit 5b6fe80

Please sign in to comment.