rtiow: add bones of a scene file format based on toml.
This commit is contained in:
@@ -18,6 +18,7 @@ fn random_in_unit_disk() -> Vec3 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Camera {
|
||||
origin: Vec3,
|
||||
lower_left_corner: Vec3,
|
||||
|
||||
@@ -16,6 +16,7 @@ pub mod material;
|
||||
pub mod moving_sphere;
|
||||
pub mod noise;
|
||||
pub mod output;
|
||||
pub mod parser;
|
||||
pub mod ray;
|
||||
pub mod rect;
|
||||
pub mod renderer;
|
||||
|
||||
94
rtiow/renderer/src/parser.rs
Normal file
94
rtiow/renderer/src/parser.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
use crate::{
|
||||
camera::Camera,
|
||||
hitable::Hit,
|
||||
hitable_list::HitableList,
|
||||
material::Lambertian,
|
||||
renderer::Scene,
|
||||
sphere::Sphere,
|
||||
texture::{EnvMap, Texture},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
use vec3::Vec3;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
scene: SceneConfig,
|
||||
camera: CameraConfig,
|
||||
spheres: Vec<SphereConfig>,
|
||||
}
|
||||
|
||||
impl From<Config> for Scene {
|
||||
fn from(c: Config) -> Scene {
|
||||
let material = Lambertian::new([1., 0., 0.]);
|
||||
let objects: Vec<Box<dyn Hit>> = c
|
||||
.spheres
|
||||
.iter()
|
||||
.map(|sc| -> Box<dyn Hit> {
|
||||
Box::new(Sphere::new(sc.center, sc.radius, material.clone()))
|
||||
})
|
||||
.collect();
|
||||
let world: Box<dyn Hit> = Box::new(HitableList::new(objects));
|
||||
let env_map: Option<EnvMap> = None;
|
||||
|
||||
let lookfrom = Vec3::new(0., 80., 80.);
|
||||
let lookat = Vec3::new(0., 0., 0.);
|
||||
let dist_to_focus = 10.0;
|
||||
let aperture = 0.0;
|
||||
let time_min = 0.;
|
||||
let time_max = 1.;
|
||||
let camera = Camera::new(
|
||||
lookfrom,
|
||||
lookat,
|
||||
Vec3::new(0., 1., 0.),
|
||||
45.,
|
||||
c.scene.width as f32 / c.scene.height as f32,
|
||||
aperture,
|
||||
dist_to_focus,
|
||||
time_min,
|
||||
time_max,
|
||||
);
|
||||
|
||||
let scene = Scene {
|
||||
world,
|
||||
camera,
|
||||
env_map,
|
||||
subsamples: c.scene.subsamples.unwrap_or(8),
|
||||
adaptive_subsampling: c.scene.adaptive_subsampling,
|
||||
num_threads: c.scene.num_threads,
|
||||
width: c.scene.width,
|
||||
height: c.scene.height,
|
||||
global_illumination: c.scene.global_illumination.unwrap_or(true),
|
||||
};
|
||||
dbg!(&scene);
|
||||
scene
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct SceneConfig {
|
||||
subsamples: Option<usize>,
|
||||
adaptive_subsampling: Option<f32>,
|
||||
num_threads: Option<usize>,
|
||||
width: usize,
|
||||
height: usize,
|
||||
global_illumination: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct SphereConfig {
|
||||
center: [f32; 3],
|
||||
radius: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CameraConfig {
|
||||
lookfrom: [f32; 3],
|
||||
lookat: [f32; 3],
|
||||
fov: f32,
|
||||
aspect: f32,
|
||||
aperture: f32,
|
||||
focus_dist: f32,
|
||||
time_min: f32,
|
||||
time_max: f32,
|
||||
}
|
||||
@@ -99,6 +99,9 @@ pub struct Opt {
|
||||
/// Select scene to render.
|
||||
#[structopt(long = "model")]
|
||||
pub model: Option<Model>,
|
||||
/// Toml config describing scene.
|
||||
#[structopt(long = "config")]
|
||||
pub config: Option<PathBuf>,
|
||||
/// Path to store pprof profile data, i.e. /tmp/cpuprofile.pprof
|
||||
#[structopt(long = "pprof", parse(from_os_str))]
|
||||
pub pprof: Option<PathBuf>,
|
||||
@@ -126,7 +129,7 @@ pub fn opt_hash(opt: &Opt) -> String {
|
||||
}
|
||||
|
||||
// TODO(wathiede): implement the skips and then the renderer could use json as an input file type.
|
||||
#[derive(Serialize)]
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Scene {
|
||||
#[serde(skip)]
|
||||
|
||||
@@ -53,7 +53,6 @@ pub fn new(opt: &Opt) -> Scene {
|
||||
|
||||
let stl_cube = STL::parse(
|
||||
BufReader::new(Cursor::new(include_bytes!("../../stls/dragon.stl"))),
|
||||
//BufReader::new(Cursor::new(include_bytes!("../../stls/cube.stl"))),
|
||||
false,
|
||||
)
|
||||
.expect("failed to parse cube");
|
||||
|
||||
Reference in New Issue
Block a user