def _startOculus(self): from oculusvr import ( Hmd, cast, POINTER, ovrHmdDesc, ovrVector3f, ) try: Hmd.initialize() except SystemError as err: self.logger.error( "Oculus initialization failed, check the physical connections and run again" ) if Hmd.detect() == 1: self._hmd = Hmd() self._description = cast(self._hmd.hmd, POINTER(ovrHmdDesc)).contents self._frame = 0 self._eyes_offset = [ovrVector3f(), ovrVector3f()] self._eyes_offset[0] = 0.0, 0.0, 0.0 self._eyes_offset[1] = 0.0, 0.0, 0.0 self._hmd.configure_tracking() self.logger.info(self._description.ProductName) else: self.logger.error("Oculus not connected") raise Exception
def _startOculus(self): from oculusvr import ( Hmd, cast, POINTER, ovrHmdDesc, ovrVector3f, ) try: Hmd.initialize() except SystemError as err: self.logger.error("Oculus initialization failed, check the physical connections and run again") if Hmd.detect() == 1: self._hmd = Hmd() self._description = cast(self._hmd.hmd, POINTER(ovrHmdDesc)).contents self._frame = 0 self._eyes_offset = [ ovrVector3f(), ovrVector3f() ] self._eyes_offset[0] = 0.0, 0.0, 0.0 self._eyes_offset[1] = 0.0, 0.0, 0.0 self._hmd.configure_tracking() self.logger.info(self._description.ProductName) else: self.logger.error("Oculus not connected") raise Exception
def quit(self): from oculusvr import Hmd if self._camera: self._camera.matrix_world = self._matrix_world self._camera.data.lens = self._lens if Hmd.detect() == 1: self._hmd.destroy() self._hmd = None Hmd.shutdown()
def _getMatrix(self): from oculusvr import Hmd from mathutils import ( Quaternion, Matrix, ) if self._hmd and Hmd.detect() == 1: self._frame += 1 poses = self._hmd.get_eye_poses(self._frame, self._eyes_offset) # oculus may be returning the matrix for both eyes # but we are using a single eye without offset rotation_raw = poses[0].Orientation.toList() position_raw = poses[0].Position.toList() rotation = Quaternion(rotation_raw).to_matrix().to_4x4() position = Matrix.Translation(position_raw) matrix = position * rotation matrix.invert() return matrix return None
class OculusDK2(base.Base): def __init__(self, parent, configuration): super(OculusDK2, self).__init__(parent) self._user = None self._hmd = None self._description = None self._matrix = None self.checkLibraryPath() try: from oculusvr import Hmd assert (Hmd) except ImportError: self.logger.info( 'Oculus DK2 plugin error: no \"oculusvr\" module available. Make sure you have the projec submodules. Please refer to the BlenderVR documentation' ) self._available = False return except Exception as err: self.logger.error(err) self._available = False return if 'users' in configuration: for user_entry in configuration['users']: try: _user = user.User(self, user_entry) if _user.isAvailable(): viewer = _user.getUser() if viewer is not None: self._user = _user # each computer can only have one user/viewer break except: self.logger.log_traceback(False) self._available = True def start(self): super(OculusDK2, self).start() from mathutils import Matrix try: self._matrix = Matrix.Identity(4) self._startOculus() except Exception: self._available = False def run(self): super(OculusDK2, self).run() try: self._updateMatrix() info = {'matrix': self._matrix} self._user.run(info) except Exception as err: self.logger.log_traceback(err) def _updateMatrix(self): try: matrix = self._getMatrix() if matrix: self._matrix = matrix except Exception as err: self.logger.log_traceback(err) def checkMethods(self): if not self._available: self.logger.info('Oculus DK2 python module not available !') return False if not self._user: self.logger.info( 'Oculus DK2 python module not available ! No valid user found for this computer.' ) return False if not self._user.checkMethod(True): self.logger.info('No Oculus DK2 processor method available !') del self._user self._user = None return False return True def checkLibraryPath(self): """if library exists append it to sys.path""" import sys import os from .... import tools libs_path = tools.getLibsPath() oculus_path = "/".join((libs_path, "python-ovrsdk")) if oculus_path not in sys.path: sys.path.append(oculus_path) def _startOculus(self): from oculusvr import ( Hmd, cast, POINTER, ovrHmdDesc, ovrVector3f, ) try: Hmd.initialize() except SystemError as err: self.logger.error( "Oculus initialization failed, check the physical connections and run again" ) if Hmd.detect() == 1: self._hmd = Hmd() self._description = cast(self._hmd.hmd, POINTER(ovrHmdDesc)).contents self._frame = 0 self._eyes_offset = [ovrVector3f(), ovrVector3f()] self._eyes_offset[0] = 0.0, 0.0, 0.0 self._eyes_offset[1] = 0.0, 0.0, 0.0 self._hmd.configure_tracking() self.logger.info(self._description.ProductName) else: self.logger.error("Oculus not connected") raise Exception def _getMatrix(self): from oculusvr import Hmd from mathutils import ( Quaternion, Matrix, ) if self._hmd and Hmd.detect() == 1: self._frame += 1 poses = self._hmd.get_eye_poses(self._frame, self._eyes_offset) # oculus may be returning the matrix for both eyes # but we are using a single eye without offset rotation_raw = poses[0].Orientation.toList() position_raw = poses[0].Position.toList() rotation = Quaternion(rotation_raw).to_matrix().to_4x4() position = Matrix.Translation(position_raw) matrix = position * rotation matrix.invert() return matrix return None
class OculusDK2(base.Base): def __init__(self, parent, configuration): super(OculusDK2, self).__init__(parent) self._user = None self._hmd = None self._description = None self._matrix = None self.checkLibraryPath() try: from oculusvr import Hmd assert(Hmd) except ImportError: self.logger.info('Oculus DK2 plugin error: no \"oculusvr\" module available. Make sure you have the projec submodules. Please refer to the BlenderVR documentation') self._available = False return except Exception as err: self.logger.error(err) self._available = False return if 'users' in configuration: for user_entry in configuration['users']: try: _user = user.User(self, user_entry) if _user.isAvailable(): viewer = _user.getUser() if viewer is not None: self._user = _user # each computer can only have one user/viewer break except: self.logger.log_traceback(False) self._available = True def start(self): super(OculusDK2, self).start() from mathutils import Matrix try: self._matrix = Matrix.Identity(4) self._startOculus() except Exception: self._available = False def run(self): super(OculusDK2, self).run() try: self._updateMatrix() info = {'matrix' : self._matrix} self._user.run(info) except Exception as err: self.logger.log_traceback(err) def _updateMatrix(self): try: matrix = self._getMatrix() if matrix: self._matrix = matrix except Exception as err: self.logger.log_traceback(err) def checkMethods(self): if not self._available: self.logger.info('Oculus DK2 python module not available !') return False if not self._user: self.logger.info('Oculus DK2 python module not available ! No valid user found for this computer.') return False if not self._user.checkMethod(True): self.logger.info('No Oculus DK2 processor method available !') del self._user self._user = None return False return True def checkLibraryPath(self): """if library exists append it to sys.path""" import sys import os from .... import tools libs_path = tools.getLibsPath() oculus_path = "/".join((libs_path, "python-ovrsdk")) if oculus_path not in sys.path: sys.path.append(oculus_path) def _startOculus(self): from oculusvr import ( Hmd, cast, POINTER, ovrHmdDesc, ovrVector3f, ) try: Hmd.initialize() except SystemError as err: self.logger.error("Oculus initialization failed, check the physical connections and run again") if Hmd.detect() == 1: self._hmd = Hmd() self._description = cast(self._hmd.hmd, POINTER(ovrHmdDesc)).contents self._frame = 0 self._eyes_offset = [ ovrVector3f(), ovrVector3f() ] self._eyes_offset[0] = 0.0, 0.0, 0.0 self._eyes_offset[1] = 0.0, 0.0, 0.0 self._hmd.configure_tracking() self.logger.info(self._description.ProductName) else: self.logger.error("Oculus not connected") raise Exception def _getMatrix(self): from oculusvr import Hmd from mathutils import ( Quaternion, Matrix, ) if self._hmd and Hmd.detect() == 1: self._frame += 1 poses = self._hmd.get_eye_poses(self._frame, self._eyes_offset) # oculus may be returning the matrix for both eyes # but we are using a single eye without offset rotation_raw = poses[0].Orientation.toList() position_raw = poses[0].Position.toList() rotation = Quaternion(rotation_raw).to_matrix().to_4x4() position = Matrix.Translation(position_raw) matrix = position * rotation matrix.invert() return matrix return None
class Oculus(): def __init__(self, camera, report): self._report = report self._available = True self._hmd = None self._description = None self._camera = camera self._matrix_world = camera.matrix_world.copy() self._lens = camera.data.lens self._checkModule() self._start() def isAvailable(self): return self._available def _checkModule(self): """if library exists append it to sys.path""" import sys import os addon_path = os.path.dirname(os.path.abspath(__file__)) oculus_path = os.path.join(addon_path, "lib", "python-ovrsdk") if oculus_path not in sys.path: sys.path.append(oculus_path) def _start(self): try: from oculusvr import ( Hmd, cast, POINTER, ovrHmdDesc, ovrVector3f, ) Hmd.initialize() except SystemError as err: self._error("Oculus initialization failed, check the physical connections and run again") return if Hmd.detect() == 1: self._hmd = Hmd() self._description = cast(self._hmd.hmd, POINTER(ovrHmdDesc)).contents self._frame = 0 self._eyes_offset = [ ovrVector3f(), ovrVector3f() ] self._eyes_offset[0] = 0.0, 0.0, 0.0 self._eyes_offset[1] = 0.0, 0.0, 0.0 self._hmd.configure_tracking() print(self._description.ProductName) self._camera.data.lens = 16 else: self._error("Oculus not connected") def _error(self, message): self._report({'ERROR'}, message) self._available = False def update(self): # update the camera matrix = self._getMatrix() if not matrix: return self._camera.matrix_world = self._matrix_world * matrix def quit(self): from oculusvr import Hmd if self._camera: self._camera.matrix_world = self._matrix_world self._camera.data.lens = self._lens if Hmd.detect() == 1: self._hmd.destroy() self._hmd = None Hmd.shutdown() def _getMatrix(self): from oculusvr import Hmd from mathutils import ( Quaternion, Matrix, ) if self._hmd and Hmd.detect() == 1: self._frame += 1 poses = self._hmd.get_eye_poses(self._frame, self._eyes_offset) # oculus may be returning the matrix for both eyes # but we are using a single eye without offset rotation_raw = poses[0].Orientation.toList() position_raw = poses[0].Position.toList() rotation = Quaternion(rotation_raw).to_matrix().to_4x4() position = Matrix.Translation(position_raw) matrix = position * rotation return matrix return None