From 65671dde166823f3472947428e6ce2c00b32a6f7 Mon Sep 17 00:00:00 2001 From: Gorgious Date: Sun, 23 Nov 2025 21:50:52 +0100 Subject: [PATCH] Make hide_render optional to improve performance for aggregate mode --- src/bonsai/bonsai/bim/import_ifc.py | 2 +- src/bonsai/bonsai/tool/blender.py | 33 +++++++++++++++++------------ src/bonsai/bonsai/tool/collector.py | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/bonsai/bonsai/bim/import_ifc.py b/src/bonsai/bonsai/bim/import_ifc.py index 6eb2639a56..9581f540b9 100644 --- a/src/bonsai/bonsai/bim/import_ifc.py +++ b/src/bonsai/bonsai/bim/import_ifc.py @@ -871,7 +871,7 @@ class IfcImporter: for ifcclass in self.classes_to_wireframe_list: if element.is_a(ifcclass): - tool.Blender.Display.set_wireframe(obj) + tool.Blender.Display.set_wireframe(obj, hide_render=True) if shape and mesh: # We use numpy here because Blender mathutils.Matrix is not accurate enough diff --git a/src/bonsai/bonsai/tool/blender.py b/src/bonsai/bonsai/tool/blender.py index 03f1677aff..a1d7ee30a0 100644 --- a/src/bonsai/bonsai/tool/blender.py +++ b/src/bonsai/bonsai/tool/blender.py @@ -1071,23 +1071,24 @@ class Blender(bonsai.core.tool.Blender): :param obj: Object to modify :param display_type: Display type to set (e.g., 'WIRE', 'TEXTURED', 'SOLID', 'BOUNDS') :param hide_render: Render visibility state. If None, render visibility is not modified. - Special cases: True for 'WIRE' and 'BOUNDS', False otherwise """ obj.display_type = display_type if hide_render is not None: obj.hide_render = hide_render @classmethod - def set_display(cls, obj: Union[bpy.types.Object, Iterable[bpy.types.Object]], display_type: str) -> None: - """Set object(s) to a specific display type with appropriate render visibility. + def set_display( + cls, + obj: Union[bpy.types.Object, Iterable[bpy.types.Object]], + display_type: str, + hide_render: Optional[bool] = None, + ) -> None: + """Set object(s) to a specific display type with optional render visibility. :param obj: Single object or iterable of objects to modify :param display_type: Display type to set (e.g., 'WIRE', 'TEXTURED', 'SOLID', 'BOUNDS') - Special handling: 'WIRE' and 'BOUNDS' hide from renders, others show in renders + :param hide_render: Render visibility state. If None, render visibility is not modified. """ - # Determine hide_render based on display type - hide_render = True if display_type in ("WIRE", "BOUNDS") else False - if isinstance(obj, bpy.types.Object): cls._set_display_type(obj, display_type, hide_render) else: @@ -1095,20 +1096,26 @@ class Blender(bonsai.core.tool.Blender): cls._set_display_type(o, display_type, hide_render) @classmethod - def set_wireframe(cls, obj: Union[bpy.types.Object, Iterable[bpy.types.Object]]) -> None: - """Set object(s) to wireframe display and hide from renders. + def set_wireframe( + cls, obj: Union[bpy.types.Object, Iterable[bpy.types.Object]], hide_render: Optional[bool] = None + ) -> None: + """Set object(s) to wireframe display and optional render visibility. :param obj: Single object or iterable of objects to set to wireframe display + :param hide_render: Render visibility state. If None, render visibility is not modified. """ - cls.set_display(obj, "WIRE") + cls.set_display(obj, "WIRE", hide_render) @classmethod - def set_textured(cls, obj: Union[bpy.types.Object, Iterable[bpy.types.Object]]) -> None: - """Set object(s) to textured display and show in renders. + def set_textured( + cls, obj: Union[bpy.types.Object, Iterable[bpy.types.Object]], hide_render: Optional[bool] = None + ) -> None: + """Set object(s) to textured display and optional render visibility. :param obj: Single object or iterable of objects to set to textured display + :param hide_render: Render visibility state. If None, render visibility is not modified. """ - cls.set_display(obj, "TEXTURED") + cls.set_display(obj, "TEXTURED", hide_render) class Modifier: @classmethod diff --git a/src/bonsai/bonsai/tool/collector.py b/src/bonsai/bonsai/tool/collector.py index 595eb89b02..7be15c0ccb 100644 --- a/src/bonsai/bonsai/tool/collector.py +++ b/src/bonsai/bonsai/tool/collector.py @@ -133,7 +133,7 @@ class Collector(bonsai.core.tool.Collector): cls.link_collection_object_safe(collection, obj) if element.is_a("IfcFeatureElementSubtraction"): - tool.Blender.Display.set_wireframe(obj) + tool.Blender.Display.set_wireframe(obj, hide_render=True) @classmethod def _create_project_child_collection(cls, name: str) -> bpy.types.Collection: