ft (wip): deserialization
This commit is contained in:
61
src/scenes/raw_camera.rs
Normal file
61
src/scenes/raw_camera.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{camera::Camera, vec3::Vec3};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct RawCamera {
|
||||
// output
|
||||
image_width: u32, // TODO: test these are now explicitly required (and that default impl does
|
||||
// not make these optional)
|
||||
image_height: u32,
|
||||
|
||||
// raytracing
|
||||
#[serde(default)]
|
||||
anti_alias_rate: u32,
|
||||
#[serde(default)]
|
||||
max_depth: u32,
|
||||
|
||||
// camera
|
||||
#[serde(default)]
|
||||
fov: f32,
|
||||
#[serde(default)]
|
||||
look_from: Vec3,
|
||||
#[serde(default)]
|
||||
look_at: Vec3,
|
||||
#[serde(default)]
|
||||
vup: Vec3,
|
||||
}
|
||||
|
||||
impl Default for RawCamera {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
image_width: 400,
|
||||
image_height: 300,
|
||||
anti_alias_rate: 1,
|
||||
max_depth: 10,
|
||||
fov: 70.,
|
||||
look_from: Vec3::new(0., 0., 0.),
|
||||
look_at: Vec3::new(0., 0., -1.),
|
||||
vup: Vec3::new(0., 1., 0.),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<RawCamera> for Camera {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(raw: RawCamera) -> Result<Self, Self::Error> {
|
||||
let c = Camera::new_full(
|
||||
raw.image_width,
|
||||
raw.image_height,
|
||||
raw.anti_alias_rate,
|
||||
raw.max_depth,
|
||||
raw.fov,
|
||||
raw.look_from,
|
||||
raw.look_at,
|
||||
raw.vup,
|
||||
);
|
||||
|
||||
Ok(c)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user