]>
Dogcows Code - chaz/rasterize/blob - animate.lua
4 -- CS5600 University of Utah
6 -- mcgarvey@eng.utah.edu
9 -- This program automates the process of creating simple fly-by animations.
10 -- The rasters are saved in the `frames' directory, and if ffmpeg is
11 -- installed, the frames will also be combined into a video file. This script
12 -- must be called from the same directory where the rasterize program is.
13 -- The CACHE_GEOMETRY option is also recommended to improve performance.
15 -- Set the number of frames to be rendered for the animation.
18 -- Define the code to calculate where the camera is, in world coordinates.
19 local eye
= function(frame
)
20 -- just rotate around the center of the scene on the XZ plane
21 local center
= vec_new(0, 0.4, 0)
24 local t
= start
+ 2 * math
.pi
* frame
/ frames
25 local v
= vec_new(math
.cos(t
), 0, math
.sin(t
))
26 return vec_add(vec_scale(v
, distance
), center
)
29 -- Define the code to calculate where the focal point of the scene is.
30 local look
= function(frame
)
31 -- keep the camera focused at the center
32 return vec_new(0, 0, 0)
35 -- Define the actual objects of the scene that will be rendered, in the
36 -- extended u3d format.
38 l -14687.0 7986.0 8976.0 1.0 1.0 1.0
51 -- Set the number of samples for supersampling. If this is set to a value
52 -- of two or greater, each frame will be rendered larger by the factor
53 -- specified. ImageMagick is used to scale the frames back down to size;
54 -- if ImageMagick is not installed, this script will exit with error 1.
57 -- Set the width and height of the viewport.
58 local size
= {w
= 640, h
= 480}
60 -- Set the number of concurrent renderings (for multi-core machines).
63 -- Set the options to be passed directly to ffmpeg.
64 local ffmpeg_opts
= "-b 1024k"
66 -- end of configuration
67 ---------------------------------------------------------------------------
69 function vec_new(x
, y
, z
)
70 return {x
= x
, y
= y
, z
= z
}
73 function vec_add(a
, b
)
74 return vec_new(a
.x
+ b
.x
, a
.y
+ b
.y
, a
.z
+ b
.z
)
77 function vec_scale(v
, s
)
78 return vec_new(v
.x
* s
, v
.y
* s
, v
.z
* s
)
81 local fmt
= string.format
82 local write = function(...) io
.write(fmt(...)) io
.flush() end
83 local run
= function(...) return os
.execute(fmt(...)) end
87 local w
, h
= size
.w
, size
.h
88 if 1 < supersample
then
92 local filename
= fmt("frames/anim%04d.bmp", i
)
93 local command
= fmt("./rasterize -o %s >/dev/null", filename
)
94 local out
= io
.popen(command
, "w")
97 write("\27[80D\27[2Kframe\t %4d / %d", i
, frames
)
108 ]], w
, h
, e
.x
, e
.y
, e
.z
, l
.x
, l
.y
, l
.z
, size
.w
/size
.h
, scene
))
109 i
= coroutine
.yield()
111 if 1 < supersample
and
112 run("convert %s -scale %dx%d %s", filename
, size
.w
, size
.h
, filename
) ~= 0 then
119 function renderings()
122 table.insert(t
, coroutine
.wrap(render
))
124 local iterations
= frames
+ jobs
128 if frame
<= iterations
then
130 if frames
< i
then i
= null
end
131 return t
[1 + frame
% jobs
], i
136 print("Animating scene...")
138 run("rm -rf frames && mkdir frames >/dev/null 2>&1")
139 for render
,frame
in renderings() do render(frame
) end
143 if run("ffmpeg -i frames/anim%%04d.bmp %s -y -an scene.avi", ffmpeg_opts
) == 0 then
144 print("Animation written to scene.avi.")
146 print("The animation could not be created. Is ffmpeg installed?")
This page took 0.042024 seconds and 4 git commands to generate.