Make Camera own its own memory.
This commit is contained in:
parent
6decc48648
commit
b5bf580b96
|
@ -9,23 +9,22 @@ use crate::{
|
||||||
sampling::square_to_circle,
|
sampling::square_to_circle,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Camera<'a> {
|
pub struct Camera {
|
||||||
transforms: &'a [Xform],
|
transforms: Vec<Xform>,
|
||||||
fovs: &'a [f32],
|
fovs: Vec<f32>,
|
||||||
tfovs: &'a [f32],
|
tfovs: Vec<f32>,
|
||||||
aperture_radii: &'a [f32],
|
aperture_radii: Vec<f32>,
|
||||||
focus_distances: &'a [f32],
|
focus_distances: Vec<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Camera<'a> {
|
impl Camera {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
arena: &'a Arena,
|
|
||||||
transforms: &[Xform],
|
transforms: &[Xform],
|
||||||
fovs: &[f32],
|
fovs: &[f32],
|
||||||
mut aperture_radii: &[f32],
|
mut aperture_radii: &[f32],
|
||||||
mut focus_distances: &[f32],
|
mut focus_distances: &[f32],
|
||||||
) -> Camera<'a> {
|
) -> Camera {
|
||||||
assert!(!transforms.is_empty(), "Camera has no transform(s)!");
|
assert!(!transforms.is_empty(), "Camera has no transform(s)!");
|
||||||
assert!(!fovs.is_empty(), "Camera has no fov(s)!");
|
assert!(!fovs.is_empty(), "Camera has no fov(s)!");
|
||||||
|
|
||||||
|
@ -63,20 +62,20 @@ impl<'a> Camera<'a> {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Camera {
|
Camera {
|
||||||
transforms: arena.copy_slice(&transforms),
|
transforms: transforms.into(),
|
||||||
fovs: arena.copy_slice(&fovs),
|
fovs: fovs.into(),
|
||||||
tfovs: arena.copy_slice(&tfovs),
|
tfovs: tfovs.into(),
|
||||||
aperture_radii: arena.copy_slice(&aperture_radii),
|
aperture_radii: aperture_radii.into(),
|
||||||
focus_distances: arena.copy_slice(&focus_distances),
|
focus_distances: focus_distances.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_ray(&self, x: f32, y: f32, time: f32, wavelength: f32, u: f32, v: f32) -> Ray {
|
pub fn generate_ray(&self, x: f32, y: f32, time: f32, wavelength: f32, u: f32, v: f32) -> Ray {
|
||||||
// Get time-interpolated camera settings
|
// Get time-interpolated camera settings
|
||||||
let transform = lerp_slice(self.transforms, time).to_full_fast().unwrap();
|
let transform = lerp_slice(&self.transforms, time).to_full_fast().unwrap();
|
||||||
let tfov = lerp_slice(self.tfovs, time);
|
let tfov = lerp_slice(&self.tfovs, time);
|
||||||
let aperture_radius = lerp_slice(self.aperture_radii, time);
|
let aperture_radius = lerp_slice(&self.aperture_radii, time);
|
||||||
let focus_distance = lerp_slice(self.focus_distances, time);
|
let focus_distance = lerp_slice(&self.focus_distances, time);
|
||||||
|
|
||||||
// Ray origin
|
// Ray origin
|
||||||
let orig = {
|
let orig = {
|
||||||
|
|
|
@ -150,10 +150,7 @@ pub fn parse_scene<'a>(
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Parse camera
|
// Parse camera
|
||||||
let camera = parse_camera(
|
let camera = parse_camera(tree.iter_children_with_type("Camera").nth(0).unwrap())?;
|
||||||
arena,
|
|
||||||
tree.iter_children_with_type("Camera").nth(0).unwrap(),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Parse world
|
// Parse world
|
||||||
let world = parse_world(arena, tree.iter_children_with_type("World").nth(0).unwrap())?;
|
let world = parse_world(arena, tree.iter_children_with_type("World").nth(0).unwrap())?;
|
||||||
|
@ -347,7 +344,7 @@ fn parse_render_settings(tree: &DataTree) -> Result<((u32, u32), u32, u32), PsyP
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_camera<'a>(arena: &'a Arena, tree: &'a DataTree) -> Result<Camera<'a>, PsyParseError> {
|
fn parse_camera<'a>(tree: &'a DataTree) -> Result<Camera, PsyParseError> {
|
||||||
if let DataTree::Internal { ref children, .. } = *tree {
|
if let DataTree::Internal { ref children, .. } = *tree {
|
||||||
let mut mats = Vec::new();
|
let mut mats = Vec::new();
|
||||||
let mut fovs = Vec::new();
|
let mut fovs = Vec::new();
|
||||||
|
@ -432,13 +429,7 @@ fn parse_camera<'a>(arena: &'a Arena, tree: &'a DataTree) -> Result<Camera<'a>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(Camera::new(
|
return Ok(Camera::new(&mats, &fovs, &aperture_radii, &focus_distances));
|
||||||
arena,
|
|
||||||
&mats,
|
|
||||||
&fovs,
|
|
||||||
&aperture_radii,
|
|
||||||
&focus_distances,
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
return Err(PsyParseError::ExpectedInternalNode(
|
return Err(PsyParseError::ExpectedInternalNode(
|
||||||
tree.byte_offset(),
|
tree.byte_offset(),
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub use self::{
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Scene<'a> {
|
pub struct Scene<'a> {
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub camera: Camera<'a>,
|
pub camera: Camera,
|
||||||
pub world: World<'a>,
|
pub world: World<'a>,
|
||||||
pub root: Assembly<'a>,
|
pub root: Assembly<'a>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user