def start_vr(self):
        hmd = steamvr.HMD()
        if not hmd.getSensor():
            sys.exit('SteamVR HMD not detected')
        viz.link(hmd.getSensor(), viz.MainView)

        # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
        hmd_stream = self.subject.create_non_phasespace_rigid_body_stream('headRigid', 0)
        # stream 6dof of HMD as pos (x,y,z) and ori(x,y,z,w) --> quaternion
        vizact.onupdate(0, self.subject.update_and_push_rigid_body, viz.MainView, self.subject.head_sphere, hmd_stream)

        #  connecting present controllers
        trackers = steamvr.getTrackerList()
        self.controller = steamvr.getControllerList()[0]
        print self.controller
        tracker_names = ['handRigid', 'armRigid', 'torsoRigid']

        find_out_tracker = vizact.onupdate(0, self.assign_trackers, trackers)
        yield viztask.waitTime(5) # wait two seconds to figure out which tracker is more to the front in z direction = hand tracker
        find_out_tracker.remove()
        
        # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
        # stream 6dof as pos (x,y,z) and ori(x,y,z,w) --> quaternion
        hand_stream = self.subject.create_non_phasespace_rigid_body_stream(tracker_names[self.hand_tracker_id], 0)
        vizact.onupdate(0, self.subject.update_and_push_rigid_body, trackers[self.hand_tracker_id], self.subject.right_hand_sphere, hand_stream)
        
        # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
        arm_stream = self.subject.create_non_phasespace_rigid_body_stream(tracker_names[self.arm_tracker_id], 0)
        vizact.onupdate(0, self.subject.update_and_push_rigid_body, trackers[self.arm_tracker_id], None, arm_stream)

        # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
        torso_stream = self.subject.create_non_phasespace_rigid_body_stream(tracker_names[self.torso_tracker_id], 0)
        vizact.onupdate(0, self.subject.update_and_push_rigid_body, trackers[self.torso_tracker_id], None, torso_stream)
    def steamvr_setup_vm2(self, right_hand_object, head_object):

        hmd = steamvr.HMD()
        if not hmd.getSensor():
            sys.exit('SteamVR HMD not detected')
        viz.link(hmd.getSensor(), viz.MainView)

        # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
        hmd_stream = self.create_non_phasespace_rigid_body_stream(
            'headRigid', 0)
        # stream 6dof of HMD as pos (x,y,z) and ori(x,y,z,w) --> quaternion
        vizact.onupdate(18, self.update_and_push_rigid_body, viz.MainView,
                        head_object, hmd_stream)

        #  connecting present controllers
        trackers = steamvr.getTrackerList()
        self.controller = steamvr.getControllerList()[0]
        tracker_names = ['handRigid', 'torsoRigid']

        for i in range(len(trackers)):
            # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
            tracker_stream = self.create_non_phasespace_rigid_body_stream(
                tracker_names[i], 0)
            # stream 6dof as pos (x,y,z) and ori(x,y,z,w) --> quaternion

            print(trackers[i].getData())
            print(trackers[i].getPosition())

            if i == 0:
                vizact.onupdate(19, self.update_and_push_rigid_body,
                                trackers[i], right_hand_object, tracker_stream)
            else:
                vizact.onupdate(19, self.update_and_push_rigid_body,
                                trackers[i], None, tracker_stream)
def initDisplays(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
    #VC: place any general initialization code here
    rawDisplay = vizconnect.getRawDisplayDict()

    #VC: initialize a new display
    _name = 'main_display'
    if vizconnect.isPendingInit('display', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set the window for the display
            _window = viz.MainWindow

            #VC: set some parameters
            index = 0

            #VC: create the raw object
            import steamvr
            # Get sensor from extension if not specified
            hmd = None
            sensor = None
            hmdList = steamvr.getExtension().getHMDList()
            if hmdList:
                try:
                    sensor = hmdList[index]
                except IndexError:
                    viz.logError("** ERROR: Not enough HMD's")
            else:
                viz.logError('** ERROR: Failed to detect SteamVR HMD')
            if sensor:
                hmd = steamvr.HMD(sensor=sensor, window=_window)
                hmd.setMonoMirror(True)
            _window.displayNode = hmd
            rawDisplay[_name] = _window

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addDisplay(rawDisplay[_name],
                                  _name,
                                  make='Valve',
                                  model='SteamVR HMD')

        #VC: set the parent of the node
        if initFlag & vizconnect.INIT_PARENTS:
            vizconnect.getDisplay(_name).setParent(
                vizconnect.getAvatar('main_avatar').getAttachmentPoint('head'))

    #VC: set the name of the default
    vizconnect.setDefault('display', 'main_display')

    #VC: return values can be modified here
    return None
Пример #4
0
def InitVive():
    viz.setMultiSample(8)
    # Setup SteamVR HMD
    hmd = steamvr.HMD()
    if not hmd.getSensor():
        sys.exit('SteamVR HMD not detected')

    navigationNode = viz.addGroup()
    viewLink = viz.link(navigationNode, viz.MainView)
    viewLink.preMultLinkable(hmd.getSensor())

    # setting starting camera position and rotation of the view
    navigationNode.setEuler(180, 0, 0)
    navigationNode.setPosition(-0, 0.3, 3.0)

    # setting starting camera position and rotation
    viz.MainView.setEuler([180, 0, 0])
    viz.MainView.setPosition([0, 1.3, 4])
def main():
    # Initialize window
    viz.setMultiSample(8)
    viz.go()

    # Setup SteamVR HMD
    hmd = steamvr.HMD()
    if not hmd.getSensor():
        sys.exit('SteamVR HMD not detected')

    # Setup navigation node and link to main view
    navigationNode = viz.addGroup()
    viewLink = viz.link(navigationNode, viz.MainView)
    viewLink.preMultLinkable(hmd.getSensor())

    # Load environment
    gallery = vizfx.addChild('gallery.osgb')
    gallery.hint(viz.OPTIMIZE_INTERSECT_HINT)
    gallery.disable(viz.SHADOW_CASTING)

    #Create skylight
    viz.MainView.getHeadLight().disable()
    sky_light = viz.addDirectionalLight(euler=(0,90,0), color=viz.WHITE)
    sky_light.setShadowMode(viz.SHADOW_DEPTH_MAP)
    
    #Start the Leap Motion!
    handGenerator = LeapListener()
    handGenerator.startLeap(hmd.getSensor())
    
    # Add controllers
    for controller in steamvr.getControllerList():

        # Create model for controller
        controller.model = controller.addModel(parent=navigationNode)
        controller.model.disable(viz.INTERSECTION)
        viz.link(controller, controller.model)
Пример #6
0
sphere_size = .015
depth = 2 # m
confidence_level = .2





# initialize window
viz.setMultiSample(8)
viz.fov(60)
viz.go()

# setup SteamVR HMD
hmd = steamvr.HMD()
if not hmd.getSensor():
	sys.exit('SteamVR HMD not detected')
	
# setup navigation node and link to main view
navigationNode = viz.addGroup()
viewLink = viz.link(navigationNode, viz.MainView)
viewLink.preMultLinkable(hmd.getSensor())



# create a zmq REQ socket to talk to Pupil Service
ctx = zmq.Context()
req = ctx.socket(zmq.REQ)
addr = '134.176.175.219'
sub_port = '50020'
Пример #7
0
# h - Face Down		f - Fly Down
if controlType == MONITOR:
	HZ = 60
	headTrack = viztracker.Keyboard6DOF()
	link = viz.link(headTrack, viz.MainView)
	headTrack.eyeheight(1.6)
	link.setEnabled(True)
	viz.go()

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
# Use HMD
elif controlType == HMD:
	HZ = 90
	# viz.fullscreen.x is the inital x position when run	
	# add Odyssey tracker
	ODTracker = steamvr.HMD().getSensor()

	# add the virtual tracker, link it to the MainView and set an offset to get the eye position
	link = viz.link(ODTracker, viz.MainView)

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


viz.clip(.001,1000) # Adjust size of the viewing frustum
viz.go()


######################################################################################################
# Helper functions
def goToStage(nextTrialStage):
	global trial_stage
Пример #8
0
    def findDevices(self):
        """ Enumerate SteamVR devices and set up models """

        # HMD
        hmd = steamvr.HMD()
        self.hmd['sensor'] = hmd.getSensor()

        hmd_ui = viz.addText('N/A')
        self._ui.addItem(viz.addText('Headset'))        
        self._ui.addLabelItem('0', hmd_ui)
        self._ui.addSeparator()
        self.hmd['ui'] = hmd_ui

        hud = viz.addText3D('X: 0.00 (123.0°)', scale=(self.VALUE_SCALE * 2.5,) * 3, color=viz.GRAY)
        hud_link = viz.link(viz.MainView, hud)
        hud_link.preTrans(self.HUD_POS, viz.REL_LOCAL)
        self.hmd['hud'] = hud
        self._obj.append(hud)

        # Lighthouses
        for lidx, lighthouse in enumerate(steamvr.getCameraList()):
            lighthouse.model = lighthouse.addModel(parent=self._root)
            if not lighthouse.model:
                lighthouse.model = viz.addGroup()
            lighthouse.model.setCompositeAlpha(self.DEBUG_ALPHA)
            lighthouse.model.disable(viz.INTERSECTION)
            viz.link(lighthouse, lighthouse.model)
            
            l_text = viz.addText3D(str(lidx), scale=(self.LABEL_SCALE,) * 3, color=viz.YELLOW,
                                parent=lighthouse.model, pos=(0.1, 0, 0))
            l_text.setEuler(180, 0, 0)
            
            # Lighthouse normal vector
            l_normal = addRayPrimitive(origin=[0,0,0], direction=[0,0,1], color=viz.YELLOW, parent=lighthouse.model)
            l_normal.visible(False)

            self.lighthouses[lidx] = {'model': lighthouse.model,
                                      'normal': l_normal,
                                      'text': l_text}
            self._obj.append(lighthouse.model)
            print('* Found Lighthouse: {:d}'.format(lidx))

        # Controllers
        if steamvr.getControllerList():
            self._ui.addItem(viz.addText('Controllers'))

            for cidx, controller in enumerate(steamvr.getControllerList()):
                
                controller.model = controller.addModel(parent=self._root)
                if not controller.model:
                    controller.model = viz.addGroup(parent=self._root)
                controller.model.setCompositeAlpha(self.DEBUG_ALPHA)
                controller.model.disable(viz.INTERSECTION)
                viz.link(controller, controller.model)
                
                c_axes = vizshape.addAxes(scale=(0.1, 0.1, 0.1))
                viz.link(controller, c_axes)

                markers = {'axes': c_axes}
                for m in self._markers:
                    markers[m] = self._markers[m].copy()
                    markers[m].visible(False)
                    viz.link(controller, markers[m])

                c_text = viz.addText3D(str(cidx), scale=(self.LABEL_SCALE,) * 3, 
                                    parent=controller.model, pos=(-0.05, 0, 0))
                val_x = viz.addText3D('X: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=controller.model, pos=(-0.18, 0.04, 0), color=viz.RED)
                val_y = viz.addText3D('Y: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=controller.model, pos=(-0.18, 0.02, 0), color=viz.GREEN)
                val_z = viz.addText3D('Z: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=controller.model, pos=(-0.18, 0, 0), color=viz.BLUE)
                
                self.controllers[cidx] = {'model': controller.model,
                                          'axes': c_axes,
                                          'text': c_text,
                                          'values': [val_x, val_y, val_z],
                                          'ui': viz.addText('N/A'),
                                          'markers': markers,
                                          'active_marker': 'axes'}

                self._ui.addLabelItem(str(cidx), self.controllers[cidx]['ui'])
                self._obj.extend([controller.model, c_axes, val_x, val_y, val_z])
                print('* Found Controller: {:d}'.format(cidx))

                self._callbacks.append(vizact.onsensordown(controller, steamvr.BUTTON_TRIGGER, self._storePoint, controller, cidx))
                self._callbacks.append(vizact.onsensordown(controller, steamvr.BUTTON_TRACKPAD, self._switchMarker, cidx))
                self._callbacks.append(vizact.onsensordown(controller, 1, self.savePoints))
                self._callbacks.append(vizact.onsensordown(controller, 0, self.saveScreenshot))
        else:
            print('* No controllers detected.')

        # Trackers
        if steamvr.getTrackerList():
            self._ui.addSeparator()
            self._ui.addItem(viz.addText('Trackers'))

            for tidx, tracker in enumerate(steamvr.getTrackerList()):
                
                tracker.model = tracker.addModel(parent=self._root)
                if not tracker.model:
                    tracker.model = viz.addGroup(parent=self._root)
                tracker.model.setCompositeAlpha(self.DEBUG_ALPHA)
                tracker.model.disable(viz.INTERSECTION)
                viz.link(tracker, tracker.model)

                t_axes = vizshape.addAxes(scale=(0.1, 0.1, 0.1))
                viz.link(tracker, t_axes)

                t_text = viz.addText3D(str(tidx), scale=(0.05, 0.05, 0.05), color=viz.BLUE,
                                    parent=tracker.model, pos=(-0.1, 0, 0))
                val_x = viz.addText3D('X: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=tracker.model, pos=(0.18, 0.04, 0), color=viz.RED)
                val_x.setEuler([180, 0, 0], mode=viz.REL_LOCAL)
                val_y = viz.addText3D('Y: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=tracker.model, pos=(0.18, 0.02, 0), color=viz.GREEN)
                val_y.setEuler([180, 0, 0], mode=viz.REL_LOCAL)
                val_z = viz.addText3D('Z: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=tracker.model, pos=(0.18, 0, 0), color=viz.BLUE)
                val_z.setEuler([180, 0, 0], mode=viz.REL_LOCAL)

                self.trackers[tidx] = {'model': tracker.model,
                                       'axes': t_axes,
                                       'text': t_text,
                                       'values': [val_x, val_y, val_z],
                                       'ui': viz.addText('N/A')}
                self._ui.addLabelItem(str(tidx), self.trackers[tidx]['ui'])
                self._obj.extend([tracker.model, t_axes, val_x, val_y, val_z])
                print('* Found Vive tracker: {:d}'.format(tidx))
        else:
            print('* No trackers detected.')