use crate::scene::node::constructor::NodeConstructor;
use crate::{
core::{
math::aabb::AxisAlignedBoundingBox,
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
visitor::prelude::*,
},
scene::{
base::{Base, BaseBuilder},
graph::Graph,
node::{Node, NodeTrait},
},
};
use fyrox_graph::constructor::ConstructorProvider;
use fyrox_graph::SceneGraph;
use std::ops::{Deref, DerefMut};
#[derive(Clone, Reflect, Default, Debug, ComponentProvider)]
#[reflect(derived_type = "Node")]
pub struct Pivot {
base: Base,
}
impl Visit for Pivot {
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
self.base.visit(name, visitor)
}
}
impl Deref for Pivot {
type Target = Base;
fn deref(&self) -> &Self::Target {
&self.base
}
}
impl TypeUuidProvider for Pivot {
fn type_uuid() -> Uuid {
uuid!("dd2ecb96-b1f4-4ee0-943b-2a4d1844e3bb")
}
}
impl DerefMut for Pivot {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.base
}
}
impl ConstructorProvider<Node, Graph> for Pivot {
fn constructor() -> NodeConstructor {
NodeConstructor::new::<Self>().with_variant("Pivot", |_| {
PivotBuilder::new(BaseBuilder::new().with_name("Pivot"))
.build_node()
.into()
})
}
}
impl NodeTrait for Pivot {
fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
self.base.local_bounding_box()
}
fn world_bounding_box(&self) -> AxisAlignedBoundingBox {
self.base.world_bounding_box()
}
fn id(&self) -> Uuid {
Self::type_uuid()
}
}
pub struct PivotBuilder {
base_builder: BaseBuilder,
}
impl PivotBuilder {
pub fn new(base_builder: BaseBuilder) -> Self {
Self { base_builder }
}
pub fn build_node(self) -> Node {
Node::new(Pivot {
base: self.base_builder.build_base(),
})
}
pub fn build(self, graph: &mut Graph) -> Handle<Pivot> {
graph.add_node(self.build_node()).to_variant()
}
}