From 2122dc231d25bbf8bb604d11892f0b01cc4bd8e9 Mon Sep 17 00:00:00 2001 From: Merwan Date: Tue, 16 Jul 2019 20:37:41 +0200 Subject: [PATCH 1/2] Fix line continuations in OBJ files --- code/Obj/ObjFileParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Obj/ObjFileParser.cpp b/code/Obj/ObjFileParser.cpp index d1603c6f0..97ef4af70 100644 --- a/code/Obj/ObjFileParser.cpp +++ b/code/Obj/ObjFileParser.cpp @@ -118,7 +118,7 @@ void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { size_t lastFilePos( 0 ); std::vector buffer; - while ( streamBuffer.getNextDataLine( buffer, '\0' ) ) { + while ( streamBuffer.getNextDataLine( buffer, '\\' ) ) { m_DataIt = buffer.begin(); m_DataItEnd = buffer.end(); From 2f6a005fb8c0f5830e03ad6dfe218810d3aebadf Mon Sep 17 00:00:00 2001 From: Merwan Date: Wed, 17 Jul 2019 18:19:17 +0200 Subject: [PATCH 2/2] Add unit test for OBJ line continuations --- test/unit/utObjImportExport.cpp | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index bb0d36b13..8156091b8 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -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); +}