do not load ifc materials as blender materials #4843

also deprecate blender_material style argument as it's not used anywhere now
This commit is contained in:
Andrej730
2024-06-11 18:11:45 +05:00
parent 2e2c116180
commit 9906149b0d
3 changed files with 8 additions and 28 deletions
+5 -20
View File
@@ -273,8 +273,6 @@ class IfcImporter:
self.profile_code("Create project")
self.process_element_filter()
self.profile_code("Process element filter")
self.create_materials()
self.profile_code("Create materials")
self.create_styles()
self.profile_code("Create styles")
self.parse_native_elements()
@@ -1602,28 +1600,15 @@ class IfcImporter:
self.project["blender"].BIMCollectionProperties.obj = obj
obj.BIMObjectProperties.collection = self.collections[project.GlobalId] = self.project["blender"]
def create_materials(self) -> None:
for material in self.file.by_type("IfcMaterial"):
self.create_material(material)
def create_material(self, material: ifcopenshell.entity_instance) -> bpy.types.Material:
blender_material = bpy.data.materials.new(material.Name)
self.link_element(material, blender_material)
self.material_creator.materials[material.id()] = blender_material
blender_material.use_fake_user = True
return blender_material
def create_styles(self) -> None:
for style in self.file.by_type("IfcSurfaceStyle"):
self.create_style(style)
def create_style(
self, style: ifcopenshell.entity_instance, blender_material: Optional[bpy.types.Material] = None
) -> None:
if not blender_material:
name = style.Name or str(style.id())
blender_material = bpy.data.materials.new(name)
blender_material.use_fake_user = True
def create_style(self, style: ifcopenshell.entity_instance) -> None:
"""Set up a Blender material for an IfcSurfaceStyle."""
name = style.Name or str(style.id())
blender_material = bpy.data.materials.new(name)
blender_material.use_fake_user = True
self.link_element(style, blender_material)
@@ -188,7 +188,6 @@ class ExecuteIfcDiff(bpy.types.Operator):
tool.Ifc.set(ifc_diff.old)
ifc_importer.file = ifc_diff.old
ifc_importer.process_context_filter()
ifc_importer.create_materials()
ifc_importer.create_styles()
elements = {ifc_diff.old.by_guid(guid) for guid in ifc_diff.deleted_elements}
@@ -204,7 +203,6 @@ class ExecuteIfcDiff(bpy.types.Operator):
tool.Ifc.set(ifc_diff.new)
ifc_importer.file = ifc_diff.new
ifc_importer.process_context_filter()
ifc_importer.create_materials()
ifc_importer.create_styles()
elements = {ifc_diff.new.by_guid(guid) for guid in ifc_diff.added_elements}
@@ -470,8 +470,7 @@ class AppendLibraryElement(bpy.types.Operator):
ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger)
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
ifc_importer.file = self.file
blender_material = ifc_importer.create_material(element)
self.import_material_styles(blender_material, element, ifc_importer)
self.import_material_styles(element, ifc_importer)
def import_product_from_ifc(self, element: ifcopenshell.entity_instance, context: bpy.types.Context) -> None:
self.file = IfcStore.get_file()
@@ -515,8 +514,7 @@ class AppendLibraryElement(bpy.types.Operator):
for material in ifcopenshell.util.element.get_materials(element):
if IfcStore.get_element(material.id()):
continue
blender_material = ifc_importer.create_material(material)
self.import_material_styles(blender_material, material, ifc_importer)
self.import_material_styles(material, ifc_importer)
def import_styles(self, element: ifcopenshell.entity_instance, ifc_importer: import_ifc.IfcImporter) -> None:
if element.is_a("IfcTypeProduct"):
@@ -533,7 +531,6 @@ class AppendLibraryElement(bpy.types.Operator):
def import_material_styles(
self,
blender_material: bpy.types.Material,
material: ifcopenshell.entity_instance,
ifc_importer: import_ifc.IfcImporter,
) -> None:
@@ -541,7 +538,7 @@ class AppendLibraryElement(bpy.types.Operator):
return
for element in self.file.traverse(material.HasRepresentation[0]):
if element.is_a("IfcSurfaceStyle") and not IfcStore.get_element(element.id()):
ifc_importer.create_style(element, blender_material)
ifc_importer.create_style(element)
class EnableEditingHeader(bpy.types.Operator):