From 6c8aa1d2b83e274b82a389c3f9707c6dd2f41535 Mon Sep 17 00:00:00 2001 From: Petru Conduraru Date: Mon, 20 Jul 2026 20:17:08 +0300 Subject: [PATCH] Bonsai: align BCF snapshot camera to the active 3D view Add BCF Viewpoint used the scene camera's own transform verbatim, so whenever that camera wasn't already aligned with what the user was looking at, the resulting viewpoint snapshot could be captured from far away and frame nothing useful. Align the camera to the active 3D view before taking the snapshot, then restore its original transform so any other use of that camera object (e.g. drawings) is unaffected. Fixes part of #6981. Generated with the assistance of an AI coding tool. --- src/bonsai/bonsai/bim/module/bcf/operator.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bonsai/bonsai/bim/module/bcf/operator.py b/src/bonsai/bonsai/bim/module/bcf/operator.py index 461321852d..df2c46786b 100644 --- a/src/bonsai/bonsai/bim/module/bcf/operator.py +++ b/src/bonsai/bonsai/bim/module/bcf/operator.py @@ -555,6 +555,15 @@ class AddBcfViewpoint(bpy.types.Operator): blender_topic = props.active_topic topic = bcfxml.topics[blender_topic.name] + # Align the camera to the active 3D view for the snapshot, then restore it. + assert isinstance(blender_camera.data, bpy.types.Camera) + original_matrix_world = blender_camera.matrix_world.copy() + original_ortho_scale = blender_camera.data.ortho_scale + space = tool.Blender.get_view3d_space() + if space and space.region_3d.view_perspective != "CAMERA": + with context.temp_override(**tool.Blender.get_viewport_context()): + bpy.ops.view3d.camera_to_view() + direction = blender_camera.matrix_world.to_quaternion() @ Vector((0.0, 0.0, -1.0)) up = blender_camera.matrix_world.to_quaternion() @ Vector((0.0, 1.0, 0.0)) @@ -627,6 +636,9 @@ class AddBcfViewpoint(bpy.types.Operator): snapshot = f.read() # viewpoint.snapshot = blender_render.filepath + blender_camera.matrix_world = original_matrix_world + blender_camera.data.ortho_scale = original_ortho_scale + if isinstance(visualization_info, bcf.v2.model.VisualizationInfo): vizinfo = bcf.v2.visinfo.VisualizationInfoHandler(visualization_info=visualization_info, snapshot=snapshot) assert isinstance(topic, bcf.v2.topic.TopicHandler)