From a8d23782a4508c5bff0585c728856224fba08877 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 18 Mar 2020 15:53:33 +0100 Subject: [PATCH] library: render: scene: add deserialization --- src/render/scene.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/render/scene.rs b/src/render/scene.rs index 1f1b8e8..51d5d13 100644 --- a/src/render/scene.rs +++ b/src/render/scene.rs @@ -10,9 +10,10 @@ use bvh::ray::Ray; use image::RgbImage; use rand::prelude::thread_rng; use rand::Rng; +use serde::Deserialize; /// Represent the scene being rendered. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Deserialize)] pub struct Scene { camera: Camera, lights: LightAggregate, @@ -180,3 +181,15 @@ fn reflected(incident: Vector, normal: Vector) -> Vector { let delt = normal * (proj * 2.); incident - delt } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn deserialization_works() { + let yaml = std::include_str!("../../examples/scene.yaml"); + let _: Scene = serde_yaml::from_str(yaml).unwrap(); + // FIXME: actually test the equality ? + } +}