use glam as math;
use glam::Vec3;
use super::Node;
use crate::components::NodeTransform;
#[derive(Default)]
pub struct NodePrototype {
pub transform: NodeTransform,
}
impl NodePrototype {
pub fn take(&mut self) -> Self {
Self {
transform: std::mem::take(&mut self.transform),
}
}
}
pub trait Builder: Sized {
type Node: Node;
fn prototype(&mut self) -> &mut NodePrototype;
fn build(self) -> Self::Node;
fn transform(mut self, transform: NodeTransform) -> Self {
self.prototype().transform = transform;
self
}
fn position(mut self, position: impl Into<Vec3>) -> Self {
self.prototype().transform.position = position.into();
self
}
fn rotation(mut self, rotation: math::Quat) -> Self {
self.prototype().transform.rotation = rotation;
self
}
fn rotation_euler_xyz(mut self, rotation: impl Into<Vec3>) -> Self {
self.prototype().transform.set_euler_xyz(rotation);
self
}
fn scale(mut self, scale: impl Into<Vec3>) -> Self {
self.prototype().transform.scale = scale.into();
self
}
fn scale_factor(mut self, scale_factor: f32) -> Self {
self.prototype().transform.scale *= scale_factor;
self
}
}
pub trait Buildable {
type Builder: Builder<Node = Self>;
fn builder() -> Self::Builder;
}