PDA

View Full Version : animation pausing problem


just alex
10-11-2010, 09:08 AM
Hi,
I've got a program where a bunch of avatars are supposed to be walking around a city doing mundane things (window shopping, talking with someone, etc.)
My problem is that the avatars that I have just walking around the city block pause any time they reach a checkpoint in their animation path and they go back to their default state for a moment until they start walking again. I've tried a few tricks to get them to smooth out, but I can't figure out how to get them to just walk around. Here's the relevant code
males = []
females = []
walking = []
whichturn = 0

#List the timers.
WALKING = 0
for i in range(2):
male = viz.add('male.cfg')
male.translate(i,0,0)
male.visible(0,'male_head.cmx')
male.face(maleheads[i])
clothes = viz.add(maleclothes[i])
for j in bodyparts:
male.texture(clothes,j)
males.append(male)

for i in range(2):
female = viz.add('female.cfg')
female.translate(i,0,0)
females.append(female)
#Set up paramters for walking guy.
males[0].translate(0,0,-5)
males[0].rotate(0,1,0,-90)
males[0].whichturn = 0
males[0].set = [[1.5,0,-5],[1.5,0,15],[5,0,15],[-5,0,-5]]
males[0].end = 4
walking.append(males[0])

#Set up paramters for walking girl.
females[0].translate(1,0,-7)
females[0].rotate(0,1,0,-90)
females[0].whichturn = 0
females[0].set = [[1.5,0,0],[1,0,15],[2,0,15],[-5,0,-5]]
females[0].end = 3
walking.append(females[0])
def onkeydown(key):
if key == '0':
viz.starttimer(WALKING, .1, viz.PERPETUAL)
def ontimer(num):
global gravity, timebomb

if num == DRIVING:
for agent in driving:
path.play()
if num == WALKING:
for agent in walking:
agentposition = agent.get(viz.POSITION)
agentgap = vizmat.Distance(agentposition, agent.set[agent.whichturn])
if agentgap < .1:
agent.whichturn += 1
if agent.whichturn == agent.end:
agent.whichturn = 0

walk = vizact.walkto(agent.set[agent.whichturn][0],agent.set[agent.whichturn][1],agent.set[agent.whichturn][2])
agent.addAction(walk)

Jeff
10-11-2010, 11:53 AM
Please post an example that reproduces the issue and I can run without having to alter the code.

The viztask module may be helpful to control your program flow if you have the avatars doing one thing after another.

just alex
10-14-2010, 12:25 PM
import viz
import math
import vizmat
import vizinfo
import vizact
viz.go(viz.FULLSCREEN)


#adds the ppt
PORT_PPT = 1
ppt = viz.add('vizppt.dls')

ppt.command(3,"",3,1,3) #scales ppt tracking on xyz axis

viz.eyeheight(0)

#collisions on
#viz.collision(viz.ON)

view = viz.get(viz.MAIN_VIEWPOINT)
view.rotate(0,1,0,90)
viz.MainView.collision(viz.ON)


#This function is called when a collision occurs
#def mycollision(info):
#print 'Collided', info.object


#Create a callback for a collision event
#viz.callback(viz.COLLISION_EVENT, mycollision)

PORT_INTERSENSE = 2
isense = viz.add('intersense.dls')
tracker = viz.add('intersense.dls')
viz.tracker()
tracker.reset()



#Add the street and drop it a little bit to be below the avatars feet.
street = viz.add('objects/bspcity.bsp')
street.translate(0,-.2,0)


males = []
females = []
walking = []
whichturn = 0

#List the timers.
WALKING = 0
MALEMEETING = 3
FEMALEMEETING = 4
THROWINGMAN =7
HOLDVIEW = 8
TIMING = 9

#Add the heads for the males.
maleheads = ['Male/heads/M-015-2L.vzf','Male/heads/M-056L.vzf', 'Male/heads/M-063L.vzf']
femaleheads = []
bodyparts = ['male_legs.cmx','male_torso_LS.cmx','male_shoes.cm x']
maleclothes = ['Male/clothes/male1.jpg','Male/clothes/male2.jpg','Male/clothes/male3.jpg']
#Make some avatars.
for i in range(2):
male = viz.add('male.cfg')
male.translate(i,0,0)
male.visible(0,'male_head.cmx')
male.face(maleheads[i])
clothes = viz.add(maleclothes[i])
for j in bodyparts:
male.texture(clothes,j)
males.append(male)

for i in range(2):
female = viz.add('female.cfg')
female.translate(i,0,0)
females.append(female)



#Set up paramters for walking guy.
males[0].translate(0,0,-5)
males[0].rotate(0,1,0,-90)
males[0].whichturn = 0
males[0].set = [[1.5,0,-5],[1.5,0,15],[5,0,15],[-5,0,-5]]
males[0].end = 4
walking.append(males[0])

#Set up paramters for walking girl.
females[0].translate(1,0,-7)
females[0].rotate(0,1,0,-90)
females[0].whichturn = 0
females[0].set = [[1.5,0,0],[1,0,15],[2,0,15],[-5,0,-5]]
females[0].end = 4
walking.append(females[0])

#Add car.
car = viz.add('mini.osgx')

#set car stuff
car.translate(-1.5,0,8)
car.rotate(0,1,0,180)


#for x in range(0,len(positions)):
#cp = viz.add(viz.CONTROL_POINT)
#cp.setPosition(positions[x])
#path.add(cp,x+1)

#Set up for meeting.
males[1].translate(-9,0,21)
females[1].translate(2,0,7)
females[1].state(1)
malemoves = [2,2,4,4,2,4,4,4,4,4,4,2,2,12]
femalemoves = [6,5,12,12,1]
females[1].rotate(0,1,0,-55)
males[1].rotate(0,1,0,135)
males[1].state(1)




#Set up for timing.
timebomb = 0


def onkeydown(key):
if key == '0':
viz.starttimer(WALKING, .1, viz.PERPETUAL)


if key == '9':
females[1].addAction(6)
males[1].goto(1.6,0,7.7)
females[1].spinto(0,1,0,-55)
females[1].state(12)
viz.starttimer(MALEMEETING,.1)
viz.starttimer(FEMALEMEETING,.1)


if key == '8':
viz.starttimer(THROWINGMAN,.1)

if key == '7':
viz.starttimer(DRIVING,.1)

if key == 's':
print 's'
viz.starttimer(TIMING,1, viz.PERPETUAL)

def ontimer(num):
global gravity, timebomb

if num == WALKING:
for agent in walking:
agentposition = agent.get(viz.POSITION)
agentgap = vizmat.Distance(agentposition, agent.set[agent.whichturn])
if agentgap < .1:
agent.whichturn += 1
if agent.whichturn == agent.end:
agent.whichturn = 0

walk = vizact.walkto(agent.set[agent.whichturn][0],agent.set[agent.whichturn][1],agent.set[agent.whichturn][2])
agent.addAction(walk)


if num == MALEMEETING:
if len(malemoves)>1:
animation = malemoves.pop(0)
duration = males[1].getduration(animation)
males[1].execute(animation)
viz.starttimer(MALEMEETING, duration-.15)
else:
animation = malemoves.pop(0)
males[1].state(animation)

if num == FEMALEMEETING:
if len(femalemoves)>1:
animation = femalemoves.pop(0)
duration = females[1].getduration(animation)
females[1].execute(animation)
viz.starttimer(FEMALEMEETING, duration-.15)
else:
animation = femalemoves.pop(0)
females[1].state(animation)


if num == THROWINGMAN:
males[2].execute(9)
males[2].execute(1)
viz.starttimer(THROWINGMAN, 10)

if num == HOLDVIEW:
view.translate(-8.5,1.5,-2)

if num == TIMING:
print timebomb
timebomb += 1

if timebomb == 1:
onkeydown('0')

elif timebomb == 3:
onkeydown('8')

elif timebomb == 10:
onkeydown('9')

elif timebomb == 20:
onkeydown('3')

elif timebomb == 30:
onkeydown('1')

elif timebomb == 80:
viz.quit()

viz.callback(viz.TIMER_EVENT,ontimer)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)
viz.starttimer(HOLDVIEW,.001, viz.PERPETUAL)


There's a few left over bits from previous experiments in here, but I don't think anything left in there affects the walking around

masaki
10-15-2010, 01:34 PM
This is still not a working script. Please cut it down to *just* what produces the error and please make sure that it runs without errors.

Thanks,
Masaki

just alex
10-18-2010, 08:47 AM
Sorry, i had a case of the dumb and posted an old code I was messing with. This should all be with general stuff so you shouldn't need to make any alterations. All I really need is for the avatars to walk around continuously to create a little veracity in my city.
import viz
import math
import vizmat
import vizinfo
import vizact
viz.go()



#Add the street and drop it a little bit to be below the avatars feet.
street = viz.add('tut_ground.wrl')
street.translate(0,-.2,0)



females = []
walking = []
whichturn = 0

#List the timers.
WALKING = 0

HOLDVIEW = 8
TIMING = 9



for i in range(1):
female = viz.add('vcc_female.cfg')
female.translate(i,0,0)
females.append(female)




#Set up paramters for walking girl.
females[0].translate(1,0,-7)
females[0].rotate(0,1,0,-90)
females[0].whichturn = 0
females[0].set = [[1.5,0,0],[1,0,15],[2,0,15],[-5,0,-5]]
females[0].end = 3
walking.append(females[0])

#Add car.
car = viz.add('mini.osgx')

#set car stuff
car.translate(-1.5,0,8)
car.rotate(0,1,0,180)









#Set up for timing.
timebomb = 0


def onkeydown(key):
if key == '0':
viz.starttimer(WALKING, .1, viz.PERPETUAL)



def ontimer(num):
global gravity, timebomb


if num == WALKING:
for agent in walking:
agentposition = agent.get(viz.POSITION)
agentgap = vizmat.Distance(agentposition, agent.set[agent.whichturn])
if agentgap < .1:
agent.whichturn += 1
if agent.whichturn == agent.end:
agent.whichturn = 0

walk = vizact.walkto(agent.set[agent.whichturn][0],agent.set[agent.whichturn][1],agent.set[agent.whichturn][2])
agent.addAction(walk)



if num == HOLDVIEW:
view.translate(-8.5,1.5,-2)

if num == TIMING:
print timebomb
timebomb += 1

if timebomb == 1:
onkeydown('0')

elif timebomb == 3:
onkeydown('8')

elif timebomb == 10:
onkeydown('9')

elif timebomb == 20:
onkeydown('3')

elif timebomb == 30:
onkeydown('1')

elif timebomb == 80:
viz.quit()

viz.callback(viz.TIMER_EVENT,ontimer)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)
viz.starttimer(HOLDVIEW,.001, viz.PERPETUAL)

masaki
10-18-2010, 09:45 AM
Hi,

I rewrote your code using the viztask module. I left sample code for you in the task function to wait for a key press or a certain length of time to pass before continuing on. You might want to look into using the viztask module instead of timers - samples are in the help doc.

Best,
Masaki


import viztask

def myTask():
# wait for a certain length of time or a key press
waittime = viztask.waitTime( 1 ) #define wait one second
waitkey =viztask.waitKeyDown('0') #define wait for 0 key press
yield viztask.waitAny( [waittime, waitkey] ) # #wait for either waittime or waitkley
while True: #while loop infinitely
for agent in walking:
agentposition = agent.get(viz.POSITION)
agentgap = vizmat.Distance(agentposition, agent.set[agent.whichturn])
if agentgap < .1:
agent.whichturn += 1
if agent.whichturn == agent.end:
agent.whichturn = 0

walk = vizact.walkto(agent.set[agent.whichturn][0],agent.set[agent.whichturn][1],agent.set[agent.whichturn][2])
agent.addAction(walk)

yield viztask.waitActionEnd( agent, walk ) #wait for walk action to end for agent
print 'walk to', agent.whichturn, 'done'
yield viztask.waitTime(5) #wait 5 seconds before looping again

viztask.schedule( myTask() )

just alex
10-21-2010, 12:32 PM
Thanks much. When I was taught how to do this animation, I was taught to use timers, so I never really learned how to used viztask. It strikes me as a heck of a lot easier than using timers.