def OpenCloseHatch(self, open): #open=True or False if open: self.PlayAudio('boiler_load', self.components['coal'], viz.PLAY) angle = 120 * open openLeft = vizact.spinTo(euler=[angle,0,0], time=2, interpolate=vizact.easeOut) openRight = vizact.spinTo(euler=[-angle,0,0], time=2, interpolate=vizact.easeOut) self.hatch[0].addAction(openLeft) self.hatch[1].addAction(openRight)
def ChangePressure(self, pressure, duration): self.gauge.endAction() angle = int(pressure) * 0.06 ease = vizact.easeInOutCubic # spin to 180 degrees first, because spinTo chooses the shortest path (CCW in this case) if angle == 0: incPress = vizact.spinTo(euler=[0, 180, 0], time=2, interpolate=vizact.easeIn) self.gauge.addAction(incPress) ease = vizact.easeOut incPress = vizact.spinTo(euler=[0, angle, 0], time=int(duration), interpolate=ease) self.gauge.addAction(incPress)
def ChangePressure(self, pressure, duration): self.gauge.endAction() #dict of tuples (degrees of rotation, anim duration) for every pressure value angle = int(pressure) * 0.3 ease = vizact.easeInOutCubic # spin to 180 degrees first, because spinTo chooses the shortest path (CCW in this case) if angle == 0: incPress = vizact.spinTo(euler=[180, 0, 0], time=2, interpolate=vizact.easeIn) self.gauge.addAction(incPress) ease = vizact.easeOut incPress = vizact.spinTo(euler=[angle, 0, 0], time=int(duration), interpolate=ease) self.gauge.addAction(incPress)
def ChangePressure(self, pressure, duration): self.gauge.endAction() angle = int(pressure) * 2.25 ease = vizact.easeInOutCubic # spin to 180 degrees first, because spinTo chooses the shortest path (CCW in this case) if angle == 270 and self.gauge.getAxisAngle()[3]<180: incPress = vizact.spinTo(euler=[0,0,-180], time=int(duration)*2/3, interpolate=vizact.easeInCubic) duration = int(duration)*1/3 self.gauge.addAction(incPress) ease = vizact.easeOutCubic incPress = vizact.spinTo(axisAngle=[0,0,-1,angle], time=int(duration), interpolate=ease) self.gauge.addAction(incPress)
def MoveBarrow (self): barrow = self.components['barrow'] #update barrow to the new position self.faClass.componentPos[barrow] = [-22.5,0.5,9.5] barrow.addAction(vizact.spinTo(euler=[0,0,10], time=.5)) waitLift = vizact.signal() barrow.addAction(waitLift.trigger) self.wheel.addAction(waitLift.wait) self.wheel.addAction(vizact.spin(0,0,1,120, dur=4)) moveB = vizact.moveTo([-22.5,0.325,9.5], time=4, mode=viz.ABS_GLOBAL, interpolate=vizact.easeOut) rotateB = vizact.spinTo(euler=[-90,0,10], time=5) barrow.addAction(vizact.parallel(moveB, rotateB)) barrow.addAction(vizact.spinTo(euler=[-90,0,0], time=.5))
def rotate(object_to_rotate, duration, markerstream): """ Rotates a 3d object by a randomly chosen angle between 1 and 360 degree. Args: object_to_rotate: any 3d node object duration: duration of the rotation in seconds markerstream: LSL markerstream to push rotate value Returns: """ rotate_val = random.randint(1, 360) markerstream.push_sample(['ground_rotate']) markerstream.push_sample(['ground_rotate_angle,' + str(rotate_val)]) spinto = vizact.spinTo(euler=(rotate_val, 0, 0), time=0, mode=viz.REL_GLOBAL) fadeout = vizact.fadeTo(0, time=duration) fadein = vizact.fadeTo(1, time=duration) fadeinout = vizact.sequence(fadeout, spinto, fadein) object_to_rotate.addAction(fadeinout) markerstream.push_sample( ['object_fadeInOut, duration:' + str(duration)])
def addCarToWorld(info): car = vizfx.addChild(random.choice(info.CAR_FILES), pos=info.startPosition) actions = [] for i in range(len(info.coordinates)): actions.append(vizact.spinTo(euler=info.directions[i])) actions.append(vizact.moveTo(info.coordinates[i], speed=info.speed)) car.runAction(vizact.sequence(actions, viz.FOREVER))
def moveToDash(node): if (node == cup1):#cup1 move = vizact.sequence(vizact.moveTo([-.70,1.4,-2.4],speed=.5),vizact.moveTo([.69,1.4,-2.4],speed=.5), vizact.moveTo([.69,1.23,-2.76],speed=.5)) node.addAction(move) yield viztask.waitActionEnd(node,move) viz.sendEvent(FINDING_TASK_OVER_EVENT, SCENE) elif (node == toothBrush or node == bristles): #toothbrush move = vizact.sequence(vizact.moveTo([7,10,-3],speed=5), vizact.moveTo([10,13.5,-15],speed=5)) toothBrush.addAction(move) bristles.addAction(move) yield viztask.waitActionEnd(bristles,move) elif (node == toothPaste or node == cap): #toothpaste move = vizact.sequence(vizact.moveTo([0,1,10],speed=7),vizact.moveTo([18,1,-3],speed=7)) toothPaste.addAction(move) cap.addAction(move) yield viztask.waitActionEnd(cap,move) elif (node == bottle1 or node == bottleCap1):#bottle 1 move = vizact.moveTo([0,-17.5, -8], time=1) spin = vizact.spinTo(euler=[0,25,0], time = 1) spinMove = vizact.parallel(spin, move) move = vizact.sequence(spinMove, vizact.moveTo([15,-13,-6],speed=8), vizact.moveTo([15,-3,-6],speed=8), vizact.moveTo([18,-5,-17],speed=8)) bottle1.addAction(move) bottleCap1.addAction(move) yield viztask.waitActionEnd(bottle1,move) elif (node == bottle2 or node == bottleCap2): #bottle 2 move = vizact.sequence(vizact.moveTo([7,12,-3],speed=5), vizact.moveTo([8,12,-14],speed=5)) bottle2.addAction(move) bottleCap2.addAction(move) yield viztask.waitActionEnd(bottle2,move) elif (node == cup2): #cup 2 move = vizact.sequence(vizact.moveTo([0,2.5,0],speed=5),vizact.moveTo([15,2.5,0],speed=5), vizact.moveTo([15,0,0],speed=5)) node.addAction(move) yield viztask.waitActionEnd(node,move) viz.sendEvent(FINDING_TASK_OVER_EVENT, SCENE)
def loadMeshes(self, meshes = [], animate = False, randomize = True): """Load all of the files from the dataset into puzzle.mesh instances""" for i, fileName in enumerate(meshes): # This is the actual mesh we will see b = model.Mesh(fileName) print b.name if (not randomize): #Hardcoded keystone b.setPosition([0.0,1.5,0.0]) b.setEuler([0.0,90.0,180.0]) # [0,0,180] flip upright [0,90,180] flip upright and vertical else: # b.setPosition([(random.random()-0.5)*3, 1.0, (random.random()-0.5)*3]) # random sheet, not a donut angle = random.random() * 2 * math.pi radius = random.random() + 1.5 targetPosition = [math.sin(angle) * radius, 1.0, math.cos(angle) * radius] targetEuler = [0.0,90.0,180.0] #targetEuler = [(random.random()-0.5)*40,(random.random()-0.5)*40 + 90.0, (random.random()-0.5)*40 + 180.0] if (animate): move = vizact.moveTo(targetPosition, time = 2) spin = vizact.spinTo(euler = targetEuler, time = 2) transition = vizact.parallel(spin, move) b.addAction(transition) else: b.setPosition(targetPosition) b.setEuler(targetEuler) self._meshes.append(b) self._meshesById[b.id] = b
def SackAnim (self, sid): #sid is the sack id: {1R, 2R, 1L, or 2L} self._usedSackCounter += 1 sack = self.components['sack'+sid] self.sack_path = self.sackItem.getChild('path'+sid).copy() self.sack_path.setParent(self.factory) #prevent from appearing in MainWindow sack.setParent(self.sack_path, node='path'+sid) self.sack_path.setAnimationSpeed(1) sack.addAction(vizact.waittime(3)) #wait for sack animation endAnimSignal = vizact.signal() trig = endAnimSignal.trigger hide = vizact.method.visible(0) sack.addAction(vizact.parallel(hide, trig)) self.sackPour.addAction(endAnimSignal.wait) # wait for animation before pouring starts self.sackPour.addAction(vizact.method.alpha(1, node='sack_bent')) self.sackPour.addAction(vizact.spinTo(euler=[0,-45,0], time=.75, interpolate=vizact.easeInStrong)) self.sackPour.addAction(vizact.fadeTo(1, begin=0, time=.5, node='olive_flow')) loadSignal = vizact.signal() self.sackPour.addAction(loadSignal.trigger) self.sackPour.addAction(vizact.waittime(5)) self.sackPour.addAction(vizact.fadeTo(0, time=.5)) self.sackPour.addAction(vizact.method.setEuler([0,0,0])) # put it back standing self.mixedPulp.addAction(loadSignal.wait) # wait for olive pouring before pulp appears self.mixedPulp.addAction(vizact.method.visible(1)) #self.mixedPulp.addAction(vizact.fadeTo(1, begin=0, time=1, node='olives')) move = vizact.moveTo([0, 0, 0], time=5) resize = vizact.sizeTo([1, 1, 1], time=5, interpolate=vizact.easeIn) self.mixedPulp.addAction(vizact.parallel(move, resize)) self.sack_path.addAction(loadSignal.wait) self.sack_path.addAction(vizact.method.setAnimationSpeed(-100)) #put sack back
def MainTask(): """Top level task that controls the game""" # Display instructions and wait for key press to continue yield DisplayInstructionsTask() # Create panel to display trial results resultPanel = vizinfo.InfoPanel("", align=viz.ALIGN_CENTER, fontSize=25, icon=False, key=None) resultPanel.visible(False) viztask.waitDirector(getData) while True: num_trials += 1 # Randomly choose hiding spots from list locations = random.sample(HIDING_SPOTS, TRIAL_COUNT) # Reset score score = 0 UpdateScore(score) # Go through each position for pos in locations: # Perform a trial found = yield TrialTask(pos) # Update score and display status text if found: viz.playSound("sounds/pigeon_catch.wav") score += 1 total_score += 1 UpdateScore(score) tracker.runAction(vizact.spinTo(point=pos, time=0.8, interpolate=vizact.easeOutStrong)) resultPanel.setText(TRIAL_SUCCESS) else: viz.playSound("sounds/pigeon_fly.wav") viztask.schedule(FadeToGrayTask()) resultPanel.setText(TRIAL_FAIL) # Display success/failure message resultPanel.visible(True) # Add delay before starting next trial yield viztask.waitTime(TRIAL_DELAY) resultPanel.visible(False) # Disable gray effect gray_effect.setEnabled(False) viztask.waitDirector(writeScore, score) # Display results and ask to quit or play again resultPanel.setText(RESULTS.format(score, TRIAL_COUNT)) resultPanel.visible(True) yield viztask.waitKeyDown(" ") resultPanel.visible(False)
def snap(dog, dogTarget): """ Moves dog to the pos and euler of its target (dogTarget) """ movePos = vizact.moveTo(dogTarget.getPosition(), time=snapTransitionTime) moveAng = vizact.spinTo(euler=dogTarget.getEuler(), time=snapTransitionTime) transition = vizact.parallel(movePos, moveAng) dog.addAction(transition) viz.playSound(".\\dataset\\snap.wav") viztask.schedule(Tutorial.mechanics())
def snap(self): """ Moves dog to the pos and euler of its target (dogTarget) """ movePos = vizact.moveTo(self.outlineCenter.getPosition(), time = self.snapTransitionTime) moveAng = vizact.spinTo(euler = self.outlineCenter.getEuler(), time = self.snapTransitionTime) transition = vizact.parallel(movePos, moveAng) self.dogCenter.addAction(transition) viz.playSound(".\\dataset\\snap.wav") viztask.schedule(self.mechanics())
def moveTo(self, matrix, animate = True, time = 0.3): """ Invoked by the puzzle.snap method to handle local business """ # WARNING the full setMatrix cannot be assigned because scale is different! if (animate): move = vizact.moveTo(matrix.getPosition(), time = time, mode = viz.ABS_GLOBAL) spin = vizact.spinTo(euler = matrix.getEuler(), time = time, mode = viz.ABS_GLOBAL) transition = vizact.parallel(spin, move) self.addAction(transition) else: self.setPosition(targetPosition, viz.ABS_GLOBAL) self.setEuler(targetEuler,viz.ABS_GLOBAL)
def moveTo(self, BB, animate = True, time = 0.3): """ move bounding box to new targetPos and targetEuler """ targetPos = BB.checker.getPosition(viz.ABS_GLOBAL) targetEuler = BB.checker.getEuler(viz.ABS_GLOBAL) if (animate): move = vizact.moveTo(pos = targetPos, time = time, mode = viz.ABS_GLOBAL) spin = vizact.spinTo(euler = targetEuler, time = time, mode = viz.ABS_GLOBAL) transition = vizact.parallel(spin, move) self.addAction(transition) else: self.setPosition(targetPosition, viz.ABS_GLOBAL) self.setEuler(targetEuler,viz.ABS_GLOBAL)
def MoveTank (self): #change tank and cart animation depending on mill if self.LR == 'L': offset = .50 self.cart = self.factory.add('models/objects/cart.osgb', pos = [-23.835,0,3.97]) else: offset = 0 self.cart = self.factory.add('models/objects/cart.osgb', pos = [-5.2166,0,4.448]) self.cart.setEuler(360*offset,0,0) #millL: rotate 180 deg cTank = self.cart.insertGroupBelow('tank') cTank.visible(0) cTank.alpha(0, node='pourPulp') tank = self.components['tank'+self.LR] tank.addAction(vizact.moveTo([-0.25+offset,0,-.5], time=1, interpolate=vizact.easeInOutSine)) tank.addAction(vizact.moveTo([-0.25+offset,.5,-.5], time=.5, interpolate=vizact.easeInOutSine)) tank.addAction(vizact.spinTo(euler=[60-270*offset,0,0], time=.5)) #millL: rotate -75 deg tank.addAction(vizact.moveTo([offset,.5,-1.5], time=1, interpolate=vizact.easeInOutSine)) tank.addAction(vizact.moveTo([offset,.2,-1.5], time=.5, interpolate=vizact.easeInSine)) waitLoad = vizact.signal() tank.addAction(waitLoad.trigger) tank.addAction(vizact.method.visible(0)) cTank.addAction(waitLoad.wait) cTank.addAction(vizact.method.visible(1)) self.cart.addAction(waitLoad.wait) self.cart.addAction(vizact.call(self.PlayAudio, 'cart_roll', self.cart, viz.PLAY)) self.cart.addAction(vizact.spinTo(euler=[-20+440*offset,0,0], time=.5)) #millL: rotate to 200 deg moveCart = vizact.moveTo([-14.65-4.9*offset, 0, .75], time=3, interpolate=vizact.easeInOut) rotateCart = vizact.spinTo(euler=[0+360*offset,0,0], time=3) #millL: rotate to 180 deg self.cart.addAction(vizact.parallel(moveCart, rotateCart)) waitMove = vizact.signal() self.cart.addAction(waitMove.trigger) cTank.addAction(waitMove.wait) cTank.addAction(vizact.moveTo([0,1,-0.1], time=1)) cTank.addAction(vizact.spinTo(euler=[0,-90,0], time=1)) cTank.addAction(vizact.fadeTo(1, time=.5, node='pourPulp')) cTank.addAction(vizact.fadeTo(0, time=3, node='pulp', interpolate=vizact.easeInExp)) cTank.addAction(vizact.fadeTo(0, time=.5, node='pourPulp'))
def disperseRandom(self, nodes, animate = False): for m in nodes: angle = random.random() * 2 * math.pi radius = random.random() + 1.5 targetPosition = [math.sin(angle) * radius, math.cos(angle) * radius, -1.0] targetEuler = m.getEuler() # targetEuler = [0.0,90.0,180.0] #targetEuler = [(random.random()-0.5)*40,(random.random()-0.5)*40 + 90.0, (random.random()-0.5)*40 + 180.0] if (animate): move = vizact.moveTo(targetPosition, time = 2) spin = vizact.spinTo(euler = targetEuler, time = 2) transition = vizact.parallel(spin, move) m.addAction(transition) else: m.setPosition(targetPosition) m.setEuler(targetEuler) if isinstance(m, BoundingBox): m.disperseMembers()
def CarUpdate(): global rotateX global currentcar global speed global rotateY global deaccel if speed > 0: speed -= deaccel if speed < 0: speed += deaccel if speed < 0.1: motion = 0 else: motion = 1 move = vizact.move([0, 0, speed / 1.5], 0.1) rotate = vizact.spin(0, 1, 0, steer * (speed / 1.5) * 0.05, 0.1) viewmoveX = vizact.spinTo(quat=[rotateX, rotateY, 0, 2], time=0.1) offsetNode.clearActions() offsetNode.clearActionList() offsetNode.add(move, 0) offsetNode.add(rotate, 1) environment.setPosition(offsetNode.getPosition()) speeddisplay.message('Speed: ' + str(speed)) steerdisplay.message('Steer: ' + str(steer)) if auto: geardisplay.message('Gear: Automatic') else: if gear < 0: geardisplay.message('Gear: Reverse') if gear == 0: geardisplay.message('Gear: Neutral') else: geardisplay.message('Gear: ' + str(gear)) cardisplay.message(str(currentcar))
def closeDoor(doorObject): action2 = vizact.spinTo(axisAngle=[0, 0, -1, 0], speed=30) yield doorObject.add(action2)
def onTimer(self,num): #animation for flight if num == 1: self.count2 = self.count2+1 print(self.count2) if self.count2 == 1: viz.MainView.runAction(vizact.move([0,1,0],2)) elif self.count2 == 2: viz.MainView.runAction(vizact.move([0,0,-1],3)) elif self.count2 == 5: x=0 viz.MainView.runAction(vizact.spinTo(point=[0,30,0],time=2)) elif self.count2 == 9: #end of flight or state 2 self.avatar.stopAction(2) self.avatar.state(0) viz.MainView.setPosition([0,10,20]) viz.lookAt([0,10,0]) self.object2 = viz.addTexQuad(size=10) self.object = viz.addTexQuad(size=2) self.object2.setPosition([0,10,17]) video = viz.addVideo('fly2.avi') video.setRate(1) video.volume(0) video.play() self.object.texture(video) self.object.setAxisAngle( [0, 1, 0 , 180] ) self.object.setPosition([0,10,18]) #destroy stage for illusion flightand start next state self.model.remove() self.avatar.state(3) #start next part and reset cound self.count2 = 0 self.starttimer(3,1,28) elif num == 2: #start of animation self.count = self.count +1 print(self.count) if self.count == 17: self.textScreen.remove() self.object.remove() self.avatar.state(1) elif self.count == 20: self.avatar.stopAnimation(1) elif self.count == 22: #start flight self.starttimer(1,1,8) self.avatar.execute(2) elif num == 3: self.count2 = self.count2 + 1 if self.count2 == 9: #adding last stage viz.MainView.runAction(vizact.move([0,0,-1],7)) self.object3 = viz.addTexQuad(size=55) video = viz.addVideo('skyanim.avi') video.setRate(1) video.volume(0) video.play() video.loop() #fixing video position self.object3.texture(video) self.object3.setAxisAngle( [0, 1, 0 , 180] ) self.object3.setPosition([0,10,-10]) self.object4 = viz.addTexQuad(size=50) self.object4.setPosition([0,10,-11]) self.object.remove() self.object2.remove()
def EnterProximity(e): global wheel, steeringLink # print 'entered' origin = wheel.getCenter() vizact.spinTo(axisAngle=[0,1,0,10],point = wheel.getBoundingBox(mode = viz.ABS_LOCAL).center, speed=1)
def MainTask(): """Top level task that controls the game""" global won global manChase # Display instructions and wait for key press to continue yield DisplayInstructionsTask() yield manKicksBall() # Create panel to display trial results resultPanel = vizinfo.InfoPanel('',align=viz.ALIGN_CENTER,fontSize=25,icon=False,key=None) resultPanel.visible(False) resetManChase = False if manChase == True: resetManChase = True while True: # Randomly choose hiding spots from list locations = random.sample(HIDING_SPOTS,TRIAL_COUNT) # Reset score score = 0 UpdateScore(score) # Go through each position for pos in locations: # Perform a trial found = yield TrialTask(pos) # Update score and display status text if found: viz.playSound('sounds/pigeon_catch.wav') score += 1 UpdateScore(score) tracker.runAction(vizact.spinTo(point=pos,time=0.8,interpolate=vizact.easeOutStrong)) resultPanel.setText(TRIAL_SUCCESS) won = True data = yield viztask.waitDirector(writeData) else: viz.playSound('sounds/pigeon_fly.wav') viztask.schedule(FadeToGrayTask()) resultPanel.setText(TRIAL_FAIL) data = yield viztask.waitDirector(writeData) #allow for other animations for male2 while also ensuring #he chases the pigeon each round if resetManChase: manChase = True #Display success/failure message resultPanel.visible(True) # Add delay before starting next trial yield viztask.waitTime(TRIAL_DELAY) resultPanel.visible(False) # Disable gray effect gray_effect.setEnabled(False) #Display results and ask to quit or play again resultPanel.setText(RESULTS.format(score,TRIAL_COUNT)) resultPanel.visible(True) yield viztask.waitKeyDown(' ') resultPanel.visible(False)
def openDoor(door): action1 = vizact.spinTo(axisAngle=[0, 0, -1, 60], speed=120) yield door.addAction(action1)
def LiftBar (self, flag): self.bar.addAction(vizact.spinTo(euler=[0,0,-20*flag], time=5, interpolate=vizact.easeOut)) self.barRod.addAction(vizact.moveTo([0,40*flag,0], time=5, interpolate=vizact.easeOut))