Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Dalai Felinto
virtual_reality_viewport
Commits
5cd94083
Commit
5cd94083
authored
Oct 16, 2015
by
Dalai Felinto
Browse files
Pause system, special treatment for OSX, sorted redraw changes
parent
cc72374a
Changes
2
Hide whitespace changes
Inline
Side-by-side
space_view3d_virtual_reality/lib.py
View file @
5cd94083
...
@@ -10,7 +10,9 @@ def getAddonName():
...
@@ -10,7 +10,9 @@ def getAddonName():
def
getDisplayBackend
(
context
):
def
getDisplayBackend
(
context
):
"""preference set in the addon"""
"""
Preference set in the addon
"""
addon
=
getAddonName
()
addon
=
getAddonName
()
preferences
=
context
.
user_preferences
.
addons
[
addon
].
preferences
preferences
=
context
.
user_preferences
.
addons
[
addon
].
preferences
return
preferences
.
display_backend
return
preferences
.
display_backend
...
@@ -29,3 +31,10 @@ def checkModule(path):
...
@@ -29,3 +31,10 @@ def checkModule(path):
if
library_path
not
in
sys
.
path
:
if
library_path
not
in
sys
.
path
:
sys
.
path
.
append
(
library_path
)
sys
.
path
.
append
(
library_path
)
def
isMac
():
"""
Return True if OS is Mac OSX
"""
from
sys
import
platform
as
_platform
return
_platform
==
"darwin"
space_view3d_virtual_reality/operator.py
View file @
5cd94083
...
@@ -8,6 +8,7 @@ from .preview import Preview
...
@@ -8,6 +8,7 @@ from .preview import Preview
from
.lib
import
(
from
.lib
import
(
getDisplayBackend
,
getDisplayBackend
,
isMac
,
)
)
...
@@ -32,12 +33,11 @@ class SlaveStatus:
...
@@ -32,12 +33,11 @@ class SlaveStatus:
uiless
=
2
# view3d without UI
uiless
=
2
# view3d without UI
waituser
=
3
# waiting for user to move window to HMD
waituser
=
3
# waiting for user to move window to HMD
usermoved
=
4
# user moved window
usermoved
=
4
# user moved window
fullscreen
=
5
# wait a bit to prevent a crash on OSX
ready
=
5
# all went well
ready
=
6
# all went well
play
=
6
# play
play
=
8
# play
pause
=
7
# pause
pause
=
9
# pause
paused
=
8
# paused
paused
=
10
# paused
error
=
9
# something didn't work
error
=
11
# something didn't work
# ############################################################
# ############################################################
...
@@ -50,6 +50,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -50,6 +50,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
bl_label
=
"Toggle Virtual Reality Display"
bl_label
=
"Toggle Virtual Reality Display"
bl_description
=
""
bl_description
=
""
# update the values in def _init_static
_hmd
=
None
_hmd
=
None
_timer
=
None
_timer
=
None
_handle
=
None
_handle
=
None
...
@@ -57,6 +58,8 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -57,6 +58,8 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
_hash_master
=
-
1
_hash_master
=
-
1
_slave_status
=
0
_slave_status
=
0
_slave_window
=
None
_slave_window
=
None
_slave_area
=
None
_is_mac
=
False
action
=
bpy
.
props
.
EnumProperty
(
action
=
bpy
.
props
.
EnumProperty
(
description
=
""
,
description
=
""
,
...
@@ -91,8 +94,12 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -91,8 +94,12 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
area
.
tag_redraw
()
area
.
tag_redraw
()
return
{
'FINISHED'
}
return
{
'FINISHED'
}
if
event
.
type
==
'TIMER'
:
if
event
.
type
==
'TIMER'
and
\
if
self
.
_hmd
and
not
self
.
_hmd
.
is_direct_mode
:
not
vr
.
is_paused
:
if
self
.
_slave_area
:
self
.
_slave_area
.
tag_redraw
()
if
vr
.
use_preview
:
area
.
tag_redraw
()
area
.
tag_redraw
()
return
{
'PASS_THROUGH'
}
return
{
'PASS_THROUGH'
}
...
@@ -136,10 +143,14 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -136,10 +143,14 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
elif
self
.
action
==
'PLAY'
:
elif
self
.
action
==
'PLAY'
:
vr
.
command_push
(
Commands
.
play
)
vr
.
command_push
(
Commands
.
play
)
# we define is_paused right away, so
# the next MODAL loop already tag_redraw
vr
.
is_paused
=
False
return
{
'FINISHED'
}
return
{
'FINISHED'
}
elif
self
.
action
==
'PAUSE'
:
elif
self
.
action
==
'PAUSE'
:
vr
.
command_push
(
Commands
.
pause
)
vr
.
command_push
(
Commands
.
pause
)
self
.
_redraw
(
context
)
return
{
'FINISHED'
}
return
{
'FINISHED'
}
else
:
else
:
...
@@ -147,6 +158,13 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -147,6 +158,13 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
return
{
'CANCELLED'
}
return
{
'CANCELLED'
}
def
_redraw
(
self
,
context
,
redraw_master
=
True
,
redraw_slave
=
True
):
if
redraw_slave
and
self
.
_slave_area
:
self
.
_slave_area
.
tag_redraw
()
if
redraw_master
:
context
.
area
.
tag_redraw
()
def
quit
(
self
,
context
):
def
quit
(
self
,
context
):
"""garbage collect"""
"""garbage collect"""
# change it so the original modal operator will clean things up
# change it so the original modal operator will clean things up
...
@@ -180,6 +198,17 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -180,6 +198,17 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
if
context
.
area
:
if
context
.
area
:
context
.
area
.
tag_redraw
()
context
.
area
.
tag_redraw
()
def
_init_static
(
self
):
self
.
_hmd
=
None
self
.
_timer
=
None
self
.
_handle
=
None
self
.
_hash_slave
=
-
1
self
.
_hash_master
=
-
1
self
.
_slave_status
=
0
self
.
_slave_window
=
None
self
.
_slave_area
=
None
self
.
_is_mac
=
isMac
()
def
init
(
self
,
context
):
def
init
(
self
,
context
):
"""
"""
Initialize the callbacks and the external devices
Initialize the callbacks and the external devices
...
@@ -187,9 +216,10 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -187,9 +216,10 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
wm
=
context
.
window_manager
wm
=
context
.
window_manager
vr
=
wm
.
virtual_reality
vr
=
wm
.
virtual_reality
vr
.
reset
()
vr
.
is_enabled
=
True
vr
.
is_enabled
=
True
vr
.
error_message
=
""
vr
.
is_slave_setup
=
False
self
.
_init_static
()
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
)
...
@@ -243,18 +273,20 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -243,18 +273,20 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
return
True
return
True
elif
self
.
_slave_status
==
SlaveStatus
.
usermoved
:
elif
self
.
_slave_status
==
SlaveStatus
.
usermoved
:
bpy
.
ops
.
wm
.
window_fullscreen_toggle
()
if
not
self
.
_is_mac
:
self
.
_slave_status
=
SlaveStatus
.
fullscreen
bpy
.
ops
.
wm
.
window_
fullscreen
_toggle
()
elif
self
.
_slave_status
==
SlaveStatus
.
fullscreen
:
context
.
window_manager
.
virtual_reality
.
is_slave_setup
=
False
context
.
window_manager
.
virtual_reality
.
is_slave_setup
=
False
ok
=
self
.
_init
(
context
)
ok
=
self
.
_init
(
context
)
self
.
_slave_status
=
SlaveStatus
.
ready
self
.
_slave_status
=
SlaveStatus
.
ready
elif
self
.
_slave_status
==
SlaveStatus
.
play
:
elif
self
.
_slave_status
==
SlaveStatus
.
play
:
context
.
window_manager
.
virtual_reality
.
is_paused
=
False
self
.
_slave_status
=
SlaveStatus
.
ready
self
.
_slave_status
=
SlaveStatus
.
ready
elif
self
.
_slave_status
==
SlaveStatus
.
pause
:
elif
self
.
_slave_status
==
SlaveStatus
.
pause
:
context
.
window_manager
.
virtual_reality
.
is_paused
=
True
context
.
area
.
tag_redraw
()
self
.
_slave_status
=
SlaveStatus
.
paused
self
.
_slave_status
=
SlaveStatus
.
paused
else
:
else
:
...
@@ -269,6 +301,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -269,6 +301,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
def
_slaveHook
(
self
,
context
,
mode
=
''
):
def
_slaveHook
(
self
,
context
,
mode
=
''
):
self
.
_hash_slave
=
-
1
self
.
_hash_slave
=
-
1
self
.
_slave_area
=
None
self
.
_slave_status
=
SlaveStatus
.
non_setup
self
.
_slave_status
=
SlaveStatus
.
non_setup
hashes
=
[]
hashes
=
[]
...
@@ -299,6 +332,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -299,6 +332,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
except
ValueError
:
except
ValueError
:
self
.
_hash_slave
=
_hash
self
.
_hash_slave
=
_hash
self
.
_slave_area
=
area
print
(
'Success finding slave'
)
print
(
'Success finding slave'
)
return
True
return
True
...
@@ -360,17 +394,28 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -360,17 +394,28 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
if
self
.
_hmd
.
is_direct_mode
:
if
self
.
_hmd
.
is_direct_mode
:
self
.
_commands
(
context
)
self
.
_commands
(
context
)
if
vr
.
is_paused
:
return
if
self
.
_hmd
.
is_direct_mode
:
self
.
_loop
(
context
)
self
.
_loop
(
context
)
if
vr
.
use_preview
:
if
vr
.
use_preview
:
self
.
_preview
.
loop
(
vr
.
preview_scale
)
self
.
_preview
.
loop
(
vr
.
preview_scale
)
def
_drawSlave
(
self
,
context
):
def
_drawSlave
(
self
,
context
):
wm
=
context
.
window_manager
vr
=
wm
.
virtual_reality
if
self
.
_hmd
.
is_direct_mode
:
if
self
.
_hmd
.
is_direct_mode
:
return
return
self
.
_commands
(
context
)
self
.
_commands
(
context
)
if
vr
.
is_paused
:
return
if
self
.
_slave_status
==
SlaveStatus
.
ready
:
if
self
.
_slave_status
==
SlaveStatus
.
ready
:
self
.
_loop
(
context
)
self
.
_loop
(
context
)
...
@@ -398,6 +443,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -398,6 +443,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
x
=
int
(
0.1
*
width
)
x
=
int
(
0.1
*
width
)
y
=
int
(
0.5
*
height
)
y
=
int
(
0.5
*
height
)
font_size
=
int
(
width
*
0.035
)
font_size
=
int
(
width
*
0.035
)
line_gap
=
int
(
font_size
*
1.5
)
from
blf
import
(
from
blf
import
(
SHADOW
,
SHADOW
,
...
@@ -413,11 +459,21 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -413,11 +459,21 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
enable
(
font_id
,
SHADOW
)
enable
(
font_id
,
SHADOW
)
shadow
(
font_id
,
5
,
0.0
,
0.0
,
0.0
,
1.0
)
shadow
(
font_id
,
5
,
0.0
,
0.0
,
0.0
,
1.0
)
shadow_offset
(
font_id
,
-
2
,
-
2
)
shadow_offset
(
font_id
,
-
2
,
-
2
)
position
(
font_id
,
x
,
y
,
0
)
size
(
font_id
,
font_size
,
72
)
size
(
font_id
,
font_size
,
72
)
draw
(
font_id
,
"1. Move this window to the external HMD display"
)
position
(
font_id
,
x
,
y
-
int
(
font_size
*
1.5
),
0
)
if
self
.
_is_mac
:
draw
(
font_id
,
"2. Select
\"
Start
\"
in the main window"
)
position
(
font_id
,
x
,
y
+
line_gap
,
0
)
draw
(
font_id
,
"1. Move this window to the external HMD display"
)
position
(
font_id
,
x
,
y
,
0
)
draw
(
font_id
,
"2. Set this window to fullscreen (Alt + F11)"
)
position
(
font_id
,
x
,
y
-
line_gap
,
0
)
draw
(
font_id
,
"3. Select
\"
Start
\"
in the main window"
)
else
:
position
(
font_id
,
x
,
y
,
0
)
draw
(
font_id
,
"1. Move this window to the external HMD display"
)
position
(
font_id
,
x
,
y
-
line_gap
,
0
)
draw
(
font_id
,
"2. Select
\"
Start
\"
in the main window"
)
disable
(
font_id
,
SHADOW
)
disable
(
font_id
,
SHADOW
)
def
_draw_callback_px
(
self
,
context
):
def
_draw_callback_px
(
self
,
context
):
...
@@ -481,6 +537,11 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
...
@@ -481,6 +537,11 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
default
=
False
,
default
=
False
,
)
)
is_paused
=
BoolProperty
(
name
=
"Paused"
,
default
=
False
,
)
use_preview
=
BoolProperty
(
use_preview
=
BoolProperty
(
name
=
"Preview"
,
name
=
"Preview"
,
default
=
False
,
default
=
False
,
...
@@ -533,6 +594,7 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
...
@@ -533,6 +594,7 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
self
.
error_message
=
""
self
.
error_message
=
""
self
.
is_enabled
=
False
self
.
is_enabled
=
False
self
.
is_slave_setup
=
False
self
.
is_slave_setup
=
False
self
.
is_paused
=
False
# ############################################################
# ############################################################
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment