Commit 533241c9 authored by Dalai Felinto's avatar Dalai Felinto
Browse files

Oculus Legacy backend, barebones

parent 02c6b921
......@@ -48,6 +48,7 @@ class VirtualRealityPreferences(bpy.types.AddonPreferences):
name="Display Backend",
description="Library to use for the display",
items=(("OCULUS", "Oculus", "Oculus - oculus.com"),
("OCULUS_LEGACY", "Oculus Legacy", "Oculus 0.5 - oculus.com"),
("DEBUG", "Debug", "Debug backend - no real HMD"),
),
default="OCULUS",
......
......@@ -15,28 +15,32 @@ VERBOSE = True
# Data structs
# ############################################################
def HMD(display_backend, error_callback):
def HMD(display_backend, context, error_callback):
"""
return the head mounted display device class
(defined in another file)
:param display_backend: backend engine
:type display_backend: str
:param context: BPY context
:type context: bpy.types.Context
:param error_callback: error handler
:type error_callback: func(message, is_fatal)
"""
from .oculus import Oculus
from .oculus_legacy import OculusLegacy
from .debug import Debug
displays = {
'OCULUS':Oculus,
'OCULUS_LEGACY':OculusLegacy,
'DEBUG':Debug,
}
if display_backend not in displays:
assert False, "Display Backend \"{0}\" not implemented".format(display_backend)
return displays[display_backend](error_callback)
return displays[display_backend](context, error_callback)
# ############################################################
......@@ -59,7 +63,7 @@ class HMD_Base:
"_modelview_matrix",
}
def __init__(self, name, error_callback):
def __init__(self, name, context, error_callback):
self._name = name
self._error_callback = error_callback
self._current_eye = 0
......@@ -72,6 +76,8 @@ class HMD_Base:
self._offscreen_object = [None, None]
self._eye_orientation_raw = [[i for i in range(4)], [i for i in range(4)]]
self._eye_position_raw = [[i for i in range(3)], [i for i in range(3)]]
self._scale = self._calculateScale(context)
@property
def width(self):
......@@ -217,3 +223,35 @@ class HMD_Base:
near = camera.clip_start
far = camera.clip_end
return near, far
def _calculateScale(self, context):
"""
if BU != 1 meter, scale the transformations
"""
scene = context.scene
unit_settings = scene.unit_settings
system = unit_settings.system
if system == 'NONE':
return None
elif system == 'METRIC':
return 1.0 / unit_settings.scale_length
elif system == 'IMPERIAL':
return 0.3048 / unit_settings.scale_length
else:
assert('Unit system not supported ({0})'.format(system))
def _scaleMovement(self, position):
"""
if BU != 1 meter, scale the transformations
"""
if self._scale is None:
return position
return [position[0] * self._scale,
position[1] * self._scale,
position[2] * self._scale]
......@@ -15,8 +15,8 @@ def print_debug(*args):
class Debug(HMD_Base):
def __init__(self, error_callback):
super(Debug, self).__init__('Debug', error_callback)
def __init__(self, context, error_callback):
super(Debug, self).__init__('Debug', context, error_callback)
def init(self, context):
"""
......
......@@ -16,23 +16,13 @@ from ..lib import (
)
class Oculus(HMD_Base):
def __init__(self, error_callback):
super(Oculus, self).__init__('Oculus', error_callback)
def __init__(self, context, error_callback):
super(Oculus, self).__init__('Oculus', context, error_callback)
checkModule('oculus_sdk_bridge')
# self._debug()
def _debug(self):
import bridge
import bridge_wrapper
input = 3
device = bridge_wrapper.Debug_new(input)
factor = bridge_wrapper.Debug_multiplicationFactor()
print("Multiplication factor is {0}".format(factor))
output = bridge_wrapper.Debug_multiplicationResult(device)
print("Return of {0} is {1}".format(input, output))
def _getHMDClass(self):
from bridge.oculus import HMD
return HMD
def init(self, context):
"""
......@@ -42,7 +32,7 @@ class Oculus(HMD_Base):
:rtype: bool
"""
try:
from bridge.oculus import HMD
HMD = self._getHMDClass()
self._hmd = HMD()
# gather arguments from HMD
......
......@@ -137,7 +137,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
vr.error_message = ""
display_backend = getDisplayBackend(context)
self._hmd = HMD(display_backend, self._error_callback)
self._hmd = HMD(display_backend, context, self._error_callback)
self._preview = Preview()
if not self._hmd.init(context):
......
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