[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2605] contrib/py/scripts/addons/ space_view3d_enhanced_3d_cursor.py: moving to Contrib (version 2.8)

dima glib dima.glib at gmail.com
Sun Nov 13 14:27:26 CET 2011


Revision: 2605
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2605
Author:   dairin0d
Date:     2011-11-13 13:27:26 +0000 (Sun, 13 Nov 2011)
Log Message:
-----------
moving to Contrib (version 2.8)

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

Added: contrib/py/scripts/addons/space_view3d_enhanced_3d_cursor.py
===================================================================
--- contrib/py/scripts/addons/space_view3d_enhanced_3d_cursor.py	                        (rev 0)
+++ contrib/py/scripts/addons/space_view3d_enhanced_3d_cursor.py	2011-11-13 13:27:26 UTC (rev 2605)
@@ -0,0 +1,4917 @@
+#  ***** BEGIN GPL LICENSE BLOCK *****
+#
+#  This program is free software: you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation, either version 3 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+#  ***** END GPL LICENSE BLOCK *****
+
+# <pep8-80 compliant>
+
+bl_info = {
+    "name": "Enhanced 3D Cursor",
+    "description": "Cursor history and bookmarks; drag/snap cursor.",
+    "author": "dairin0d",
+    "version": (2, 8, 0),
+    "blender": (2, 6, 0),
+    "api": 35853, # just copied from some Blender 2.59 script # 31236 ?
+    "location": "View3D > Action mouse; F10; Properties panel",
+    "warning": "",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
+        "Scripts/3D_interaction/Enhanced_3D_Cursor",
+    "tracker_url": "http://projects.blender.org/tracker/index.php?"\
+        "func=detail&aid=28451",
+    "category": "3D View"}
+#============================================================================#
+
+"""
+TODO:
+    IDEAS:
+        - make 'NORMAL' system also work for bones?
+        - an option to select which normals/tangentials
+          are displayed? (only N, only T1, N+T1, all,
+          only meaningful)
+        - create spline/edge_mesh from history?
+        - API to access history/bookmarks/operators from other scripts?
+        - Snap selection to bookmark?
+        - Optimize
+        - Clean up code, move to several files?
+    LATER:
+    ISSUES:
+        Limitations:
+            - I need to emulate in Python some things that Blender doesn't
+              currently expose through API:
+              - obtaining matrix of predefined transform orientation
+              - obtaining position of pivot
+              For some kinds of information (e.g. active vertex/edge,
+              selected meta-elements), there is simply no workaround.
+            - Snapping to vertices/edges works differently than in Blender.
+              First of all, iteration over all vertices/edges of all
+              objects along the ray is likely to be very slow.
+              Second, it's more human-friendly to snap to visible
+              elements (or at least with approximately known position).
+            - In editmode I have to exit-and-enter it to get relevant
+              information about current selection. Thus any operator
+              would automatically get applied when you click on 3D View.
+        Mites:
+    QUESTIONS:
+==============================================================================
+Borrowed code/logic:
+- space_view3d_panel_measure.py (Buerbaum Martin "Pontiac"):
+  - OpenGL state storing/restoring; working with projection matrices.
+"""
+
+import bpy
+import bgl
+import blf
+
+from mathutils import Vector, Matrix, Quaternion, Euler
+
+from mathutils.geometry import (intersect_line_sphere,
+                                intersect_ray_tri,
+                                barycentric_transform,
+                                tesselate_polygon,
+                                intersect_line_line,
+                                intersect_line_plane,
+                                )
+
+from bpy_extras.view3d_utils import (region_2d_to_vector_3d,
+                                     region_2d_to_location_3d,
+                                     location_3d_to_region_2d,
+                                     )
+
+import math
+import time
+
+# ====== MODULE GLOBALS / CONSTANTS ====== #
+tmp_name = chr(0x10ffff) # maximal Unicode value
+epsilon = 0.000001
+
+# ====== SET CURSOR OPERATOR ====== #
+class EnhancedSetCursor(bpy.types.Operator):
+    """Cursor history and bookmarks; drag/snap cursor."""
+    bl_idname = "view3d.cursor3d_enhanced"
+    bl_label = "Enhanced Set Cursor"
+    
+    key_char_map = {
+        'PERIOD':".", 'NUMPAD_PERIOD':".",
+        'MINUS':"-", 'NUMPAD_MINUS':"-",
+        'EQUAL':"+", 'NUMPAD_PLUS':"+",
+        #'E':"e", # such big/small numbers aren't useful
+        'ONE':"1", 'NUMPAD_1':"1",
+        'TWO':"2", 'NUMPAD_2':"2",
+        'THREE':"3", 'NUMPAD_3':"3",
+        'FOUR':"4", 'NUMPAD_4':"4",
+        'FIVE':"5", 'NUMPAD_5':"5",
+        'SIX':"6", 'NUMPAD_6':"6",
+        'SEVEN':"7", 'NUMPAD_7':"7",
+        'EIGHT':"8", 'NUMPAD_8':"8",
+        'NINE':"9", 'NUMPAD_9':"9",
+        'ZERO':"0", 'NUMPAD_0':"0",
+        'SPACE':" ",
+        'SLASH':"/", 'NUMPAD_SLASH':"/",
+        'NUMPAD_ASTERIX':"*",
+    }
+    
+    key_coordsys_map = {
+        'LEFT_BRACKET':-1,
+        'RIGHT_BRACKET':1,
+        'J':'VIEW',
+        'K':"Surface",
+        'L':'LOCAL',
+        'B':'GLOBAL',
+        'N':'NORMAL',
+        'M':"Scaled",
+    }
+    
+    key_pivot_map = {
+        'H':'ACTIVE',
+        'U':'CURSOR',
+        'I':'INDIVIDUAL',
+        'O':'CENTER',
+        'P':'MEDIAN',
+    }
+    
+    key_snap_map = {
+        'C':'INCREMENT',
+        'V':'VERTEX',
+        'E':'EDGE',
+        'F':'FACE',
+    }
+    
+    key_tfm_mode_map = {
+        'G':'MOVE',
+        'R':'ROTATE',
+        'S':'SCALE',
+    }
+    
+    key_map = {
+        "confirm":{'ACTIONMOUSE'}, # also 'RET' ?
+        "cancel":{'SELECTMOUSE', 'ESC'},
+        "free_mouse":{'F10'},
+        "make_normal_snapshot":{'W'},
+        "make_tangential_snapshot":{'Q'},
+        "use_absolute_coords":{'A'},
+        "snap_to_raw_mesh":{'D'},
+        "use_object_centers":{'T'},
+        "precision_up":{'PAGE_UP'},
+        "precision_down":{'PAGE_DOWN'},
+        "move_caret_prev":{'LEFT_ARROW'},
+        "move_caret_next":{'RIGHT_ARROW'},
+        "move_caret_home":{'HOME'},
+        "move_caret_end":{'END'},
+        "change_current_axis":{'TAB', 'RET', 'NUMPAD_ENTER'},
+        "prev_axis":{'UP_ARROW'},
+        "next_axis":{'DOWN_ARROW'},
+        "remove_next_character":{'DEL'},
+        "remove_last_character":{'BACK_SPACE'},
+        "copy_axes":{'C'},
+        "paste_axes":{'V'},
+        "cut_axes":{'X'},
+    }
+    
+    gizmo_factor = 0.15
+    click_period = 0.25
+    
+    angle_grid_steps = {True:1.0, False:5.0}
+    scale_grid_steps = {True:0.01, False:0.1}
+    
+    # ====== OPERATOR METHOD OVERLOADS ====== #
+    @classmethod
+    def poll(cls, context):
+        area_types = {'VIEW_3D',} # also: IMAGE_EDITOR ?
+        return (context.area.type in area_types) and \
+               (context.region.type == "WINDOW")
+    
+    def modal(self, context, event):
+        context.area.tag_redraw()
+        return self.try_process_input(context, event)
+    
+    def invoke(self, context, event):
+        # Attempt to launch the monitor
+        if bpy.ops.view3d.cursor3d_monitor.poll():
+            bpy.ops.view3d.cursor3d_monitor()
+        
+        # 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'}
+        
+        CursorDynamicSettings.active_transform_operator = self
+        
+        tool_settings = context.tool_settings
+        
+        settings = find_settings()
+        tfm_opts = settings.transform_options
+        
+        settings_scene = context.scene.cursor_3d_tools_settings
+        
+        self.setup_keymaps(context)
+        
+        # Coordinate System Utility
+        self.particles, self.csu = gather_particles(context=context)
+        self.particles = [View3D_Cursor(context)]
+        
+        self.csu.source_pos = self.particles[0].get_location()
+        self.csu.source_rot = self.particles[0].get_rotation()
+        self.csu.source_scale = self.particles[0].get_scale()
+        
+        # View3D Utility
+        self.vu = ViewUtility(context.region, context.space_data,
+            context.region_data)
+        
+        # Snap Utility
+        self.su = SnapUtility(context)
+        
+        # turn off view locking for the duration of the operator
+        self.view_pos = self.vu.get_position(True)
+        self.vu.set_position(self.vu.get_position(), True)
+        self.view_locks = self.vu.get_locks()
+        self.vu.set_locks({})
+        
+        # Initialize runtime states
+        self.initiated_by_mouse = ("MOUSE" in event.type)
+        self.free_mouse = not self.initiated_by_mouse
+        self.use_object_centers = False
+        self.axes_values = ["", "", ""]
+        self.axes_coords = [None, None, None]
+        self.axes_eval_success = [True, True, True]
+        self.allowed_axes = [True, True, True]
+        self.current_axis = 0
+        self.caret_pos = 0
+        self.coord_format = "{:." + str(settings.free_coord_precision) + "f}"
+        self.transform_mode = 'MOVE'
+        self.init_xy_angle_distance(context, event)
+        
+        self.click_start = time.time()
+        if not self.initiated_by_mouse:
+            self.click_start -= self.click_period
+        
+        self.stick_obj_name = settings_scene.stick_obj_name
+        self.stick_obj_pos = settings_scene.stick_obj_pos
+        
+        # Initial run
+        self.try_process_input(context, event, True)
+        
+        context.window_manager.modal_handler_add(self)
+        return {'RUNNING_MODAL'}
+    
+    def cancel(self, context):
+        for particle in self.particles:
+            particle.revert()
+        
+        set_stick_obj(context.scene, self.stick_obj_name, self.stick_obj_pos)
+        
+        self.finalize(context)
+        return {'CANCELLED'}
+    
+    # ====== CLEANUP/FINALIZE ====== #
+    def finalize(self, context):
+        # restore view locking
+        self.vu.set_locks(self.view_locks)
+        self.vu.set_position(self.view_pos, True)
+        

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list