Advertisement
Guest User

Untitled

a guest
Sep 30th, 2018
371
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import bpy
  2. from bpy.types import Operator, Macro
  3. from bpy_extras import view3d_utils
  4. from mathutils import Vector
  5. import rna_keymap_ui
  6. from bpy.props import (
  7. EnumProperty,
  8. )
  9.  
  10. bl_info = {
  11. "name": "view snap",
  12. "location": "View3D > view snap",
  13. "description": "Snap View",
  14. "author": "Vladislav Kindushov",
  15. "version": (0, 3),
  16. "blender": (2, 80, 0),
  17. "category": "View3D",
  18. }
  19. PREFS = None
  20.  
  21.  
  22. def getView(self, context, event):
  23. region = context.region
  24. rv3d = context.region_data
  25. coord = event.mouse_region_x, event.mouse_region_y
  26. return rv3d.view_rotation * Vector((0.0, 0.0, -1.0))
  27.  
  28.  
  29. def findView(self, context, event):
  30. vector = getView(self, context, event)
  31. if vector == Vector((0.0, -1.0, 0.0)):
  32. bpy.ops.view3d.viewnumpad(type='BACK', align_active=False)
  33. elif vector == Vector((0.0, 1.0, 0.0)):
  34. bpy.ops.view3d.viewnumpad(type='FRONT', align_active=False)
  35. elif vector == Vector((1.0, 0.0, 0.0)):
  36. bpy.ops.view3d.viewnumpad(type='RIGHT', align_active=False)
  37. elif vector == Vector((-1.0, 0.0, 0.0)):
  38. bpy.ops.view3d.viewnumpad(type='LEFT', align_active=False)
  39. elif vector == Vector((0.0, 0.0, 1.0)):
  40. bpy.ops.view3d.viewnumpad(type='TOP', align_active=False)
  41. elif vector == Vector((0.0, 0.0, -1.0)):
  42. bpy.ops.view3d.viewnumpad(type='BOTTOM', align_active=False)
  43.  
  44.  
  45. def ExcludeAxis(self, context, vector):
  46. x = vector[0]
  47. y = vector[1]
  48. z = vector[2]
  49.  
  50. if abs(x) > abs(y) and abs(x) > abs(z):
  51. return 'x', x
  52. elif abs(y) > abs(x) and abs(y) > abs(z):
  53. return 'y', y
  54. elif abs(z) > abs(x) and abs(z) > abs(y):
  55. return 'z', z
  56.  
  57.  
  58. def findView2(self, context, axis, ax):
  59. if axis == 'x':
  60. if ax < 0:
  61. bpy.ops.view3d.viewnumpad(type='RIGHT', align_active=False)
  62. else:
  63. bpy.ops.view3d.viewnumpad(type='LEFT', align_active=False)
  64. elif axis == 'y':
  65. if ax < 0:
  66. bpy.ops.view3d.viewnumpad(type='BACK', align_active=False)
  67. else:
  68. bpy.ops.view3d.viewnumpad(type='FRONT', align_active=False)
  69. elif axis == 'z':
  70. if ax < 0:
  71. bpy.ops.view3d.viewnumpad(type='TOP', align_active=False)
  72. else:
  73. bpy.ops.view3d.viewnumpad(type='BOTTOM', align_active=False)
  74.  
  75.  
  76. class SnapView_OT_darcvizer(bpy.types.Operator):
  77. """Border Occlusion selection """
  78. bl_idname = "view3d.snap_view_ot_darcvizer"
  79. bl_label = "SnapView"
  80.  
  81. def invoke(self, context, event):
  82.  
  83. if PREFS.Mode == 'blender':
  84. if event.ctrl:
  85. vector = getView(self, context, event)
  86. name, value = ExcludeAxis(self, context, vector)
  87. findView2(self, context, name, value)
  88. elif PREFS.Mode == 'maya':
  89. if event.shift:
  90. vector = getView(self, context, event)
  91. name, value = ExcludeAxis(self, context, vector)
  92. findView2(self, context, name, value)
  93. elif PREFS.Mode == '3ds max':
  94. if event.shift:
  95. vector = getView(self, context, event)
  96. name, value = ExcludeAxis(self, context, vector)
  97. findView2(self, context, name, value)
  98.  
  99. return {'FINISHED'}
  100.  
  101.  
  102. class ViewMacro_ot_darcvizer(Macro):
  103. bl_idname = 'view3d.view_snap_ot_darcvizer'
  104. bl_label = 'view_snap'
  105. #bl_options = {'REGISTER', 'UNDO'}
  106.  
  107. def execute(self, context):
  108. ViewMacro.define('VIEW3D_OT_rotate')
  109. return {'FINISHED'}
  110.  
  111.  
  112. def use_cashes(self, context):
  113. self.caches_valid = True
  114.  
  115.  
  116. class ViewSnapPref_ot_darcvizer(bpy.types.AddonPreferences):
  117. bl_idname = __name__
  118. bl_options = {'REGISTER'}
  119. Mode = EnumProperty(
  120. items=[('blender', "Blender", "Press ctrl after middle mouse button "),
  121. ('maya', "Maya", "Press shift after left mouse button "),
  122. ('3ds max', "3DS Max", "Press shift after middle mouse button")],
  123. name="Rotate mode",
  124. default='maya',
  125. # update=use_cashes
  126. )
  127. caches_valid = True
  128.  
  129. def draw(self, context):
  130. layout = self.layout
  131. layout.prop(self, "Mode")
  132.  
  133.  
  134.  
  135.  
  136.  
  137. ViewMacro_ot_darcvizer.define('view3d.snap_view_ot_darcvizer')
  138. ViewMacro_ot_darcvizer.define('view3d.view_snap_ot_darcvizer')
  139.  
  140.  
  141. PREFS = bpy.context.user_preferences.addons[__name__].preferences
  142.  
  143. classes = (ViewSnapPref_ot_darcvizer, ViewMacro_ot_darcvizer, SnapView_OT_darcvizer)
  144.  
  145.  
  146. register, unregister = bpy.utils.register_classes_factory(classes)
  147.  
  148.  
  149. if __name__ == "__main__":
  150. register()
Advertisement
RAW Paste Data Copied
Advertisement