Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormano-wii <germano.costa@ig.com.br>2018-11-05 03:43:06 +0300
committermano-wii <germano.costa@ig.com.br>2018-11-05 03:44:00 +0300
commitf7f65ffa7e592b3d101a67ce75e244ec9830a006 (patch)
treef5b28555656cbf47c21b0537942e6b6c450e58b7 /mesh_snap_utilities_line
parentbaaf58872bf83049637f2e4da9c444265846f2af (diff)
Snap Utilities Line: Use a custom rotation operator to be able to orbit around a chosen pivot.
This was previously done using `use_rotate_around_active`. But now no element of bmesh is selected.
Diffstat (limited to 'mesh_snap_utilities_line')
-rw-r--r--mesh_snap_utilities_line/__init__.py2
-rw-r--r--mesh_snap_utilities_line/common_classes.py47
-rw-r--r--mesh_snap_utilities_line/ops_line.py3
3 files changed, 48 insertions, 4 deletions
diff --git a/mesh_snap_utilities_line/__init__.py b/mesh_snap_utilities_line/__init__.py
index d196a537..c8ab1f4b 100644
--- a/mesh_snap_utilities_line/__init__.py
+++ b/mesh_snap_utilities_line/__init__.py
@@ -81,6 +81,7 @@ def register():
return cls._tools[context_mode]
bpy.utils.register_class(preferences.SnapUtilitiesLinePreferences)
+ bpy.utils.register_class(common_classes.VIEW3D_OT_rotate_custom_pivot)
bpy.utils.register_class(ops_line.SnapUtilitiesLine)
# bpy.utils.register_class(common_classes.MousePointWidget)
# bpy.utils.register_class(common_classes.MousePointWidgetGroup)
@@ -100,6 +101,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_rotate_custom_pivot)
bpy.utils.unregister_class(preferences.SnapUtilitiesLinePreferences)
if __name__ == "__main__":
diff --git a/mesh_snap_utilities_line/common_classes.py b/mesh_snap_utilities_line/common_classes.py
index 784ec568..e5ee0a91 100644
--- a/mesh_snap_utilities_line/common_classes.py
+++ b/mesh_snap_utilities_line/common_classes.py
@@ -256,7 +256,10 @@ class SnapNavigation():
evkey = (self.convert_to_flag(event.shift, event.ctrl, event.alt), event.type, event.value)
if evkey in self._rotate:
- bpy.ops.view3d.rotate('INVOKE_DEFAULT')
+ if snap_location:
+ bpy.ops.view3d.rotate_custom_pivot('INVOKE_DEFAULT', pivot=snap_location)
+ else:
+ bpy.ops.view3d.rotate('INVOKE_DEFAULT', use_mouse_init=True)
return True
if evkey in self._move:
@@ -432,3 +435,45 @@ class MousePointWidgetGroup(bpy.types.GizmoGroup):
snap_widget = self.gizmos.new(MousePointWidget.bl_idname)
props = snap_widget.target_set_operator("mesh.make_line")
props.wait_for_input = False
+
+
+class VIEW3D_OT_rotate_custom_pivot(bpy.types.Operator):
+ bl_idname = "view3d.rotate_custom_pivot"
+ bl_label = "Rotate the view"
+ bl_options = {'BLOCKING', 'GRAB_CURSOR'}
+
+ pivot = bpy.props.FloatVectorProperty("Pivot", subtype='XYZ')
+ g_up_axis = bpy.props.FloatVectorProperty("up_axis", default=(0.0, 0.0, 1.0), subtype='XYZ')
+ sensitivity = bpy.props.FloatProperty("sensitivity", default=0.007)
+
+ def modal(self, context, event):
+ from mathutils import Matrix
+ if event.value == 'PRESS' and event.type in {'MOUSEMOVE', 'INBETWEEN_MOUSEMOVE'}:
+ dx = self.init_coord[0] - event.mouse_region_x
+ dy = self.init_coord[1] - event.mouse_region_y
+ rot_ver = Matrix.Rotation(dx * self.sensitivity, 3, self.g_up_axis)
+ rot_hor = Matrix.Rotation(dy * self.sensitivity, 3, self.view_rot[0])
+ rot_mat = rot_hor @ rot_ver
+ view_matrix = self.view_rot @ rot_mat
+
+ pos = self.pos1 @ rot_mat + self.pivot
+ qua = view_matrix.to_quaternion()
+ qua.invert()
+
+ self.rv3d.view_location = pos
+ self.rv3d.view_rotation = qua
+ #self.rv3d.view_distance = dist
+
+ context.area.tag_redraw()
+ return {'RUNNING_MODAL'}
+
+ return {'FINISHED'}
+
+ def invoke(self, context, event):
+ self.rv3d = context.region_data
+ self.init_coord = event.mouse_region_x, event.mouse_region_y
+ self.pos1 = self.rv3d.view_location - self.pivot
+ self.view_rot = self.rv3d.view_matrix.to_3x3()
+
+ context.window_manager.modal_handler_add(self)
+ return {'RUNNING_MODAL'}
diff --git a/mesh_snap_utilities_line/ops_line.py b/mesh_snap_utilities_line/ops_line.py
index 8ae95ff7..11a40871 100644
--- a/mesh_snap_utilities_line/ops_line.py
+++ b/mesh_snap_utilities_line/ops_line.py
@@ -247,7 +247,6 @@ class SnapUtilitiesLine(bpy.types.Operator):
#Restore initial state
context.tool_settings.mesh_select_mode = self.select_mode
- context.user_preferences.view.use_rotate_around_active = self.use_rotate_around_active
context.space_data.overlay.show_face_center = self.show_face_center
def modal(self, context, event):
@@ -428,13 +427,11 @@ class SnapUtilitiesLine(bpy.types.Operator):
# print('name', __name__, __package__)
#Store current state
- self.use_rotate_around_active = context.user_preferences.view.use_rotate_around_active
self.select_mode = context.tool_settings.mesh_select_mode[:]
self.show_face_center = context.space_data.overlay.show_face_center
#Modify the current state
bpy.ops.mesh.select_all(action='DESELECT')
- context.user_preferences.view.use_rotate_around_active = True
context.tool_settings.mesh_select_mode = (True, False, True)
context.space_data.overlay.show_face_center = True