Skip to content

Commit

Permalink
See #4481. Defer setting render visibility to drawing generation to s…
Browse files Browse the repository at this point in the history
…peed up switching between drawings.

Doing obj.hide_render = True/False in a loop is slow and there is no bulk set command.
  • Loading branch information
Moult committed Apr 10, 2024
1 parent 153389f commit b61d870
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/blenderbim/blenderbim/bim/module/drawing/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ def generate_underlay(self, context):
if not ifcopenshell.util.element.get_pset(self.drawing, "EPset_Drawing", "HasUnderlay"):
return
svg_path = self.get_svg_path(cache_type="underlay")

visible_object_names = {obj.name for obj in bpy.context.visible_objects}
for obj in bpy.context.view_layer.objects:
obj.hide_render = obj.name not in visible_object_names

context.scene.render.filepath = svg_path[0:-4] + ".png"
drawing_style = context.scene.DocProperties.drawing_styles[self.cprops.active_drawing_style_index]

Expand Down
28 changes: 9 additions & 19 deletions src/blenderbim/blenderbim/tool/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,20 +1716,6 @@ def activate_drawing(cls, camera: bpy.types.Object) -> None:

filtered_elements = cls.get_drawing_elements(drawing) | cls.get_drawing_spaces(drawing)
filtered_elements.add(drawing)
# Hide everything first, then selectively show. This is significantly faster.
with bpy.context.temp_override(area=next(a for a in bpy.context.screen.areas if a.type == "VIEW_3D")):
bpy.ops.object.hide_view_set(unselected=False)
bpy.ops.object.hide_view_set(unselected=True)

for view_layer_object in bpy.context.view_layer.objects:
element = tool.Ifc.get_entity(view_layer_object)
if not element or element.is_a("IfcTypeProduct"):
continue
if element in filtered_elements:
view_layer_object.hide_set(False)
view_layer_object.hide_render = False
elif view_layer_object.hide_render is not True:
view_layer_object.hide_render = True

subcontexts: list[ifcopenshell.entity_instance] = []
target_view = cls.get_drawing_target_view(drawing)
Expand Down Expand Up @@ -1764,6 +1750,11 @@ def activate_drawing(cls, camera: bpy.types.Object) -> None:
if subcontext:
subcontexts.append(context_filter)

# Hide everything first, then selectively show. This is significantly faster.
with bpy.context.temp_override(area=next(a for a in bpy.context.screen.areas if a.type == "VIEW_3D")):
bpy.ops.object.hide_view_set(unselected=False)
bpy.ops.object.hide_view_set(unselected=True)

# switch representations and hide elements without representations
for element in filtered_elements:
obj = tool.Ifc.get_object(element)
Expand Down Expand Up @@ -1793,11 +1784,10 @@ def activate_drawing(cls, camera: bpy.types.Object) -> None:
has_context = True
break

# don't hide IfcAnnotations as some of them might exist without representations
# e.g. with ObjectType = SYMBOL
if not has_context and not element.is_a("IfcAnnotation"):
obj.hide_set(True)
obj.hide_render = True
# Don't hide IfcAnnotations as some of them might exist without representations
if has_context or element.is_a("IfcAnnotation"):
# Note that render visibility is only set on drawing generation time for speed.
obj.hide_set(False)

@classmethod
def get_elements_in_camera_view(
Expand Down

0 comments on commit b61d870

Please sign in to comment.