WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   question about avatar (https://forum.worldviz.com/showthread.php?t=398)

shai 08-25-2005 04:37 PM

question about avatar
 
Hey,

I want to have an avatar animation in my program and want to wait until the whole animation has finished and then let the program keep on running.

What is the easiest way to do this? Is there some function I can use (waitfor?)?

.
.
.
male.act(2)
#command that has to be executed AFTER male.act(2) has completed

thanks,

dominic

farshizzo 08-26-2005 12:12 PM

Hi,

There are many ways to do this. You can get the duration of the animation and then setup a timer to go off in that time. Or you can use callbacks to detect when the action has finished. Here's an example of using the callback method:
Code:

import viz
viz.go()

male = viz.add('male.cfg')
male.translate(0,0,5)

action2 = vizact.animation(2)

male.add(action2)

def actionend(obj,action,pool):
        if action == action2:
                print 'Action 2 is finished'

male.callback(viz.ACTION_END_EVENT,actionend)


dominic 08-26-2005 01:35 PM

Hey,

Thanks for the reply, I guess I could try it that way.
Nevertheless, is there a way that I could do it without leaving a loop?

So something like:

x = 0
while (x < 5)
male.act(1)
ball.translate(x, 1, 1)
x++

so, that the ball wont move before the male has finished his animation? I am looking more something along the line of male.waitfor(action)

thanks,

dominic

farshizzo 08-26-2005 01:40 PM

Hi,

Is this code inside a director function? If it is, then you could do the following:
Code:

male.act(1)
viz.waittime(male.getduration(1))
ball.translate(x, 1, 1)

Otherwise you can't do this in a loop since the wait command will stall the graphics engine.

dominic 08-26-2005 01:53 PM

I tried this but that doesnt accomplish that the animation finishes before it translates the ball.

Now, the animation just is blocked until the waittime is done and after that, we are back to the original problem.

any other ideas? Or is the way to go the callback method?

thanks,

dominic

farshizzo 08-26-2005 02:47 PM

Hi,

If your code is inside a director function and you call waittime, then it will wait for the specified amount of seconds. The following sample demonstrates this. Run the script and press spacebar to start the director function.
Code:

import viz
viz.go()

male = viz.add('male.cfg')
male.translate(0,0,5)

def PerformAction():
        male.act(2)
        viz.waittime(male.getduration(2))
        print 'Action finished'

def onkeydown(key):
        if key == ' ':
                viz.director(PerformAction)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)



All times are GMT -7. The time now is 09:17 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC