From 9909e2f7e2b8da3f68ffffb0783d4700f6e796c5 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 24 May 2016 15:01:34 +0200 Subject: [PATCH] Don't emit OBJ vertex normal if absent (e.g --weld-vertices) --- src/ifcconvert/WavefrontObjSerializer.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ifcconvert/WavefrontObjSerializer.cpp b/src/ifcconvert/WavefrontObjSerializer.cpp index 3fb2da8a9d..f130c8e504 100644 --- a/src/ifcconvert/WavefrontObjSerializer.cpp +++ b/src/ifcconvert/WavefrontObjSerializer.cpp @@ -109,6 +109,7 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement* std::vector::const_iterator material_it = mesh.material_ids().begin(); const bool has_uvs = !mesh.uvs().empty(); + const bool has_normals = !mesh.normals().empty(); for ( std::vector::const_iterator it = mesh.faces().begin(); it != mesh.faces().end(); ) { const int material_id = *(material_it++); @@ -128,9 +129,18 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement* const int v1 = *(it++)+vcount_total; const int v2 = *(it++)+vcount_total; const int v3 = *(it++)+vcount_total; - obj_stream << "f " << v1 << "/" << (has_uvs ? boost::lexical_cast(v1) : "") << "/" << v1 << " " - << v2 << "/" << (has_uvs ? boost::lexical_cast(v2) : "") << "/" << v2 << " " - << v3 << "/" << (has_uvs ? boost::lexical_cast(v3) : "") << "/" << v3 << "\n"; + + if (has_normals && has_uvs) { + obj_stream << "f " << v1 << "/" << v1 << "/" << v1 << " " + << v2 << "/" << v2 << "/" << v2 << " " + << v3 << "/" << v3 << "/" << v3 << "\n"; + } else if (has_normals) { + obj_stream << "f " << v1 << "//" << v1 << " " + << v2 << "//" << v2 << " " + << v3 << "//" << v3 << "\n"; + } else { + obj_stream << "f " << v1 << " " << v2 << " " << v3 << "\n"; + } }