use crate::core::{Node, Object3D};
use crate::materials::MeshBasicNodeMaterial;
use crate::math::{Color, Matrix4};
use crate::nodes::tsl::FogNode;
use crate::textures::CubeTexture;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum Background {
Color(Color),
CubeTexture(CubeTexture),
Node(crate::nodes::NodeRef),
Pmrem(crate::materials::environment::PmremHandle),
EnvironmentNode(crate::materials::environment::EnvironmentNode),
}
impl From<Color> for Background {
fn from(color: Color) -> Self {
Background::Color(color)
}
}
impl From<CubeTexture> for Background {
fn from(texture: CubeTexture) -> Self {
Background::CubeTexture(texture)
}
}
pub struct Scene {
pub node: Node,
pub background: Option<Background>,
pub background_blurriness: f64,
pub environment: Option<crate::materials::environment::PmremHandle>,
pub environment_node: Option<crate::materials::environment::EnvironmentNode>,
pub fog: Option<super::SceneFog>,
pub fog_node: Option<FogNode>,
pub override_material: Option<MeshBasicNodeMaterial>,
}
impl Default for Scene {
fn default() -> Self {
let object = Object3D {
object_type: "Scene",
is_scene: true,
..Default::default()
};
Self {
node: object.into_node(),
background: None,
background_blurriness: 0.0,
environment: None,
environment_node: None,
fog: None,
fog_node: None,
override_material: None,
}
}
}
impl Scene {
pub fn new() -> Self {
Self::default()
}
pub fn matrix_world(&self) -> Matrix4 {
self.node.borrow().matrix_world
}
pub fn set_background(&mut self, background: impl Into<Background>) {
self.background = Some(background.into());
}
pub fn add(&self, object: &Node) -> &Self {
self.node.add(object);
self
}
pub fn remove(&self, object: &Node) -> &Self {
self.node.remove(object);
self
}
pub fn children(&self) -> Vec<Node> {
self.node.children()
}
pub fn update_matrix_world(&self) {
self.node.update_matrix_world(false);
}
}