animatepath.py
This script demonstrates
how to use animation paths. The 4 semi-transparent balls represent the
control points. The rest of the animation is done by Vizard.
Run this example
script animatepath.py from the /examples/animationPaths folder. GUI controls provided to change the
animation path properties are defined in the associated .viz file in that folder.
import viz
import vizinfo
import vizact
viz.setMultiSample(4)
viz.fov(60)
viz.go()
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
ground = viz.addChild('ground.osgb')
#Add the ball to animate
ball = viz.addChild('beachball.osgb')
#Move the viewpoint back
viz.MainView.move([0,0,-7])
#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.addChild('beachball.osgb',cache=viz.CACHE_CLONE)
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)