rtiow: add bones of a scene file format based on toml.

This commit is contained in:
2023-02-15 14:40:25 -08:00
parent 9353ff675e
commit 37137ac9ca
8 changed files with 152 additions and 8 deletions

View File

@@ -7,8 +7,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.69"
log = "0.4.17"
renderer = { path = "../renderer" }
stderrlog = "0.4.3"
structopt = "0.2.18"
strum = "0.24.1"
toml = "0.7.2"

View File

@@ -0,0 +1,24 @@
[scene]
width = 768
height = 768
subsamples = 1000
[camera]
lookfrom = [0.0, 10.0, 0.0]
lookat = [0.0, 0.0, 0.0]
fov = 45.0
aspect = 1
aperture = 0.0
focus_dist = 10.0
time_min = 0.0
time_max = 1.0
[[spheres]]
center = [0.0, 0.0, 0.0]
radius = 10
[[spheres]]
center = [30.0, 0.0, 0.0]
radius = 10
[[spheres]]
center = [-30.0, 0.0, 0.0]
radius = 10

View File

@@ -1,12 +1,16 @@
#![warn(unused_extern_crates)]
use std::{fs, time::Instant};
use anyhow::Result;
#[cfg(feature = "profile")]
use cpuprofiler::PROFILER;
use log::info;
use structopt::StructOpt;
use renderer::renderer::{render, Model, Opt};
use renderer::{
parser::Config,
renderer::{render, Model, Opt},
};
use strum::VariantNames;
#[cfg(not(feature = "profile"))]
@@ -35,7 +39,7 @@ impl MockProfiler {
#[cfg(not(feature = "profile"))]
static PROFILER: MockProfiler = MockProfiler {};
fn main() -> Result<(), std::io::Error> {
fn main() -> Result<()> {
let start_time = Instant::now();
stderrlog::new()
.verbosity(3)
@@ -43,12 +47,28 @@ fn main() -> Result<(), std::io::Error> {
.init()
.unwrap();
let opt = Opt::from_args();
if opt.model.is_none() {
eprintln!("--model should be one of {:?}", Model::VARIANTS);
if opt.model.is_none() && opt.config.is_none() {
eprintln!(
"--config <path> or --model should be one of {:?}",
Model::VARIANTS
);
return Ok(());
}
if opt.model.is_some() && opt.config.is_some() {
eprintln!("only specify one of --config or --model");
return Ok(());
}
info!("{:#?}", opt);
let scene = opt.model.as_ref().unwrap().scene(&opt);
let scene = match (&opt.model, &opt.config) {
(Some(model), None) => model.scene(&opt),
(None, Some(config)) => {
let s = std::fs::read_to_string(config)?;
let cfg: Config = toml::from_str(&s)?;
println!("{:#?}", cfg);
cfg.into()
}
_ => unreachable!(),
};
fs::create_dir_all(&opt.output)?;
if opt.pprof.is_some() && !cfg!(feature = "profile") {
panic!("profiling disabled at compile time, but -pprof specified");
@@ -68,5 +88,5 @@ fn main() -> Result<(), std::io::Error> {
let time_diff = Instant::now() - start_time;
info!("Total runtime {} seconds", time_diff.as_secs_f32());
res
Ok(res?)
}