Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (43 sloc) 1.79 KB
use io::{Writer, WriterUtil};
use consts::*;
use raytracer::*;
fn write_ppm( fname: &str, width: uint, height: uint, pixels: &[color] ){
let writer = result::get( &io::file_writer( &Path(fname), [io::Create, io::Truncate] ) );
writer.write_str(#fmt("P6\n%u %u\n255\n", width, height));
for pixels.each |pixel| {
writer.write([pixel.r, pixel.g, pixel.b]);
};
}
fn main()
{
// Get command line args
let args = os::args();
if vec::len(args) != 2u {
io::println("Usage: rustray OBJ");
io::println("");
io::println("For example:");
io::println(" $ wget http://groups.csail.mit.edu/graphics/classes/6.837/F03/models/cow-nonormals.obj");
io::println(" $ ./rustray cow-nonormals.obj");
io::println(" $ gimp oput.ppm");
io::println("");
fail;
}
let start = std::time::precise_time_s();
io::println(~"Reading \"" + args[1] + "\"...");
let model = model::read_mesh( args[1] );
let {depth,count} = model::count_kd_tree_nodes( copy model.kd_tree );
io::println(#fmt("Done.\nLoaded model.\n\tVerts: %u, Tris: %u\n\tKD-tree depth: %u, #nodes: %u",
vec::len(model.polys.vertices),
vec::len(model.polys.indices)/3u,
depth, count));
io::print("Tracing rays... ");
let start_tracing = std::time::precise_time_s();
let pixels = raytracer::generate_raytraced_image(model, FOV, WIDTH, HEIGHT, SAMPLE_GRID_SIZE);
io::println("Done!");
let outputfile = "./oput.ppm";
io::print(~"Writing \"" + outputfile + "\"...");
write_ppm( outputfile, WIDTH, HEIGHT, pixels );
io::println("Done!");
let end = std::time::precise_time_s();
io::print(#fmt("Total time: %3.3fs, of which tracing: %3.3f\n", end - start, end - start_tracing) );
}