From 4cff2f1fc195ec291692329f7686c5df830646ba Mon Sep 17 00:00:00 2001 From: falken10 Date: Mon, 10 Mar 2025 14:44:11 +0100 Subject: [PATCH] Add traverse_transparent property to control sun light traversal through transparent objects --- src/bonsai/bonsai/bim/module/light/prop.py | 31 ++++++++++++++++++++++ src/bonsai/bonsai/bim/module/light/ui.py | 6 +++++ 2 files changed, 37 insertions(+) diff --git a/src/bonsai/bonsai/bim/module/light/prop.py b/src/bonsai/bonsai/bim/module/light/prop.py index c8f249cefd..1f2c17b898 100644 --- a/src/bonsai/bonsai/bim/module/light/prop.py +++ b/src/bonsai/bonsai/bim/module/light/prop.py @@ -73,6 +73,8 @@ def update_sun_path_size(self, context): def update_display_shadows(self, context): if self.display_shadows: + if context.scene.BIMSolarProperties.traverse_transparent: + context.scene.BIMSolarProperties.traverse_transparent = False update_sun_path(self) context.scene.render.engine = "BLENDER_WORKBENCH" context.scene.display.shading.light = "FLAT" @@ -86,6 +88,27 @@ def update_display_shadows(self, context): space = tool.Blender.get_view3d_space() space.shading.type = "SOLID" +def update_traverse_transparent(self, context): + if self.traverse_transparent: + if context.scene.BIMSolarProperties.display_shadows: + context.scene.BIMSolarProperties.display_shadows = False + if context.scene.sun_pos_properties.sun_object is None: + bpy.ops.object.light_add(type="SUN", radius=1, align="WORLD", location=(0, 0, 0), scale=(1, 1, 1)) + bpy.ops.object.move_to_collection(collection_index=0) + context.scene.sun_pos_properties.sun_object = bpy.context.active_object + update_sun_path(self) + context.scene.render.engine = "BLENDER_EEVEE_NEXT" + context.scene.display.shading.light = "FLAT" + context.scene.display.shading.show_shadows = True + context.scene.display.shading.show_object_outline = True + context.scene.display.shadow_focus = 1.0 + context.scene.view_settings.view_transform = "Standard" # Preserve shading colours + space = tool.Blender.get_view3d_space() + space.shading.type = "RENDERED" + else: + context.scene.render.engine = "BLENDER_WORKBENCH" + space = tool.Blender.get_view3d_space() + space.shading.type = "SOLID" def update_display_sun_path(self, context): if self.display_sun_path: @@ -400,6 +423,14 @@ class BIMSolarProperties(PropertyGroup): description="Enables a visual style to display shadows easily", update=update_display_shadows, ) + + traverse_transparent: BoolProperty( + name="Enable Sun: Shadows and Light traversal of transparent objects", + default=False, + description="Enables a visual style so Sun light can traverse transparent objects and cast shadows (it toggles the render engine to EEVEE)", + update=update_traverse_transparent, + ) + display_sun_path: BoolProperty( name="Display Sun Path", default=False, diff --git a/src/bonsai/bonsai/bim/module/light/ui.py b/src/bonsai/bonsai/bim/module/light/ui.py index 37aa632372..1ecdd009c4 100644 --- a/src/bonsai/bonsai/bim/module/light/ui.py +++ b/src/bonsai/bonsai/bim/module/light/ui.py @@ -239,5 +239,11 @@ class BIM_PT_solar(bpy.types.Panel): row.prop(props, "display_shadows", icon="SHADING_RENDERED") row.prop(context.scene.display.shading, "shadow_intensity", text="Shadow Intensity") + row = self.layout.row(align=True) + row.prop(props, "traverse_transparent", icon="SHADING_RENDERED") + if props.traverse_transparent: + row = self.layout.row(align=True) + row.prop(context.scene.sun_pos_properties.sun_object.data , "energy", text="Sun Intensity") + row = self.layout.row(align=True) row.operator("bim.view_from_sun", icon="LIGHT_HEMI")