66#include < fstream>
77#include < queue>
88
9- SplineNode::SplineNode () : Node(typeid (SplineNode)), m_animate(false ), m_speed(1 ), m_time(0 ), m_spline(nullptr ), m_quat_spline(nullptr )
9+ static bool initialized = false ;
10+
11+ SplineNode::SplineNode (std::string name) : Node(typeid (SplineNode)), m_name(name), m_animate(false ), m_speed(1 ), m_time(0 ), m_spline(nullptr ), m_quat_spline(nullptr )
1012{
13+ if (initialized) return ;
14+ initialized = true ;
15+
1116 wr::imgui::window::SceneGraphEditorDetails::sg_editor_type_names[typeid (SplineNode)] =
1217 {
1318 [](std::shared_ptr<Node> node) -> std::string {
14- return " Spline Node" ;
19+ auto spline_node = std::static_pointer_cast<SplineNode>(node);
20+ return spline_node->m_name ;
1521 }
1622 };
1723
1824 wr::imgui::window::SceneGraphEditorDetails::sg_editor_type_inspect[typeid (SplineNode)] =
1925 {
2026 [&](std::shared_ptr<Node> node, wr::SceneGraph* scene_graph) {
21- bool animate = m_animate;
27+ auto spline_node = std::static_pointer_cast<SplineNode>(node);
28+
29+ bool animate = spline_node->m_animate ;
2230
23- ImGui::Checkbox (" Animate" , &m_animate);
24- ImGui::DragFloat (" Speed" , &m_speed);
25- ImGui::DragFloat (" Time " , &m_time);
31+ ImGui::Checkbox (" Animate" , &spline_node-> m_animate );
32+ ImGui::DragFloat (" Speed" , &spline_node-> m_speed );
33+ ImGui::DragFloat (" Time " , &spline_node-> m_time );
2634
2735 // Started animating
28- if (m_animate && animate != m_animate)
36+ if (spline_node-> m_animate && animate != spline_node-> m_animate )
2937 {
3038 m_initial_position = scene_graph->GetActiveCamera ()->m_position ;
3139 m_initial_rotation = scene_graph->GetActiveCamera ()->m_rotation_radians ;
3240 }
3341
3442 // Stopped animating
35- if (!m_animate && animate != m_animate)
43+ if (!spline_node-> m_animate && animate != spline_node-> m_animate )
3644 {
3745 scene_graph->GetActiveCamera ()->SetPosition (m_initial_position);
3846 scene_graph->GetActiveCamera ()->SetRotation (m_initial_rotation);
@@ -44,7 +52,7 @@ SplineNode::SplineNode() : Node(typeid(SplineNode)), m_animate(false), m_speed(1
4452
4553 if (result.has_value ())
4654 {
47- SaveSplineToFile (result.value ());
55+ spline_node-> SaveSplineToFile (result.value ());
4856 }
4957 else
5058 {
@@ -60,7 +68,7 @@ SplineNode::SplineNode() : Node(typeid(SplineNode)), m_animate(false), m_speed(1
6068
6169 if (result.has_value ())
6270 {
63- LoadSplineFromFile (result.value ());
71+ spline_node-> LoadSplineFromFile (result.value ());
6472 }
6573 else
6674 {
@@ -74,18 +82,18 @@ SplineNode::SplineNode() : Node(typeid(SplineNode)), m_animate(false), m_speed(1
7482 cp.m_position = scene_graph->GetActiveCamera ()->m_position ;
7583 cp.m_rotation = scene_graph->GetActiveCamera ()->m_rotation_radians ;
7684
77- m_control_points.push_back (cp);
85+ spline_node-> m_control_points .push_back (cp);
7886 }
7987
8088 ImGui::Separator ();
8189
82- for (std::size_t i = 0 ; i < m_control_points.size (); i++)
90+ for (std::size_t i = 0 ; i < spline_node-> m_control_points .size (); i++)
8391 {
8492 auto i_str = std::to_string (i);
8593
8694 if (ImGui::TreeNode ((" Control Point " + i_str).c_str ()))
8795 {
88- auto & cp = m_control_points[i];
96+ auto & cp = spline_node-> m_control_points [i];
8997 ImGui::DragFloat3 ((" Pos##" + i_str).c_str (), cp.m_position .m128_f32 );
9098 ImGui::DragFloat3 ((" Rot##" + i_str).c_str (), cp.m_rotation .m128_f32 );
9199
@@ -106,14 +114,14 @@ SplineNode::SplineNode() : Node(typeid(SplineNode)), m_animate(false), m_speed(1
106114 }
107115 }
108116
109- UpdateNaturalSpline ();
117+ spline_node-> UpdateNaturalSpline ();
110118 }
111119 };
112120}
113121
114122SplineNode::~SplineNode ()
115123{
116- delete m_spline;
124+ if (m_spline) delete m_spline;
117125}
118126
119127void SplineNode::UpdateSplineNode (float delta, std::shared_ptr<wr::Node> node)
0 commit comments