[Bf-blender-cvs] [61baf6e] master: Fix T41902: Flipped persp/ortho region_2d_to_vector_3d

Campbell Barton noreply at git.blender.org
Mon Sep 22 03:13:11 CEST 2014


Commit: 61baf6e8135d11bc53cbfa45c75f910a99e57971
Author: Campbell Barton
Date:   Mon Sep 22 11:01:59 2014 +1000
Branches: master
https://developer.blender.org/rB61baf6e8135d11bc53cbfa45c75f910a99e57971

Fix T41902: Flipped persp/ortho region_2d_to_vector_3d

- Ortho result from view3d_utils.region_2d_to_vector_3d was flipped.
- Persp result wasn't normalized.
- operator_modal_view3d_raycast.py failed for ortho views.

Thanks to Philipp Oeser for the initial fix.

===================================================================

M	release/scripts/modules/bpy_extras/view3d_utils.py
M	release/scripts/templates_py/operator_modal_view3d_raycast.py

===================================================================

diff --git a/release/scripts/modules/bpy_extras/view3d_utils.py b/release/scripts/modules/bpy_extras/view3d_utils.py
index ad555a4..b25024f 100644
--- a/release/scripts/modules/bpy_extras/view3d_utils.py
+++ b/release/scripts/modules/bpy_extras/view3d_utils.py
@@ -54,9 +54,13 @@ def region_2d_to_vector_3d(region, rv3d, coord):
 
         w = out.dot(persinv[3].xyz) + persinv[3][3]
 
-        return ((persinv * out) / w) - viewinv.translation
+        view_vector = ((persinv * out) / w) - viewinv.translation
     else:
-        return viewinv.col[2].xyz.normalized()
+        view_vector = -viewinv.col[2].xyz
+
+    view_vector.normalize()
+
+    return view_vector
 
 
 def region_2d_to_origin_3d(region, rv3d, coord):
diff --git a/release/scripts/templates_py/operator_modal_view3d_raycast.py b/release/scripts/templates_py/operator_modal_view3d_raycast.py
index 6c59603..1aa13c9 100644
--- a/release/scripts/templates_py/operator_modal_view3d_raycast.py
+++ b/release/scripts/templates_py/operator_modal_view3d_raycast.py
@@ -2,7 +2,7 @@ import bpy
 from bpy_extras import view3d_utils
 
 
-def main(context, event, ray_max=10000.0):
+def main(context, event, ray_max=1000.0):
     """Run this function on left mouse, execute the ray cast"""
     # get the context arguments
     scene = context.scene
@@ -13,6 +13,11 @@ def main(context, event, ray_max=10000.0):
     # get the ray from the viewport and mouse
     view_vector = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
     ray_origin = view3d_utils.region_2d_to_origin_3d(region, rv3d, coord)
+
+    if rv3d.view_perspective == 'ORTHO':
+        # move ortho origin back
+        ray_origin = ray_origin - (view_vector * (ray_max / 2.0))
+
     ray_target = ray_origin + (view_vector * ray_max)
 
     def visible_objects_and_duplis():




More information about the Bf-blender-cvs mailing list