Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import bpy
from mathutils import Euler
class TurntableOperator(bpy.types.Operator):
bl_idname = "wm.turntable_operations"
bl_label = "Turntable Operator"
# command = bpy.props.StringProperty()
def execute(self, context):
wm = context.window_manager
# currently only does stop
context.scene.turntable_activation = False
class ModalViewRotationOperator(bpy.types.Operator):
bl_idname = "wm.modal_turntable_operator"
bl_label = "Modal Turntable Operator"
_timer = None
command = bpy.props.StringProperty()
def modal(self, context, event):
active = context.scene.turntable_activation
if event.type in {'RIGHTMOUSE', 'ESC'} or active == False:
context.scene.turntable_activation = False
self.cancel(context)
return {'CANCELLED'}
if event.type == 'TIMER':
v3d = context.space_data
rv3d = v3d.region_3d
# rv3d.view_location.x += 1.0
# rv3d = bpy.context.screen.areas[2].spaces[0].region_3d
rv3d.view_rotation.rotate(Euler((0, 0, 0.1)))
# rv3d.view_location.x += 1.0
# rv3d.view_distance -= 1.0
return {'PASS_THROUGH'}
def execute(self, context):
context.scene.turntable_activation = True
wm = context.window_manager
self._timer = wm.event_timer_add(0.3, context.window)
wm.modal_handler_add(self)
return {'RUNNING_MODAL'}
def cancel(self, context):
context.scene.turntable_activation = False
wm = context.window_manager
wm.event_timer_remove(self._timer)
class ViewTurntablePanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Turntable Demo"
bl_idname = "SCENE_PT_turntable"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
# Big render button
row = layout.row()
row.scale_y = 3.0
row.operator("wm.modal_turntable_operator", text='start')
# Big render button
row = layout.row()
row.scale_y = 3.0
row.operator("wm.turntable_operations", text='stop')
def register():
bpy.types.Scene.turntable_activation = bpy.props.BoolProperty(default=False)
bpy.utils.register_class(ModalViewRotationOperator)
bpy.utils.register_class(ViewTurntablePanel)
bpy.utils.register_class(TurntableOperator)
def unregister():
bpy.utils.unregister_class(TurntableOperator)
bpy.utils.unregister_class(ViewTurntablePanel)
bpy.utils.unregister_class(ModalViewRotationOperator)
del bpy.types.Scene.turntable_activation
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.