Commit fcd225b9 authored by Dalai Felinto's avatar Dalai Felinto
Browse files

Slave system working

parent 5971e8bd
...@@ -20,9 +20,20 @@ TODO = False ...@@ -20,9 +20,20 @@ TODO = False
class Commands: class Commands:
recenter = 'RECENTER' recenter = 'RECENTER'
fullscreen = 'FULLSCREEN'
test = 'TEST' test = 'TEST'
class SlaveStatus:
non_setup = 0 # initial
dupli = 1 # view3d duplicated
uiless = 2 # view3d without UI
waituser = 3 # waiting for user to move window to HMD
usermoved = 4 # user moved window
ready = 5 # all went well
error = 6 # something didn't work
# ############################################################ # ############################################################
# Main Operator # Main Operator
# ############################################################ # ############################################################
...@@ -38,7 +49,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -38,7 +49,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
_handle = None _handle = None
_hash_slave = -1 _hash_slave = -1
_hash_master = -1 _hash_master = -1
_slave_setup = False _slave_status = 0
action = bpy.props.EnumProperty( action = bpy.props.EnumProperty(
description="", description="",
...@@ -46,6 +57,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -46,6 +57,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
("DISABLE", "Disable", "Disable"), ("DISABLE", "Disable", "Disable"),
("TOGGLE", "Toggle", "Toggle"), ("TOGGLE", "Toggle", "Toggle"),
("RECENTER", "Re-Center", "Re-Center tracking data"), ("RECENTER", "Re-Center", "Re-Center tracking data"),
("FULLSCREEN", "Fullscreen", "Make slave fullscreen"),
), ),
default="TOGGLE", default="TOGGLE",
options={'SKIP_SAVE'}, options={'SKIP_SAVE'},
...@@ -70,13 +82,9 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -70,13 +82,9 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
area.tag_redraw() area.tag_redraw()
return {'FINISHED'} return {'FINISHED'}
"""
if event.type == 'TIMER': if event.type == 'TIMER':
self.loop(context) TODO # only if extended mode
area.tag_redraw()
if vr.preview_scale and context.area:
area.tag_redraw()
"""
return {'PASS_THROUGH'} return {'PASS_THROUGH'}
...@@ -113,6 +121,10 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -113,6 +121,10 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
vr.command_push(Commands.recenter) vr.command_push(Commands.recenter)
return {'FINISHED'} return {'FINISHED'}
elif self.action == 'FULLSCREEN':
vr.command_push(Commands.fullscreen)
return {'FINISHED'}
else: else:
assert False, "action \"{0}\" not implemented".format(self.action) assert False, "action \"{0}\" not implemented".format(self.action)
...@@ -127,6 +139,11 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -127,6 +139,11 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
def _quit(self, context): def _quit(self, context):
"""actual quit""" """actual quit"""
if self._timer:
wm = context.window_manager
wm.event_timer_remove(self._timer)
self._timer = None
if self._handle: if self._handle:
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW') bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
self._handle = None self._handle = None
...@@ -149,6 +166,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -149,6 +166,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
vr.is_enabled = True vr.is_enabled = True
vr.error_message = "" vr.error_message = ""
vr.is_slave_setup = False
display_backend = getDisplayBackend(context) display_backend = getDisplayBackend(context)
self._hmd = HMD(display_backend, context, self._error_callback) self._hmd = HMD(display_backend, context, self._error_callback)
...@@ -157,13 +175,15 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -157,13 +175,15 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
self._hash_master = hash(context.area) self._hash_master = hash(context.area)
# setup modal # setup modal
self._timer = wm.event_timer_add(1.0 / 75.0, context.window) # 75 Hz
self._handle = bpy.types.SpaceView3D.draw_handler_add(self._draw_callback_px, (context,), 'WINDOW', 'POST_PIXEL') self._handle = bpy.types.SpaceView3D.draw_handler_add(self._draw_callback_px, (context,), 'WINDOW', 'POST_PIXEL')
wm.modal_handler_add(self) wm.modal_handler_add(self)
if self._hmd.is_direct_mode: if self._hmd.is_direct_mode:
self._masterInit(context) self._init(context)
else: else:
return self._slaveHook(context) vr.is_slave_setup = True
return self._slaveSetup(context)
return True return True
...@@ -181,18 +201,43 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -181,18 +201,43 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
self._preview.init(color_object[0], color_object[1]) self._preview.init(color_object[0], color_object[1])
return True return True
def _masterInit(self, context): def _slaveSetup(self, context):
return self._init(context) ok = True
def _slaveInit(self, context): if self._slave_status == SlaveStatus.error:
self._slave_setup = True return False
elif self._slave_status == SlaveStatus.non_setup:
ok = self._slaveHook(context, SlaveStatus.dupli)
self._slave_status = SlaveStatus.dupli
elif self._slave_status == SlaveStatus.dupli:
ok = self._slaveHook(context, SlaveStatus.uiless)
self._slave_status = SlaveStatus.waituser
elif self._slave_status == SlaveStatus.waituser:
# waiting for the user input
return True
elif self._slave_status == SlaveStatus.usermoved:
context.window_manager.virtual_reality.is_slave_setup = False
bpy.ops.wm.window_fullscreen_toggle()
ok = self._init(context)
self._slave_status = SlaveStatus.ready
else:
assert False, "_slaveSetup: Slave status \"{0}\" not defined".format(self._slave_status)
if not self._init(context): if not ok:
self._slave_status = SlaveStatus.error
self.quit(context) self.quit(context)
def _slaveHook(self, context): return ok
def _slaveHook(self, context, mode=''):
self._hash_slave = -1 self._hash_slave = -1
self._slave_setup = False self._slave_status = SlaveStatus.non_setup
hashes = [] hashes = []
...@@ -201,7 +246,14 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -201,7 +246,14 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
if area.type == 'VIEW_3D': if area.type == 'VIEW_3D':
hashes.append(hash(area)) hashes.append(hash(area))
bpy.ops.screen.area_dupli('INVOKE_DEFAULT') if mode == SlaveStatus.dupli:
bpy.ops.screen.area_dupli('INVOKE_DEFAULT')
elif mode == SlaveStatus.uiless:
bpy.ops.screen.screen_full_area(use_hide_panels=True)
else:
assert False, "_slaveHook: Slave status \"{0}\" not defined".format(self._slave_status)
for screen in bpy.data.screens: for screen in bpy.data.screens:
for area in screen.areas: for area in screen.areas:
...@@ -234,14 +286,20 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -234,14 +286,20 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
if self._hmd: if self._hmd:
self._hmd.reCenter() self._hmd.reCenter()
elif command == Commands.fullscreen:
self._slave_status = SlaveStatus.usermoved
self._slaveSetup(context)
elif command == Commands.test: elif command == Commands.test:
print("Testing !!!") print("Testing !!!")
else:
assert False, "_commands: command \"{0}\" not implemented"
def _loop(self, context): def _loop(self, context):
""" """
Get fresh tracking data and render into the FBO Get fresh tracking data and render into the FBO
""" """
self._commands(context)
self._hmd.loop(context) self._hmd.loop(context)
for i in range(2): for i in range(2):
...@@ -261,6 +319,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -261,6 +319,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
vr = wm.virtual_reality vr = wm.virtual_reality
if self._hmd.is_direct_mode: if self._hmd.is_direct_mode:
self._commands(context)
self._loop(context) self._loop(context)
if vr.use_preview: if vr.use_preview:
...@@ -270,11 +329,20 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -270,11 +329,20 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
if self._hmd.is_direct_mode: if self._hmd.is_direct_mode:
return return
if not self._slave_setup: self._commands(context)
self._slaveInit(context)
self._loop(context) if self._slave_status == SlaveStatus.ready:
area.tag_redraw() self._loop(context)
elif self._slave_status == SlaveStatus.waituser:
self._drawDisplayMessage()
else:
self._slaveSetup(context)
def _drawDisplayMessage(self):
"""Message telling user to move the window the HMD display"""
TODO
def _draw_callback_px(self, context): def _draw_callback_px(self, context):
""" """
...@@ -283,7 +351,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -283,7 +351,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
area = context.area area = context.area
hash_area = hash(area) hash_area = hash(area)
if hash_area == self._hash_slave: if (hash_area == self._hash_slave):
self._drawSlave(context) self._drawSlave(context)
elif hash_area == self._hash_master: elif hash_area == self._hash_master:
...@@ -316,11 +384,13 @@ from bpy.props import ( ...@@ -316,11 +384,13 @@ from bpy.props import (
IntProperty, IntProperty,
) )
class VirtualRealityCommandInfo(bpy.types.PropertyGroup): class VirtualRealityCommandInfo(bpy.types.PropertyGroup):
action = EnumProperty( action = EnumProperty(
name="Action", name="Action",
items=(("NONE", "None", ""), items=(("NONE", "None", ""),
(Commands.recenter, "Re-Center", ""), (Commands.recenter, "Re-Center", ""),
(Commands.fullscreen, "Fullscreen", ""),
(Commands.test, "Test", ""), (Commands.test, "Test", ""),
), ),
default="NONE", default="NONE",
...@@ -360,6 +430,10 @@ class VirtualRealityInfo(bpy.types.PropertyGroup): ...@@ -360,6 +430,10 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
default="ALL", default="ALL",
) )
is_slave_setup = BoolProperty(
default = False,
)
commands = CollectionProperty(type=VirtualRealityCommandInfo) commands = CollectionProperty(type=VirtualRealityCommandInfo)
...@@ -380,6 +454,7 @@ class VirtualRealityInfo(bpy.types.PropertyGroup): ...@@ -380,6 +454,7 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
self.use_preview = False self.use_preview = False
self.error_message = "" self.error_message = ""
self.is_enabled = False self.is_enabled = False
self.is_slave_setup = False
# ############################################################ # ############################################################
......
...@@ -23,24 +23,28 @@ class VirtualRealityPanel(bpy.types.Panel): ...@@ -23,24 +23,28 @@ class VirtualRealityPanel(bpy.types.Panel):
col.operator("view3d.virtual_reality_display", text="Virtual Reality", icon="PLAY").action='ENABLE' col.operator("view3d.virtual_reality_display", text="Virtual Reality", icon="PLAY").action='ENABLE'
else: else:
col.operator("view3d.virtual_reality_display", text="Virtual Reality", icon="X").action='DISABLE' col.operator("view3d.virtual_reality_display", text="Virtual Reality", icon="X").action='DISABLE'
col.separator() col.separator()
row = col.row()
row.prop(vr, "use_preview") if vr.is_slave_setup:
sub = row.column() col.operator("view3d.virtual_reality_display", text="Start", icon="CAMERA_STEREO").action='FULLSCREEN'
sub.active = vr.use_preview
sub.prop(vr, "preview_scale", text="Scale")
col.separator() else:
col.operator("view3d.virtual_reality_display", text="Re-Center").action='RECENTER' row = col.row()
col.separator() row.prop(vr, "use_preview")
col.label(text="Tracking:") sub = row.column()
col.row().prop(vr, "tracking_mode", expand=True) sub.active = vr.use_preview
sub.prop(vr, "preview_scale", text="Scale")
col.separator() col.separator()
col.label(text=vr.error_message) col.operator("view3d.virtual_reality_display", text="Re-Center").action='RECENTER'
col.separator()
col.label(text="Tracking:")
col.row().prop(vr, "tracking_mode", expand=True)
col.separator()
col.label(text=vr.error_message)
# ############################################################ # ############################################################
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment