def routeAvatar(self, aId): # assign new waypoint wp = self.UDPmanHdl.getAgentPos(aId) # get avatar by index # return -1 if this avaar has not been added yet avInd = self.getAvatarInd(aId) if avInd == -1: avInd = self.addNewAvatar(aId, wp[0], wp[1]) wp = self.UDPmanHdl.getAgentPos(aId) if not self.oneCtx: if self.avatars[aId].getCtx() == 1: if self.sceneDefHdl.bbCtx2.isPinObst(np.array([wp[0], wp[1]]), 'world'): self.avatars[aId].visible(viz.OFF) self.avatars[aId].isVisible = 0 warnings.warn( "A red avatar (# %d) tried to enter the blue zone! (# action: %d)" % (aId, self.avatars[aId].getActionCtr())) if self.avatars[aId].getCtx() == 2: if self.sceneDefHdl.bbCtx1.isPinObst(np.array([wp[0], wp[1]]), 'world'): self.avatars[aId].visible(viz.OFF) self.avatars[aId].isVisible = 0 warnings.warn( "A blue avatar (# %d) tried to enter the red zone! (# action: %d)" % (aId, self.avatars[aId].getActionCtr())) if isinstance(wp, tuple): # define walking action walk = viz.ActionData() #walk.data = [wp[0], 0, wp[1], viz.AUTO_COMPUTE, viz.AUTO_COMPUTE, vizact.ROTATION_SPEED] walk.data = [ wp[0], 0, wp[1], viz.AUTO_COMPUTE, None, vizact.ROTATION_SPEED ] # prevents animation from resetting walk.verb = 'walk' walk.turnInPlace = False walk.actionclass = vizact.VizWalkRotAction # add walk action self.avatars[avInd].addAction(walk) else: warnings.warn("Could not assign waypoint to %d" % aId)
def stiInitial(stiDuration ,frequence,phase,refreshRate): action = viz.ActionData() action.data = [stiDuration,frequence,phase,refreshRate] action.actionclass = stiAction return action
def updateWalkTarget(self, evtData): # this function will be called after any action is finished # however: only update avatars if isinstance(evtData.object, VizAvatar): # if avatar is walker if evtData.object.getAvType() == 'walker': # if there is less than X clones around if len(self.actors) < ct.N_CLONES: # if we need a clone of this context if len([ cl.getCtx() for cl in self.actors if cl.getCtx() == evtData.object.getCtx() ]) < ct.N_CLONES / 2: # if this walker has not a clone already if not evtData.object.getAvID() in [ cl.getAvID() for cl in self.actors ]: # copy avatar to clone and assign orig ID cClone = evtData.object.copy() cClone.setAvType('clone') # DEBUGGING -> set clone to transparent #cClone.alpha(0.5) # set walker avatar to invisible # -> allows to continue walking evtData.object.visible(viz.OFF) evtData.object.isVisible = 0 # queue process to look for path to closest entrance self.homeTargetFinder.findPath( evtData.object.getPosition(), cClone.getCtx(), cClone.getAvID()) # assign animation if not self.oneCtx: do = vizact.animation(random.randint(6, 10)) else: # draw from all animations anInds = [6, 7, 8, 9, 10, 14, 15, 16, 17, 18] random.shuffle(anInds) do = vizact.animation(anInds[0]) cClone.addAction(do, viz.tick()) # override addAction # save this clone in list self.actors.append(cClone) #print "Orig: ", evtData.object.getAvID() #print "Clone: ", cClone.getAvID() # assign next routing point to orig avatar self.routeAvatar(evtData.object.getAvID()) # if avatar is clone elif evtData.object.getAvType() == 'clone': cClone = evtData.object # did clone complete current action? if cClone.isActionReady(): # if clone arrived at pZone if cClone.hasArrived: # we are reaching our destination if cClone.isInHouse: # remove clone, update clone list cClone.pZone.pNode.setAnimationState(viz.STOP, node='door') # set walker to visible for cA in self.avatars: if cA.getAvID() == cClone.getAvID(): cA.visible(viz.ON) cA.isVisible = 1 # DEBUGGING: set to transparent #cA.alpha(0.5) break # remove clone node from scene and actors list cClone.remove() self.actors = [ cl for cl in self.actors if cl.getAvID() is not cA.getAvID() ] #print "actors: ", self.actors return else: # walk in house dX, dY, dZ = cClone.pZone.getDoorXYZ() walk = viz.ActionData() walk.data = [ dX, dY, dZ, viz.AUTO_COMPUTE, None, vizact.ROTATION_SPEED ] # prevents animation from resetting walk.verb = 'walk' walk.turnInPlace = False walk.actionclass = vizact.VizWalkRotAction # add walk action cClone.addAction(walk) cClone.isInHouse = 1 return # check whether this clone has been assigned to a path already # returns [] if not ready yet if not cClone.path: # poll queue pData = self.homeTargetFinder.getTarget( cClone.getAvID()) # if path is ready if pData: #print pData cClone.path = pData["path"] cClone.pZone = self.deliveryHdl.pZones[ pData["targetInd"]] cClone.nPathSteps = len(cClone.path) cClone.cPathStep = 0 # start walk animation cClone.state(2) # walk! if cClone.path: # increase pathstep cClone.cPathStep = cClone.cPathStep + 1 # if we reached middle of path -> stay a while and do an animation if cClone.cPathStep == round(cClone.nPathSteps / 2.0): # assign animation if not self.oneCtx: do = vizact.animation(random.randint(6, 10)) else: # draw from all animations anInds = [6, 7, 8, 9, 10, 14, 15, 16, 17, 18] random.shuffle(anInds) do = vizact.animation(anInds[0]) cClone.addAction(do, viz.tick()) # walk else: # if this is the last waypoint if len(cClone.path) == 1: # open door cClone.pZone.pNode.setAnimationState( viz.STOP, node='door') cClone.pZone.pNode.setAnimationSpeed( 2, node='door') cClone.pZone.pNode.setAnimationState( viz.PLAY, node='door') cClone.hasArrived = 1 # walk wp = cClone.path.pop(0) walk = viz.ActionData() # flip y coord to get to world space walk.data = [ wp[0], 0, wp[1], viz.AUTO_COMPUTE, None, vizact.ROTATION_SPEED ] # prevents animation from resetting walk.verb = 'walk' walk.turnInPlace = False walk.actionclass = vizact.VizWalkRotAction # add walk action cClone.addAction(walk) else: # assign animation if not self.oneCtx: do = vizact.animation(random.randint(6, 10)) else: # draw from all animations anInds = [6, 7, 8, 9, 10, 14, 15, 16, 17, 18] random.shuffle(anInds) do = vizact.animation(anInds[0]) cClone.addAction(do, viz.tick())
def cueInitial(cueDuration = 2): action = viz.ActionData() action.data = [cueDuration] action.actionclass = cueAction return action