From 06783174429fa28fb132724534155e3b5a31007e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 26 Mar 2020 18:48:48 +0100 Subject: [PATCH] library: render: scene: deserialize meshes --- pathtracer/src/render/mesh.rs | 7 +++++-- pathtracer/src/render/scene.rs | 13 +++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pathtracer/src/render/mesh.rs b/pathtracer/src/render/mesh.rs index 1c79b05..f5ad91c 100644 --- a/pathtracer/src/render/mesh.rs +++ b/pathtracer/src/render/mesh.rs @@ -1,8 +1,11 @@ use super::Object; +use serde::Deserialize; /// Represent a mesh of objects. +#[derive(Debug, PartialEq, Deserialize)] pub struct Mesh { /// The shapes composing the mesh - #[allow(unused)] // FIXME: remove when used - shapes: Vec, + pub(crate) shapes: Vec, } + +// FIXME: wavefront mesh deserialized in mesh diff --git a/pathtracer/src/render/scene.rs b/pathtracer/src/render/scene.rs index 678a5b9..57b2180 100644 --- a/pathtracer/src/render/scene.rs +++ b/pathtracer/src/render/scene.rs @@ -1,6 +1,6 @@ //! Scene rendering logic -use super::{light_aggregate::LightAggregate, object::Object, utils::*}; +use super::{light_aggregate::LightAggregate, mesh::Mesh, object::Object, utils::*}; use crate::{ core::{Camera, LightProperties, LinearColor, ReflTransEnum}, material::Material, @@ -307,6 +307,8 @@ struct SerializedScene { #[serde(default)] objects: Vec, #[serde(default)] + meshes: Vec, + #[serde(default)] background: LinearColor, #[serde(default)] aliasing_limit: u32, @@ -317,7 +319,14 @@ struct SerializedScene { } impl From for Scene { - fn from(scene: SerializedScene) -> Self { + fn from(mut scene: SerializedScene) -> Self { + let mut flattened_meshes: Vec = scene + .meshes + .into_iter() + .map(|m| m.shapes) + .flatten() + .collect(); + scene.objects.append(&mut flattened_meshes); Scene::new( scene.camera, scene.lights,