[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4479] contrib/py/scripts/addons/ space_view3d_enhanced_3d_cursor.py: Added circumvention for bug introduced at least in r55223 (obj. ray_cast does not see geometry of other objects in Local View mode).

dima glib dima.glib at gmail.com
Tue Apr 16 21:36:15 CEST 2013


Revision: 4479
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4479
Author:   dairin0d
Date:     2013-04-16 19:36:15 +0000 (Tue, 16 Apr 2013)
Log Message:
-----------
Added circumvention for bug introduced at least in r55223 (obj.ray_cast does not see geometry of other objects in Local View mode).
Fixed & optimized cursor-stick-to-object feature.
Changed print(e) to print(repr(e)), since console window can't handle unicode.

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=55223

Modified Paths:
--------------
    contrib/py/scripts/addons/space_view3d_enhanced_3d_cursor.py

Modified: contrib/py/scripts/addons/space_view3d_enhanced_3d_cursor.py
===================================================================
--- contrib/py/scripts/addons/space_view3d_enhanced_3d_cursor.py	2013-04-16 12:24:48 UTC (rev 4478)
+++ contrib/py/scripts/addons/space_view3d_enhanced_3d_cursor.py	2013-04-16 19:36:15 UTC (rev 4479)
@@ -21,7 +21,7 @@
     "name": "Enhanced 3D Cursor",
     "description": "Cursor history and bookmarks; drag/snap cursor.",
     "author": "dairin0d",
-    "version": (2, 8, 9),
+    "version": (2, 9, 0),
     "blender": (2, 65, 4),
     "location": "View3D > Action mouse; F10; Properties panel",
     "warning": "",
@@ -250,7 +250,8 @@
         
         # Don't interfere with these modes when only mouse is pressed
         if ('SCULPT' in context.mode) or ('PAINT' in context.mode):
-            if "MOUSE" in event.type:                return {'CANCELLED'}
+            if "MOUSE" in event.type:
+                return {'CANCELLED'}
         
         CursorDynamicSettings.active_transform_operator = self
         
@@ -697,6 +698,8 @@
         self.prev_delta_xy = delta_xy
     
     def transform_move(self, particle):
+        global set_cursor_location__reset_stick
+        
         src_matrix = particle.get_matrix()
         initial_matrix = particle.get_initial_matrix()
         
@@ -707,7 +710,9 @@
             self.modify_surface_orientation,
             self.use_object_centers)
         
+        set_cursor_location__reset_stick = False
         particle.set_matrix(matrix)
+        set_cursor_location__reset_stick = True
     
     def rotate_matrix(self, matrix):
         sys_matrix = self.csu.get_matrix()
@@ -1230,7 +1235,7 @@
                 text = axes_text[i]
                 coord_cells.append(TextCell(text, color))
         except Exception as e:
-            print(e)
+            print(repr(e))
         
         mode_cells = []
         
@@ -1261,7 +1266,7 @@
                 color = tet.syntax_special
             mode_cells.append(TextCell(text, color))
         except Exception as e:
-            print(e)
+            print(repr(e))
         
         hdr_w, hdr_h = header_size
         
@@ -1379,7 +1384,7 @@
             bgl.glEnd()
             
         except Exception as e:
-            print(e)
+            print(repr(e))
         
         return
     
@@ -2668,7 +2673,26 @@
                 lb, la = sec
             
             # Does ray actually intersect something?
-            lp, ln, face_id = obj.ray_cast(la, lb)
+            try:
+                lp, ln, face_id = obj.ray_cast(la, lb)
+            except Exception as e:
+                # Somewhy this seems to happen when snapping cursor
+                # in Local View mode at least since r55223:
+                # <<Object "\U0010ffff" has no mesh data to be used
+                # for raycasting>> despite obj.data.polygons
+                # being non-empty.
+                try:
+                    # 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)
+                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
+            
             if face_id == -1:
                 continue
             
@@ -2753,7 +2777,11 @@
         
         _ln = ln.copy()
         
-        face = obj.data.tessfaces[face_id]
+        try:
+            face = obj.data.tessfaces[face_id]
+        except IndexError:
+            obj.data.update(calc_tessface=True)
+            face = obj.data.tessfaces[face_id]
         L = None
         t1 = None
         
@@ -4502,14 +4530,14 @@
             return (not CursorMonitor.is_running) or \
                 (runtime_settings.current_monitor_id == 0)
         except Exception as e:
-            print("Cursor monitor exeption in poll:\n" + str(e))
+            print("Cursor monitor exeption in poll:\n" + repr(e))
             return False
     
     def modal(self, context, event):
         try:
             return self._modal(context, event)
         except Exception as e:
-            print("Cursor monitor exeption in modal:\n" + str(e))
+            print("Cursor monitor exeption in modal:\n" + repr(e))
             # Remove callbacks at any cost
             self.cancel(context)
             #raise
@@ -5207,10 +5235,14 @@
 
 # ===== UTILITY FUNCTIONS ===== #
 
+cursor_stick_pos_cache = None
 def update_stick_to_obj(context):
+    global cursor_stick_pos_cache
+    
     settings = find_settings()
     
     if not settings.stick_to_obj:
+        cursor_stick_pos_cache = None
         return
     
     scene = context.scene
@@ -5218,14 +5250,20 @@
     settings_scene = scene.cursor_3d_tools_settings
     
     name = settings_scene.stick_obj_name
+    if (not name) or (name not in scene.objects):
+        cursor_stick_pos_cache = None
+        return
     
-    try:
-        obj = scene.objects[name]
-        pos = settings_scene.stick_obj_pos
-        pos = obj.matrix_world * pos
+    obj = scene.objects[name]
+    pos = settings_scene.stick_obj_pos
+    pos = obj.matrix_world * pos
+    
+    if pos != cursor_stick_pos_cache:
+        cursor_stick_pos_cache = pos
+        
+        # THIS IS AN EXPENSIVE OPERATION!
+        # (eats 50% of my CPU if called each frame)
         context.space_data.cursor_location = pos
-    except Exception as e:
-        pass
 
 def get_cursor_location(v3d=None, scene=None):
     if v3d:
@@ -5235,6 +5273,7 @@
     
     return pos.copy()
 
+set_cursor_location__reset_stick = True
 def set_cursor_location(pos, v3d=None, scene=None):
     pos = pos.to_3d().copy()
     
@@ -5247,7 +5286,8 @@
     elif scene:
         scene.cursor_location = pos
     
-    set_stick_obj(scene, None)
+    if set_cursor_location__reset_stick:
+        set_stick_obj(scene, None)
 
 def set_stick_obj(scene, name=None, pos=None):
     settings_scene = scene.cursor_3d_tools_settings
@@ -5500,5 +5540,5 @@
     try:
         register()
     except Exception as e:
-        print(e)
+        print(repr(e))
         raise



More information about the Bf-extensions-cvs mailing list