mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 03:05:33 +00:00
shared_ptr styles all over #4833
This commit is contained in:
@@ -31,9 +31,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace IfcGeom {
|
namespace IfcGeom {
|
||||||
IFC_GEOM_API const ifcopenshell::geometry::taxonomy::style& get_default_style(const std::string& ifc_type);
|
IFC_GEOM_API const ifcopenshell::geometry::taxonomy::style::ptr& get_default_style(const std::string& ifc_type);
|
||||||
|
|
||||||
IFC_GEOM_API ifcopenshell::geometry::taxonomy::style& update_default_style(const std::string& ifc_type);
|
IFC_GEOM_API ifcopenshell::geometry::taxonomy::style::ptr& update_default_style(const std::string& ifc_type);
|
||||||
|
|
||||||
IFC_GEOM_API void set_default_style_file(const std::string& json_file);
|
IFC_GEOM_API void set_default_style_file(const std::string& json_file);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -334,10 +334,10 @@ IfcGeom::Representation::Triangulation::Triangulation(const BRep& shape_model)
|
|||||||
|
|
||||||
int surface_style_id = -1;
|
int surface_style_id = -1;
|
||||||
if (iit->hasStyle()) {
|
if (iit->hasStyle()) {
|
||||||
auto jt = std::find(_materials.begin(), _materials.end(), iit->Style());
|
auto jt = std::find(_materials.begin(), _materials.end(), iit->StylePtr());
|
||||||
if (jt == _materials.end()) {
|
if (jt == _materials.end()) {
|
||||||
surface_style_id = (int)_materials.size();
|
surface_style_id = (int)_materials.size();
|
||||||
_materials.push_back(iit->Style());
|
_materials.push_back(iit->StylePtr());
|
||||||
} else {
|
} else {
|
||||||
surface_style_id = (int)(jt - _materials.begin());
|
surface_style_id = (int)(jt - _materials.begin());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ namespace IfcGeom {
|
|||||||
std::vector<double> _normals;
|
std::vector<double> _normals;
|
||||||
std::vector<double> uvs_;
|
std::vector<double> uvs_;
|
||||||
std::vector<int> _material_ids;
|
std::vector<int> _material_ids;
|
||||||
std::vector<ifcopenshell::geometry::taxonomy::style> _materials;
|
std::vector<ifcopenshell::geometry::taxonomy::style::ptr> _materials;
|
||||||
std::vector<int> _item_ids;
|
std::vector<int> _item_ids;
|
||||||
size_t weld_offset_;
|
size_t weld_offset_;
|
||||||
VertexKeyMap welds;
|
VertexKeyMap welds;
|
||||||
@@ -127,7 +127,7 @@ namespace IfcGeom {
|
|||||||
std::vector<double>& uvs() { return uvs_; }
|
std::vector<double>& uvs() { return uvs_; }
|
||||||
const std::vector<double>& uvs() const { return uvs_; }
|
const std::vector<double>& uvs() const { return uvs_; }
|
||||||
const std::vector<int>& material_ids() const { return _material_ids; }
|
const std::vector<int>& material_ids() const { return _material_ids; }
|
||||||
const std::vector<ifcopenshell::geometry::taxonomy::style>& materials() const { return _materials; }
|
const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& materials() const { return _materials; }
|
||||||
const std::vector<int>& item_ids() const { return _item_ids; }
|
const std::vector<int>& item_ids() const { return _item_ids; }
|
||||||
|
|
||||||
Triangulation(const BRep& shape_model);
|
Triangulation(const BRep& shape_model);
|
||||||
@@ -142,7 +142,7 @@ namespace IfcGeom {
|
|||||||
const std::vector<double>& normals,
|
const std::vector<double>& normals,
|
||||||
const std::vector<double>& uvs,
|
const std::vector<double>& uvs,
|
||||||
const std::vector<int>& material_ids,
|
const std::vector<int>& material_ids,
|
||||||
const std::vector<ifcopenshell::geometry::taxonomy::style>& materials,
|
const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& materials,
|
||||||
const std::vector<int>& item_ids
|
const std::vector<int>& item_ids
|
||||||
)
|
)
|
||||||
: Representation(settings, entity)
|
: Representation(settings, entity)
|
||||||
|
|||||||
@@ -8,48 +8,48 @@
|
|||||||
|
|
||||||
namespace pt = boost::property_tree;
|
namespace pt = boost::property_tree;
|
||||||
|
|
||||||
static std::map<std::string, ifcopenshell::geometry::taxonomy::style> default_materials;
|
static std::map<std::string, ifcopenshell::geometry::taxonomy::style::ptr> default_materials;
|
||||||
static ifcopenshell::geometry::taxonomy::style default_material;
|
static ifcopenshell::geometry::taxonomy::style::ptr default_material;
|
||||||
static bool default_materials_initialized = false;
|
static bool default_materials_initialized = false;
|
||||||
|
|
||||||
void InitDefaultMaterials() {
|
void InitDefaultMaterials() {
|
||||||
default_materials.insert(std::make_pair("IfcSite", ifcopenshell::geometry::taxonomy::style("IfcSite")));
|
default_materials.insert(std::make_pair("IfcSite", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcSite")));
|
||||||
default_materials["IfcSite"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.8, 0.65);
|
default_materials["IfcSite"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.8, 0.65);
|
||||||
|
|
||||||
default_materials.insert(std::make_pair("IfcSlab", ifcopenshell::geometry::taxonomy::style("IfcSlab")));
|
default_materials.insert(std::make_pair("IfcSlab", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcSlab")));
|
||||||
default_materials["IfcSlab"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.4, 0.4, 0.4);
|
default_materials["IfcSlab"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.4, 0.4, 0.4);
|
||||||
|
|
||||||
default_materials.insert(std::make_pair("IfcWallStandardCase", ifcopenshell::geometry::taxonomy::style("IfcWallStandardCase")));
|
default_materials.insert(std::make_pair("IfcWallStandardCase", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcWallStandardCase")));
|
||||||
default_materials["IfcWallStandardCase"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.9, 0.9, 0.9);
|
default_materials["IfcWallStandardCase"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.9, 0.9, 0.9);
|
||||||
|
|
||||||
default_materials.insert(std::make_pair("IfcWall", ifcopenshell::geometry::taxonomy::style("IfcWall")));
|
default_materials.insert(std::make_pair("IfcWall", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcWall")));
|
||||||
default_materials["IfcWall"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.9, 0.9, 0.9);
|
default_materials["IfcWall"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.9, 0.9, 0.9);
|
||||||
|
|
||||||
default_materials.insert(std::make_pair("IfcWindow", ifcopenshell::geometry::taxonomy::style("IfcWindow")));
|
default_materials.insert(std::make_pair("IfcWindow", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcWindow")));
|
||||||
default_materials["IfcWindow"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.8, 0.75);
|
default_materials["IfcWindow"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.8, 0.75);
|
||||||
default_materials["IfcWindow"].transparency = 0.3;
|
default_materials["IfcWindow"]->transparency = 0.3;
|
||||||
|
|
||||||
default_materials.insert(std::make_pair("IfcDoor", ifcopenshell::geometry::taxonomy::style("IfcDoor")));
|
default_materials.insert(std::make_pair("IfcDoor", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcDoor")));
|
||||||
default_materials["IfcDoor"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.55, 0.3, 0.15);
|
default_materials["IfcDoor"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.55, 0.3, 0.15);
|
||||||
|
|
||||||
default_materials.insert(std::make_pair("IfcBeam", ifcopenshell::geometry::taxonomy::style("IfcBeam")));
|
default_materials.insert(std::make_pair("IfcBeam", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcBeam")));
|
||||||
default_materials["IfcBeam"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.7, 0.7);
|
default_materials["IfcBeam"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.7, 0.7);
|
||||||
|
|
||||||
default_materials.insert(std::make_pair("IfcRailing", ifcopenshell::geometry::taxonomy::style("IfcRailing")));
|
default_materials.insert(std::make_pair("IfcRailing", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcRailing")));
|
||||||
default_materials["IfcRailing"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.6, 0.6);
|
default_materials["IfcRailing"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.6, 0.6);
|
||||||
|
|
||||||
default_materials.insert(std::make_pair("IfcMember", ifcopenshell::geometry::taxonomy::style("IfcMember")));
|
default_materials.insert(std::make_pair("IfcMember", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcMember")));
|
||||||
default_materials["IfcMember"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.6, 0.6);
|
default_materials["IfcMember"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.6, 0.6);
|
||||||
|
|
||||||
default_materials.insert(std::make_pair("IfcPlate", ifcopenshell::geometry::taxonomy::style("IfcPlate")));
|
default_materials.insert(std::make_pair("IfcPlate", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcPlate")));
|
||||||
default_materials["IfcPlate"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.8, 0.8, 0.8);
|
default_materials["IfcPlate"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.8, 0.8, 0.8);
|
||||||
|
|
||||||
default_materials.insert(std::make_pair("IfcSpace", ifcopenshell::geometry::taxonomy::style("IfcSpace")));
|
default_materials.insert(std::make_pair("IfcSpace", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcSpace")));
|
||||||
default_materials["IfcSpace"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.75, 0.8);
|
default_materials["IfcSpace"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.75, 0.8);
|
||||||
default_materials["IfcSpace"].transparency = 0.8;
|
default_materials["IfcSpace"]->transparency = 0.8;
|
||||||
|
|
||||||
default_material = ifcopenshell::geometry::taxonomy::style("DefaultMaterial");
|
default_material = std::make_shared<ifcopenshell::geometry::taxonomy::style>("DefaultMaterial");
|
||||||
default_material.diffuse = ifcopenshell::geometry::taxonomy::colour(0.7, 0.7, 0.7);
|
default_material->diffuse = ifcopenshell::geometry::taxonomy::colour(0.7, 0.7, 0.7);
|
||||||
|
|
||||||
default_materials_initialized = true;
|
default_materials_initialized = true;
|
||||||
}
|
}
|
||||||
@@ -83,20 +83,20 @@ void IfcGeom::set_default_style_file(const std::string& json_file) {
|
|||||||
|
|
||||||
for (pt::ptree::value_type &material_pair : root) {
|
for (pt::ptree::value_type &material_pair : root) {
|
||||||
std::string name = material_pair.first;
|
std::string name = material_pair.first;
|
||||||
default_materials.insert(std::make_pair(name, ifcopenshell::geometry::taxonomy::style(name)));
|
default_materials.insert(std::make_pair(name, std::make_shared<ifcopenshell::geometry::taxonomy::style>(name)));
|
||||||
|
|
||||||
pt::ptree material = material_pair.second;
|
pt::ptree material = material_pair.second;
|
||||||
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);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
if (material.get_child_optional("specular-roughness")) {
|
if (material.get_child_optional("specular-roughness")) {
|
||||||
default_materials[name].specularity = 1.0 / material.get<double>("specular-roughness");
|
default_materials[name]->specularity = 1.0 / material.get<double>("specular-roughness");
|
||||||
}
|
}
|
||||||
if (material.get_child_optional("transparency")) {
|
if (material.get_child_optional("transparency")) {
|
||||||
default_materials[name].transparency = material.get<double>("transparency");
|
default_materials[name]->transparency = material.get<double>("transparency");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ void IfcGeom::set_default_style_file(const std::string& json_file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ifcopenshell::geometry::taxonomy::style& IfcGeom::get_default_style(const std::string& s) {
|
const ifcopenshell::geometry::taxonomy::style::ptr& IfcGeom::get_default_style(const std::string& s) {
|
||||||
static std::mutex m;
|
static std::mutex m;
|
||||||
std::lock_guard<std::mutex> lk(m);
|
std::lock_guard<std::mutex> lk(m);
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ const ifcopenshell::geometry::taxonomy::style& IfcGeom::get_default_style(const
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifcopenshell::geometry::taxonomy::style& IfcGeom::update_default_style(const std::string& s) {
|
ifcopenshell::geometry::taxonomy::style::ptr& IfcGeom::update_default_style(const std::string& s) {
|
||||||
if (!default_materials_initialized) InitDefaultMaterials();
|
if (!default_materials_initialized) InitDefaultMaterials();
|
||||||
auto it = default_materials.find(s);
|
auto it = default_materials.find(s);
|
||||||
if (it == default_materials.end()) {
|
if (it == default_materials.end()) {
|
||||||
|
|||||||
@@ -40,8 +40,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%template(material_vector) std::vector<ifcopenshell::geometry::taxonomy::style>;
|
|
||||||
|
|
||||||
// SWIG does not support bool references in a meaningful way, so the
|
// SWIG does not support bool references in a meaningful way, so the
|
||||||
// ifcopenshell::geometry::Settings functions degrade to return a read only value
|
// ifcopenshell::geometry::Settings functions degrade to return a read only value
|
||||||
%typemap(out) double& {
|
%typemap(out) double& {
|
||||||
@@ -198,6 +196,8 @@ std::string taxonomy_item_repr(ifcopenshell::geometry::taxonomy::item::ptr i) {
|
|||||||
%include "../serializers/XmlSerializer.h"
|
%include "../serializers/XmlSerializer.h"
|
||||||
%include "../serializers/GltfSerializer.h"
|
%include "../serializers/GltfSerializer.h"
|
||||||
|
|
||||||
|
%template(material_vector) std::vector<ifcopenshell::geometry::taxonomy::style::ptr>;
|
||||||
|
|
||||||
%extend ifcopenshell::geometry::taxonomy::style {
|
%extend ifcopenshell::geometry::taxonomy::style {
|
||||||
size_t instance_id() const {
|
size_t instance_id() const {
|
||||||
// @todo for some reason we have the IfcStyledItem/IfcMaterial here, but
|
// @todo for some reason we have the IfcStyledItem/IfcMaterial here, but
|
||||||
@@ -529,7 +529,8 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
PyObject* colors_buffer() const {
|
PyObject* colors_buffer() const {
|
||||||
std::vector<double> clrs;
|
std::vector<double> clrs;
|
||||||
clrs.reserve(self->materials().size() * 4);
|
clrs.reserve(self->materials().size() * 4);
|
||||||
for (auto& m : self->materials()) {
|
for (auto& mptr : self->materials()) {
|
||||||
|
auto& m = *mptr;
|
||||||
if (m.diffuse) {
|
if (m.diffuse) {
|
||||||
clrs.push_back(m.diffuse.ccomponents()[0]);
|
clrs.push_back(m.diffuse.ccomponents()[0]);
|
||||||
clrs.push_back(m.diffuse.ccomponents()[1]);
|
clrs.push_back(m.diffuse.ccomponents()[1]);
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ void ColladaSerializer::ColladaExporter::ColladaGeometries::write(
|
|||||||
const std::string &mesh_id, const std::string &/**<@todo 'default_material_name' unused, remove? */,
|
const std::string &mesh_id, const std::string &/**<@todo 'default_material_name' unused, remove? */,
|
||||||
const std::vector<double>& positions, const std::vector<double>& normals,
|
const std::vector<double>& positions, const std::vector<double>& normals,
|
||||||
const std::vector<int>& faces, const std::vector<int>& edges,
|
const std::vector<int>& faces, const std::vector<int>& edges,
|
||||||
const std::vector<int>& material_ids, const std::vector<ifcopenshell::geometry::taxonomy::style>& /**<@todo 'materials' unused, remove? */,
|
const std::vector<int>& material_ids, const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& /**<@todo 'materials' unused, remove? */,
|
||||||
const std::vector<double>& uvs, const std::vector<std::string>& material_references)
|
const std::vector<double>& uvs, const std::vector<std::string>& material_references)
|
||||||
{
|
{
|
||||||
openMesh(mesh_id);
|
openMesh(mesh_id);
|
||||||
@@ -302,24 +302,24 @@ void ColladaSerializer::ColladaExporter::ColladaScene::write() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::write(
|
void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::write(
|
||||||
const ifcopenshell::geometry::taxonomy::style &material, const std::string &material_uri)
|
const ifcopenshell::geometry::taxonomy::style::ptr &material, const std::string &material_uri)
|
||||||
{
|
{
|
||||||
openEffect(material_uri + "-fx");
|
openEffect(material_uri + "-fx");
|
||||||
COLLADASW::EffectProfile effect(mSW);
|
COLLADASW::EffectProfile effect(mSW);
|
||||||
effect.setShaderType(COLLADASW::EffectProfile::LAMBERT);
|
effect.setShaderType(COLLADASW::EffectProfile::LAMBERT);
|
||||||
if (material.diffuse) {
|
if (material->diffuse) {
|
||||||
const auto& diffuse = material.diffuse.ccomponents();
|
const auto& diffuse = material->diffuse.ccomponents();
|
||||||
effect.setDiffuse(COLLADASW::ColorOrTexture(COLLADASW::Color(diffuse(0),diffuse(1),diffuse(2))));
|
effect.setDiffuse(COLLADASW::ColorOrTexture(COLLADASW::Color(diffuse(0),diffuse(1),diffuse(2))));
|
||||||
}
|
}
|
||||||
if (material.specular) {
|
if (material->specular) {
|
||||||
const auto& specular = material.specular.ccomponents();
|
const auto& specular = material->specular.ccomponents();
|
||||||
effect.setSpecular(COLLADASW::ColorOrTexture(COLLADASW::Color(specular(0),specular(1),specular(2))));
|
effect.setSpecular(COLLADASW::ColorOrTexture(COLLADASW::Color(specular(0),specular(1),specular(2))));
|
||||||
}
|
}
|
||||||
if (material.specularity == material.specularity) {
|
if (material->specularity == material->specularity) {
|
||||||
effect.setShininess(material.specularity);
|
effect.setShininess(material->specularity);
|
||||||
}
|
}
|
||||||
if (material.transparency == material.transparency) {
|
if (material->transparency == material->transparency) {
|
||||||
const double transparency = material.transparency;
|
const double transparency = material->transparency;
|
||||||
if (transparency > 0) {
|
if (transparency > 0) {
|
||||||
// The default opacity mode for Collada is A_ONE, which apparently indicates a
|
// The default opacity mode for Collada is A_ONE, which apparently indicates a
|
||||||
// transparency value of 1 to be fully opaque. Hence transparency is inverted.
|
// transparency value of 1 to be fully opaque. Hence transparency is inverted.
|
||||||
@@ -334,12 +334,12 @@ void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::close
|
|||||||
closeLibrary();
|
closeLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const ifcopenshell::geometry::taxonomy::style& material) {
|
void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const ifcopenshell::geometry::taxonomy::style::ptr& material) {
|
||||||
if (!contains(material)) {
|
if (!contains(material)) {
|
||||||
std::string material_name = material.name;
|
std::string material_name = material->name;
|
||||||
|
|
||||||
if (material_name.empty()) {
|
if (material_name.empty()) {
|
||||||
material_name = "missing-material-" + material.name;
|
material_name = "missing-material-" + material->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
collada_id(material_name);
|
collada_id(material_name);
|
||||||
@@ -350,19 +350,19 @@ void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const ifcopenshel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ColladaSerializer::ColladaExporter::ColladaMaterials::getMaterialUri(const ifcopenshell::geometry::taxonomy::style& material) {
|
std::string ColladaSerializer::ColladaExporter::ColladaMaterials::getMaterialUri(const ifcopenshell::geometry::taxonomy::style::ptr& material) {
|
||||||
std::vector<ifcopenshell::geometry::taxonomy::style>::iterator it = std::find(materials.begin(), materials.end(), material);
|
std::vector<ifcopenshell::geometry::taxonomy::style::ptr>::iterator it = std::find(materials.begin(), materials.end(), material);
|
||||||
ptrdiff_t index = std::distance(materials.begin(), it);
|
ptrdiff_t index = std::distance(materials.begin(), it);
|
||||||
return material_uris.at(index);
|
return material_uris.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColladaSerializer::ColladaExporter::ColladaMaterials::contains(const ifcopenshell::geometry::taxonomy::style& material) {
|
bool ColladaSerializer::ColladaExporter::ColladaMaterials::contains(const ifcopenshell::geometry::taxonomy::style::ptr& material) {
|
||||||
return std::find(materials.begin(), materials.end(), material) != materials.end();
|
return std::find(materials.begin(), materials.end(), material) != materials.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaSerializer::ColladaExporter::ColladaMaterials::write() {
|
void ColladaSerializer::ColladaExporter::ColladaMaterials::write() {
|
||||||
effects.close();
|
effects.close();
|
||||||
BOOST_FOREACH(const ifcopenshell::geometry::taxonomy::style& material, materials) {
|
BOOST_FOREACH(const ifcopenshell::geometry::taxonomy::style::ptr& material, materials) {
|
||||||
std::string material_name = getMaterialUri(material);
|
std::string material_name = getMaterialUri(material);
|
||||||
openMaterial(material_name);
|
openMaterial(material_name);
|
||||||
|
|
||||||
@@ -396,7 +396,7 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme
|
|||||||
collada_id(representation_id);
|
collada_id(representation_id);
|
||||||
|
|
||||||
std::vector<std::string> material_references;
|
std::vector<std::string> material_references;
|
||||||
BOOST_FOREACH(const ifcopenshell::geometry::taxonomy::style& material, mesh.materials()) {
|
BOOST_FOREACH(const ifcopenshell::geometry::taxonomy::style::ptr& material, mesh.materials()) {
|
||||||
materials.add(material);
|
materials.add(material);
|
||||||
|
|
||||||
std::string material_name = materials.getMaterialUri(material);
|
std::string material_name = materials.getMaterialUri(material);
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ private:
|
|||||||
const std::string &mesh_id, const std::string &default_material_name,
|
const std::string &mesh_id, const std::string &default_material_name,
|
||||||
const std::vector<double>& positions, const std::vector<double>& normals,
|
const std::vector<double>& positions, const std::vector<double>& normals,
|
||||||
const std::vector<int>& faces, const std::vector<int>& edges,
|
const std::vector<int>& faces, const std::vector<int>& edges,
|
||||||
const std::vector<int>& material_ids, const std::vector<ifcopenshell::geometry::taxonomy::style>& materials,
|
const std::vector<int>& material_ids, const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& materials,
|
||||||
const std::vector<double>& uvs, const std::vector<std::string>& material_references);
|
const std::vector<double>& uvs, const std::vector<std::string>& material_references);
|
||||||
void close();
|
void close();
|
||||||
ColladaSerializer *serializer;
|
ColladaSerializer *serializer;
|
||||||
@@ -118,11 +118,11 @@ private:
|
|||||||
explicit ColladaEffects(COLLADASW::StreamWriter& stream)
|
explicit ColladaEffects(COLLADASW::StreamWriter& stream)
|
||||||
: COLLADASW::LibraryEffects(&stream)
|
: COLLADASW::LibraryEffects(&stream)
|
||||||
{}
|
{}
|
||||||
void write(const ifcopenshell::geometry::taxonomy::style &material, const std::string &material_uri);
|
void write(const ifcopenshell::geometry::taxonomy::style::ptr& material, const std::string &material_uri);
|
||||||
void close();
|
void close();
|
||||||
ColladaSerializer *serializer;
|
ColladaSerializer *serializer;
|
||||||
};
|
};
|
||||||
std::vector<ifcopenshell::geometry::taxonomy::style> materials;
|
std::vector<ifcopenshell::geometry::taxonomy::style::ptr> materials;
|
||||||
std::vector<std::string> material_uris;
|
std::vector<std::string> material_uris;
|
||||||
public:
|
public:
|
||||||
explicit ColladaMaterials(COLLADASW::StreamWriter& stream, ColladaSerializer *_serializer)
|
explicit ColladaMaterials(COLLADASW::StreamWriter& stream, ColladaSerializer *_serializer)
|
||||||
@@ -130,9 +130,9 @@ private:
|
|||||||
, serializer(_serializer)
|
, serializer(_serializer)
|
||||||
, effects(stream)
|
, effects(stream)
|
||||||
{}
|
{}
|
||||||
void add(const ifcopenshell::geometry::taxonomy::style& material);
|
void add(const ifcopenshell::geometry::taxonomy::style::ptr& material);
|
||||||
std::string getMaterialUri(const ifcopenshell::geometry::taxonomy::style& material);
|
std::string getMaterialUri(const ifcopenshell::geometry::taxonomy::style::ptr& material);
|
||||||
bool contains(const ifcopenshell::geometry::taxonomy::style& material);
|
bool contains(const ifcopenshell::geometry::taxonomy::style::ptr& material);
|
||||||
void write();
|
void write();
|
||||||
ColladaSerializer *serializer;
|
ColladaSerializer *serializer;
|
||||||
ColladaEffects effects;
|
ColladaEffects effects;
|
||||||
@@ -165,14 +165,14 @@ private:
|
|||||||
std::vector<int> faces;
|
std::vector<int> faces;
|
||||||
std::vector<int> edges;
|
std::vector<int> edges;
|
||||||
std::vector<int> material_ids;
|
std::vector<int> material_ids;
|
||||||
std::vector<ifcopenshell::geometry::taxonomy::style> materials;
|
std::vector<ifcopenshell::geometry::taxonomy::style::ptr> materials;
|
||||||
std::vector<std::string> material_references;
|
std::vector<std::string> material_references;
|
||||||
std::vector<double> uvs;
|
std::vector<double> uvs;
|
||||||
std::vector<const IfcGeom::Element*> parents_;
|
std::vector<const IfcGeom::Element*> parents_;
|
||||||
|
|
||||||
DeferredObject(const std::string& unique_id, const std::string& representation_id, const std::string& type, const IfcGeom::Transformation& transformation,
|
DeferredObject(const std::string& unique_id, const std::string& representation_id, const std::string& type, const IfcGeom::Transformation& transformation,
|
||||||
const std::vector<double>& vertices, const std::vector<double>& normals, const std::vector<int>& faces,
|
const std::vector<double>& vertices, const std::vector<double>& normals, const std::vector<int>& faces,
|
||||||
const std::vector<int>& edges, const std::vector<int>& material_ids, const std::vector<ifcopenshell::geometry::taxonomy::style>& materials,
|
const std::vector<int>& edges, const std::vector<int>& material_ids, const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& materials,
|
||||||
const std::vector<std::string>& material_references, const std::vector<double>& uvs)
|
const std::vector<std::string>& material_references, const std::vector<double>& uvs)
|
||||||
: unique_id(unique_id)
|
: unique_id(unique_id)
|
||||||
, representation_id(representation_id)
|
, representation_id(representation_id)
|
||||||
|
|||||||
@@ -86,29 +86,29 @@ void GltfSerializer::writeHeader() {
|
|||||||
json_["materials"] = json::array();
|
json_["materials"] = json::array();
|
||||||
}
|
}
|
||||||
|
|
||||||
int GltfSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style& style) {
|
int GltfSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style::ptr style) {
|
||||||
auto it = materials_.find(style.name);
|
auto it = materials_.find(style->name);
|
||||||
if (it != materials_.end()) {
|
if (it != materials_.end()) {
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = json_["materials"].size();
|
int idx = json_["materials"].size();
|
||||||
materials_[style.name] = idx;
|
materials_[style->name] = idx;
|
||||||
|
|
||||||
std::array<double, 4> base;
|
std::array<double, 4> base;
|
||||||
base.fill(1.0);
|
base.fill(1.0);
|
||||||
if (style.diffuse) {
|
if (style->diffuse) {
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
base[i] = style.diffuse.ccomponents()(i);
|
base[i] = style->diffuse.ccomponents()(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (style.transparency == style.transparency) {
|
if (style->transparency == style->transparency) {
|
||||||
base[3] = 1. - style.transparency;
|
base[3] = 1. - style->transparency;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_["materials"].push_back({ {"doubleSided", true}, {"pbrMetallicRoughness", {{"baseColorFactor", base}, {"metallicFactor", 0}}} });
|
json_["materials"].push_back({ {"doubleSided", true}, {"pbrMetallicRoughness", {{"baseColorFactor", base}, {"metallicFactor", 0}}} });
|
||||||
|
|
||||||
if (style.transparency == style.transparency && style.transparency > 1.e-9) {
|
if (style->transparency == style->transparency && style->transparency > 1.e-9) {
|
||||||
json_["materials"].back()["alphaMode"] = "BLEND";
|
json_["materials"].back()["alphaMode"] = "BLEND";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ private:
|
|||||||
boost::optional<json> ecef_transform_, north_rotation_;
|
boost::optional<json> ecef_transform_, north_rotation_;
|
||||||
int bufferViewId;
|
int bufferViewId;
|
||||||
|
|
||||||
int writeMaterial(const ifcopenshell::geometry::taxonomy::style& style);
|
int writeMaterial(const ifcopenshell::geometry::taxonomy::style::ptr style);
|
||||||
public:
|
public:
|
||||||
GltfSerializer(const std::string& filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings);
|
GltfSerializer(const std::string& filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings);
|
||||||
virtual ~GltfSerializer();
|
virtual ~GltfSerializer();
|
||||||
|
|||||||
@@ -233,7 +233,8 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HdfSerializer::read_surface_style(surface_style_serialization& s, ifcopenshell::geometry::taxonomy::style& gss) {
|
void HdfSerializer::read_surface_style(surface_style_serialization& s, const ifcopenshell::geometry::taxonomy::style::ptr& gss_) {
|
||||||
|
auto& gss = *gss_;
|
||||||
if (strlen(s.name) || s.id) {
|
if (strlen(s.name) || s.id) {
|
||||||
if (s.diffuse[0] == s.diffuse[0]) {
|
if (s.diffuse[0] == s.diffuse[0]) {
|
||||||
gss.diffuse = ifcopenshell::geometry::taxonomy::colour(s.diffuse[0], s.diffuse[1], s.diffuse[2]);
|
gss.diffuse = ifcopenshell::geometry::taxonomy::colour(s.diffuse[0], s.diffuse[1], s.diffuse[2]);
|
||||||
@@ -355,7 +356,7 @@ IfcGeom::Element* HdfSerializer::read(IfcParse::IfcFile& f, const std::string& g
|
|||||||
matrix->components() << Eigen::Map<Eigen::Matrix4d>(&part.matrix[0][0]);
|
matrix->components() << Eigen::Map<Eigen::Matrix4d>(&part.matrix[0][0]);
|
||||||
|
|
||||||
auto style_ptr = ifcopenshell::geometry::taxonomy::make<ifcopenshell::geometry::taxonomy::style>();
|
auto style_ptr = ifcopenshell::geometry::taxonomy::make<ifcopenshell::geometry::taxonomy::style>();
|
||||||
read_surface_style(part.surface_style, *style_ptr);
|
read_surface_style(part.surface_style, style_ptr);
|
||||||
|
|
||||||
shapes.push_back(IfcGeom::ConversionResult(part.id, matrix, new ifcopenshell::geometry::OpenCascadeShape(shp), style_ptr));
|
shapes.push_back(IfcGeom::ConversionResult(part.id, matrix, new ifcopenshell::geometry::OpenCascadeShape(shp), style_ptr));
|
||||||
}
|
}
|
||||||
@@ -416,7 +417,7 @@ IfcGeom::Element* HdfSerializer::read(IfcParse::IfcFile& f, const std::string& g
|
|||||||
ds.read(surface_styles.data(), style_compound);
|
ds.read(surface_styles.data(), style_compound);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ifcopenshell::geometry::taxonomy::style> surface_style_ptrs(surface_styles.size());
|
std::vector<ifcopenshell::geometry::taxonomy::style::ptr> surface_style_ptrs(surface_styles.size());
|
||||||
|
|
||||||
for (size_t i = 0; i < surface_styles.size(); ++i) {
|
for (size_t i = 0; i < surface_styles.size(); ++i) {
|
||||||
read_surface_style(surface_styles[i], surface_style_ptrs[i]);
|
read_surface_style(surface_styles[i], surface_style_ptrs[i]);
|
||||||
@@ -536,7 +537,8 @@ H5::Group HdfSerializer::createRepresentationGroup(const H5::Group& element_grou
|
|||||||
return representation_group;
|
return representation_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HdfSerializer::write_style(surface_style_serialization& data, const ifcopenshell::geometry::taxonomy::style& s) {
|
void HdfSerializer::write_style(surface_style_serialization& data, const ifcopenshell::geometry::taxonomy::style::ptr& sptr) {
|
||||||
|
auto& s = *sptr;
|
||||||
data.name = s.name.c_str();
|
data.name = s.name.c_str();
|
||||||
// @todo
|
// @todo
|
||||||
data.original_name = s.name.c_str();
|
data.original_name = s.name.c_str();
|
||||||
@@ -609,7 +611,7 @@ void HdfSerializer::write(const IfcGeom::BRepElement* o) {
|
|||||||
|
|
||||||
parts[i].surface_style = { "", "", 0, {nan,nan,nan}, {nan,nan,nan}, nan, nan };
|
parts[i].surface_style = { "", "", 0, {nan,nan,nan}, {nan,nan,nan}, nan, nan };
|
||||||
if (it->hasStyle()) {
|
if (it->hasStyle()) {
|
||||||
auto& s = it->Style();
|
auto s = it->StylePtr();
|
||||||
write_style(parts[i].surface_style, s);
|
write_style(parts[i].surface_style, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ private:
|
|||||||
std::map<std::string, std::string> group_cache_;
|
std::map<std::string, std::string> group_cache_;
|
||||||
|
|
||||||
H5::Group createRepresentationGroup(const H5::Group& element_group, const std::string& gid);
|
H5::Group createRepresentationGroup(const H5::Group& element_group, const std::string& gid);
|
||||||
void read_surface_style(surface_style_serialization& sss, ifcopenshell::geometry::taxonomy::style& style_ptr);
|
void read_surface_style(surface_style_serialization& sss, const ifcopenshell::geometry::taxonomy::style::ptr& style_ptr);
|
||||||
void write_style(surface_style_serialization& data, const ifcopenshell::geometry::taxonomy::style& s);
|
void write_style(surface_style_serialization& data, const ifcopenshell::geometry::taxonomy::style::ptr& s);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HdfSerializer(const std::string& hdf_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, bool read_only=false);
|
HdfSerializer(const std::string& hdf_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, bool read_only=false);
|
||||||
|
|||||||
@@ -59,8 +59,9 @@ void WaveFrontOBJSerializer::writeHeader() {
|
|||||||
mtl_stream.stream << "# File generated by IfcOpenShell " << IFCOPENSHELL_VERSION << "\n";
|
mtl_stream.stream << "# File generated by IfcOpenShell " << IFCOPENSHELL_VERSION << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaveFrontOBJSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style& style)
|
void WaveFrontOBJSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style::ptr styleptr)
|
||||||
{
|
{
|
||||||
|
auto& style = *styleptr;
|
||||||
std::string material_name = style.name;
|
std::string material_name = style.name;
|
||||||
IfcUtil::sanitate_material_name(material_name);
|
IfcUtil::sanitate_material_name(material_name);
|
||||||
mtl_stream.stream << "newmtl " << material_name << "\n";
|
mtl_stream.stream << "newmtl " << material_name << "\n";
|
||||||
@@ -127,8 +128,8 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement* o)
|
|||||||
|
|
||||||
const int material_id = *(material_it++);
|
const int material_id = *(material_it++);
|
||||||
if (material_id != previous_material_id) {
|
if (material_id != previous_material_id) {
|
||||||
const ifcopenshell::geometry::taxonomy::style& material = mesh.materials()[material_id];
|
const ifcopenshell::geometry::taxonomy::style::ptr material = mesh.materials()[material_id];
|
||||||
std::string material_name = material.name;
|
std::string material_name = material->name;
|
||||||
IfcUtil::sanitate_material_name(material_name);
|
IfcUtil::sanitate_material_name(material_name);
|
||||||
obj_stream.stream << "usemtl " << material_name << "\n";
|
obj_stream.stream << "usemtl " << material_name << "\n";
|
||||||
if (materials.find(material_name) == materials.end()) {
|
if (materials.find(material_name) == materials.end()) {
|
||||||
@@ -170,8 +171,8 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement* o)
|
|||||||
const int material_id = *(material_it++);
|
const int material_id = *(material_it++);
|
||||||
|
|
||||||
if (material_id != previous_material_id) {
|
if (material_id != previous_material_id) {
|
||||||
const ifcopenshell::geometry::taxonomy::style& material = mesh.materials()[material_id];
|
const ifcopenshell::geometry::taxonomy::style::ptr material = mesh.materials()[material_id];
|
||||||
std::string material_name = material.name;
|
std::string material_name = material->name;
|
||||||
IfcUtil::sanitate_material_name(material_name);
|
IfcUtil::sanitate_material_name(material_name);
|
||||||
obj_stream.stream << "usemtl " << material_name << "\n";
|
obj_stream.stream << "usemtl " << material_name << "\n";
|
||||||
if (materials.find(material_name) == materials.end()) {
|
if (materials.find(material_name) == materials.end()) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
virtual ~WaveFrontOBJSerializer() {}
|
virtual ~WaveFrontOBJSerializer() {}
|
||||||
bool ready();
|
bool ready();
|
||||||
void writeHeader();
|
void writeHeader();
|
||||||
void writeMaterial(const ifcopenshell::geometry::taxonomy::style& style);
|
void writeMaterial(const ifcopenshell::geometry::taxonomy::style::ptr style);
|
||||||
void write(const IfcGeom::TriangulationElement* o);
|
void write(const IfcGeom::TriangulationElement* o);
|
||||||
void write(const IfcGeom::BRepElement* /*o*/) {}
|
void write(const IfcGeom::BRepElement* /*o*/) {}
|
||||||
void finalize() {}
|
void finalize() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user