Add Default implementation for Scene.
Some checks failed
continuous-integration/drone/push Build is failing

This makes it so adding new fields doesn't require changing all the
Scene's at once.
This commit is contained in:
Bill Thiede 2019-10-12 20:27:57 -07:00
parent d796896f26
commit 7b5571344e
11 changed files with 49 additions and 17 deletions

View File

@ -1,6 +1,4 @@
use std::fmt;
use std::io;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;
use std::str;
@ -24,8 +22,11 @@ use rand::Rng;
use crate::camera::Camera;
use crate::hitable::Hit;
use crate::human;
use crate::material::Lambertian;
use crate::ray::Ray;
use crate::scenes;
use crate::sphere::Sphere;
use crate::texture::ConstantTexture;
use crate::texture::EnvMap;
use crate::vec3::Vec3;
@ -186,6 +187,42 @@ pub struct Scene {
pub env_map: Option<EnvMap>,
}
impl Default for Scene {
fn default() -> Scene {
let lookfrom = Vec3::new(20., 20., 20.);
let lookat = Vec3::new(0., 0., 0.);
let dist_to_focus = (lookfrom - lookat).length();
let aperture = 0.1;
let time_min = 0.;
let time_max = 1.;
let camera = Camera::new(
lookfrom,
lookat,
Vec3::new(0., 1., 0.),
70.,
1.,
aperture,
dist_to_focus,
time_min,
time_max,
);
Scene {
world: Box::new(Sphere::new(
Vec3::new(0., 0., 0.),
1.0,
Lambertian::new(ConstantTexture::new([0., 1., 0.])),
)),
camera,
subsamples: 0,
num_threads: None,
width: 0,
height: 0,
global_illumination: false,
env_map: None,
}
}
}
// color will trace ray up to 50 bounces deep accumulating color as it goes. If
// global_illumination is true, a default light background color is assumed and will light the
// world. If false, it is expected the scene has emissive light sources.

View File

@ -72,7 +72,6 @@ pub fn new(opt: &Opt) -> Scene {
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
global_illumination: true,
env_map: None,
..Default::default()
}
}

View File

@ -56,6 +56,7 @@ pub fn new(opt: &Opt) -> Scene {
height: opt.height,
global_illumination: true,
env_map: Some(EnvMap::new(skybox)),
..Default::default()
}
}

View File

@ -66,7 +66,6 @@ pub fn new(opt: &Opt) -> Scene {
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
global_illumination: true,
env_map: None,
..Default::default()
}
}

View File

@ -134,6 +134,6 @@ pub fn new(opt: &Opt) -> Scene {
width: opt.width,
height: opt.height,
global_illumination: false,
env_map: None,
..Default::default()
}
}

View File

@ -119,7 +119,6 @@ pub fn new(opt: &Opt) -> Scene {
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
global_illumination: false,
env_map: None,
..Default::default()
}
}

View File

@ -172,7 +172,6 @@ pub fn new(opt: &Opt) -> Scene {
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
global_illumination: false,
env_map: None,
..Default::default()
}
}

View File

@ -152,7 +152,6 @@ pub fn new(opt: &Opt) -> Scene {
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
global_illumination: false,
env_map: None,
..Default::default()
}
}

View File

@ -69,6 +69,6 @@ pub fn new(opt: &Opt) -> Scene {
width: opt.width,
height: opt.height,
global_illumination: true,
env_map: None,
..Default::default()
}
}

View File

@ -145,7 +145,6 @@ pub fn new(opt: &Opt) -> Scene {
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
global_illumination: false,
env_map: None,
..Default::default()
}
}

View File

@ -74,6 +74,6 @@ pub fn new(opt: &Opt) -> Scene {
width: opt.width,
height: opt.height,
global_illumination: true,
env_map: None,
..Default::default()
}
}