def enable(): global enabled if not enabled: if NARRATE_ON_CLICK: vizact.onmousedown(viz.MOUSEBUTTON_LEFT, selector.enable) #vizact.onkeydown(' ', selector.enable) else: selector.enable() #selector.crosshair.visible(True) enabled = True
def __init__(self, node=None, scene=viz.Scene1): self.scene = scene self.node = node self.found = [] self.returnPosition = True self.returnEuler = True self.returnCurrent = True self.selected = None self.enabled = False vizact.ontimer(.1, self.cursorChange) vizact.onmousedown(viz.MOUSEBUTTON_LEFT, self.computeDistance)
def loadNarrationObjects( apartment, objects, scene=viz.MainScene, rift=False ): global OBJECTS, OBJS_WITH_NARRATION, SCENE, APARTMENT, NARRATE_ON_CLICK, RIFT RIFT = rift OBJECTS = objects APARTMENT = apartment SCENE = scene OBJS_WITH_NARRATION = [o for o in objects if o.narration] global selector selector = NodeSelectionWithFeedbackOptions.Selector(scene,True, True) #selector.crosshair.visible(False) #selector.enable() global RADIO RADIO = apartment.getChild('Radio.OSGB') selector.onSelect(next(obj for obj in OBJS_WITH_NARRATION if obj.name == 'Radio.OSGB'), activateNarration) selector.onSelect(next(obj for obj in OBJS_WITH_NARRATION if obj.name == 'Radio.OSGB'), lookedAtRadio) selector.onDeselect(next(obj for obj in OBJS_WITH_NARRATION if obj.name == 'Radio.OSGB'), lookedAwayFromRadio) vizact.onmousedown(viz.MOUSEBUTTON_LEFT, selectRadio)
def fadeAndAppear(): global screen, fadeInAndOut, selector, phoneEvent yield viztask.waitTime(3) yield screen.playsound('resources/audio/vibrate.wav', viz.LOOP) selector.enable() fadeInAndOut = vizact.sequence([vizact.fadeTo(0, time=0.5), vizact.fadeTo(1,time=0.5)], viz.PERPETUAL) phoneEvent = vizact.onmousedown(viz.MOUSEBUTTON_LEFT, selectPhone) screen.addAction( fadeInAndOut )
def begin(): global introAudio introAudio.play() yield viztask.waitMediaEnd(introAudio) global selectedAvatar selectedAvatar = None global playing playing = False global avs, SCENE global selector selector.onSelect(avs, allowSelection) selector.onDeselect(avs, endSelection) selector.enable() vizact.onmousedown(viz.MOUSEBUTTON_LEFT, startStory)
def __init__(self, background_noise): """ Initializes a BaseScene instance which loads vizconnect configuration. Args: background_noise: if enabled plays a background white noise on repeat """ if background_noise: noise = self.add_and_play_background_noise(volume=0.1) # todo test vizact.onkeydown('s', self.noise.play, viz.TOGGLE) self.instruction = self.instruction_canvas_vr(40) # Press 'i' to toggle instruction visibility vizact.onkeydown('i', self.instruction.visible, viz.TOGGLE) vizact.onmousedown(viz.MOUSEBUTTON_RIGHT, self.instruction.visible, viz.TOGGLE)
def enable(): global enabled if not enabled: selector.enable() counter.enable() enabled = True if SELL_ON_CLICK and enabled: global sellObjOnClick sellObjOnClick = vizact.onmousedown(viz.MOUSEBUTTON_LEFT, viztask.schedule, sellSelectedObject()) viz.mouse(viz.OFF)
def __init__(self, mouseClickCallback=None, mouseOverCallback=None): self.mouseOverCallback = mouseOverCallback self.mouseClickCallback = mouseClickCallback self.timer = vizact.ontimer(.1, self.pick) if mouseClickCallback: self.mouseEvent = vizact.onmousedown(viz.MOUSEBUTTON_LEFT, self.executeMouseClickCallback) else: self.mouseEvent = None self.pause()
def bmw_card_driver(): car = viz.addChild('bmw.dae') car.setEuler([0,0,0]) car.setScale(0.5,0.5,0.5) MOVE_SPEED = 5 TURN_SPEED = 60 def updatecar(): #move view forward and backward if viz.key.isDown(viz.KEY_UP): view.move([0,0,MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) elif viz.key.isDown(viz.KEY_DOWN): view.move([0,0,-MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) #rotate body of view left and right if viz.key.isDown(viz.KEY_RIGHT): view.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) elif viz.key.isDown(viz.KEY_LEFT): view.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) #set the car to view position and body orientation car.setPosition(view.getPosition()) car.setEuler(view.getEuler(viz.BODY_ORI)) car.setPosition([3.02,-5.50,5.04],viz.REL_LOCAL) vizact.ontimer(0,updatecar) #update head of view based on mouse movements def mousemove(e): euler = view.getEuler(viz.HEAD_ORI) euler[0] += e.dx*0.1 euler[1] += -e.dy*0.1 euler[1] = viz.clamp(euler[1],-85.0,85.0) view.setEuler(euler,viz.HEAD_ORI) viz.callback(viz.MOUSE_MOVE_EVENT,mousemove) viz.mouse(viz.OFF) viz.mouse.setVisible(False) vizact.onmousedown(viz.MOUSEBUTTON_LEFT,view.reset,viz.HEAD_ORI) vizact.onmousedown(viz.MOUSEBUTTON_RIGHT,view.reset, viz.BODY_ORI |viz.HEAD_POS) vizact.onmousedown(viz.MOUSEBUTTON_RIGHT,updatecar)
def enable(): print 'REAL SLIM SHADY' vizact.onmousedown(viz.MOUSEBUTTON_LEFT, selectItem) viztask.schedule( findToothBrush() )
ser = serial.Serial('COM3', 9600, timeout=1) # Open serial channel or selected port link = None # The handle to the link object def grabBall(): object = viz.pick( ) # Command detects which object the mouse is currently over and returns it if object == basketball: # Check to see if object is basketball print "You've clicked on the basketball" ser.writelines(b'T') # Turn led/thumb electrode on global link link = viz.grab(hand, basketball) # Use hand to grab basketball else: print "This is not a basketball" def releaseBall(): global link link.remove() link = None ser.writelines(b'L') vizact.onmousedown( viz.MOUSEBUTTON_LEFT, grabBall) # When left mouse button is clicked, go to pickBall function vizact.onmouseup(viz.MOUSEBUTTON_LEFT, releaseBall)
ballPhysicalShape.friction = ballFriction.get() ballPhysicalShape.hardness = ballHardness.get() ballPhysicalShape.bounce = ballBounce.get() #Place object on collision course with speed determined by the force slider ball.applyForce( dir = [ -10 * ballForce.get(), 0, 0 ], duration=0.1, pos = ballStartPOS ) reset() vizact.onkeydown( ' ', reset ) #use keyboard navigation and use mouse for applying forces to objects import vizcam viz.cam.setHandler(vizcam.KeyboardCamera()) #Push objects around with mouse clicks def pushObject(): info = viz.pick( True ) #Get object that cursor is pointing at if info.valid and ( info.object == ball or info.object ==box ): #Create a vector from the mouse position into the world line = viz.MainWindow.screenToWorld(viz.mouse.getPosition()) vec = viz.Vector( line.dir ) vec.setLength( 1 ) info.object.applyForce( dir = vec, duration = 0.1, pos = info.point ) return True vizact.onmousedown(viz.MOUSEBUTTON_LEFT, pushObject) #Move viewpoint so that it can see the action viz.MainView.setPosition([0, 2, -5])
#Make it twice as long. textbox1.length(2) textbox1.setPosition(.5, .5) #Have it grow when text reaches its boundary. textbox1.overflow(viz.OVERFLOW_GROW) textbox1.message('you are at the gas station') textbox1.add(fadeInOut) vizact.onmousedown(viz.MOUSEBUTTON_LEFT, landmark) vizact.onkeydown('p', landmark) ###############################sensor visible############################# #Create sensors for destinations bomb_in_trashcan1 = vizproximity.Sensor(vizproximity.Box([4, 5, 5], center=[0, 2.5, 0]), source=bomb_in_trashcan) bomb_in_school1 = vizproximity.Sensor(vizproximity.Box([5, 4, 4], center=[0, 1.7, 0]), source=bomb_in_school) #Add main viewpoint as proximity target target = vizproximity.Target(viz.MainView)
def waitForNextClick(): if SELL_ON_CLICK: global sellObjOnClick, SELLABLES, selector selector.enable() sellObjOnClick = vizact.onmousedown(viz.MOUSEBUTTON_LEFT, viztask.schedule, sellSelectedObject()) viz.mouse(viz.OFF)
def use_control(self, control_style): """ Enable the control modality depending on the provided input modality. Different experimental setup make use of different ways to exert control over the experimental world. Use this function to define and setup the necessary things depending on the control modality to be used. Args: control_style: interaction possibilities between subject and VR world. Currently supports: 'mouse and keyboard', 'joystick', 'wiimote with dk2 head', 'dk2 head only', 'dk2 head hands' """ # control type for test purposes if control_style == 'mouse and keyboard': # control type for test purposes viz.mouse(viz.ON) vizact.onmousedown(viz.MOUSEBUTTON_LEFT, self.on_button_press, 'A') vizact.onmousedown(viz.MOUSEBUTTON_RIGHT, self.on_button_press, 'B') self.sphere_radius = 0.02 self.right_hand_sphere = vizshape.addSphere(radius=self.sphere_radius) self.right_hand_sphere.color(viz.GREEN) self.right_hand_target = self.right_hand_sphere.collideSphere() self.right_hand_sphere.disable(viz.DYNAMICS) self.right_hand_sphere.alpha(1) self.head_sphere = vizshape.addSphere(radius=self.sphere_radius) self.head_sphere.color(viz.YELLOW) self.head_target = self.head_sphere.collideSphere() self.head_sphere.disable(viz.DYNAMICS) MOVE_SPEED = 0.025 def move_hand(): if viz.key.isDown(viz.KEY_UP): self.right_hand_sphere.setPosition([self.right_hand_sphere.getPosition()[0], 1.6, self.right_hand_sphere.getPosition()[2]+MOVE_SPEED]) elif viz.key.isDown(viz.KEY_DOWN): self.right_hand_sphere.setPosition([self.right_hand_sphere.getPosition()[0], 1.6, self.right_hand_sphere.getPosition()[2]-MOVE_SPEED]) elif viz.key.isDown(viz.KEY_LEFT): self.right_hand_sphere.setPosition(self.right_hand_sphere.getPosition()[0]-MOVE_SPEED, 1.6, self.right_hand_sphere.getPosition()[2]) elif viz.key.isDown(viz.KEY_RIGHT): self.right_hand_sphere.setPosition(self.right_hand_sphere.getPosition()[0]+MOVE_SPEED, 1.6, self.right_hand_sphere.getPosition()[2]) def move_head(): if viz.key.isDown('w'): self.head_sphere.setPosition([self.head_sphere.getPosition()[0], 1.6, self.head_sphere.getPosition()[2]+MOVE_SPEED]) elif viz.key.isDown('s'): self.head_sphere.setPosition([self.head_sphere.getPosition()[0], 1.6, self.head_sphere.getPosition()[2]-MOVE_SPEED]) elif viz.key.isDown('a'): self.head_sphere.setPosition(self.head_sphere.getPosition()[0]-MOVE_SPEED, 1.6, self.head_sphere.getPosition()[2]) elif viz.key.isDown('d'): self.head_sphere.setPosition(self.head_sphere.getPosition()[0]+MOVE_SPEED, 1.6, self.head_sphere.getPosition()[2]) vizact.ontimer(0, move_hand) vizact.ontimer(0, move_head) elif control_style == 'joystick': # first load the oculus rift plugin and link sensor to viewpoint import oculus hmd = oculus.Rift() # loads the DirectInput plug-in and adds first available joystick dinput = viz.add('DirectInput.dle') self.joy = dinput.addJoystick() # Set dead zone threshold so small movements of joystick are ignored self.joy.setDeadZone(0.2) # add viewpoint at subject height eye_height = float(self._height) - 0.05 joystick_node = viz.addGroup(pos=(0, eye_height, 0)) viz.link(joystick_node, viz.MainView) # joystick control class with lsl streams of pos and ori as in the dk2 tracker class # stream pos and ori in joystick movement function which gets called with ontimer / onupdate # set lsl stream parameters lsl_streamName = 'vizard_hmd6dof_stateLog_joystick' lsl_streamType = 'sixFloat' # no official lsl type (not recognized by eeglab or mobilab) lsl_numChannels = 6 lsl_regularSPS = 75 # regular rate, one sample per DK2 frame lsl_dataType = 'float32' lsl_streamUuid = socket.gethostname() # PC name as uuid # create stream lsl_hmd6dofStreamInfo = StreamInfo(lsl_streamName, lsl_streamType, lsl_numChannels, lsl_regularSPS, lsl_dataType, lsl_streamUuid) lsl_hmd6dofStreamInfo.desc().append_child('synchronization').append_child_value('can_drop_samples', 'true') lsl_hmd6dofOutlet = StreamOutlet(lsl_hmd6dofStreamInfo) viz.callback(viz.SENSOR_DOWN_EVENT, self.on_button_press) vizact.onupdate(0, self.update_joystick_movement, self.joy, joystick_node, 5, 90, lsl_hmd6dofOutlet) else: self.start_dk2_head_tracker(control_style)
if viz.key.isDown(viz.KEY_UP): view.move([0,0,MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) elif viz.key.isDown(viz.KEY_DOWN): view.move([0,0,-MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) elif viz.key.isDown(viz.KEY_RIGHT): view.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) elif viz.key.isDown(viz.KEY_LEFT): view.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) #Hier wurde das auto an den Viewpoint getakert car.setPosition(view.getPosition()) car.setEuler(view.getEuler(viz.BODY_ORI)) car.setPosition([0.35,-1.2,0.2],viz.REL_LOCAL) vizact.ontimer(0,updatecar) def mousemove(e): euler = view.getEuler(viz.HEAD_ORI) euler[0] = viz.clamp(euler[0] + e.dx*0.1,-85.0,85.0) euler[1] += -e.dy*0.1 euler[1] = viz.clamp(euler[1],-85.0,85.0) view.setEuler(euler,viz.HEAD_ORI) viz.callback(viz.MOUSE_MOVE_EVENT,mousemove) viz.mouse(viz.OFF) viz.mouse.setVisible(False) vizact.onmousedown(viz.MOUSEBUTTON_LEFT,view.reset,viz.HEAD_ORI) vizact.onmousedown(viz.MOUSEBUTTON_RIGHT,view.reset, viz.BODY_ORI |viz.HEAD_POS) vizact.onmousedown(viz.MOUSEBUTTON_RIGHT,updatecar)
# vizact.onkeydown('r', engine.Stop) pump = Pump(ground, [5, 2, 10], [90,0,0], 'L', None) #43 drawables # press = Press(ground, [5, 1, 2.97], [0,0,0], 'L') #32 drawables # boiler = Boiler(ground, [15, 0, 2.97]) #219 drawables # laval = Laval(ground, [10, 0, 2.97], [-90,0,0], 'L' ,None) #35 drawables # mill = Mill(ground, [5, 0, 2.97], [-90,0,0], 'L') #150 drawables cam = vizcam.PivotNavigate(distance=2) cam.centerNode(pump.object) # OilPump = OilPump(ground, [0, 1, 10], [180,0,0], False) #29 drawables # vizact.onkeydown('s', OilPump.SetMotion) # vizact.onkeydown('d', OilPump.EndMotion) # cam = vizcam.PivotNavigate(distance=2) # cam.centerNode(OilPump.rod) def onPick(): object = viz.pick() handle = pump.components['bypassL'] if object == handle: print 'valve picked' object.color(viz.GREEN, op=viz.OP_OVERRIDE) elif getattr(object, 'pick_parent', False): object.getParents()[0].color(viz.GREEN, op=viz.OP_OVERRIDE) else: handle.clearAttribute(viz.ATTR_COLOR, op=viz.OP_OVERRIDE) vizact.onmousedown(viz.MOUSEBUTTON_LEFT,onPick)
lab.collideMesh() lab.disable(viz.DYNAMICS) #use keyboard navigation and use mouse for applying forces to objects import vizcam viz.cam.setHandler(vizcam.KeyboardCamera()) node = viz.addChild('crate.osgb') node.setPosition(INITIAL_POSITION) def reset(): node.collideNone() shape = node.collideBox(density=5) shape.friction = 0.01 node.setPosition(INITIAL_POSITION) node.setEuler(0, 0, 0) def pushUp(): node.applyForce(dir=[0, 250, 0], duration=0.1) def pushForward(): node.applyForce(dir=[0, 0, 150], duration=0.1) reset() vizact.onkeydown(' ', reset) vizact.onmousedown(viz.MOUSEBUTTON_LEFT, pushUp) vizact.onmousedown(viz.MOUSEBUTTON_RIGHT, pushForward) viz.MainView.setPosition([0, 2, -5])
doorSC() if sen == 3: #doorbath(e) #SALA RV doorbath() if sen == 4: print 'planta' if sen == 5: #doorKitchen(e) #SALA RV doorKitchen() if sen == 6: #doorSalon(e) #SALA RV doorSalon() if sen == 7: #RollupBed(e) #SALA RV RollupBed() if sen == 8: #RollupSal(e) #SALA RV RollupSal() if sen == 9: #RollupKit(e) #SALA RV RollupKit() if sen == 10: #RollupSC(e) #SALA RV RollupSC() if sen == 11: #Kitchen_lightONOFF(e) #SALA RV Kitchen_lightONOFF() vizact.onmousedown(viz.MOUSEBUTTON_LEFT, click_mouse) #CONTROL COMPU #viz.callback(hand.HAND_GESTURE_EVENT, click_mouse) #DESCOMENTAR ESTO PARA SALA RV