def __init__(self, autoDetectMonitor=True, sensor=None, stereo=viz.STEREO_HORZ, cluster_stereo=None, window=viz.MainWindow, renderMode=None):
		"""@arg sensor getExtension().addHMD()"""
		viz.EventClass.__init__(self)

		# Get sensor from extension if not specified
		if sensor is None:
			allSensors = getSensors()
			if allSensors:
				sensor = allSensors[0]
			else:
				viz.logError('** ERROR: Failed to detect Oculus HMD')

		# Render mode not supported
		if renderMode is not None:
			viz.EmitDeprecationWarning("Render mode option has been removed from the Oculus SDK. Command will be removed in a future version of Vizard.")

		#Save parameters
		self._stereo = stereo
		self._cluster_stereo = cluster_stereo
		self._lastAppliedWindow = window
		self._sensor = sensor
		self._effect = _OculusEffect(self._sensor, priority=1000)
		self._hud_root = None

		#Apply settings
		if window is not None:
			self.apply(window)
			if self._sensor:
				vizfx.postprocess.addEffect(self._effect,window)
				manager = vizfx.postprocess.getEffectManager(window)
				manager.setRenderScale(1.0)
				manager.setRenderSize(self._sensor.getRenderSize())
	def __init__(self):
		super(self.__class__,self).__init__()
		
		# --Override Key commands
		self.KEYS = { 'forward'	: 'w'
					,'back' 	: 's'
					,'left' 	: 'a'
					,'right'	: 'd'
					,'camera'	: 'c'
					,'restart'	: viz.KEY_END
					,'home'		: viz.KEY_HOME
					,'utility'	: ' '
					,'reset'	: 0
					,'showMenu' : 1
					,'down'		: 2
					,'orient'	: 3
					,'up'		: 4
					,'mode'		: 5
					,'builder'	: 6
					,'walk'		: 7
					,'angles'	: 8
					,'road'		: 10
					,'esc'		: 999
					,'slideFar'	: 0
					,'slideNear': 180
					,'env'		: '-'
					,'grid'		: '-'
					,'snapMenu'	: viz.KEY_CONTROL_L
					,'interact' : viz.MOUSEBUTTON_LEFT
					,'rotate'	: viz.MOUSEBUTTON_RIGHT
					,'proxi'	: 'p'
					,'viewer'	: 'o'
					,'collide'	: 'c'
					,'stereo' 	: 'm'
					,'hand'		: 'h'
					,'capslock'	: viz.KEY_CAPS_LOCK
		}
		
		# Get device from extension if not specified
		self.device = None
		if self.device is None:
			allDevices = getDevices()
			if allDevices:
				self.device = allDevices[0]	
			else:
				viz.logError('** ERROR: Failed to detect Joystick')

		# Connect to selected device
		self.joy = getExtension().addJoystick(self.device)
		if not self.joy:
			viz.logError('** ERROR: Failed to connect to Joystick')
			return None

		# Set dead zone threshold so small movements of joystick are ignored
		self.joy.setDeadZone(0.2)
		
		#Override parameters
		self.ORIGIN_POS = [0,self.EYE_HEIGHT,0]
		self.VIEW_LINK.remove()
		self.VIEW_LINK = viz.link(self.VIEW,self.NODE)
	def __init__(self):		
		super(self.__class__,self).__init__()
		
		# Link navigation node to main view
#		self.NODE = viz.addGroup()
#		self.VIEW_LINK = viz.link(self.NODE, self.VIEW)
		
		# --add oculus as HMD
		self.hmd = oculus.Rift()
		
		if not self.hmd.getSensor():
			viz.logError('** ERROR: Failed to detect Oculus Rift')
		else:
			# Reset HMD orientation
			self.hmd.getSensor().reset()

			# Setup navigation node and link to main view
#			self.NODE = viz.addGroup()
#			self.VIEW_LINK = viz.link(self.NODE, viz.VIEW)
			self.VIEW_LINK.preMultLinkable(self.hmd.getSensor())

			# --Apply user profile eye height to view
			profile = self.hmd.getProfile()
			if profile:
				self.VIEW_LINK.setOffset([0,profile.eyeHeight,0])
				viz.logNotice('Oculus profile name:', profile.name)
				viz.logNotice('Oculus IPD:', profile.ipd)
				viz.logNotice('Oculus player height:', profile.playerHeight)
				viz.logNotice('Oculus eye height:', profile.eyeHeight)
			else: 
				self.VIEW_LINK.setOffset([0,self.EYE_HEIGHT,0])
				
			# Check if HMD supports position tracking
			supportPositionTracking = self.hmd.getSensor().getSrcMask() & viz.LINK_POS
			if supportPositionTracking:
				
				# Add camera bounds model
				self.camera_bounds = self.hmd.addCameraBounds()
				self.camera_bounds.visible(False)

				# Change color of bounds to reflect whether position was tracked
				def checkPositionTracked():
					if self.hmd.getSensor().getStatus() & oculus.STATUS_POSITION_TRACKED:
						self.camera_bounds.color(viz.GREEN)
					else:
						self.camera_bounds.color(viz.RED)
				vizact.onupdate(0, checkPositionTracked)

				# Setup camera bounds toggle key
				def toggleBounds():
					self.camera_bounds.visible(viz.TOGGLE)
				vizact.onkeydown(self.KEYS['camera'], toggleBounds)
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
def initDisplays(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
	#VC: place any general initialization code here
	rawDisplay = vizconnect.getRawDisplayDict()

	#VC: initialize a new display
	_name = 'steamvr_hmd'
	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)
			_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('white_male').getAttachmentPoint('head'))

	#VC: return values can be modified here
	return None
Beispiel #6
0
	def __init__(self, autoDetectMonitor=True, sensor=None, stereo=viz.STEREO_HORZ, cluster_stereo=None, window=viz.MainWindow):
		viz.EventClass.__init__(self)

		# Get sensor from extension if not specified
		if sensor is None:
			allSensors = getSensors()
			if allSensors:
				sensor = allSensors[0]
			else:
				viz.logError('** ERROR: Failed to detect Oculus HMD')

		#Save parameters
		self._stereo = stereo
		self._cluster_stereo = cluster_stereo
		self._lastAppliedWindow = window
		self._sensor = sensor
		self._effect = StereoEffect(_DistortionCorrectionEffect(),_DistortionCorrectionEffect(),priority=-1000)
		self._hud_root = None

		#Apply settings
		if window is not None:
			self.apply(window)
			if self._sensor:
				vizfx.postprocess.addEffect(self._effect,window)
				vizfx.postprocess.getEffectManager(window).setRenderScale(self._sensor.getRenderScale())

		if autoDetectMonitor:
			monitor = None
			if self._sensor:
				monitor = self._sensor.getMonitorNumber(default=None)
			if monitor is None:
				monitor = self.getMonitorNumber(default=None)
			if monitor is None:
				viz.logWarn('** WARNING: Failed to detect',self.MODEL_NAME,'HMD')
			else:
				viz.window.setFullscreenMonitor(monitor)

		#Handle window size
		self.callback(viz.WINDOW_SIZE_EVENT,self._onSize)
		self._updateViewport()
Beispiel #7
0
def initTrackers(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
    #VC: place any general initialization code here
    rawTracker = vizconnect.getRawTrackerDict()

    #VC: initialize a new tracker
    _name = 'vrpn'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            trackerId = 'Tracker0'
            ip = 'localhost'
            sensorIndex = 38

            #VC: create the raw object
            vrpn7 = viz.add('vrpn7.dle')
            rawTracker[_name] = vrpn7.addTracker(trackerId + "@" + ip,
                                                 sensorIndex)

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='Generic',
                                  model='VRPN')

        #VC: init the offsets
        if initFlag & vizconnect.INIT_OFFSETS:
            _link = vizconnect.getTracker(_name).getLink()
            #VC: clear link offsets
            _link.reset(viz.RESET_OPERATORS)

            #VC: apply swap
            _link.swapPos([-1, 2, 3])

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

    #VC: initialize a new tracker
    _name = 'inertiacube'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            port = 0

            #VC: create the raw object
            isense = viz.add('intersense.dle')
            isenseTracker = isense.addTracker(port=port)
            if not isenseTracker.valid():
                viz.logWarn(
                    "** WARNING: can't connect to InterSense InertiaCube at {0}."
                    .format(port))
            rawTracker[_name] = isenseTracker

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='InterSense',
                                  model='InertiaCube')

    #VC: initialize a new tracker
    _name = 'merged'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: request that any dependencies be created
        if initFlag & vizconnect.INIT_INDEPENDENT:
            initTrackers(vizconnect.INIT_INDEPENDENT, ['vrpn'])
            initTrackers(vizconnect.INIT_INDEPENDENT, ['inertiacube'])

        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            posTracker = vizconnect.getTracker('vrpn').getNode3d()
            oriTracker = vizconnect.getTracker('inertiacube').getNode3d()

            #VC: create the raw object
            try:
                raw = viz.mergeLinkable(posTracker, oriTracker)
            except:
                viz.logError(
                    'Error **: unable to create merged tracker, providing empty tracker object.'
                )
                raw = viz.addGroup()
                raw.invalidTracker = True
            rawTracker[_name] = raw

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='Virtual',
                                  model='Merged')

    #VC: initialize a new tracker
    _name = 'vrpn3'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            trackerId = 'Tracker0'
            ip = 'localhost'
            sensorIndex = 40

            #VC: create the raw object
            vrpn7 = viz.add('vrpn7.dle')
            rawTracker[_name] = vrpn7.addTracker(trackerId + "@" + ip,
                                                 sensorIndex)

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='Generic',
                                  model='VRPN')

        #VC: init the offsets
        if initFlag & vizconnect.INIT_OFFSETS:
            _link = vizconnect.getTracker(_name).getLink()
            #VC: clear link offsets
            _link.reset(viz.RESET_OPERATORS)

            #VC: apply swap
            _link.swapPos([-1, 2, 3])
            _link.swapQuat([-1, 2, 3, -4])

        #VC: set the parent of the node
        if initFlag & vizconnect.INIT_PARENTS:
            vizconnect.getTracker(_name).setParent(vizconnect.getRoot())

    #VC: initialize a new tracker
    _name = 'vrpn2'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            trackerId = 'Tracker0'
            ip = 'localhost'
            sensorIndex = 39

            #VC: create the raw object
            vrpn7 = viz.add('vrpn7.dle')
            rawTracker[_name] = vrpn7.addTracker(trackerId + "@" + ip,
                                                 sensorIndex)

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='Generic',
                                  model='VRPN')

        #VC: init the offsets
        if initFlag & vizconnect.INIT_OFFSETS:
            _link = vizconnect.getTracker(_name).getLink()
            #VC: clear link offsets
            _link.reset(viz.RESET_OPERATORS)

            #VC: apply swap
            _link.swapPos([-1, 2, 3])
            _link.swapQuat([-1, 2, 3, -4])

    #VC: return values can be modified here
    return None
	def __init__(self):		
		super(self.__class__,self).__init__()
	
		# --Override Key commands
		self.KEYS = { 'forward'	: 'w'
					,'back' 	: 's'
					,'left' 	: 'a'
					,'right'	: 'd'
					,'camera'	: 'c'
					,'restart'	: viz.KEY_END
					,'home'		: viz.KEY_HOME
					,'utility'	: ' '
					,'reset'	: 0
					,'showMenu' : 1
					,'down'		: 2
					,'orient'	: 3
					,'up'		: 4
					,'mode'		: 5
					,'builder'	: 6
					,'walk'		: 7
					,'angles'	: 8
					,'road'		: 10
					,'esc'		: 999
					,'slideFar'	: 0
					,'slideNear': 180
					,'env'		: '-'
					,'grid'		: '-'
					,'snapMenu'	: viz.KEY_CONTROL_L
					,'interact' : viz.MOUSEBUTTON_LEFT
					,'rotate'	: viz.MOUSEBUTTON_RIGHT
					,'proxi'	: 'p'
					,'viewer'	: 'o'
					,'collide'	: 'c'
					,'stereo' 	: 'm'
					,'hand'		: 'h'
					,'capslock'	: viz.KEY_CAPS_LOCK
		}
		
		self.TURN_SPEED = 45
		
		# Get device from extension if not specified
		self.device = None
		if self.device is None:
			allDevices = getDevices()
			if allDevices:
				self.device = allDevices[0]	
			else:
				viz.logError('** ERROR: Failed to detect Joystick')

		# Connect to selected device
		self.joy = getExtension().addJoystick(self.device)
		if not self.joy:
			viz.logError('** ERROR: Failed to connect to Joystick')

		# Set dead zone threshold so small movements of joystick are ignored
		self.joy.setDeadZone(0.2)

		# Display joystick information in config window
#		vizconfig.register(self.joy)
#		vizconfig.getConfigWindow().setWindowVisible(True)
		
		# --add oculus as HMD
		self.hmd = oculus.Rift()
		
		if not self.hmd.getSensor():
			viz.logError('** ERROR: Failed to detect Oculus')
		else:
			# Reset HMD orientation
			self.hmd.getSensor().reset()

			# Setup navigation node and link to main view
			self.VIEW_LINK.preMultLinkable(self.hmd.getSensor())

			# --Apply user profile eye height to view
			profile = self.hmd.getProfile()
			if profile:
				self.VIEW_LINK.setOffset([0,profile.eyeHeight,0])
				viz.logNotice('Oculus profile name:', profile.name)
				viz.logNotice('Oculus IPD:', profile.ipd)
				viz.logNotice('Oculus player height:', profile.playerHeight)
				viz.logNotice('Oculus eye height:', profile.eyeHeight)
			else: 
				self.VIEW_LINK.setOffset([0,self.EYE_HEIGHT,0])
				
			# Check if HMD supports position tracking
			supportPositionTracking = self.hmd.getSensor().getSrcMask() & viz.LINK_POS
			if supportPositionTracking:
				
				# Add camera bounds model
				self.camera_bounds = self.hmd.addCameraBounds()
				self.camera_bounds.visible(False)

				# Change color of bounds to reflect whether position was tracked
				def checkPositionTracked():
					if self.hmd.getSensor().getStatus() & oculus.STATUS_POSITION_TRACKED:
						self.camera_bounds.color(viz.GREEN)
					else:
						self.camera_bounds.color(viz.RED)
				vizact.onupdate(0, checkPositionTracked)

				# Setup camera bounds toggle key
				def toggleBounds():
					self.camera_bounds.visible(viz.TOGGLE)
				vizact.onkeydown(self.KEYS['camera'], toggleBounds)
def initTrackers(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
	#VC: place any general initialization code here
	rawTracker = vizconnect.getRawTrackerDict()

	#VC: initialize a new tracker
	_name = 'ppt_left_eye'
	if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set some parameters
			pptHostname = '171.64.33.43'
			markerId = 1
			
			#VC: create the raw object
			vrpn7 = viz.add('vrpn7.dle')
			rawTracker[_name] = vrpn7.addTracker('PPT0@'+pptHostname, markerId-1)
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addTracker(rawTracker[_name], _name, make='WorldViz', model='PPT')

	#VC: initialize a new tracker
	_name = 'rift_orientation_tracker'
	if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set some parameters
			index = 0
			
			#VC: create the raw object
			import oculus
			sensorList = oculus.getSensors()
			if index < len(sensorList):
				orientationTracker = sensorList[index]
			else:
				viz.logWarn("** WARNING: Oculus VR Rift Orientation Tracker not present.")
				orientationTracker = viz.addGroup()
				orientationTracker.invalidTracker = True
			rawTracker[_name] = orientationTracker
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addTracker(rawTracker[_name], _name, make='Oculus VR', model='Rift Orientation Tracker')
	
		#VC: init the mappings for the wrapper
		if initFlag&vizconnect.INIT_WRAPPER_MAPPINGS:
			#VC: on-state mappings
			if initFlag&vizconnect.INIT_MAPPINGS_ON_STATE:
				vizconnect.getTracker(_name).setOnStateEventList([
						vizconnect.onstate(lambda rawInput: rawInput['keyboard'].isButtonDown(19), vizconnect.getTracker(_name).resetHeading),# make=Generic, model=Keyboard, name=keyboard, signal=Key R
				])

	#VC: initialize a new tracker
	_name = 'merged'
	if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
		#VC: request that any dependencies be created
		if initFlag&vizconnect.INIT_INDEPENDENT:
			initTrackers(vizconnect.INIT_INDEPENDENT, ['ppt_left_eye'])
			initTrackers(vizconnect.INIT_INDEPENDENT, ['rift_orientation_tracker'])
	
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set some parameters
			posTracker = vizconnect.getTracker('ppt_left_eye').getNode3d()
			oriTracker = vizconnect.getTracker('rift_orientation_tracker').getNode3d()
			
			#VC: create the raw object
			try:
				raw = viz.mergeLinkable(posTracker, oriTracker)
			except:
				viz.logError('Error **: unable to create merged tracker, providing empty tracker object.')
				raw = viz.addGroup()
				raw.invalidTracker = True
			rawTracker[_name] = raw
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addTracker(rawTracker[_name], _name, make='Virtual', model='Merged')
	
		#VC: init the offsets
		if initFlag&vizconnect.INIT_OFFSETS:
			_link = vizconnect.getTracker(_name).getLink()
			#VC: clear link offsets
			_link.reset(viz.RESET_OPERATORS)
			
			#VC: reset orientation
			_link.preEuler([0, 0, 0], target=viz.LINK_ORI_OP, priority=-20)

				#VC: apply offsets
			_link.preTrans([0.0975, -0.08, -0.07])

		#VC: set the parent of the node
		if initFlag&vizconnect.INIT_PARENTS:
			vizconnect.getTracker(_name).setParent(vizconnect.getTransport('wandmagiccarpet'))

	#VC: initialize a new tracker
	_name = 'rift_with_mouse_and_keyboard'
	if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set some parameters
			addMouseOrientation = True
			positionSensitivity = 2.5
			heightOffset = 1.82
			sensorIndex = 0
			
			#VC: create the raw object
			import oculus
			sensorList = oculus.getSensors()
			if sensorIndex < len(sensorList):
				dk2Tracker = sensorList[sensorIndex]
				from vizconnect.util import virtual_trackers
				tracker = virtual_trackers.TrackerAndKeyboardWalking(dk2Tracker, addMouseOrientation=addMouseOrientation, positionSensitivity=positionSensitivity, heightOffset=heightOffset)
			else:
				viz.logWarn("** WARNING: Oculus Tracker not present.")
				tracker = viz.addGroup()
				tracker.invalidTracker = True
			rawTracker[_name] = tracker
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addTracker(rawTracker[_name], _name, make='Oculus VR', model='Rift With Mouse And Keyboard')

	#VC: return values can be modified here
	return None
def initTrackers(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
	#VC: place any general initialization code here
	rawTracker = vizconnect.getRawTrackerDict()

	#VC: initialize a new tracker
	_name = 'merged'
	if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
		#VC: request that any dependencies be created
		if initFlag&vizconnect.INIT_INDEPENDENT:
			initTrackers(vizconnect.INIT_INDEPENDENT, ['mouse_and_keyboard_flying'])
			initTrackers(vizconnect.INIT_INDEPENDENT, ['dk2'])
	
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set some parameters
			posTracker = vizconnect.getTracker('mouse_and_keyboard_flying').getNode3d()
			oriTracker = vizconnect.getTracker('dk2').getNode3d()
			
			#VC: create the raw object
			try:
				raw = viz.mergeLinkable(posTracker, oriTracker)
			except:
				viz.logError('Error **: unable to create merged tracker, providing empty tracker object.')
				raw = viz.addGroup()
				raw.invalidTracker = True
			rawTracker[_name] = raw
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addTracker(rawTracker[_name], _name, make='Virtual', model='Merged')

	#VC: initialize a new tracker
	_name = 'dk2'
	if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set some parameters
			index = 0
			
			#VC: create the raw object
			import oculus
			sensorList = oculus.getSensors()
			if index < len(sensorList):
				orientationTracker = sensorList[index]
			else:
				viz.logWarn("** WARNING: Oculus VR Rift Orientation Tracker not present.")
				orientationTracker = viz.addGroup()
				orientationTracker.invalidTracker = True
			rawTracker[_name] = orientationTracker
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addTracker(rawTracker[_name], _name, make='Oculus VR', model='DK2')
	
		#VC: set the parent of the node
		if initFlag&vizconnect.INIT_PARENTS:
			vizconnect.getTracker(_name).setParent(vizconnect.getRoot())

	#VC: initialize a new tracker
	_name = 'mouse_and_keyboard_flying'
	if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set some parameters
			positionSensitivity = 2.5
			rotationSensitivity = 0.15
			debug = False
			
			#VC: create the raw object
			from vizconnect.util.virtual_trackers import MouseAndKeyboardFlying
			rawTracker[_name] = MouseAndKeyboardFlying(positionSensitivity=positionSensitivity, rotationSensitivity=rotationSensitivity, debug=debug)
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addTracker(rawTracker[_name], _name, make='Virtual', model='Mouse and Keyboard Flying')
	
		#VC: set the parent of the node
		if initFlag&vizconnect.INIT_PARENTS:
			vizconnect.getTracker(_name).setParent(vizconnect.getRoot())

	#VC: return values can be modified here
	return None
def initDisplays(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
    #VC: place any general initialization code here
    rawDisplay = vizconnect.getRawDisplayDict()

    #VC: initialize a new display
    _name = 'cave_data_file'
    if vizconnect.isPendingInit('display', _name, initFlag, initList):
        #VC: init which needs to happen before viz.go
        if initFlag & vizconnect.INIT_PREVIZGO:
            viz.setOption('viz.stereo', viz.QUAD_BUFFER)
            viz.setOption('viz.fullscreen', 1)

        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set the window for the display
            _window = viz.MainWindow

            #VC: set some parameters
            stereo = viz.QUAD_BUFFER
            filename = 'C:/demos/Cave_settings.txt'

            #VC: create the raw object
            # Create a cave object
            import vizcave
            cave = vizcave.Cave(stereo=stereo)
            try:
                cave.load(filename)
            except IOError:
                viz.logError(
                    "** Error: unable to load cave configuration file {}.".
                    format(filename))

            # get an origin node
            originName = _name
            initGroups(vizconnect.INIT_INDEPENDENT,
                       [originName])  # ensure it's been created
            originNode = vizconnect.getGroup(originName).getNode3d()

            # We need to pass an object which will be used to update the projection
            # or the display to the view's position, typically this would be the
            # node attached to an avatar's head tracker.
            viewpoint = viz.addGroup()
            cave.setTracker(viewpoint)

            # Create a CaveView object for manipulating the entire cave environment.
            # The caveView is a node that can be adjusted to move the entire
            # cave around the virtual environment.
            caveView = vizcave.CaveView(viewpoint)

            _window.originLink = viz.link(originNode,
                                          caveView,
                                          dstFlag=viz.ABS_GLOBAL,
                                          srcFlag=viz.ABS_GLOBAL)
            _window.caveView = caveView
            _window.originNode = originNode
            _window.displayNode = cave
            _window.viewpointNode = viewpoint

            rawDisplay[_name] = _window

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addDisplay(rawDisplay[_name],
                                  _name,
                                  make='Generic',
                                  model='Cave Data File')

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

    #VC: return values can be modified here
    return None
Beispiel #12
0
def initTrackers(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
    #VC: place any general initialization code here
    rawTracker = vizconnect.getRawTrackerDict()

    #VC: initialize a new tracker
    _name = 'marker2'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            hostname = '127.0.0.1:2'
            sensorIndex = 14

            #VC: create the raw object
            try:
                phasespace = viz.add('phasespace.dle', 0, hostname)
            except:
                viz.logWarn(
                    "** WARNING: can't connect to PhaseSpace at {0}.".format(
                        hostname))

            validTracker = False
            if phasespace.id != -1:
                try:
                    sensor = phasespace.addMarker(sensorIndex)
                    validTracker = True
                except:
                    validTracker = False

            if not validTracker:
                viz.logWarn(
                    "** WARNING: can't connect to Northern Digital Optotrack with index {0}. It's likely that not enough sensors are connected."
                    .format(sensorIndex))
                sensor = viz.addGroup()
                sensor.invalidTracker = True
            rawTracker[_name] = sensor

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='PhaseSpace',
                                  model='Marker')

    #VC: initialize a new tracker
    _name = 'look_at'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: request that any dependencies be created
        if initFlag & vizconnect.INIT_INDEPENDENT:
            initTrackers(vizconnect.INIT_INDEPENDENT, ['marker2'])
            initTrackers(vizconnect.INIT_INDEPENDENT, ['marker3'])

        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            eye = vizconnect.getTracker('marker2').getNode3d()
            target = vizconnect.getTracker('marker3').getNode3d()

            #VC: create the raw object
            from vizconnect.util import virtual_trackers
            if eye and target:
                raw = virtual_trackers.LookAt(eye=eye, target=target)
            else:
                viz.logError(
                    'Error **: unable to create merged tracker, providing empty tracker object.'
                )
                raw = viz.addGroup()
                raw.invalidTracker = True
            rawTracker[_name] = raw

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='Virtual',
                                  model='Look At')

        #VC: init the offsets
        if initFlag & vizconnect.INIT_OFFSETS:
            _link = vizconnect.getTracker(_name).getLink()
            #VC: clear link offsets
            _link.reset(viz.RESET_OPERATORS)

            #VC: apply offsets
            _link.postEuler([0, 0, 2])

    #VC: initialize a new tracker
    _name = 'marker3'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            hostname = '127.0.0.1:2'
            sensorIndex = 15

            #VC: create the raw object
            try:
                phasespace = viz.add('phasespace.dle', 0, hostname)
            except:
                viz.logWarn(
                    "** WARNING: can't connect to PhaseSpace at {0}.".format(
                        hostname))

            validTracker = False
            if phasespace.id != -1:
                try:
                    sensor = phasespace.addMarker(sensorIndex)
                    validTracker = True
                except:
                    validTracker = False

            if not validTracker:
                viz.logWarn(
                    "** WARNING: can't connect to Northern Digital Optotrack with index {0}. It's likely that not enough sensors are connected."
                    .format(sensorIndex))
                sensor = viz.addGroup()
                sensor.invalidTracker = True
            rawTracker[_name] = sensor

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='PhaseSpace',
                                  model='Marker')

    #VC: initialize a new tracker
    _name = 'head_0'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            hostname = '127.0.0.1:2'
            sensorIndex = 3

            #VC: create the raw object
            try:
                phasespace = viz.add('phasespace.dle', 0, hostname)
            except:
                viz.logWarn(
                    "** WARNING: can't connect to PhaseSpace at {0}.".format(
                        hostname))

            validTracker = False
            if phasespace.id != -1:
                try:
                    sensor = phasespace.addMarker(sensorIndex)
                    validTracker = True
                except:
                    validTracker = False

            if not validTracker:
                viz.logWarn(
                    "** WARNING: can't connect to Northern Digital Optotrack with index {0}. It's likely that not enough sensors are connected."
                    .format(sensorIndex))
                sensor = viz.addGroup()
                sensor.invalidTracker = True
            rawTracker[_name] = sensor

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='PhaseSpace',
                                  model='Marker')

    #VC: initialize a new tracker
    _name = 'marker'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            hostname = '127.0.0.1:2'
            sensorIndex = 0

            #VC: create the raw object
            try:
                phasespace = viz.add('phasespace.dle', 0, hostname)
            except:
                viz.logWarn(
                    "** WARNING: can't connect to PhaseSpace at {0}.".format(
                        hostname))

            validTracker = False
            if phasespace.id != -1:
                try:
                    sensor = phasespace.addMarker(sensorIndex)
                    validTracker = True
                except:
                    validTracker = False

            if not validTracker:
                viz.logWarn(
                    "** WARNING: can't connect to Northern Digital Optotrack with index {0}. It's likely that not enough sensors are connected."
                    .format(sensorIndex))
                sensor = viz.addGroup()
                sensor.invalidTracker = True
            rawTracker[_name] = sensor

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='PhaseSpace',
                                  model='Marker')

    #VC: initialize a new tracker
    _name = 'look_at2'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: request that any dependencies be created
        if initFlag & vizconnect.INIT_INDEPENDENT:
            initTrackers(vizconnect.INIT_INDEPENDENT, ['head_0'])
            initTrackers(vizconnect.INIT_INDEPENDENT, ['marker'])

        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            eye = vizconnect.getTracker('head_0').getNode3d()
            target = vizconnect.getTracker('marker').getNode3d()

            #VC: create the raw object
            from vizconnect.util import virtual_trackers
            if eye and target:
                raw = virtual_trackers.LookAt(eye=eye, target=target)
            else:
                viz.logError(
                    'Error **: unable to create merged tracker, providing empty tracker object.'
                )
                raw = viz.addGroup()
                raw.invalidTracker = True
            rawTracker[_name] = raw

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='Virtual',
                                  model='Look At')

    #VC: initialize a new tracker
    _name = 'marker4'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            hostname = '127.0.0.1:2'
            sensorIndex = 21

            #VC: create the raw object
            try:
                phasespace = viz.add('phasespace.dle', 0, hostname)
            except:
                viz.logWarn(
                    "** WARNING: can't connect to PhaseSpace at {0}.".format(
                        hostname))

            validTracker = False
            if phasespace.id != -1:
                try:
                    sensor = phasespace.addMarker(sensorIndex)
                    validTracker = True
                except:
                    validTracker = False

            if not validTracker:
                viz.logWarn(
                    "** WARNING: can't connect to Northern Digital Optotrack with index {0}. It's likely that not enough sensors are connected."
                    .format(sensorIndex))
                sensor = viz.addGroup()
                sensor.invalidTracker = True
            rawTracker[_name] = sensor

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='PhaseSpace',
                                  model='Marker')

    #VC: initialize a new tracker
    _name = 'marker5'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            hostname = '127.0.0.1:2'
            sensorIndex = 22

            #VC: create the raw object
            try:
                phasespace = viz.add('phasespace.dle', 0, hostname)
            except:
                viz.logWarn(
                    "** WARNING: can't connect to PhaseSpace at {0}.".format(
                        hostname))

            validTracker = False
            if phasespace.id != -1:
                try:
                    sensor = phasespace.addMarker(sensorIndex)
                    validTracker = True
                except:
                    validTracker = False

            if not validTracker:
                viz.logWarn(
                    "** WARNING: can't connect to Northern Digital Optotrack with index {0}. It's likely that not enough sensors are connected."
                    .format(sensorIndex))
                sensor = viz.addGroup()
                sensor.invalidTracker = True
            rawTracker[_name] = sensor

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='PhaseSpace',
                                  model='Marker')

    #VC: initialize a new tracker
    _name = 'look_at3'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: request that any dependencies be created
        if initFlag & vizconnect.INIT_INDEPENDENT:
            initTrackers(vizconnect.INIT_INDEPENDENT, ['marker4'])
            initTrackers(vizconnect.INIT_INDEPENDENT, ['marker5'])

        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            eye = vizconnect.getTracker('marker4').getNode3d()
            target = vizconnect.getTracker('marker5').getNode3d()

            #VC: create the raw object
            from vizconnect.util import virtual_trackers
            if eye and target:
                raw = virtual_trackers.LookAt(eye=eye, target=target)
            else:
                viz.logError(
                    'Error **: unable to create merged tracker, providing empty tracker object.'
                )
                raw = viz.addGroup()
                raw.invalidTracker = True
            rawTracker[_name] = raw

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='Virtual',
                                  model='Look At')

    #VC: initialize a new tracker
    _name = 'marker6'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            hostname = '127.0.0.1:2'
            sensorIndex = 12

            #VC: create the raw object
            try:
                phasespace = viz.add('phasespace.dle', 0, hostname)
            except:
                viz.logWarn(
                    "** WARNING: can't connect to PhaseSpace at {0}.".format(
                        hostname))

            validTracker = False
            if phasespace.id != -1:
                try:
                    sensor = phasespace.addMarker(sensorIndex)
                    validTracker = True
                except:
                    validTracker = False

            if not validTracker:
                viz.logWarn(
                    "** WARNING: can't connect to Northern Digital Optotrack with index {0}. It's likely that not enough sensors are connected."
                    .format(sensorIndex))
                sensor = viz.addGroup()
                sensor.invalidTracker = True
            rawTracker[_name] = sensor

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='PhaseSpace',
                                  model='Marker')

    #VC: return values can be modified here
    return None
Beispiel #13
0
	for window in viz.getWindowList():
		window.getView().getHeadLight().disable()
#		
#	# Create directional light
	sky_light = viz.addDirectionalLight(euler=(-66,37,0),color=[1,1,1])
##	light1 = vizfx.addDirectionalLight(euler=(40,20,0), color=[0.7,0.7,0.7])
##	light2 = vizfx.addDirectionalLight(euler=(-65,15,0), color=[0.5,0.25,0.0])
##	sky_light.color(viz.WHITE)
#	# Adjust ambient color
#	viz.setOption('viz.lightModel.ambient',[0]*3)
#	sky_light.ambient([0.8]*3)
#	vizfx.setAmbientColor([0.3,0.3,0.4])	
	import oculus
	hmd = oculus.Rift()
	if not hmd.getSensor(): 
		viz.logError('**ERROR: Failed to detect Oculus!')
	
	ORIGIN = [0,5,-17]
	
	gridRoot = GridRoot()
	viz.MainView.setPosition(ORIGIN)	
	
#	bridgeRoot = BridgeRoot()
#	environment_root = EnvironmentRoot()
#	wave_M = viz.addChild('resources/wave.osgb',cache=viz.CACHE_CLONE,pos=([0,0.75,0]),parent=environment_root)
#	wave_M.setAnimationSpeed(0.02)
#	wave_B = viz.addChild('resources/wave.osgb',cache=viz.CACHE_CLONE,pos=([0,0.75,-50]),parent=environment_root)
#	wave_B.setAnimationSpeed(0.02)
#	road_L1 = viz.addChild('resources/road3.osgb',cache=viz.CACHE_CLONE,pos=(-20,5,0),parent=environment_root)
#	road_L2 = viz.addChild('resources/road3.osgb',cache=viz.CACHE_CLONE,pos=(-40,5,0),parent=environment_root)
#	road_R1 = viz.addChild('resources/road3.osgb',cache=viz.CACHE_CLONE,pos=(20,5,0),parent=environment_root)