From 47b2da60827487906272b5a11cb74901e9f345f0 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Fri, 3 Apr 2020 14:23:23 +0200 Subject: [PATCH] Fix gltf serializer compilation --- src/serializers/GltfSerializer.cpp | 27 +++++++++++++++++---------- src/serializers/GltfSerializer.h | 6 +++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/serializers/GltfSerializer.cpp b/src/serializers/GltfSerializer.cpp index 9c2754f2fe..99b702d82b 100644 --- a/src/serializers/GltfSerializer.cpp +++ b/src/serializers/GltfSerializer.cpp @@ -78,29 +78,32 @@ void GltfSerializer::writeHeader() { json_["materials"] = json::array(); } -int GltfSerializer::writeMaterial(const IfcGeom::Material& style) { - auto it = materials_.find(style.name()); +int GltfSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style& style) { + // @todo is it safe to always dereference this optional? + const std::string& name = *style.name; + + auto it = materials_.find(name); if (it != materials_.end()) { return it->second; } int idx = json_["materials"].size(); - materials_[style.name()] = idx; + materials_[name] = idx; std::array base; base.fill(1.0); - if (style.hasDiffuse()) { + if (style.diffuse) { for (int i = 0; i < 3; ++i) { - base[i] = style.diffuse()[i]; + base[i] = style.diffuse->components[i]; } } - if (style.hasTransparency()) { - base[3] = 1. - style.transparency(); + if (style.transparency) { + base[3] = 1. - *style.transparency; } json_["materials"].push_back({ {"pbrMetallicRoughness", {{"baseColorFactor", base}, {"metallicFactor", 0}}} }); - if (style.hasTransparency() && style.transparency() > 1.e-9) { + if (style.transparency && *style.transparency > 1.e-9) { json_["materials"].back()["alphaMode"] = "BLEND"; } @@ -157,14 +160,17 @@ size_t write_accessor(json& j, std::ofstream& ofs, It begin, It end) { return j["accessors"].size() - 1; } -void GltfSerializer::write(const IfcGeom::TriangulationElement* o) { +void GltfSerializer::write(const ifcopenshell::geometry::TriangulationElement* o) { if (o->geometry().material_ids().empty()) { return; } node_array_.push_back(json_["nodes"].size()); - const std::vector& m = o->transformation().matrix().data(); + const double* m = o->transformation().data().components.data(); + + // @todo verify + // nb: note that this contains the Y-UP transform as well. const std::array matrix_flat = { m[0], m[ 2], -m[ 1], 0, @@ -172,6 +178,7 @@ void GltfSerializer::write(const IfcGeom::TriangulationElement* o) { m[6], m[ 8], -m[ 7], 0, m[9], m[11], -m[10], 1 }; + static const std::array identity_matrix = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1}; json node; diff --git a/src/serializers/GltfSerializer.h b/src/serializers/GltfSerializer.h index dc5312d9f1..4b490ab0cf 100644 --- a/src/serializers/GltfSerializer.h +++ b/src/serializers/GltfSerializer.h @@ -36,14 +36,14 @@ private: std::map materials_, meshes_; json json_, node_array_; - int writeMaterial(const IfcGeom::Material& style); + int writeMaterial(const ifcopenshell::geometry::taxonomy::style& style); public: GltfSerializer(const std::string& filename, const SerializerSettings& settings); virtual ~GltfSerializer(); bool ready(); void writeHeader(); - void write(const IfcGeom::TriangulationElement* o); - void write(const IfcGeom::NativeElement* /*o*/) {} + void write(const ifcopenshell::geometry::TriangulationElement* o); + void write(const ifcopenshell::geometry::NativeElement* /*o*/) {} void finalize(); bool isTesselated() const { return true; } void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}