executable: allow the choice of renderer

This commit is contained in:
Bruno BELANYI 2020-03-29 21:04:24 +02:00
parent 5ebad7c1ab
commit 83ed6406ac

View file

@ -1,8 +1,18 @@
use pathtracer::render::Raytracer; use pathtracer::render::Raytracer;
use pathtracer::scene::Scene; use pathtracer::scene::Scene;
use std::path::PathBuf; use std::path::PathBuf;
use std::str;
use structopt::clap::arg_enum;
use structopt::StructOpt; use structopt::StructOpt;
arg_enum! {
#[derive(Debug)]
enum RenderOption {
Raytracer,
Pathtracer,
}
}
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
struct Options { struct Options {
/// Input description for the scene to be rendered. /// Input description for the scene to be rendered.
@ -11,6 +21,15 @@ struct Options {
/// Output image for the rendered scene. /// Output image for the rendered scene.
#[structopt(short, long, parse(from_os_str), default_value = "scene.png")] #[structopt(short, long, parse(from_os_str), default_value = "scene.png")]
output: PathBuf, output: PathBuf,
/// Which renderer should be used on the input scene.
#[structopt(
short,
long,
possible_values = &RenderOption::variants(),
case_insensitive = true,
default_value = "Raytracer"
)]
renderer: RenderOption,
} }
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -18,7 +37,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let f = std::fs::File::open(options.input)?; let f = std::fs::File::open(options.input)?;
let scene: Scene = serde_yaml::from_reader(f)?; let scene: Scene = serde_yaml::from_reader(f)?;
let image = Raytracer::new(scene).render(); let image = match options.renderer {
RenderOption::Raytracer => Raytracer::new(scene).render(),
RenderOption::Pathtracer => todo!(),
};
image.save(options.output)?; image.save(options.output)?;
Ok(()) Ok(())