]>
Dogcows Code - chaz/rasterize/blob - animate.lua
a1c7389f8af95fe33b24e95999812140de178078
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 width and height of the viewport.
15 local size
= {w
= 640, h
= 480}
17 -- Set the number of frames to be rendered for the animation.
20 -- Define the code to calculate where the camera is, in world coordinates.
21 local eye
= function(frame
)
22 -- just rotate around the center of the scene on the XZ plane
23 local center
= vec_new(0, 1, 0)
26 local t
= start
+ 2 * math
.pi
* frame
/ frames
27 local v
= vec_new(math
.cos(t
), 0, math
.sin(t
))
28 return vec_add(vec_scale(v
, distance
), center
)
31 -- Define the code to calculate where the focal point of the scene is.
32 local look
= function(frame
)
33 -- keep the camera focused on the buddha
34 return vec_new(2, 1, 2)
37 -- Define the actual objects of the scene that will be rendered, in the
38 -- extended u3d format.
40 L 0 1000000 0 1 1 1 1 1 1
41 L 0 0 1000000 1 1 1 1 1 1
43 c 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
47 c 0.7 0.3 0.2 0.8 0.2 0.1 0.9 0.2 0.2
51 c 0.1 0.2 0.7 0.1 0.3 0.9 0.2 0.1 0.8
56 c 0.9 0.8 0.9 0.8 0.7 0.9 0.9 0.8 0.7
61 -- Set the number of concurrent renderings (for multi-core machines).
65 -- end of configuration
66 ---------------------------------------------------------------------------
68 local fmt
= string.format
69 local write = function(...) io
.write(fmt(...)) end
71 function vec_new(x
, y
, z
)
72 return {x
= x
, y
= y
, z
= z
}
75 function vec_add(a
, b
)
76 return vec_new(a
.x
+ b
.x
, a
.y
+ b
.y
, a
.z
+ b
.z
)
79 function vec_scale(v
, s
)
80 return vec_new(v
.x
* s
, v
.y
* s
, v
.z
* s
)
85 local filename
= fmt("frames/anim%04d.bmp", i
)
86 local command
= fmt("./rasterize -o %s >/dev/null", filename
)
87 local out
= io
.popen(command
, "w")
90 write("\27[80D\27[2Kframe\t %4d / %d", i
+ 1, frames
)
100 ]], size
.w
, size
.h
, e
.x
, e
.y
, e
.z
, l
.x
, l
.y
, l
.z
, size
.w
/size
.h
, scene
))
101 i
= coroutine
.yield()
106 print("Animating scene...")
110 table.insert(threads
, coroutine
.wrap(render
))
113 os
.execute("rm -rf frames && mkdir frames >/dev/null 2>&1")
114 for i
= 0,(frames
-1) do
115 threads
[1 + (i
% jobs
)](i
)
117 for _
,thread
in ipairs(threads
) do thread(null
) end
120 if os
.execute("ffmpeg -i frames/anim%04d.bmp -b 1024k -y -an scene.avi") == 0 then
121 print("Animation written to scene.avi.")
This page took 0.036325 seconds and 3 git commands to generate.