diff --git a/src/render/light_aggregate.rs b/src/render/light_aggregate.rs index aecb6e9..83052e3 100644 --- a/src/render/light_aggregate.rs +++ b/src/render/light_aggregate.rs @@ -1,7 +1,8 @@ use crate::light::*; +use serde::Deserialize; use std::iter::Iterator; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Deserialize)] pub struct LightAggregate { ambients: Vec, directionals: Vec, @@ -70,4 +71,44 @@ mod test { let lights = ::default(); assert_eq!(lights, LightAggregate::empty()) } + + #[test] + fn deserialization_works() { + use crate::{core::LinearColor, Point, Vector}; + + let yaml = r#" + ambients: + - color: {r: 1.0, g: 0.5, b: 0.2} + directionals: + - direction: [1.0, 0.0, 0.0] + color: {r: 1.0, g: 0.5, b: 0.2} + points: + - position: [1.0, 1.0, 1.0] + color: {r: 1.0, g: 0.5, b: 0.2} + spots: + - position: [0.0, 0.0, 0.0] + direction: [1.0, 0.0, 0.0] + fov: 90.0 + color: {r: 1.0, g: 0.5, b: 0.2} + "#; + let expected = LightAggregate::new( + vec![AmbientLight::new(LinearColor::new(1., 0.5, 0.2))], + vec![DirectionalLight::new( + Vector::new(1., 0., 0.), + LinearColor::new(1., 0.5, 0.2), + )], + vec![PointLight::new( + Point::new(1., 1., 1.), + LinearColor::new(1., 0.5, 0.2), + )], + vec![SpotLight::degrees_new( + Point::origin(), + Vector::new(1., 0., 0.), + 90., + LinearColor::new(1., 0.5, 0.2), + )], + ); + let lights: LightAggregate = serde_yaml::from_str(yaml).unwrap(); + assert_eq!(lights, expected) + } }