add surface styles preview (based on their blender materials)

Example - https://i.imgur.com/jH9q7iF.png
This commit is contained in:
Andrej730
2024-08-21 18:04:52 +05:00
parent e31019eb67
commit 4e75945435
2 changed files with 11 additions and 5 deletions
+3 -3
View File
@@ -44,13 +44,13 @@ class StylesData:
cls.is_loaded = True
@classmethod
def styles_to_blender_material_names(cls):
def styles_to_blender_material_names(cls) -> dict[bpy.types.PropertyGroup, Union[str, None]]:
ifc_file = tool.Ifc.get()
props = bpy.context.scene.BIMStylesProperties
materials = []
materials: dict[bpy.types.PropertyGroup, Union[str, None]] = {}
for style in props.styles:
material = tool.Ifc.get_object(ifc_file.by_id(style.ifc_definition_id))
materials.append(material.name if material is not None else None)
materials[style] = material.name if material is not None else None
return materials
@classmethod
+8 -2
View File
@@ -22,6 +22,7 @@ import bonsai.tool as tool
from bpy.types import Panel, UIList
from bonsai.bim.ifc import IfcStore
from bonsai.bim.module.style.data import StylesData, BlenderMaterialStyleData
from typing import Union
class BIM_PT_styles(Panel):
@@ -93,7 +94,7 @@ class BIM_PT_styles(Panel):
# style ui tools
if active_style:
row = self.layout.row(align=True)
material_name = StylesData.data["styles_to_blender_material_names"][self.props.active_style_index]
material_name = StylesData.data["styles_to_blender_material_names"][style]
if material_name: # The user may have unlinked the style, so the material may not exist
material = bpy.data.materials[material_name]
row.prop(material.BIMStyleProperties, "active_style_type", icon="SHADING_RENDERED", text="")
@@ -266,7 +267,12 @@ class BIM_UL_styles(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
if item:
row = layout.row(align=True)
row.prop(item, "name", text="", emboss=False)
material_name: Union[str, None] = StylesData.data["styles_to_blender_material_names"][item]
material_icon = 0
if material_name and (material := bpy.data.materials.get(material_name)):
preview = material.preview_ensure()
material_icon = preview.icon_id
row.prop(item, "name", text="", emboss=False, icon_value=material_icon)
if item.has_surface_colour:
row = row.row(align=True)
row.enabled = False