]>
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.
14 -- Set the number of frames to be rendered for the animation.
17 -- Define the code to calculate where the camera is, in world coordinates.
18 local eye
= function(frame
)
19 -- just rotate around the center of the scene on the XZ plane
20 local center
= vec_new(0, 1, 0)
23 local t
= start
+ 2 * math
.pi
* frame
/ frames
24 local v
= vec_new(math
.cos(t
), 0, math
.sin(t
))
25 return vec_add(vec_scale(v
, distance
), center
)
28 -- Define the code to calculate where the focal point of the scene is.
29 local look
= function(frame
)
30 -- keep the camera focused on the buddha
31 return vec_new(2, 1, 2)
34 -- Define the actual objects of the scene that will be rendered, in the
35 -- extended u3d format.
37 L 0 1000000 0 1 1 1 1 1 1
38 L 0 0 1000000 1 1 1 1 1 1
40 c 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
44 c 0.7 0.3 0.2 0.8 0.2 0.1 0.9 0.2 0.2
48 c 0.1 0.2 0.7 0.1 0.3 0.9 0.2 0.1 0.8
53 c 0.9 0.8 0.9 0.8 0.7 0.9 0.9 0.8 0.7
58 -- Set the number of samples for supersampling. If this is set to a value of
59 -- two or greater, each frame will be rendered larger by the factor specified.
60 -- ImageMagick is used to scale the frames back down to size; if ImageMagick
61 -- is not installed, the resulting frames will end up bigger than they should
62 -- be and the aliasing problem will not be fixed.
65 -- Set the width and height of the viewport.
66 local size
= {w
= 640, h
= 480}
68 -- Set the number of concurrent renderings (for multi-core machines).
72 -- end of configuration
73 ---------------------------------------------------------------------------
75 local fmt
= string.format
76 local write = function(...) return io
.write(fmt(...)) end
77 local run
= function(...) return os
.execute(fmt(...)) end
79 function vec_new(x
, y
, z
)
80 return {x
= x
, y
= y
, z
= z
}
83 function vec_add(a
, b
)
84 return vec_new(a
.x
+ b
.x
, a
.y
+ b
.y
, a
.z
+ b
.z
)
87 function vec_scale(v
, s
)
88 return vec_new(v
.x
* s
, v
.y
* s
, v
.z
* s
)
93 local w
, h
= size
.w
, size
.h
94 if 1 < supersample
then
98 local filename
= fmt("frames/anim%04d.bmp", i
)
99 local command
= fmt("./rasterize -o %s >/dev/null", filename
)
100 local out
= io
.popen(command
, "w")
103 write("\27[80D\27[2Kframe\t %4d / %d", i
+ 1, frames
)
113 ]], w
, h
, e
.x
, e
.y
, e
.z
, l
.x
, l
.y
, l
.z
, size
.w
/size
.h
, scene
))
114 i
= coroutine
.yield()
116 if 1 < supersample
then
117 run("convert %s -scale %dx%d %s", filename
, size
.w
, size
.h
, filename
)
122 print("Animating scene...")
126 table.insert(threads
, coroutine
.wrap(render
))
129 run("rm -rf frames && mkdir frames >/dev/null 2>&1")
130 for i
= 0,(frames
-1) do
131 threads
[1 + (i
% jobs
)](i
)
133 for _
,thread
in ipairs(threads
) do thread(null
) end
136 if run("ffmpeg -i frames/anim%04d.bmp -b 1024k -y -an scene.avi") == 0 then
137 print("Animation written to scene.avi.")
This page took 0.043086 seconds and 4 git commands to generate.