[Bf-extensions-cvs] [22fc4cc6] blender2.8: Snap Utilities Line: Move the code of zoom with target to an operator.

mano-wii noreply at git.blender.org
Tue Nov 6 05:23:50 CET 2018


Commit: 22fc4cc621026a4d0841a1395ca1461e1b90a505
Author: mano-wii
Date:   Mon Nov 5 20:44:35 2018 -0200
Branches: blender2.8
https://developer.blender.org/rBA22fc4cc621026a4d0841a1395ca1461e1b90a505

Snap Utilities Line: Move the code of zoom with target to an operator.

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

M	mesh_snap_utilities_line/__init__.py
M	mesh_snap_utilities_line/common_classes.py

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

diff --git a/mesh_snap_utilities_line/__init__.py b/mesh_snap_utilities_line/__init__.py
index c8ab1f4b..4ff67d8c 100644
--- a/mesh_snap_utilities_line/__init__.py
+++ b/mesh_snap_utilities_line/__init__.py
@@ -82,6 +82,7 @@ def register():
 
     bpy.utils.register_class(preferences.SnapUtilitiesLinePreferences)
     bpy.utils.register_class(common_classes.VIEW3D_OT_rotate_custom_pivot)
+    bpy.utils.register_class(common_classes.VIEW3D_OT_zoom_custom_target)
     bpy.utils.register_class(ops_line.SnapUtilitiesLine)
 #    bpy.utils.register_class(common_classes.MousePointWidget)
 #    bpy.utils.register_class(common_classes.MousePointWidgetGroup)
@@ -101,6 +102,7 @@ def unregister():
 #    bpy.utils.unregister_class(common_classes.MousePointWidgetGroup)
 #    bpy.utils.unregister_class(common_classes.MousePointWidget)
     bpy.utils.unregister_class(ops_line.SnapUtilitiesLine)
+    bpy.utils.unregister_class(common_classes.VIEW3D_OT_zoom_custom_target)
     bpy.utils.unregister_class(common_classes.VIEW3D_OT_rotate_custom_pivot)
     bpy.utils.unregister_class(preferences.SnapUtilitiesLinePreferences)
 
diff --git a/mesh_snap_utilities_line/common_classes.py b/mesh_snap_utilities_line/common_classes.py
index 04008be5..9251e3e1 100644
--- a/mesh_snap_utilities_line/common_classes.py
+++ b/mesh_snap_utilities_line/common_classes.py
@@ -271,17 +271,10 @@ class SnapNavigation():
 
         for key in self._zoom:
             if evkey == key[0:3]:
-                if snap_location:
-                    v3d = context.space_data
-                    dist_range = (v3d.clip_start, v3d.clip_end)
-                    rv3d = context.region_data
-                    if (key[3] < 0 and rv3d.view_distance < dist_range[1]) or\
-                       (key[3] > 0 and rv3d.view_distance > dist_range[0]):
-                            rv3d.view_location += key[3] * (snap_location - rv3d.view_location) / 6
-                            rv3d.view_distance -= key[3] * rv3d.view_distance / 6
-                    context.area.tag_redraw()
+                if snap_location and key[3]:
+                    bpy.ops.view3d.zoom_custom_target('INVOKE_DEFAULT', delta=key[3], target=snap_location)
                 else:
-                    bpy.ops.view3d.zoom('INVOKE_DEFAULT', delta = key[3])
+                    bpy.ops.view3d.zoom('INVOKE_DEFAULT', delta=key[3])
                 return True
 
         if self.use_ndof:
@@ -458,7 +451,6 @@ class VIEW3D_OT_rotate_custom_pivot(bpy.types.Operator):
 
             self.rv3d.view_location = pos
             self.rv3d.view_rotation = qua
-            #self.rv3d.view_distance = dist
 
             context.area.tag_redraw()
             return {'RUNNING_MODAL'}
@@ -473,3 +465,46 @@ class VIEW3D_OT_rotate_custom_pivot(bpy.types.Operator):
 
         context.window_manager.modal_handler_add(self)
         return {'RUNNING_MODAL'}
+
+
+class VIEW3D_OT_zoom_custom_target(bpy.types.Operator):
+    bl_idname = "view3d.zoom_custom_target"
+    bl_label = "Zoom the view"
+    bl_options = {'BLOCKING', 'GRAB_CURSOR'}
+
+    target: bpy.props.FloatVectorProperty("target", subtype='XYZ')
+    delta: bpy.props.IntProperty("delta", default=0)
+    step_factor = 0.333
+
+    def modal(self, context, event):
+        if event.value == 'PRESS' and event.type in {'MOUSEMOVE', 'INBETWEEN_MOUSEMOVE'}:
+            if not hasattr(self, "init_mouse_region_y"):
+                self.init_mouse_region_y = event.mouse_region_y
+                self.heigt_up = context.area.height - self.init_mouse_region_y
+                self.rv3d.view_location = self.target
+
+            fac = (event.mouse_region_y - self.init_mouse_region_y) / self.heigt_up
+            ret = 'RUNNING_MODAL'
+        else:
+            fac = self.step_factor * self.delta
+            ret = 'FINISHED'
+
+        self.rv3d.view_location = self.init_loc + (self.target - self.init_loc) * fac
+        self.rv3d.view_distance = self.init_dist - self.init_dist * fac
+
+        context.area.tag_redraw()
+        return {ret}
+
+    def invoke(self, context, event):
+        v3d = context.space_data
+        dist_range = (v3d.clip_start, v3d.clip_end)
+        self.rv3d = context.region_data
+        self.init_dist = self.rv3d.view_distance
+        if ((self.delta <= 0 and self.init_dist < dist_range[1]) or
+            (self.delta >  0 and self.init_dist > dist_range[0])):
+                self.init_loc = self.rv3d.view_location.copy()
+
+                context.window_manager.modal_handler_add(self)
+                return {'RUNNING_MODAL'}
+
+        return {'FINISHED'}



More information about the Bf-extensions-cvs mailing list