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,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct Camera<'a> {
|
||||
transforms: &'a [Xform],
|
||||
fovs: &'a [f32],
|
||||
tfovs: &'a [f32],
|
||||
aperture_radii: &'a [f32],
|
||||
focus_distances: &'a [f32],
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Camera {
|
||||
transforms: Vec<Xform>,
|
||||
fovs: Vec<f32>,
|
||||
tfovs: Vec<f32>,
|
||||
aperture_radii: Vec<f32>,
|
||||
focus_distances: Vec<f32>,
|
||||
}
|
||||
|
||||
impl<'a> Camera<'a> {
|
||||
impl Camera {
|
||||
pub fn new(
|
||||
arena: &'a Arena,
|
||||
transforms: &[Xform],
|
||||
fovs: &[f32],
|
||||
mut aperture_radii: &[f32],
|
||||
mut focus_distances: &[f32],
|
||||
) -> Camera<'a> {
|
||||
) -> Camera {
|
||||
assert!(!transforms.is_empty(), "Camera has no transform(s)!");
|
||||
assert!(!fovs.is_empty(), "Camera has no fov(s)!");
|
||||
|
||||
|
@ -63,20 +62,20 @@ impl<'a> Camera<'a> {
|
|||
.collect();
|
||||
|
||||
Camera {
|
||||
transforms: arena.copy_slice(&transforms),
|
||||
fovs: arena.copy_slice(&fovs),
|
||||
tfovs: arena.copy_slice(&tfovs),
|
||||
aperture_radii: arena.copy_slice(&aperture_radii),
|
||||
focus_distances: arena.copy_slice(&focus_distances),
|
||||
transforms: transforms.into(),
|
||||
fovs: fovs.into(),
|
||||
tfovs: tfovs.into(),
|
||||
aperture_radii: aperture_radii.into(),
|
||||
focus_distances: focus_distances.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_ray(&self, x: f32, y: f32, time: f32, wavelength: f32, u: f32, v: f32) -> Ray {
|
||||
// Get time-interpolated camera settings
|
||||
let transform = lerp_slice(self.transforms, time).to_full_fast().unwrap();
|
||||
let tfov = lerp_slice(self.tfovs, time);
|
||||
let aperture_radius = lerp_slice(self.aperture_radii, time);
|
||||
let focus_distance = lerp_slice(self.focus_distances, time);
|
||||
let transform = lerp_slice(&self.transforms, time).to_full_fast().unwrap();
|
||||
let tfov = lerp_slice(&self.tfovs, time);
|
||||
let aperture_radius = lerp_slice(&self.aperture_radii, time);
|
||||
let focus_distance = lerp_slice(&self.focus_distances, time);
|
||||
|
||||
// Ray origin
|
||||
let orig = {
|
||||
|
|
|
@ -150,10 +150,7 @@ pub fn parse_scene<'a>(
|
|||
)?;
|
||||
|
||||
// Parse camera
|
||||
let camera = parse_camera(
|
||||
arena,
|
||||
tree.iter_children_with_type("Camera").nth(0).unwrap(),
|
||||
)?;
|
||||
let camera = parse_camera(tree.iter_children_with_type("Camera").nth(0).unwrap())?;
|
||||
|
||||
// Parse world
|
||||
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 {
|
||||
let mut mats = 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(
|
||||
arena,
|
||||
&mats,
|
||||
&fovs,
|
||||
&aperture_radii,
|
||||
&focus_distances,
|
||||
));
|
||||
return Ok(Camera::new(&mats, &fovs, &aperture_radii, &focus_distances));
|
||||
} else {
|
||||
return Err(PsyParseError::ExpectedInternalNode(
|
||||
tree.byte_offset(),
|
||||
|
|
|
@ -18,7 +18,7 @@ pub use self::{
|
|||
#[derive(Debug)]
|
||||
pub struct Scene<'a> {
|
||||
pub name: Option<String>,
|
||||
pub camera: Camera<'a>,
|
||||
pub camera: Camera,
|
||||
pub world: World<'a>,
|
||||
pub root: Assembly<'a>,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user