Example #1
0
    class Processor(blendervr.processor.getProcessor()):
        def __init__(self, parent):
            super(Processor, self).__init__(parent)

            if self.BlenderVR.isMaster():
                self.BlenderVR.getSceneSynchronizer().getItem(bge.logic).activate(True, True)

                from blendervr.interactor.head_controlled_navigation import HCNav

                self._navigator = HCNav(self, method=None, one_per_user=True)
                self._user = self.BlenderVR.getUserByName('user A')
                self._navigator.setDefaultUser(self._user)
                self.registerInteractor(self._navigator)
                self._navigator.setPositionFactors(1, 20.0, 1.0)

                from blendervr.interactor.viewpoint import ViewPoint

                self._viewpoint = ViewPoint(self)
                self._viewpoint.viewpointScale = 0.2
                self.registerInteractor(self._viewpoint)

        def keyboardAndMouse(self, info):
            """
            Function called by the processor during running-time everytime a key
            is pressed or a mouse event is triggered.
            """
            try:
                from blendervr.player import device

                if info['state'] == device.STATE_PRESS:
                    if info['key'] == ord('q'):
                        self.BlenderVR.quit("pressed 'q' key")

                    elif info['key'] == ord('v'):
                        self._viewpoint.activation(not self._viewpoint.isActivated())

                    # Head Navigation Setup
                    elif info['key'] == ord('1'):
                        self.logger.info("Calibrating Navigation")
                        self._navigator.update(self._navigator.CALIBRATE, self._user)

                    elif info['key'] == ord('2'):
                        self.logger.info("Start Navigation")
                        self._navigator.update(self._navigator.TOGGLE, self._user)

                    elif info['key'] == ord('3'):
                        self.logger.info("Reset Navigation")
                        self.reset()

                    elif info['key'] == ord('4'):
                        self.logger.info("Quitting")
                        self.BlenderVR.quit("Because user asked!")

            except (KeyError, SystemExit):
                pass

            except Exception as err:
                self.logger.log_traceback(err)

            super(Processor, self).keyboardAndMouse(info)

        def reset(self):
            """
            Reset all the user position and orientations.
            A new calibration will be required.
            """
            if not hasattr(self, '_navigator'):
                return

            self._navigator.update(self._navigator.RESET, self._user)
            self._user.resetVehiclePosition()

        def user_position(self, info):
            """
            Callback for one of the sensors of a tracker device.
            Defined in the XML config file.

            Callback defined in the XML config file to one of the VRPN tracker sensors
            """
            super(Processor, self).user_position(info)

            try:
                for user in info['users']:
                    if user == self._user:
                        self._navigator.setHeadLocation(user, info)

            except Exception as err:
                self.logger.log_traceback(err)
Example #2
0
    class Common(blendervr.processor.getProcessor()):
        def __init__(self,
                     parent,
                     head_navigator=None,
                     laser=False,
                     use_viewpoint=False):
            super(Common, self).__init__(parent)

            if laser:
                controller = bge.logic.getCurrentController()
                from blendervr.interactor.laser import Laser
                self._laser = Laser(self, controller.owner,
                                    controller.sensors[laser])

            if self.BlenderVR.isMaster() and head_navigator is not None:
                if type(head_navigator) is not dict:
                    head_navigator = {}
                if 'method' not in head_navigator:
                    head_navigator['method'] = None
                if 'one_per_user' not in head_navigator:
                    head_navigator['one_per_user'] = True

                from blendervr.interactor.head_controlled_navigation import (
                    HCNav)
                self._navigator = HCNav(
                    self,
                    method=head_navigator['method'],
                    one_per_user=head_navigator['one_per_user'])
                self._navigator.setDefaultUser(
                    self.BlenderVR.getUserByName('user A'))
                self.registerInteractor(self._navigator)

            if use_viewpoint:
                from blendervr.interactor.viewpoint import ViewPoint
                self._viewpoint = ViewPoint(self)
                self._viewpoint.viewpointScale = 0.2
                self.registerInteractor(self._viewpoint)

        def user_position(self, info):
            super(Common, self).user_position(info)
            if hasattr(self, '_navigator'):
                for user in info['users']:
                    self._navigator.setHeadLocation(user, info)

        def tracker_1(self, info):
            if hasattr(self, '_laser'):
                obj = self._laser.getObject()
                obj.localPosition = info['matrix'].to_translation()
                obj.localOrientation = info['matrix'].to_3x3() \
                    * mathutils.Matrix.Rotation(math.radians(-90.0), 3, 'X')

        def texts(self, info):
            self.logger.debug(info['message'])
            if info['message'] == 'COMPUTER QUIT':
                self.BlenderVR.quit("because user asked !")
            if hasattr(self, '_navigator'):
                cmd = None
                if info['message'] == 'COMPUTER CALIBRATION':
                    cmd = self._navigator.CALIBRATE
                elif info['message'] == 'COMPUTER NAVIGATION':
                    cmd = self._navigator.TOGGLE
                elif info['message'] == 'COMPUTER HOME':
                    self.reset(info['users'])

                if cmd is not None:
                    for user in info['users']:
                        self._navigator.update(cmd, user)
                    self.sendToConsole('navigation_state',
                                       self._navigator.getNavigationState())

        def reset(self, users=None):
            if not hasattr(self, '_navigator'):
                return
            if users is None:
                users = list(self.BlenderVR.getAllUsers().values())
            for user in users:
                self._navigator.update(self._navigator.RESET, user)
                user.resetVehiclePosition()

        def keyboardAndMouse(self, info):
            try:
                if info['key'] == ord('q'):
                    self.BlenderVR.quit("pressed 'q' key")
                if (info['key'] == ord('v')
                        and info['state'] == device.STATE_PRESS
                        and hasattr(self, '_viewpoint')):
                    self._viewpoint.activation(
                        not self._viewpoint.isActivated())
                    return
            except (KeyError, SystemExit):
                pass
            except:
                self.logger.log_traceback(False)
            super(Common, self).keyboardAndMouse(info)
Example #3
0
    class Common(blendervr.processor.getProcessor()):
        def __init__(self, parent, head_navigator=None, laser=False,
                                                    use_viewpoint=False):
            super(Common, self).__init__(parent)

            if laser:
                controller = bge.logic.getCurrentController()
                from blendervr.interactor.laser import Laser
                self._laser = Laser(self, controller.owner,
                                                controller.sensors[laser])

            if self.BlenderVR.isMaster() and head_navigator is not None:
                if type(head_navigator) is not dict:
                    head_navigator = {}
                if 'method' not in head_navigator:
                    head_navigator['method'] = None
                if 'one_per_user' not in head_navigator:
                    head_navigator['one_per_user'] = True

                from blendervr.interactor.head_controlled_navigation import (
                                                                        HCNav)
                self._navigator = HCNav(self, method=head_navigator['method'],
                                one_per_user=head_navigator['one_per_user'])
                self._navigator.setDefaultUser(
                                        self.BlenderVR.getUserByName('user A'))
                self.registerInteractor(self._navigator)

            if use_viewpoint:
                from blendervr.interactor.viewpoint import ViewPoint
                self._viewpoint = ViewPoint(self)
                self._viewpoint.viewpointScale = 0.2
                self.registerInteractor(self._viewpoint)

        def user_position(self, info):
            super(Common, self).user_position(info)
            if hasattr(self, '_navigator'):
                for user in info['users']:
                    self._navigator.setHeadLocation(user, info)

        def tracker_1(self, info):
            if hasattr(self, '_laser'):
                obj = self._laser.getObject()
                obj.localPosition = info['matrix'].to_translation()
                obj.localOrientation = info['matrix'].to_3x3() \
                    * mathutils.Matrix.Rotation(math.radians(-90.0), 3, 'X')

        def texts(self, info):
            self.logger.debug(info['message'])
            if info['message'] == 'COMPUTER QUIT':
                self.BlenderVR.quit("because user asked !")
            if hasattr(self, '_navigator'):
                cmd = None
                if info['message'] == 'COMPUTER CALIBRATION':
                    cmd = self._navigator.CALIBRATE
                elif info['message'] == 'COMPUTER NAVIGATION':
                    cmd = self._navigator.TOGGLE
                elif info['message'] == 'COMPUTER HOME':
                    self.reset(info['users'])

                if cmd is not None:
                    for user in info['users']:
                        self._navigator.update(cmd, user)
                    self.sendToConsole('navigation_state',
                                self._navigator.getNavigationState())

        def reset(self, users = None):
            if not hasattr(self, '_navigator'):
                return
            if users is None:
                users = list(self.BlenderVR.getAllUsers().values())
            for user in users:
                self._navigator.update(self._navigator.RESET, user)
                user.resetVehiclePosition()

        def keyboardAndMouse(self, info):
            try:
                if info['key'] == ord('q'):
                    self.BlenderVR.quit("pressed 'q' key")
                if (info['key'] == ord('v')
                        and info['state'] == device.STATE_PRESS
                        and hasattr(self, '_viewpoint')):
                    self._viewpoint.activation(
                                    not self._viewpoint.isActivated())
                    return
            except (KeyError, SystemExit):
                pass
            except:
                self.logger.log_traceback(False)
            super(Common, self).keyboardAndMouse(info)