[Bf-extensions-cvs] [5d90b01] master: Enhanced 3D Cursor: updated ray_cast to 2.77 API

dairin0d noreply at git.blender.org
Sat Mar 5 18:23:05 CET 2016


Commit: 5d90b018226fc0650288f4ae67e9ba633efeb597
Author: dairin0d
Date:   Sat Mar 5 19:23:06 2016 +0200
Branches: master
https://developer.blender.org/rBAC5d90b018226fc0650288f4ae67e9ba633efeb597

Enhanced 3D Cursor: updated ray_cast to 2.77 API

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

M	space_view3d_enhanced_3d_cursor.py

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

diff --git a/space_view3d_enhanced_3d_cursor.py b/space_view3d_enhanced_3d_cursor.py
index 377c952..8887c71 100644
--- a/space_view3d_enhanced_3d_cursor.py
+++ b/space_view3d_enhanced_3d_cursor.py
@@ -2662,9 +2662,18 @@ class Snap3DUtility(SnapUtilityBase):
                 # returns points in flipped order
                 lb, la = sec
 
+            # Note: in 2.77 the ray_cast API has changed.
+            # was: location, normal, index
+            # now: result, location, normal, index
+            def ray_cast(obj, la, lb):
+                res = obj.ray_cast(la, lb)
+                if bpy.app.version < (2, 77, 0):
+                    return ((res[-1] >= 0), res[0], res[1], res[2])
+                return res
+
             # Does ray actually intersect something?
             try:
-                lp, ln, face_id = obj.ray_cast(la, lb)
+                success, lp, ln, face_id = ray_cast(obj, la, lb)
             except Exception as e:
                 # Somewhy this seems to happen when snapping cursor
                 # in Local View mode at least since r55223:
@@ -2675,15 +2684,15 @@ class Snap3DUtility(SnapUtilityBase):
                     # Work-around: in Local View at least the object
                     # in focus permits raycasting (modifiers are
                     # applied in 'PREVIEW' mode)
-                    lp, ln, face_id = orig_obj.ray_cast(la, lb)
+                    success, lp, ln, face_id = ray_cast(orig_obj, la, lb)
                 except Exception as e:
                     # However, in Edit mode in Local View we have
                     # no luck -- during the edit mode, mesh is
                     # inaccessible (thus no mesh data for raycasting).
                     #print(repr(e))
-                    face_id = -1
+                    success = False
 
-            if face_id == -1:
+            if not success:
                 continue
 
             # transform position to global space
@@ -2740,8 +2749,7 @@ class Snap3DUtility(SnapUtilityBase):
 
         # In this context, Volume represents BBox :P
         is_bbox = (self.snap_type == 'VOLUME')
-        is_local = (csu.tou.get() in \
-            {'LOCAL', "Scaled"})
+        is_local = (csu.tou.get() in {'LOCAL', "Scaled"})
 
         res = self.raycast(a, b, clip, view_dir, \
             is_bbox, sys_matrix, sys_matrix_inv, is_local, True)



More information about the Bf-extensions-cvs mailing list