mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
Define diffuse colour, and give possibility for externally defined material URI
This commit is contained in:
@@ -673,14 +673,13 @@ class IfcExporter():
|
|||||||
|
|
||||||
def create_materials(self):
|
def create_materials(self):
|
||||||
for material in self.ifc_parser.materials.values():
|
for material in self.ifc_parser.materials.values():
|
||||||
surface_colour = self.file.createIfcColourRgb(None,
|
styles = []
|
||||||
material['raw'].diffuse_color[0],
|
styles.append(self.create_surface_style_rendering(material))
|
||||||
material['raw'].diffuse_color[1],
|
if 'IsExternal' in material['raw'].keys():
|
||||||
material['raw'].diffuse_color[2])
|
styles.append(self.file.create_entity('IfcExternallyDefinedSurfaceStyle',
|
||||||
surface_style_rendering = self.file.create_entity('IfcSurfaceStyleRendering', **{
|
**self.get_material_external_definition(material['raw'])))
|
||||||
'SurfaceColour': surface_colour
|
|
||||||
})
|
surface_style = self.file.createIfcSurfaceStyle(None, 'BOTH', styles)
|
||||||
surface_style = self.file.createIfcSurfaceStyle(None, 'BOTH', [surface_style_rendering])
|
|
||||||
styled_item = self.file.createIfcStyledItem(None, [surface_style], None)
|
styled_item = self.file.createIfcStyledItem(None, [surface_style], None)
|
||||||
styled_representation = self.file.createIfcStyledRepresentation(
|
styled_representation = self.file.createIfcStyledRepresentation(
|
||||||
self.ifc_rep_subcontext, None, None, [styled_item])
|
self.ifc_rep_subcontext, None, None, [styled_item])
|
||||||
@@ -688,6 +687,31 @@ class IfcExporter():
|
|||||||
self.file.createIfcMaterialDefinitionRepresentation(
|
self.file.createIfcMaterialDefinitionRepresentation(
|
||||||
material['raw'].name, None, [styled_representation], material['ifc'])
|
material['raw'].name, None, [styled_representation], material['ifc'])
|
||||||
|
|
||||||
|
def create_surface_style_rendering(self, material):
|
||||||
|
surface_colour = self.create_colour_rgb(material['raw'].diffuse_color)
|
||||||
|
rendering_attributes = { 'SurfaceColour': surface_colour }
|
||||||
|
rendering_attributes.update(self.get_rendering_attributes(material['raw']))
|
||||||
|
return self.file.create_entity('IfcSurfaceStyleRendering', **rendering_attributes)
|
||||||
|
|
||||||
|
def get_rendering_attributes(self, material):
|
||||||
|
if 'Principled BSDF' not in material.node_tree.nodes:
|
||||||
|
return {}
|
||||||
|
bsdf = material.node_tree.nodes['Principled BSDF']
|
||||||
|
return {
|
||||||
|
'Transparency': (bsdf.inputs['Alpha'].default_value - 1) * -1,
|
||||||
|
'DiffuseColour': self.create_colour_rgb(bsdf.inputs['Base Color'].default_value)
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_material_external_definition(self, material):
|
||||||
|
return {
|
||||||
|
'Location': material['Location'],
|
||||||
|
'Identification': material['Identification'] if 'Identification' in material else material.name,
|
||||||
|
'Name': material['Name'] if 'Name' in material else material.name
|
||||||
|
}
|
||||||
|
|
||||||
|
def create_colour_rgb(self, colour):
|
||||||
|
return self.file.createIfcColourRgb(None, colour[0], colour[1], colour[2])
|
||||||
|
|
||||||
def create_representations(self):
|
def create_representations(self):
|
||||||
for representation in self.ifc_parser.representations.values():
|
for representation in self.ifc_parser.representations.values():
|
||||||
representation['ifc'] = self.create_representation(representation)
|
representation['ifc'] = self.create_representation(representation)
|
||||||
|
|||||||
Reference in New Issue
Block a user