mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 19:27:10 +00:00
Merge pull request #5184 from csritter/v0.8.0
Adding --surface-colour in conversion settings to force the use of surface color instead of diffuse color. Issue #5075
This commit is contained in:
@@ -351,6 +351,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 };
|
||||||
@@ -486,7 +493,7 @@ namespace ifcopenshell {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class IFC_GEOM_API Settings : public SettingsContainer<
|
class IFC_GEOM_API Settings : public SettingsContainer<
|
||||||
std::tuple<MesherLinearDeflection, MesherAngularDeflection, ReorientShells, LengthUnit, PlaneUnit, Precision, OutputDimensionality, LayersetFirst, DisableBooleanResult, NoWireIntersectionCheck, NoWireIntersectionTolerance, PrecisionFactor, DebugBooleanOperations, BooleanAttempt2d, WeldVertices, UseWorldCoords, UseMaterialNames, ConvertBackUnits, ContextIds, ContextTypes, ContextIdentifiers, IteratorOutput, DisableOpeningSubtractions, ApplyDefaultMaterials, DontEmitNormals, GenerateUvs, ApplyLayerSets, UseElementHierarchy, ValidateQuantities, EdgeArrows, BuildingLocalPlacement, SiteLocalPlacement, ForceSpaceTransparency, CircleSegments, KeepBoundingBoxes, PiecewiseStepType, PiecewiseStepParam, NoParallelMapping, ModelOffset, ModelRotation, TriangulationType>
|
std::tuple<MesherLinearDeflection, MesherAngularDeflection, ReorientShells, LengthUnit, PlaneUnit, Precision, OutputDimensionality, LayersetFirst, DisableBooleanResult, NoWireIntersectionCheck, NoWireIntersectionTolerance, PrecisionFactor, DebugBooleanOperations, BooleanAttempt2d, SurfaceColour, WeldVertices, UseWorldCoords, UseMaterialNames, ConvertBackUnits, ContextIds, ContextTypes, ContextIdentifiers, IteratorOutput, DisableOpeningSubtractions, ApplyDefaultMaterials, DontEmitNormals, GenerateUvs, ApplyLayerSets, UseElementHierarchy, ValidateQuantities, EdgeArrows, BuildingLocalPlacement, SiteLocalPlacement, ForceSpaceTransparency, CircleSegments, KeepBoundingBoxes, PiecewiseStepType, PiecewiseStepParam, NoParallelMapping, ModelOffset, ModelRotation, TriangulationType>
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
|
|||||||
int sid = -1;
|
int sid = -1;
|
||||||
|
|
||||||
if (it->hasStyle()) {
|
if (it->hasStyle()) {
|
||||||
const auto& clr = it->Style().diffuse.ccomponents();
|
const auto& clr = it->Style().get_color().ccomponents();
|
||||||
surface_styles_.push_back(clr(0));
|
surface_styles_.push_back(clr(0));
|
||||||
surface_styles_.push_back(clr(1));
|
surface_styles_.push_back(clr(1));
|
||||||
surface_styles_.push_back(clr(2));
|
surface_styles_.push_back(clr(2));
|
||||||
|
|||||||
@@ -89,6 +89,10 @@ void IfcGeom::set_default_style_file(const std::string& json_file) {
|
|||||||
boost::optional<pt::ptree&> diffuse = material.get_child_optional("diffuse");
|
boost::optional<pt::ptree&> diffuse = material.get_child_optional("diffuse");
|
||||||
default_materials[name]->diffuse = read_colour_component(diffuse);
|
default_materials[name]->diffuse = read_colour_component(diffuse);
|
||||||
|
|
||||||
|
// @todo Is it necessary to get the surface too?
|
||||||
|
// boost::optional<pt::ptree&> surface = material.get_child_optional("surface");
|
||||||
|
// default_materials[name]->surface = read_colour_component(surface);
|
||||||
|
|
||||||
boost::optional<pt::ptree&> specular = material.get_child_optional("specular");
|
boost::optional<pt::ptree&> specular = material.get_child_optional("specular");
|
||||||
default_materials[name]->specular = read_colour_component(specular);
|
default_materials[name]->specular = read_colour_component(specular);
|
||||||
|
|
||||||
|
|||||||
@@ -565,11 +565,14 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcStyledItem* inst) {
|
|||||||
return surface_style;
|
return surface_style;
|
||||||
}
|
}
|
||||||
|
|
||||||
static taxonomy::colour white = taxonomy::colour(1., 1., 1.);
|
surface_style->use_surface_color = settings_.get<settings::SurfaceColour>().get();
|
||||||
double rgb[3];
|
|
||||||
if (process_colour(shading->SurfaceColour(), rgb)) {
|
static taxonomy::colour white = taxonomy::colour(1., 1., 1.);
|
||||||
surface_style->diffuse.components() << rgb[0], rgb[1], rgb[2];
|
double rgb[3];
|
||||||
}
|
if (process_colour(shading->SurfaceColour(), rgb)) {
|
||||||
|
surface_style->surface.components() << rgb[0], rgb[1], rgb[2];
|
||||||
|
surface_style->diffuse = surface_style->surface;
|
||||||
|
}
|
||||||
|
|
||||||
if (auto rendering_style = shading->as<IfcSchema::IfcSurfaceStyleRendering>()) {
|
if (auto rendering_style = shading->as<IfcSchema::IfcSurfaceStyleRendering>()) {
|
||||||
if (rendering_style->DiffuseColour() && process_colour(rendering_style->DiffuseColour(), rgb)) {
|
if (rendering_style->DiffuseColour() && process_colour(rendering_style->DiffuseColour(), rgb)) {
|
||||||
|
|||||||
+12
-3
@@ -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;
|
||||||
|
|
||||||
@@ -314,15 +316,22 @@ typedef item const* ptr;
|
|||||||
virtual kinds kind() const { return STYLE; }
|
virtual kinds kind() const { return STYLE; }
|
||||||
|
|
||||||
virtual size_t calc_hash() const {
|
virtual size_t calc_hash() const {
|
||||||
auto v = std::make_tuple(static_cast<size_t>(STYLE), name, diffuse.hash(), specular.hash(), specularity, transparency);
|
auto v = std::make_tuple(static_cast<size_t>(STYLE), name, diffuse.hash(), surface.hash(), specular.hash(), specularity, transparency);
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @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) {}
|
||||||
|
|
||||||
|
const 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);
|
||||||
|
|||||||
@@ -354,8 +354,8 @@ protected:
|
|||||||
std::vector<boost::optional<std::array<float, 4> > > diffuse_color_array;
|
std::vector<boost::optional<std::array<float, 4> > > diffuse_color_array;
|
||||||
for (auto it = geom->geometry().materials().begin(); it != geom->geometry().materials().end(); ++it) {
|
for (auto it = geom->geometry().materials().begin(); it != geom->geometry().materials().end(); ++it) {
|
||||||
const auto& mat = **it;
|
const auto& mat = **it;
|
||||||
if (mat.diffuse) {
|
if (mat.get_color()) {
|
||||||
const auto& color = mat.diffuse.ccomponents();
|
const auto& color = mat.get_color().ccomponents();
|
||||||
diffuse_color_array.push_back(std::array<float, 4>{
|
diffuse_color_array.push_back(std::array<float, 4>{
|
||||||
static_cast<float>(color(0)),
|
static_cast<float>(color(0)),
|
||||||
static_cast<float>(color(1)),
|
static_cast<float>(color(1)),
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ void WaveFrontOBJSerializer::writeMaterial(const ifcopenshell::geometry::taxonom
|
|||||||
mtl_stream.stream << "newmtl " << material_name << "\n";
|
mtl_stream.stream << "newmtl " << material_name << "\n";
|
||||||
|
|
||||||
{
|
{
|
||||||
auto& diffuse = style.diffuse.ccomponents();
|
auto& diffuse = style.get_color().ccomponents();
|
||||||
mtl_stream.stream << "Kd " << diffuse(0) << " " << diffuse(1) << " " << diffuse(2) << "\n";
|
mtl_stream.stream << "Kd " << diffuse(0) << " " << diffuse(1) << " " << diffuse(2) << "\n";
|
||||||
}
|
}
|
||||||
if (style.specular) {
|
if (style.specular) {
|
||||||
|
|||||||
Reference in New Issue
Block a user