library: render: object: allow use in BVH

This commit is contained in:
Bruno BELANYI 2020-03-18 18:18:03 +01:00
parent 09af312b86
commit be4da14313

View file

@ -1,6 +1,8 @@
use crate::material::MaterialEnum; use crate::material::MaterialEnum;
use crate::shape::ShapeEnum; use crate::shape::{Shape, ShapeEnum};
use crate::texture::TextureEnum; use crate::texture::TextureEnum;
use bvh::aabb::{Bounded, AABB};
use bvh::bounding_hierarchy::BHShape;
use serde::Deserialize; use serde::Deserialize;
/// An object being rendered in the scene. /// An object being rendered in the scene.
@ -9,6 +11,8 @@ pub struct Object {
pub shape: ShapeEnum, pub shape: ShapeEnum,
pub material: MaterialEnum, pub material: MaterialEnum,
pub texture: TextureEnum, pub texture: TextureEnum,
#[serde(skip_deserializing)]
index: usize,
} }
impl Object { impl Object {
@ -17,10 +21,26 @@ impl Object {
shape, shape,
material, material,
texture, texture,
index: 0,
} }
} }
} }
impl Bounded for Object {
fn aabb(&self) -> AABB {
self.shape.aabb()
}
}
impl BHShape for Object {
fn set_bh_node_index(&mut self, index: usize) {
self.index = index
}
fn bh_node_index(&self) -> usize {
self.index
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
@ -56,6 +76,7 @@ mod test {
shape: shape.into(), shape: shape.into(),
material: material.into(), material: material.into(),
texture: texture.into(), texture: texture.into(),
index: 0,
} }
) )
} }