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
b1854c9c
Commit
b1854c9c
authored
Oct 14, 2015
by
Dalai Felinto
Browse files
Slave boosted mode wip + UI for preview
parent
7e7d2765
Changes
6
Hide whitespace changes
Inline
Side-by-side
space_view3d_virtual_reality/hmd/__init__.py
View file @
b1854c9c
...
@@ -56,6 +56,7 @@ class HMD_Base:
...
@@ -56,6 +56,7 @@ class HMD_Base:
"_height"
,
"_height"
,
"_projection_matrix"
,
"_projection_matrix"
,
"_head_transformation"
,
"_head_transformation"
,
"_is_direct_mode"
,
"_eye_pose"
,
"_eye_pose"
,
"_offscreen_object"
,
"_offscreen_object"
,
"_framebuffer_object"
,
"_framebuffer_object"
,
...
@@ -65,8 +66,9 @@ class HMD_Base:
...
@@ -65,8 +66,9 @@ class HMD_Base:
"_far"
,
"_far"
,
}
}
def
__init__
(
self
,
name
,
context
,
error_callback
):
def
__init__
(
self
,
name
,
is_direct_mode
,
context
,
error_callback
):
self
.
_name
=
name
self
.
_name
=
name
self
.
_is_direct_mode
=
is_direct_mode
self
.
_error_callback
=
error_callback
self
.
_error_callback
=
error_callback
self
.
_current_eye
=
0
self
.
_current_eye
=
0
self
.
_width
=
[
0
,
0
]
self
.
_width
=
[
0
,
0
]
...
@@ -82,6 +84,10 @@ class HMD_Base:
...
@@ -82,6 +84,10 @@ class HMD_Base:
self
.
_updateViewClipping
(
context
)
self
.
_updateViewClipping
(
context
)
@
property
def
is_direct_mode
(
self
):
return
self
.
_is_direct_mode
@
property
@
property
def
width
(
self
):
def
width
(
self
):
return
self
.
_width
[
self
.
_current_eye
]
return
self
.
_width
[
self
.
_current_eye
]
...
...
space_view3d_virtual_reality/hmd/debug.py
View file @
b1854c9c
...
@@ -16,7 +16,7 @@ def print_debug(*args):
...
@@ -16,7 +16,7 @@ def print_debug(*args):
class
Debug
(
HMD_Base
):
class
Debug
(
HMD_Base
):
def
__init__
(
self
,
context
,
error_callback
):
def
__init__
(
self
,
context
,
error_callback
):
super
(
Debug
,
self
).
__init__
(
'Debug'
,
context
,
error_callback
)
super
(
Debug
,
self
).
__init__
(
'Debug'
,
False
,
context
,
error_callback
)
def
init
(
self
,
context
):
def
init
(
self
,
context
):
"""
"""
...
...
space_view3d_virtual_reality/hmd/oculus.py
View file @
b1854c9c
...
@@ -17,7 +17,7 @@ from ..lib import (
...
@@ -17,7 +17,7 @@ from ..lib import (
class
Oculus
(
HMD_Base
):
class
Oculus
(
HMD_Base
):
def
__init__
(
self
,
context
,
error_callback
):
def
__init__
(
self
,
context
,
error_callback
):
super
(
Oculus
,
self
).
__init__
(
'Oculus'
,
context
,
error_callback
)
super
(
Oculus
,
self
).
__init__
(
'Oculus'
,
True
,
context
,
error_callback
)
checkModule
(
'oculus_sdk_bridge'
)
checkModule
(
'oculus_sdk_bridge'
)
def
_getHMDClass
(
self
):
def
_getHMDClass
(
self
):
...
...
space_view3d_virtual_reality/hmd/oculus_legacy.py
View file @
b1854c9c
...
@@ -16,7 +16,7 @@ from ..lib import (
...
@@ -16,7 +16,7 @@ from ..lib import (
class
OculusLegacy
(
Oculus
):
class
OculusLegacy
(
Oculus
):
def
__init__
(
self
,
context
,
error_callback
):
def
__init__
(
self
,
context
,
error_callback
):
HMD_Base
.
__init__
(
self
,
'Oculus Legacy'
,
context
,
error_callback
)
HMD_Base
.
__init__
(
self
,
'Oculus Legacy'
,
False
,
context
,
error_callback
)
checkModule
(
'python-ovrsdk'
)
checkModule
(
'python-ovrsdk'
)
def
_getHMDClass
(
self
):
def
_getHMDClass
(
self
):
...
...
space_view3d_virtual_reality/operator.py
View file @
b1854c9c
...
@@ -10,8 +10,8 @@ from .lib import (
...
@@ -10,8 +10,8 @@ from .lib import (
getDisplayBackend
,
getDisplayBackend
,
)
)
import
gpu
TODO
=
False
# ############################################################
# ############################################################
...
@@ -36,7 +36,9 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -36,7 +36,9 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
_hmd
=
None
_hmd
=
None
_timer
=
None
_timer
=
None
_handle
=
None
_handle
=
None
_area_hash
=
-
1
_hash_slave
=
-
1
_hash_master
=
-
1
_slave_setup
=
False
action
=
bpy
.
props
.
EnumProperty
(
action
=
bpy
.
props
.
EnumProperty
(
description
=
""
,
description
=
""
,
...
@@ -120,17 +122,14 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -120,17 +122,14 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
"""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
wm
=
context
.
window_manager
wm
=
context
.
window_manager
vr
=
wm
.
virtual_reality
wm
.
virtual_reality
.
reset
()
vr
.
is_enabled
=
False
vr
.
error_message
=
""
def
_quit
(
self
,
context
):
def
_quit
(
self
,
context
):
"""actual quit"""
"""actual quit"""
if
self
.
_handle
:
if
self
.
_handle
:
bpy
.
types
.
SpaceView3D
.
draw_handler_remove
(
self
.
_handle
,
'WINDOW'
)
bpy
.
types
.
SpaceView3D
.
draw_handler_remove
(
self
.
_handle
,
'WINDOW'
)
del
self
.
_handle
self
.
_handle
=
None
self
.
_preview
.
quit
()
self
.
_preview
.
quit
()
...
@@ -155,6 +154,20 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -155,6 +154,20 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
self
.
_hmd
=
HMD
(
display_backend
,
context
,
self
.
_error_callback
)
self
.
_hmd
=
HMD
(
display_backend
,
context
,
self
.
_error_callback
)
self
.
_preview
=
Preview
()
self
.
_preview
=
Preview
()
self
.
_hash_master
=
hash
(
context
.
area
)
# setup modal
self
.
_handle
=
bpy
.
types
.
SpaceView3D
.
draw_handler_add
(
self
.
_draw_callback_px
,
(
context
,),
'WINDOW'
,
'POST_PIXEL'
)
wm
.
modal_handler_add
(
self
)
if
self
.
_hmd
.
is_direct_mode
:
self
.
_masterInit
(
context
)
else
:
return
self
.
_slaveHook
(
context
)
return
True
def
_init
(
self
,
context
):
if
not
self
.
_hmd
.
init
(
context
):
if
not
self
.
_hmd
.
init
(
context
):
self
.
report
({
'ERROR'
},
"Error initializing device"
)
self
.
report
({
'ERROR'
},
"Error initializing device"
)
return
False
return
False
...
@@ -166,13 +179,46 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -166,13 +179,46 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
color_object
[
i
]
=
self
.
_hmd
.
color_object
color_object
[
i
]
=
self
.
_hmd
.
color_object
self
.
_preview
.
init
(
color_object
[
0
],
color_object
[
1
])
self
.
_preview
.
init
(
color_object
[
0
],
color_object
[
1
])
self
.
_area_hash
=
hash
(
context
.
area
)
return
True
# setup modal
def
_masterInit
(
self
,
context
):
self
.
_handle
=
bpy
.
types
.
SpaceView3D
.
draw_handler_add
(
self
.
_draw_callback_px
,
(
context
,),
'WINDOW'
,
'POST_PIXEL'
)
return
self
.
_init
(
context
)
wm
.
modal_handler_add
(
self
)
return
True
def
_slaveInit
(
self
,
context
):
self
.
_slave_setup
=
True
if
not
self
.
_init
(
context
):
self
.
quit
(
context
)
def
_slaveHook
(
self
,
context
):
self
.
_hash_slave
=
-
1
self
.
_slave_setup
=
False
hashes
=
[]
for
screen
in
bpy
.
data
.
screens
:
for
area
in
screen
.
areas
:
if
area
.
type
==
'VIEW_3D'
:
hashes
.
append
(
hash
(
area
))
bpy
.
ops
.
screen
.
area_dupli
(
'INVOKE_DEFAULT'
)
for
screen
in
bpy
.
data
.
screens
:
for
area
in
screen
.
areas
:
if
area
.
type
!=
'VIEW_3D'
:
continue
_hash
=
hash
(
area
)
try
:
hashes
.
remove
(
_hash
)
except
ValueError
:
self
.
_hash_slave
=
_hash
print
(
'Success finding slave'
)
return
True
return
False
def
_commands
(
self
,
context
):
def
_commands
(
self
,
context
):
"""
"""
...
@@ -210,21 +256,38 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
...
@@ -210,21 +256,38 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
self
.
_hmd
.
frameReady
()
self
.
_hmd
.
frameReady
()
def
_draw_callback_px
(
self
,
context
):
def
_drawMaster
(
self
,
context
):
"""callback function, run every time the viewport is refreshed"""
wm
=
context
.
window_manager
vr
=
wm
.
virtual_reality
area
=
context
.
area
if
self
.
_hmd
.
is_direct_mode
:
if
not
self
.
_area_hash
==
hash
(
area
):
self
.
_loop
(
context
)
if
vr
.
use_preview
:
self
.
_preview
.
loop
(
vr
.
preview_scale
)
def
_drawSlave
(
self
,
context
):
if
self
.
_hmd
.
is_direct_mode
:
return
return
if
not
self
.
_slave_setup
:
self
.
_slaveInit
(
context
)
self
.
_loop
(
context
)
self
.
_loop
(
context
)
area
.
tag_redraw
()
area
.
tag_redraw
()
def
_draw_callback_px
(
self
,
context
):
"""
"""
wm = context.window_manager
callback function, run every time the viewport is refreshed
vr = wm.virtual_reality
self._preview.loop(vr.preview_scale)
"""
"""
area
=
context
.
area
hash_area
=
hash
(
area
)
if
hash_area
==
self
.
_hash_slave
:
self
.
_drawSlave
(
context
)
elif
hash_area
==
self
.
_hash_master
:
self
.
_drawMaster
(
context
)
def
_error_callback
(
self
,
message
,
is_fatal
):
def
_error_callback
(
self
,
message
,
is_fatal
):
"""
"""
...
@@ -270,11 +333,16 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
...
@@ -270,11 +333,16 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
default
=
False
,
default
=
False
,
)
)
use_preview
=
BoolProperty
(
name
=
"Preview"
,
default
=
False
,
)
preview_scale
=
IntProperty
(
preview_scale
=
IntProperty
(
name
=
"Preview Scale"
,
name
=
"Preview Scale"
,
min
=
0
,
min
=
0
,
max
=
100
,
max
=
100
,
default
=
10
0
,
default
=
2
0
,
subtype
=
'PERCENTAGE'
,
subtype
=
'PERCENTAGE'
,
)
)
...
@@ -305,10 +373,14 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
...
@@ -305,10 +373,14 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
self
.
commands
.
remove
(
0
)
self
.
commands
.
remove
(
0
)
return
action
return
action
def
command_
reset
(
self
):
def
reset
(
self
):
while
self
.
commands
:
while
self
.
commands
:
self
.
commands
.
remove
(
0
)
self
.
commands
.
remove
(
0
)
self
.
use_preview
=
False
self
.
error_message
=
""
self
.
is_enabled
=
False
# ############################################################
# ############################################################
# Callbacks
# Callbacks
...
@@ -317,21 +389,13 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
...
@@ -317,21 +389,13 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
@
persistent
@
persistent
def
virtual_reality_load_pre
(
dummy
):
def
virtual_reality_load_pre
(
dummy
):
wm
=
bpy
.
context
.
window_manager
wm
=
bpy
.
context
.
window_manager
vr
=
wm
.
virtual_reality
wm
.
virtual_reality
.
reset
()
vr
.
is_enabled
=
False
vr
.
command_reset
()
@
persistent
@
persistent
def
virtual_reality_load_post
(
dummy
):
def
virtual_reality_load_post
(
dummy
):
wm
=
bpy
.
context
.
window_manager
wm
=
bpy
.
context
.
window_manager
vr
=
wm
.
virtual_reality
wm
.
virtual_reality
.
reset
()
vr
.
is_enabled
=
False
vr
.
command_reset
()
vr
.
error_message
=
""
# ############################################################
# ############################################################
...
...
space_view3d_virtual_reality/ui.py
View file @
b1854c9c
...
@@ -25,16 +25,23 @@ class VirtualRealityPanel(bpy.types.Panel):
...
@@ -25,16 +25,23 @@ class VirtualRealityPanel(bpy.types.Panel):
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
()
#
col.
p
ro
p(vr, "preview_scale", text="Preview"
)
row
=
col
.
ro
w
(
)
col
.
label
(
text
=
vr
.
error_message
)
row
.
prop
(
vr
,
"use_preview"
)
sub
=
row
.
column
()
sub
.
active
=
vr
.
use_preview
sub
.
prop
(
vr
,
"preview_scale"
,
text
=
"Scale"
)
col
.
separator
()
col
.
separator
()
col
.
operator
(
"view3d.virtual_reality_display"
,
text
=
"Re-Center"
).
action
=
'RECENTER'
col
.
operator
(
"view3d.virtual_reality_display"
,
text
=
"Re-Center"
).
action
=
'RECENTER'
col
.
separator
()
col
.
separator
()
col
.
label
(
text
=
"Tracking:"
)
col
.
row
().
prop
(
vr
,
"tracking_mode"
,
expand
=
True
)
col
.
row
().
prop
(
vr
,
"tracking_mode"
,
expand
=
True
)
col
.
separator
()
col
.
label
(
text
=
vr
.
error_message
)
# ############################################################
# ############################################################
# Un/Registration
# Un/Registration
...
...
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