Add Default implementation for Scene.
Some checks failed
continuous-integration/drone/push Build is failing
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:
parent
d796896f26
commit
7b5571344e
@ -1,6 +1,4 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str;
|
use std::str;
|
||||||
@ -24,8 +22,11 @@ use rand::Rng;
|
|||||||
use crate::camera::Camera;
|
use crate::camera::Camera;
|
||||||
use crate::hitable::Hit;
|
use crate::hitable::Hit;
|
||||||
use crate::human;
|
use crate::human;
|
||||||
|
use crate::material::Lambertian;
|
||||||
use crate::ray::Ray;
|
use crate::ray::Ray;
|
||||||
use crate::scenes;
|
use crate::scenes;
|
||||||
|
use crate::sphere::Sphere;
|
||||||
|
use crate::texture::ConstantTexture;
|
||||||
use crate::texture::EnvMap;
|
use crate::texture::EnvMap;
|
||||||
use crate::vec3::Vec3;
|
use crate::vec3::Vec3;
|
||||||
|
|
||||||
@ -186,6 +187,42 @@ pub struct Scene {
|
|||||||
pub env_map: Option<EnvMap>,
|
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
|
// 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
|
// 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.
|
// world. If false, it is expected the scene has emissive light sources.
|
||||||
|
|||||||
@ -72,7 +72,6 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
num_threads: opt.num_threads,
|
num_threads: opt.num_threads,
|
||||||
width: opt.width,
|
width: opt.width,
|
||||||
height: opt.height,
|
height: opt.height,
|
||||||
global_illumination: true,
|
..Default::default()
|
||||||
env_map: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,6 +56,7 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
height: opt.height,
|
height: opt.height,
|
||||||
global_illumination: true,
|
global_illumination: true,
|
||||||
env_map: Some(EnvMap::new(skybox)),
|
env_map: Some(EnvMap::new(skybox)),
|
||||||
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,6 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
num_threads: opt.num_threads,
|
num_threads: opt.num_threads,
|
||||||
width: opt.width,
|
width: opt.width,
|
||||||
height: opt.height,
|
height: opt.height,
|
||||||
global_illumination: true,
|
..Default::default()
|
||||||
env_map: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -134,6 +134,6 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
width: opt.width,
|
width: opt.width,
|
||||||
height: opt.height,
|
height: opt.height,
|
||||||
global_illumination: false,
|
global_illumination: false,
|
||||||
env_map: None,
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -119,7 +119,6 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
num_threads: opt.num_threads,
|
num_threads: opt.num_threads,
|
||||||
width: opt.width,
|
width: opt.width,
|
||||||
height: opt.height,
|
height: opt.height,
|
||||||
global_illumination: false,
|
..Default::default()
|
||||||
env_map: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -172,7 +172,6 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
num_threads: opt.num_threads,
|
num_threads: opt.num_threads,
|
||||||
width: opt.width,
|
width: opt.width,
|
||||||
height: opt.height,
|
height: opt.height,
|
||||||
global_illumination: false,
|
..Default::default()
|
||||||
env_map: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -152,7 +152,6 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
num_threads: opt.num_threads,
|
num_threads: opt.num_threads,
|
||||||
width: opt.width,
|
width: opt.width,
|
||||||
height: opt.height,
|
height: opt.height,
|
||||||
global_illumination: false,
|
..Default::default()
|
||||||
env_map: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,6 +69,6 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
width: opt.width,
|
width: opt.width,
|
||||||
height: opt.height,
|
height: opt.height,
|
||||||
global_illumination: true,
|
global_illumination: true,
|
||||||
env_map: None,
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -145,7 +145,6 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
num_threads: opt.num_threads,
|
num_threads: opt.num_threads,
|
||||||
width: opt.width,
|
width: opt.width,
|
||||||
height: opt.height,
|
height: opt.height,
|
||||||
global_illumination: false,
|
..Default::default()
|
||||||
env_map: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,6 +74,6 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
width: opt.width,
|
width: opt.width,
|
||||||
height: opt.height,
|
height: opt.height,
|
||||||
global_illumination: true,
|
global_illumination: true,
|
||||||
env_map: None,
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user