]>
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 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
= {x
= 0, y
= 1, z
= 0}
26 local t
= start
+ 2 * math
.pi
* frame
/ frames
32 return vec_add(vec_scale(v
, distance
), center
)
35 -- Define the code to calculate where the focal point of the scene is.
36 local look
= function(frame
)
37 return {x
= 2, y
= 1, z
= 2} -- keep focused on the buddha
40 -- Define the actual objects of the scene that will be rendered, in the
41 -- extended u3d format.
43 L 0 1000000 0 1 1 1 1 1 1
44 L 0 0 1000000 1 1 1 1 1 1
46 c 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1
50 c 0.7 0.3 0.2 0.8 0.2 0.1 0.9 0.2 0.2
54 c 0.1 0.2 0.7 0.1 0.3 0.9 0.2 0.1 0.8
58 c 0.9 0.8 0.9 0.8 0.7 0.9 0.9 0.8 0.7
67 -- Set the number of concurrent renderings (for multi-core machines).
71 -- end of configuration
72 ---------------------------------------------------------------------------
74 local fmt
= string.format
75 local write = function(...) io
.write(fmt(...)) end
77 function vec_add(a
, b
)
78 return {x
= a
.x
+ b
.x
, y
= a
.y
+ b
.y
, z
= a
.z
+ b
.z
}
81 function vec_scale(v
, s
)
82 return {x
= v
.x
* s
, y
= v
.y
* s
, z
= v
.z
* s
}
87 local filename
= fmt("frames/anim%04d.bmp", i
)
88 local command
= fmt("./rasterize -o %s >/dev/null", filename
)
89 local out
= io
.popen(command
, "w")
92 write("\27[80D\27[2Kframe\t %4d / %d", i
+ 1, frames
)
102 ]], size
.w
, size
.h
, e
.x
, e
.y
, e
.z
, l
.x
, l
.y
, l
.z
, size
.w
/size
.h
, scene
))
103 i
= coroutine
.yield()
108 print("Animating scene...")
112 table.insert(threads
, coroutine
.wrap(render
))
115 os
.execute("rm -rf frames && mkdir frames >/dev/null 2>&1")
116 for i
= 0,(frames
-1) do
117 threads
[1 + (i
% jobs
)](i
)
119 for _
,thread
in ipairs(threads
) do thread(null
) end
122 if os
.execute("ffmpeg -i frames/anim%04d.bmp -b 1024k -y -an scene.avi") == 0 then
123 print("Animation written to scene.avi.")
This page took 0.038805 seconds and 5 git commands to generate.