Fixed bug with remembering materials assigned to faces

The problem was that bim.update_representation was assigning representation styles without taking into account that some styles may not be actually used in the mesh, so it was always assigning first style (blender material) to the first IFCPOLYGONALFACESET even though it might be using for example the 3rd style.

More - https://community.osarch.org/discussion/1636/materials-not-remembering-their-assigment
This commit is contained in:
Andrej730
2023-08-23 11:07:38 +05:00
parent 66f5081ada
commit 422f772c40
2 changed files with 11 additions and 3 deletions
@@ -329,7 +329,7 @@ class UpdateRepresentation(bpy.types.Operator, Operator):
"style.assign_representation_styles",
self.file,
shape_representation=new_representation,
styles=tool.Geometry.get_styles(obj),
styles=tool.Geometry.get_styles(obj, only_assigned_to_faces=True),
should_use_presentation_style_assignment=context.scene.BIMGeometryProperties.should_use_presentation_style_assignment,
)
tool.Geometry.record_object_materials(obj)
+10 -2
View File
@@ -396,8 +396,16 @@ class Geometry(blenderbim.core.tool.Geometry):
return f"{representation.ContextOfItems.id()}/{representation.id()}"
@classmethod
def get_styles(cls, obj):
return [tool.Style.get_style(s.material) for s in obj.material_slots if s.material]
def get_styles(cls, obj, only_assigned_to_faces=False):
styles = [tool.Style.get_style(s.material) for s in obj.material_slots if s.material]
if not only_assigned_to_faces:
return styles
usage_count = [0] * len(obj.material_slots)
for poly in obj.data.polygons:
usage_count[poly.material_index] += 1
styles = [style for style, usage in zip(styles, usage_count, strict=True) if usage > 0]
return styles
# TODO: multiple Literals?
@classmethod