fyrox_impl/scene/
pivot.rs1use crate::scene::node::constructor::NodeConstructor;
23use crate::{
24 core::{
25 math::aabb::AxisAlignedBoundingBox,
26 pool::Handle,
27 reflect::prelude::*,
28 type_traits::prelude::*,
29 uuid::{uuid, Uuid},
30 visitor::prelude::*,
31 },
32 scene::{
33 base::{Base, BaseBuilder},
34 graph::Graph,
35 node::{Node, NodeTrait},
36 },
37};
38use fyrox_graph::constructor::ConstructorProvider;
39use fyrox_graph::SceneGraph;
40use std::ops::{Deref, DerefMut};
41
42#[derive(Clone, Reflect, Default, Debug, ComponentProvider)]
44#[reflect(derived_type = "Node")]
45pub struct Pivot {
46 base: Base,
47}
48
49impl Visit for Pivot {
50 fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
51 self.base.visit(name, visitor)
52 }
53}
54
55impl Deref for Pivot {
56 type Target = Base;
57
58 fn deref(&self) -> &Self::Target {
59 &self.base
60 }
61}
62
63impl TypeUuidProvider for Pivot {
64 fn type_uuid() -> Uuid {
65 uuid!("dd2ecb96-b1f4-4ee0-943b-2a4d1844e3bb")
66 }
67}
68
69impl DerefMut for Pivot {
70 fn deref_mut(&mut self) -> &mut Self::Target {
71 &mut self.base
72 }
73}
74
75impl ConstructorProvider<Node, Graph> for Pivot {
76 fn constructor() -> NodeConstructor {
77 NodeConstructor::new::<Self>().with_variant("Pivot", |_| {
78 PivotBuilder::new(BaseBuilder::new().with_name("Pivot"))
79 .build_node()
80 .into()
81 })
82 }
83}
84
85impl NodeTrait for Pivot {
86 fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
87 self.base.local_bounding_box()
88 }
89
90 fn world_bounding_box(&self) -> AxisAlignedBoundingBox {
91 self.base.world_bounding_box()
92 }
93
94 fn id(&self) -> Uuid {
95 Self::type_uuid()
96 }
97}
98
99pub struct PivotBuilder {
101 base_builder: BaseBuilder,
102}
103
104impl PivotBuilder {
105 pub fn new(base_builder: BaseBuilder) -> Self {
107 Self { base_builder }
108 }
109
110 pub fn build_node(self) -> Node {
112 Node::new(Pivot {
113 base: self.base_builder.build_base(),
114 })
115 }
116
117 pub fn build(self, graph: &mut Graph) -> Handle<Pivot> {
119 graph.add_node(self.build_node()).to_variant()
120 }
121}