Compare commits

...

1 Commits

Author SHA1 Message Date
Petru Conduraru 6c8aa1d2b8 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.
2026-07-20 20:17:08 +03:00
@@ -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)