From b5a61753a5ffc2ad55bcdf829b99168b9512182e Mon Sep 17 00:00:00 2001 From: Cristian Ritter Date: Thu, 15 Aug 2024 13:56:31 -0300 Subject: [PATCH] Adding --surface-color in conversion settings to force the use of surface color instead of diffuse color. Issue #5075 --- src/ifcgeom/ConversionSettings.h | 7 +++++++ src/ifcgeom/mapping/mapping.cpp | 6 +++++- src/ifcgeom/taxonomy.h | 13 +++++++++++-- src/serializers/GltfSerializer.cpp | 4 ++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/ifcgeom/ConversionSettings.h b/src/ifcgeom/ConversionSettings.h index f49941ec4b..611c615001 100644 --- a/src/ifcgeom/ConversionSettings.h +++ b/src/ifcgeom/ConversionSettings.h @@ -331,6 +331,13 @@ namespace ifcopenshell { static constexpr bool defaultvalue = false; }; + struct SurfaceColour : public SettingBase { + static constexpr const char* const name = "surface-colour"; + static constexpr const char* const description = + "Prioritizes the surface color instead of using diffuse."; + static constexpr bool defaultvalue = false; + }; + enum PiecewiseStepMethod { MAXSTEPSIZE, MINSTEPS }; diff --git a/src/ifcgeom/mapping/mapping.cpp b/src/ifcgeom/mapping/mapping.cpp index 1fbd73d0c7..00cbacaba4 100644 --- a/src/ifcgeom/mapping/mapping.cpp +++ b/src/ifcgeom/mapping/mapping.cpp @@ -565,10 +565,14 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcStyledItem* inst) { return surface_style; } + surface_style->use_surface_color = settings_.get().get(); + static taxonomy::colour white = taxonomy::colour(1., 1., 1.); double rgb[3]; if (process_colour(shading->SurfaceColour(), rgb)) { - surface_style->diffuse.components() << rgb[0], rgb[1], rgb[2]; + surface_style->surface.components() << rgb[0], rgb[1], rgb[2]; + } else { + surface_style->surface = white; } if (auto rendering_style = shading->as()) { diff --git a/src/ifcgeom/taxonomy.h b/src/ifcgeom/taxonomy.h index 3b77273240..9b02e7a2fc 100644 --- a/src/ifcgeom/taxonomy.h +++ b/src/ifcgeom/taxonomy.h @@ -305,8 +305,10 @@ typedef item const* ptr; std::string name; colour diffuse; + colour surface; colour specular; double specularity, transparency; + bool use_surface_color; void print(std::ostream& o, int indent = 0) const; @@ -321,8 +323,15 @@ typedef item const* ptr; // @todo equality implementation based on values? bool operator==(const style& other) const { return instance == other.instance; } - style() : specularity(std::numeric_limits::quiet_NaN()), transparency(std::numeric_limits::quiet_NaN()) {} - style(const std::string& name) : name(name), specularity(std::numeric_limits::quiet_NaN()), transparency(std::numeric_limits::quiet_NaN()) {} + style() : specularity(std::numeric_limits::quiet_NaN()), transparency(std::numeric_limits::quiet_NaN()), use_surface_color(false) {} + style(const std::string& name) : name(name), specularity(std::numeric_limits::quiet_NaN()), transparency(std::numeric_limits::quiet_NaN()), use_surface_color(false) {} + + colour get_color() const { + if (use_surface_color && surface) { + return surface; + } + return diffuse; + } bool has_specularity() const { return !std::isnan(specularity); diff --git a/src/serializers/GltfSerializer.cpp b/src/serializers/GltfSerializer.cpp index c5b4d4c776..980788e1c2 100644 --- a/src/serializers/GltfSerializer.cpp +++ b/src/serializers/GltfSerializer.cpp @@ -97,9 +97,9 @@ int GltfSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style: std::array base; base.fill(1.0); - if (style->diffuse) { + if (style->get_color()) { for (int i = 0; i < 3; ++i) { - base[i] = style->diffuse.ccomponents()(i); + base[i] = style->get_color().ccomponents()(i); } } if (style->transparency == style->transparency) {