Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Commit b560a14

Browse files
committed
fixed wrong animate
1 parent 6dac8e4 commit b560a14

File tree

6 files changed

+60
-38
lines changed

6 files changed

+60
-38
lines changed

demo/demo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int WispEntry()
8585
};
8686

8787
render_system = std::make_unique<wr::D3D12RenderSystem>();
88-
auto window = std::make_unique<wr::Window>(GetModuleHandleA(nullptr), "D3D12 Test App", 1280, 720);
88+
auto window = std::make_unique<wr::Window>(GetModuleHandleA(nullptr), "D3D12 Test App", 1920, 1080);
8989

9090
window->SetKeyCallback([](int key, int action, int mods)
9191
{

demo/scene_viknell.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace viknell_scene
6969
bamboo_material_internal->SetMetallic(bamboo_metallic);
7070

7171
plane_model = model_pool->Load<wr::VertexColor>(material_pool.get(), texture_pool.get(), "resources/models/plane.fbx");
72-
test_model = model_pool->LoadWithMaterials<wr::VertexColor>(material_pool.get(), texture_pool.get(), "resources/models/xbot.fbx");
72+
test_model = model_pool->LoadWithMaterials<wr::VertexColor>(material_pool.get(), texture_pool.get(), "resources/models/sponza_jacco/sponza.obj");
7373
sphere_model = model_pool->Load<wr::VertexColor>(material_pool.get(), texture_pool.get(), "resources/models/sphere.fbx");
7474
}
7575

@@ -84,9 +84,12 @@ namespace viknell_scene
8484

8585
static std::shared_ptr<DebugCamera> camera;
8686
static std::shared_ptr<SplineNode> camera_spline_node;
87+
static std::shared_ptr<SplineNode> light_1_spline_node;
88+
static std::shared_ptr<SplineNode> light_2_spline_node;
8789
static std::shared_ptr<wr::LightNode> directional_light_node;
8890
static std::shared_ptr<wr::MeshNode> test_model;
8991
static std::shared_ptr<wr::LightNode> point_light_1;
92+
static std::shared_ptr<wr::LightNode> point_light_2;
9093
static float t = 0;
9194

9295
void CreateScene(wr::SceneGraph* scene_graph, wr::Window* window)
@@ -95,7 +98,9 @@ namespace viknell_scene
9598
camera->SetPosition({0, 0, 2});
9699
camera->SetSpeed(10);
97100

98-
camera_spline_node = scene_graph->CreateChild<SplineNode>(nullptr);
101+
camera_spline_node = scene_graph->CreateChild<SplineNode>(nullptr, "Camera Spline");
102+
light_1_spline_node = scene_graph->CreateChild<SplineNode>(nullptr, "Light 1 Spline");
103+
light_2_spline_node = scene_graph->CreateChild<SplineNode>(nullptr, "Light 2 Spline");
99104

100105
scene_graph->m_skybox = resources::equirectangular_environment_map;
101106
auto skybox = scene_graph->CreateChild<wr::SkyboxNode>(nullptr, resources::equirectangular_environment_map);
@@ -141,7 +146,7 @@ namespace viknell_scene
141146
point_light_1->SetRadius(5.0f);
142147
point_light_1->SetPosition({0.5, 0, -0.3});
143148

144-
auto point_light_2 = scene_graph->CreateChild<wr::LightNode>(nullptr, wr::LightType::POINT, DirectX::XMVECTOR{0, 0, 1});
149+
point_light_2 = scene_graph->CreateChild<wr::LightNode>(nullptr, wr::LightType::POINT, DirectX::XMVECTOR{0, 0, 1});
145150
point_light_2->SetRadius(5.0f);
146151
point_light_2->SetPosition({-0.5, 0.5, -0.3});
147152

@@ -157,6 +162,8 @@ namespace viknell_scene
157162
//test_model->SetPosition(pos);
158163

159164
camera->Update(ImGui::GetIO().DeltaTime);
160-
camera_spline_node->UpdateSplineNode(ImGui::GetIO().DeltaTime, point_light_1);
165+
camera_spline_node->UpdateSplineNode(ImGui::GetIO().DeltaTime, camera);
166+
light_1_spline_node->UpdateSplineNode(ImGui::GetIO().DeltaTime, point_light_1);
167+
light_2_spline_node->UpdateSplineNode(ImGui::GetIO().DeltaTime, point_light_2);
161168
}
162169
} /* cube_scene */

demo/spline_node.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,41 @@
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

114122
SplineNode::~SplineNode()
115123
{
116-
delete m_spline;
124+
if (m_spline) delete m_spline;
117125
}
118126

119127
void SplineNode::UpdateSplineNode(float delta, std::shared_ptr<wr::Node> node)

demo/spline_node.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class SplineNode : public wr::Node
1414
};
1515

1616
public:
17-
SplineNode();
17+
SplineNode(std::string name);
1818
~SplineNode();
1919

2020
void UpdateSplineNode(float delta, std::shared_ptr<wr::Node> node);
@@ -42,4 +42,6 @@ class SplineNode : public wr::Node
4242
std::vector<ControlPoint> m_control_points;
4343
float m_speed;
4444
float m_time;
45+
46+
std::string m_name;
4547
};

splines/imgui.ini

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Window][DockspaceViewport_11111111]
22
Pos=0,21
3-
Size=1878859392,597
3+
Size=32,457
44
Collapsed=0
55

66
[Window][Debug##Default]
@@ -9,20 +9,20 @@ Size=228,150
99
Collapsed=1
1010

1111
[Window][Theme]
12-
Pos=1499559168,275
13-
Size=379300224,262
12+
Pos=26,216
13+
Size=6,200
1414
Collapsed=0
1515
DockId=0x00000007,0
1616

1717
[Window][ImGui Details]
18-
Pos=1499559168,539
19-
Size=379300224,79
18+
Pos=26,418
19+
Size=6,60
2020
Collapsed=0
2121
DockId=0x00000008,0
2222

2323
[Window][Camera Settings]
24-
Pos=0,380
25-
Size=283,238
24+
Pos=0,296
25+
Size=11,182
2626
Collapsed=0
2727
DockId=0x0000000A,0
2828

@@ -48,14 +48,14 @@ Size=169,259
4848
Collapsed=0
4949

5050
[Window][DirectX 12 Settings]
51-
Pos=1499559168,275
52-
Size=379300224,262
51+
Pos=26,216
52+
Size=6,200
5353
Collapsed=0
5454
DockId=0x00000007,1
5555

5656
[Window][Hardware Info]
57-
Pos=1499559168,21
58-
Size=379300224,252
57+
Pos=26,21
58+
Size=6,193
5959
Collapsed=0
6060
DockId=0x00000003,1
6161

@@ -78,25 +78,25 @@ Collapsed=0
7878
DockId=0x00000003,2
7979

8080
[Window][Viewport]
81-
Pos=285,21
82-
Size=1499558912,597
81+
Pos=13,21
82+
Size=11,457
8383
Collapsed=0
8484
DockId=0x00000002,0
8585

8686
[Window][Scene Graph Editor]
8787
Pos=0,21
88-
Size=283,357
88+
Size=11,273
8989
Collapsed=0
9090
DockId=0x00000011,0
9191

9292
[Window][Inspector]
93-
Pos=1499559168,21
94-
Size=379300224,252
93+
Pos=26,21
94+
Size=6,193
9595
Collapsed=0
9696
DockId=0x00000003,0
9797

9898
[Docking][Data]
99-
DockSpace ID=0x4DDED0D8 Pos=0,21 Size=7808,597 Split=X
99+
DockSpace ID=0x4DDED0D8 Pos=0,21 Size=32,457 Split=X
100100
DockNode ID=0x00000004 Parent=0x4DDED0D8 SizeRef=1020,699 Split=X
101101
DockNode ID=0x00000001 Parent=0x00000004 SizeRef=283,699 Split=Y SelectedTab=0x1FA76273
102102
DockNode ID=0x00000009 Parent=0x00000001 SizeRef=463,418 Split=Y SelectedTab=0x1FA76273

splines/sponza_l1_down_hw.spl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-11.1251,1.01596,-4.34654,-0.28,-1.54,0,
2+
-4.91262,1.57599,-5.33681,-0.0799998,-3.15,0,
3+
0.683072,-0.103731,-5.63904,-0.0999997,-3.09,0,
4+
6.4464,1.81091,-5.74368,-0.13,-3.05,0,
5+
11.9735,0.973531,-4.26975,-0.14,-4.65,0,

0 commit comments

Comments
 (0)