feat: modal for snap view

This commit is contained in:
Swann
2019-10-15 15:04:34 +02:00
parent 6969e386e2
commit d322531dc0

View File

@ -249,6 +249,8 @@ class SessionSnapUserOperator(bpy.types.Operator):
bl_description = "Snap 3d view to selected user" bl_description = "Snap 3d view to selected user"
bl_options = {"REGISTER"} bl_options = {"REGISTER"}
_timer = None
target_client: bpy.props.StringProperty(default="None") target_client: bpy.props.StringProperty(default="None")
@classmethod @classmethod
@ -256,18 +258,32 @@ class SessionSnapUserOperator(bpy.types.Operator):
return True return True
def execute(self, context): def execute(self, context):
wm = context.window_manager
self._timer = wm.event_timer_add(0.1, window=context.window)
wm.modal_handler_add(self)
return {'RUNNING_MODAL'}
def cancel(self, context):
wm = context.window_manager
wm.event_timer_remove(self._timer)
def modal(self, context, event):
if event.type in {'RIGHTMOUSE', 'ESC'}:
self.cancel(context)
return {'CANCELLED'}
if event.type == 'TIMER':
area, region, rv3d = presence.view3d_find() area, region, rv3d = presence.view3d_find()
global client global client
target_client = client.get(uuid=self.target_client) target_client = client.get(uuid=self.target_client)
if target_client: if target_client:
rv3d.view_matrix = mathutils.Matrix(target_client.data['view_matrix']) rv3d.view_matrix = mathutils.Matrix(target_client.data['view_matrix'])
# rv3d.view_distance = 30.0 else:
return {"FINISHED"}
return {"CANCELLED"} return {"CANCELLED"}
return {'PASS_THROUGH'}
class SessionApply(bpy.types.Operator): class SessionApply(bpy.types.Operator):
bl_idname = "session.apply" bl_idname = "session.apply"