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::BaseSceneGraph;
40use std::ops::{Deref, DerefMut};
41
42#[derive(Clone, Reflect, Default, Debug, ComponentProvider)]
44pub struct Pivot {
45 base: Base,
46}
47
48impl Visit for Pivot {
49 fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
50 self.base.visit(name, visitor)
51 }
52}
53
54impl Deref for Pivot {
55 type Target = Base;
56
57 fn deref(&self) -> &Self::Target {
58 &self.base
59 }
60}
61
62impl TypeUuidProvider for Pivot {
63 fn type_uuid() -> Uuid {
64 uuid!("dd2ecb96-b1f4-4ee0-943b-2a4d1844e3bb")
65 }
66}
67
68impl DerefMut for Pivot {
69 fn deref_mut(&mut self) -> &mut Self::Target {
70 &mut self.base
71 }
72}
73
74impl ConstructorProvider<Node, Graph> for Pivot {
75 fn constructor() -> NodeConstructor {
76 NodeConstructor::new::<Self>().with_variant("Pivot", |_| {
77 PivotBuilder::new(BaseBuilder::new().with_name("Pivot"))
78 .build_node()
79 .into()
80 })
81 }
82}
83
84impl NodeTrait for Pivot {
85 fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
86 self.base.local_bounding_box()
87 }
88
89 fn world_bounding_box(&self) -> AxisAlignedBoundingBox {
90 self.base.world_bounding_box()
91 }
92
93 fn id(&self) -> Uuid {
94 Self::type_uuid()
95 }
96}
97
98pub struct PivotBuilder {
100 base_builder: BaseBuilder,
101}
102
103impl PivotBuilder {
104 pub fn new(base_builder: BaseBuilder) -> Self {
106 Self { base_builder }
107 }
108
109 pub fn build_node(self) -> Node {
111 Node::new(Pivot {
112 base: self.base_builder.build_base(),
113 })
114 }
115
116 pub fn build(self, graph: &mut Graph) -> Handle<Node> {
118 graph.add_node(self.build_node())
119 }
120}