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"; + } }