animatepath.py
This script demonstrates
how to use animation paths. The 4 transparent balls represent the control
points. The rest of the animation is done by Vizard. Use keys 1-7 to change
various properties of the animation path.
If you run
the script animatepath.py included in the /examples/animationPaths folder, GUI controls are provided to change
the animation path properties. These
are saved in the associated .viz file in that folder.
import viz
viz.go()
import vizinfo
vizinfo.add('This
script demonstrates how to use animation paths\nThe 4 transparent balls
represent the control points\nThe rest of the animation is done by Vizard\nUse
the on screen buttons to change certain options')
#Add the ground plane
viz.add('tut_ground.wrl')
#Add the ball to animate
ball = viz.add('ball.wrl')
#Move the viewpoint back
viz.MainView.move([0,0,-8])
#Create the animation path
path = viz.addAnimationPath()
#Initialize an array of control points
positions = [ [0,0,2], [2,0,0], [0,0,-2], [-2,0,0] ]
for x,pos in
enumerate(positions):
#Add a ball at each control point and make
it
#semi-transparent, so the user can see where
the
#control points are
b = viz.add('ball.wrl')
b.setPosition(pos)
b.alpha(0.2)
#Add the control point to the animation path
#at the new time
cp = viz.addControlPoint()
cp.setPosition(pos)
path.add(cp,x+1)
#Set the initial loop mode to circular
path.loop(viz.CIRCULAR)
#Automatically compute tangent vectors for cubic bezier
translations
path.computeTangents()
#Automatically rotate the path
path.setAutoRotate(viz.ON)
#Link the ball to the path
viz.link(path,
ball)
#Play the animation path
path.play()
def changeSpeed(pos):
#Adjust the speed of the animation path
path.speed(pos*10)
#Setup callbacks for slider events
vizact.onslider(speed, changeSpeed)
#Setup button click events
vizact.onbuttondown(no_loop,path.loop,viz.OFF)
vizact.onbuttondown(loop,path.loop,viz.LOOP)
vizact.onbuttondown(swing,path.loop,viz.SWING)
vizact.onbuttondown(circular,path.loop,viz.CIRCULAR)
vizact.onbuttondown(linear,path.setTranslateMode,viz.LINEAR_INTERP)
vizact.onbuttondown(bezier,path.setTranslateMode,viz.BEZIER)
vizact.onbuttondown(cubic,path.setTranslateMode,viz.CUBIC_BEZIER)