From 7339325cc9e1ff869cebd3d7a81f9bccf08f5876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Mon, 23 Sep 2024 22:25:28 -0300 Subject: [PATCH] Fix #5464 --- src/bonsai/bonsai/tool/raycast.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/bonsai/bonsai/tool/raycast.py b/src/bonsai/bonsai/tool/raycast.py index 584b1c134d..254368dd62 100644 --- a/src/bonsai/bonsai/tool/raycast.py +++ b/src/bonsai/bonsai/tool/raycast.py @@ -85,6 +85,12 @@ class Raycast(bonsai.core.tool.Raycast): def get_viewport_ray_data(cls, context, event, mouse_pos=None): region = context.region rv3d = context.region_data + original_perspective = rv3d.view_perspective + + # TODO The raycast was working for orthographic view, but not when you are inside a camera view. This solution feels hacky, + # but it temporarily switches the perspective_matrix from camera to the perspective_matrix from ortho view. + if original_perspective == "CAMERA": + rv3d.view_perspective = "ORTHO" if not mouse_pos: mouse_pos = event.mouse_region_x, event.mouse_region_y @@ -93,6 +99,9 @@ class Raycast(bonsai.core.tool.Raycast): ray_target = ray_origin + view_vector ray_direction = ray_target - ray_origin + if original_perspective == "CAMERA": + rv3d.view_perspective = "CAMERA" + return ray_origin, ray_target, ray_direction @classmethod