mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
WIP allow partial mesh geometry editing to preserve style assignments. See #1222.
This commit is contained in:
@@ -256,6 +256,7 @@ class MaterialCreator:
|
||||
|
||||
def create_new_single(self, material):
|
||||
self.materials[material.Name] = obj = bpy.data.materials.new(material.Name)
|
||||
obj.BIMMaterialProperties.ifc_definition_id = int(material.id())
|
||||
self.ifc_importer.add_element_attributes(material, obj.BIMMaterialProperties)
|
||||
for pset in getattr(material, "HasProperties", ()):
|
||||
self.ifc_importer.add_pset(pset, obj.BIMMaterialProperties)
|
||||
@@ -286,6 +287,7 @@ class MaterialCreator:
|
||||
for style in styles:
|
||||
if not style.is_a("IfcSurfaceStyle"):
|
||||
continue
|
||||
material.BIMMaterialProperties.ifc_style_id = int(style.id())
|
||||
external_style = None
|
||||
for surface_style in style.Styles:
|
||||
if surface_style.is_a("IfcSurfaceStyleShading"):
|
||||
|
||||
@@ -18,7 +18,6 @@ class Usecase:
|
||||
self.ifc_vertices = []
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
self.context_of_items = None
|
||||
|
||||
def execute(self):
|
||||
if self.settings["unit_scale"] is None:
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {"shape_representation": None, "styles": []}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
self.results = []
|
||||
for element in self.file.traverse(self.settings["shape_representation"]):
|
||||
if not element.is_a("IfcShapeRepresentation"):
|
||||
continue
|
||||
for item in element.Items:
|
||||
if not item.is_a("IfcGeometricRepresentationItem"):
|
||||
continue
|
||||
style = self.settings["styles"].pop(0)
|
||||
self.results.append(
|
||||
self.file.createIfcStyledItem(
|
||||
item, [style], style.Name
|
||||
)
|
||||
)
|
||||
return self.results
|
||||
@@ -4347,10 +4347,11 @@ class BakeParametricGeometry(bpy.types.Operator):
|
||||
bl_label = "Bake Parametric Geometry"
|
||||
|
||||
def execute(self, context):
|
||||
import blenderbim.bim.module.geometry.add_shape_representation as add_shape_representation
|
||||
obj = bpy.context.active_object
|
||||
self.file = ifc.IfcStore.get_file()
|
||||
element = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
||||
|
||||
import blenderbim.bim.module.geometry.add_shape_representation as add_shape_representation
|
||||
usecase = add_shape_representation.Usecase(self.file, {
|
||||
"context": element.ContextOfItems,
|
||||
"geometry": obj.data,
|
||||
@@ -4360,10 +4361,17 @@ class BakeParametricGeometry(bpy.types.Operator):
|
||||
if not result:
|
||||
print("Failed to write shape representation")
|
||||
return {"FINISHED"}
|
||||
|
||||
import blenderbim.bim.module.geometry.assign_styles as assign_styles
|
||||
usecase = assign_styles.Usecase(self.file, {
|
||||
"shape_representation": result,
|
||||
"styles": [self.file.by_id(s.material.BIMMaterialProperties.ifc_style_id) for s in obj.material_slots if s.material]
|
||||
})
|
||||
usecase.execute()
|
||||
|
||||
for inverse in self.file.get_inverse(element):
|
||||
ifcopenshell.util.element.replace_attribute(inverse, element, result)
|
||||
obj.data.BIMMeshProperties.ifc_definition_id = int(result.id())
|
||||
print(result)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
|
||||
@@ -1525,6 +1525,9 @@ class BIMMaterialProperties(PropertyGroup):
|
||||
psets: CollectionProperty(name="Psets", type=PsetQto)
|
||||
attributes: CollectionProperty(name="Attributes", type=Attribute)
|
||||
applicable_attributes: EnumProperty(items=getApplicableMaterialAttributes, name="Attribute Names")
|
||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||
# In Blender, a material object can map to an IFC material, IFC surface style, or both
|
||||
ifc_style_id: IntProperty(name="IFC Style ID")
|
||||
|
||||
|
||||
class SweptSolid(PropertyGroup):
|
||||
|
||||
Reference in New Issue
Block a user