library: render: scene: deserialize meshes
This commit is contained in:
parent
f03880799b
commit
0678317442
|
@ -1,8 +1,11 @@
|
||||||
use super::Object;
|
use super::Object;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
/// Represent a mesh of objects.
|
/// Represent a mesh of objects.
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
pub struct Mesh {
|
pub struct Mesh {
|
||||||
/// The shapes composing the mesh
|
/// The shapes composing the mesh
|
||||||
#[allow(unused)] // FIXME: remove when used
|
pub(crate) shapes: Vec<Object>,
|
||||||
shapes: Vec<Object>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: wavefront mesh deserialized in mesh
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Scene rendering logic
|
//! Scene rendering logic
|
||||||
|
|
||||||
use super::{light_aggregate::LightAggregate, object::Object, utils::*};
|
use super::{light_aggregate::LightAggregate, mesh::Mesh, object::Object, utils::*};
|
||||||
use crate::{
|
use crate::{
|
||||||
core::{Camera, LightProperties, LinearColor, ReflTransEnum},
|
core::{Camera, LightProperties, LinearColor, ReflTransEnum},
|
||||||
material::Material,
|
material::Material,
|
||||||
|
@ -307,6 +307,8 @@ struct SerializedScene {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
objects: Vec<Object>,
|
objects: Vec<Object>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
meshes: Vec<Mesh>,
|
||||||
|
#[serde(default)]
|
||||||
background: LinearColor,
|
background: LinearColor,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
aliasing_limit: u32,
|
aliasing_limit: u32,
|
||||||
|
@ -317,7 +319,14 @@ struct SerializedScene {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SerializedScene> for Scene {
|
impl From<SerializedScene> for Scene {
|
||||||
fn from(scene: SerializedScene) -> Self {
|
fn from(mut scene: SerializedScene) -> Self {
|
||||||
|
let mut flattened_meshes: Vec<Object> = scene
|
||||||
|
.meshes
|
||||||
|
.into_iter()
|
||||||
|
.map(|m| m.shapes)
|
||||||
|
.flatten()
|
||||||
|
.collect();
|
||||||
|
scene.objects.append(&mut flattened_meshes);
|
||||||
Scene::new(
|
Scene::new(
|
||||||
scene.camera,
|
scene.camera,
|
||||||
scene.lights,
|
scene.lights,
|
||||||
|
|
Loading…
Reference in a new issue