From 4f9f3d185693e8fdaea63da90e3fa3fe92d4ad3b Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 21 Apr 2024 13:34:25 +0200 Subject: [PATCH] Work around for obtaining instance id that blenderbim expects for materials --- src/ifcwrap/IfcGeomWrapper.i | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index 62e3582fb9..802dade8ed 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -29,6 +29,8 @@ } } +%template(material_vector) std::vector; + // SWIG does not support bool references in a meaningful way, so the // ifcopenshell::geometry::Settings functions degrade to return a read only value %typemap(out) double& { @@ -104,6 +106,28 @@ std::pair vector_to_buffer(const T& t) { %include "../serializers/XmlSerializer.h" %include "../serializers/GltfSerializer.h" +%extend ifcopenshell::geometry::taxonomy::style { + size_t instance_id() const { + // @todo for some reason we have the IfcStyledItem/IfcMaterial here, but + // BlenderBIM expects IfcSurfaceStyle/IfcMaterial + if (self->instance == nullptr) { + return 0; + } + const IfcUtil::IfcBaseEntity* ent; + if ((ent = self->instance->as()) == nullptr) { + return 0; + } + if (ent->declaration().name() == "IfcStyledItem") { + aggregate_of_instance::ptr styles = *ent->get("Styles"); + if (styles->size() == 1) { + ent = (*styles->begin())->as(); + } else { + return 0; + } + } + return ent->data().id(); + } +} %extend ifcopenshell::geometry::Settings { void set_(const std::string& name, bool val) {