use alloc::string::String;
#[cfg(feature = "std")]
use scenix_core::Named;
use scenix_core::{CameraId, LightId, MaterialId, MeshId};
use scenix_math::Transform;
use crate::Sprite;
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum NodeKind {
#[default]
Empty,
Group,
Mesh {
mesh_id: MeshId,
material_id: MaterialId,
},
Light {
light_id: LightId,
},
Camera {
camera_id: CameraId,
},
Sprite(Sprite),
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SceneNode {
pub name: String,
pub transform: Transform,
pub visible: bool,
pub layer: u32,
pub kind: NodeKind,
}
impl SceneNode {
#[inline]
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
transform: Transform::IDENTITY,
visible: true,
layer: u32::MAX,
kind: NodeKind::Empty,
}
}
#[inline]
pub fn empty(name: impl Into<String>) -> Self {
Self::new(name)
}
#[inline]
pub fn group(name: impl Into<String>) -> Self {
Self::new(name).kind(NodeKind::Group)
}
#[inline]
pub fn mesh(name: impl Into<String>, mesh_id: MeshId, material_id: MaterialId) -> Self {
Self::new(name).kind(NodeKind::Mesh {
mesh_id,
material_id,
})
}
#[inline]
pub fn light(name: impl Into<String>, light_id: LightId) -> Self {
Self::new(name).kind(NodeKind::Light { light_id })
}
#[inline]
pub fn camera(name: impl Into<String>, camera_id: CameraId) -> Self {
Self::new(name).kind(NodeKind::Camera { camera_id })
}
#[inline]
pub fn sprite(name: impl Into<String>, sprite: Sprite) -> Self {
Self::new(name).kind(NodeKind::Sprite(sprite))
}
#[inline]
pub fn transform(mut self, transform: Transform) -> Self {
self.transform = transform;
self
}
#[inline]
pub const fn visible(mut self, visible: bool) -> Self {
self.visible = visible;
self
}
#[inline]
pub const fn layer(mut self, layer: u32) -> Self {
self.layer = layer;
self
}
#[inline]
pub fn kind(mut self, kind: NodeKind) -> Self {
self.kind = kind;
self
}
}
impl Default for SceneNode {
#[inline]
fn default() -> Self {
Self::new("")
}
}
#[cfg(feature = "std")]
impl Named for SceneNode {
#[inline]
fn name(&self) -> &str {
&self.name
}
#[inline]
fn set_name(&mut self, name: impl Into<String>) {
self.name = name.into();
}
}