]>
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 raytrace 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, 0.4, 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 at the center
31 return vec_new(0, 0, 0)
34 -- Define the actual objects of the scene that will be rendered, in the
35 -- extended urt format.
37 l 0.0 10.0 1.0 0.8 0.7 0.8
38 s 0.0 0.0 0.0 1.0 1.0 0.0 0.0
41 -- Set the number of samples for supersampling. If this is set to a value
42 -- of two or greater, each frame will be rendered larger by the factor
43 -- specified. ImageMagick is used to scale the frames back down to size;
44 -- if ImageMagick is not installed, this script will exit with error 1.
47 -- Set the width and height of the viewport.
48 local size
= {w
= 800, h
= 600}
50 -- Set the number of concurrent renderings (for multi-core machines).
53 -- Set the options to be passed directly to ffmpeg.
54 local ffmpeg_opts
= "-b 1024k"
56 -- end of configuration
57 ---------------------------------------------------------------------------
59 function vec_new(x
, y
, z
)
60 return {x
= x
, y
= y
, z
= z
}
63 function vec_add(a
, b
)
64 return vec_new(a
.x
+ b
.x
, a
.y
+ b
.y
, a
.z
+ b
.z
)
67 function vec_scale(v
, s
)
68 return vec_new(v
.x
* s
, v
.y
* s
, v
.z
* s
)
71 local fmt
= string.format
72 local write = function(...) io
.write(fmt(...)) io
.flush() end
73 local run
= function(...) return os
.execute(fmt(...)) end
77 local w
, h
= size
.w
, size
.h
78 if 1 < supersample
then
82 local filename
= fmt("frames/anim%04d.bmp", i
)
83 local command
= fmt("./raytrace -o %s >/dev/null", filename
)
84 local out
= io
.popen(command
, "w")
87 write("\27[80D\27[2Kframe\t %4d / %d", i
, frames
)
98 ]], w
, h
, e
.x
, e
.y
, e
.z
, l
.x
, l
.y
, l
.z
, size
.w
/size
.h
, scene
))
101 if 1 < supersample
and
102 run("convert %s -scale %dx%d %s", filename
, size
.w
, size
.h
, filename
) ~= 0 then
109 function renderings()
112 table.insert(t
, coroutine
.wrap(render
))
114 local iterations
= frames
+ jobs
118 if frame
<= iterations
then
120 if frames
< i
then i
= null
end
121 return t
[1 + frame
% jobs
], i
126 print("Animating scene...")
128 run("rm -rf frames && mkdir frames >/dev/null 2>&1")
129 for render
,frame
in renderings() do render(frame
) end
133 if run("ffmpeg -i frames/anim%%04d.bmp %s -y -an scene.avi", ffmpeg_opts
) == 0 then
134 print("Animation written to scene.avi.")
136 print("The animation could not be created. Is ffmpeg installed?")
This page took 0.041745 seconds and 4 git commands to generate.