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