mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
Adding --surface-color in conversion settings to force the use of surface color instead of diffuse color. Issue #5075
This commit is contained in:
@@ -331,6 +331,13 @@ namespace ifcopenshell {
|
|||||||
static constexpr bool defaultvalue = false;
|
static constexpr bool defaultvalue = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SurfaceColour : public SettingBase<SurfaceColour, bool> {
|
||||||
|
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 {
|
enum PiecewiseStepMethod {
|
||||||
MAXSTEPSIZE,
|
MAXSTEPSIZE,
|
||||||
MINSTEPS };
|
MINSTEPS };
|
||||||
|
|||||||
@@ -565,10 +565,14 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcStyledItem* inst) {
|
|||||||
return surface_style;
|
return surface_style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
surface_style->use_surface_color = settings_.get<settings::SurfaceColour>().get();
|
||||||
|
|
||||||
static taxonomy::colour white = taxonomy::colour(1., 1., 1.);
|
static taxonomy::colour white = taxonomy::colour(1., 1., 1.);
|
||||||
double rgb[3];
|
double rgb[3];
|
||||||
if (process_colour(shading->SurfaceColour(), rgb)) {
|
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<IfcSchema::IfcSurfaceStyleRendering>()) {
|
if (auto rendering_style = shading->as<IfcSchema::IfcSurfaceStyleRendering>()) {
|
||||||
|
|||||||
+11
-2
@@ -305,8 +305,10 @@ typedef item const* ptr;
|
|||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
colour diffuse;
|
colour diffuse;
|
||||||
|
colour surface;
|
||||||
colour specular;
|
colour specular;
|
||||||
double specularity, transparency;
|
double specularity, transparency;
|
||||||
|
bool use_surface_color;
|
||||||
|
|
||||||
void print(std::ostream& o, int indent = 0) const;
|
void print(std::ostream& o, int indent = 0) const;
|
||||||
|
|
||||||
@@ -321,8 +323,15 @@ typedef item const* ptr;
|
|||||||
// @todo equality implementation based on values?
|
// @todo equality implementation based on values?
|
||||||
bool operator==(const style& other) const { return instance == other.instance; }
|
bool operator==(const style& other) const { return instance == other.instance; }
|
||||||
|
|
||||||
style() : specularity(std::numeric_limits<double>::quiet_NaN()), transparency(std::numeric_limits<double>::quiet_NaN()) {}
|
style() : specularity(std::numeric_limits<double>::quiet_NaN()), transparency(std::numeric_limits<double>::quiet_NaN()), use_surface_color(false) {}
|
||||||
style(const std::string& name) : name(name), specularity(std::numeric_limits<double>::quiet_NaN()), transparency(std::numeric_limits<double>::quiet_NaN()) {}
|
style(const std::string& name) : name(name), specularity(std::numeric_limits<double>::quiet_NaN()), transparency(std::numeric_limits<double>::quiet_NaN()), use_surface_color(false) {}
|
||||||
|
|
||||||
|
colour get_color() const {
|
||||||
|
if (use_surface_color && surface) {
|
||||||
|
return surface;
|
||||||
|
}
|
||||||
|
return diffuse;
|
||||||
|
}
|
||||||
|
|
||||||
bool has_specularity() const {
|
bool has_specularity() const {
|
||||||
return !std::isnan(specularity);
|
return !std::isnan(specularity);
|
||||||
|
|||||||
@@ -97,9 +97,9 @@ int GltfSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style:
|
|||||||
|
|
||||||
std::array<double, 4> base;
|
std::array<double, 4> base;
|
||||||
base.fill(1.0);
|
base.fill(1.0);
|
||||||
if (style->diffuse) {
|
if (style->get_color()) {
|
||||||
for (int i = 0; i < 3; ++i) {
|
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) {
|
if (style->transparency == style->transparency) {
|
||||||
|
|||||||
Reference in New Issue
Block a user