Python Code for Camera AnimationΒΆ
Here are two python scripts to do camera animation: animation.py, and CameraMotion_rotate.py.
animations.py:
import visit, sys
import CameraMotion_rotate
def camera_orbit_z(focus, parallelScale):
# rotation views:
nrotviews = 5
#view normal and up vector list:
rotviews = []
rotviews += [(0.0, 1.0, 0.0)]
rotviews += [(1.0, 0.0, 0.0)]
rotviews += [(1, 0, 0)]
rotviews += [(0, -1, 0)]
rotviews += [(0, -1, 0)]
rotviews += [(-1, 0, 0)]
rotviews += [(-1, 0, 0)]
rotviews += [(0, 1, 0)]
rotviews += [(0.0, 1.0, 0.0)]
rotviews += [(1.0, 0.0, 0.0)]
CameraMotion_rotate.rotate(focus, parallelScale, nrotviews, rotviews, 1)
CameraMotion_rotate.py:
# in rotation, assume focus and parallelScale don't change
def rotate(focus, parallelScale, nviews, views, direction):
#
# Create the control points for the views.
cpts=[]
for i in range(nviews):
v=View3DAttributes()
# print i, "of", nviews
# print v
if direction>0:
v.viewNormal = views[i*2]
v.viewUp = views[i*2+1]
else:
v.viewNormal = views[(nviews-1-i)*2]
v.viewUp = views[(nviews-1-i)*2+1]
v.focus = focus #(450, 575, 850)
v.viewAngle = 30
v.parallelScale = parallelScale #1120.55
v.nearPlane = -2 * parallelScale #-2241.09
v.farPlane = 2*parallelScale #2241.09
v.imageZoom = 1.0
v.imagePan = (0, 0)
v.perspective = 1
cpts = cpts + [v]
# Create a tuple of camera values and x values. The x values are weights
# that help to determine where in [0,1] the control points occur.
# cpts = (c0, c1, c2, c3, c4, c5, c6)
x=[]
for i in range(nviews):
x = x + [float(i) / float(nviews-1)]
# Animate the camera. Note that we use the new built-in EvalCubicSpline
# function which takes a t value from [0,1] a tuple of t values and a tuple
# of control points. In this case, the control points are View3DAttributes
# objects that we are using to animate the camera but they can be any object
# that supports +, * operators.
nsteps = 100
for i in range(nsteps):
print i
t = float(i) / float(nsteps - 1)
c = EvalCubicSpline(t, x, cpts)
c.focus = focus
c.viewAngle = 30
c.parallelScale = parallelScale #1120.55
c.nearPlane = -2*parallelScale #-2241.09
c.farPlane = 2*parallelScale #2241.09
c.imageZoom = 1
c.perspective = 1
SetView3D(c)
# print c
DrawPlots()
SaveWindow()
In main python code, two necessary things to add.
In the beginning, add this line:
import animations
At the end, before delete all plots and close the database, add this line:
animations.camera_orbit_z(focus, parallelScale)
focus and parallelScale are attributes of a visit View. For example:
c = View3DAttributes()
c.focus = (0, 0.75, 0)
c.parallelScale = 5.0