Skip to content

Commit d79435f

Browse files
committed
Hotfixes
- Incorporate animation interpolation. - Fix incorrect / missing animation target. - Update gltf2cp. - Use `struct` in forward declarations of `Node` (instead of `class`).
1 parent ad4143e commit d79435f

File tree

7 files changed

+29
-29
lines changed

7 files changed

+29
-29
lines changed

lib/ext/src.zip

278 Bytes
Binary file not shown.

lib/scene/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ endif()
3434

3535
target_sources(${PROJECT_NAME} PRIVATE
3636
include/${target_prefix}/scene/animation.hpp
37-
include/${target_prefix}/scene/animator.hpp
3837
include/${target_prefix}/scene/camera.hpp
3938
include/${target_prefix}/scene/fly_cam.hpp
4039
include/${target_prefix}/scene/gltf_loader.hpp
@@ -50,7 +49,7 @@ target_sources(${PROJECT_NAME} PRIVATE
5049
include/${target_prefix}/scene/scene_resources.hpp
5150
include/${target_prefix}/scene/scene.hpp
5251

53-
src/animator.cpp
52+
src/animation.cpp
5453
src/camera.cpp
5554
src/gltf_loader.cpp
5655
src/material.cpp
+15-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
#pragma once
2-
#include <facade/scene/animator.hpp>
32
#include <facade/scene/id.hpp>
3+
#include <facade/scene/interpolator.hpp>
44

55
namespace facade {
6+
struct Node;
7+
8+
struct TransformAnimator {
9+
Interpolator<glm::vec3> translation{};
10+
Interpolator<glm::quat> rotation{};
11+
Interpolator<glm::vec3> scale{};
12+
std::optional<Id<Node>> target{};
13+
14+
float elapsed{};
15+
16+
void update(Node& out_node, float dt);
17+
};
18+
619
struct Animation {
7-
Animator animator{};
8-
Id<Node> target{};
20+
TransformAnimator transform{};
921
};
1022
} // namespace facade

lib/scene/include/facade/scene/animator.hpp

-16
This file was deleted.

lib/scene/src/animator.cpp renamed to lib/scene/src/animation.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#include <facade/scene/animator.hpp>
1+
#include <facade/scene/animation.hpp>
22
#include <facade/scene/node.hpp>
33
#include <facade/util/bool.hpp>
4-
#include <algorithm>
54

65
namespace facade {
7-
void Animator::update(Node& out_node, float dt) {
6+
void TransformAnimator::update(Node& out_node, float dt) {
87
elapsed += dt;
98
auto const duration = std::max({translation.duration(), rotation.duration(), scale.duration()});
109
if (auto const p = translation(elapsed)) { out_node.transform.set_position(*p); }

lib/scene/src/gltf_loader.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,14 @@ Animation to_animation(gltf2cpp::Animation const& animation, std::span<gltf2cpp:
207207
auto ret = Animation{};
208208
for (auto const& channel : animation.channels) {
209209
auto const& sampler = animation.samplers[channel.sampler];
210+
if (sampler.interpolation == gltf2cpp::Interpolation::eCubicSpline) { continue; } // facade constraint
210211
auto const& input = accessors[sampler.input];
211212
assert(input.type == gltf2cpp::Accessor::Type::eScalar && input.component_type == gltf2cpp::ComponentType::eFloat);
212213
auto times = std::get<gltf2cpp::Accessor::Float>(input.data).span();
213214
auto const& output = accessors[sampler.output];
214215
assert(output.component_type == gltf2cpp::ComponentType::eFloat);
215216
auto const values = std::get<gltf2cpp::Accessor::Float>(output.data).span();
217+
ret.transform.target = channel.target.node;
216218
switch (channel.target.path) {
217219
case Path::eTranslation:
218220
case Path::eScale: {
@@ -221,9 +223,11 @@ Animation to_animation(gltf2cpp::Animation const& animation, std::span<gltf2cpp:
221223
vec.resize(values.size() / 3);
222224
std::memcpy(vec.data(), values.data(), values.size_bytes());
223225
if (channel.target.path == Path::eScale) {
224-
ret.animator.scale = make_interpolator<glm::vec3>(times, vec);
226+
ret.transform.scale = make_interpolator<glm::vec3>(times, vec);
227+
ret.transform.scale.interpolation = static_cast<Interpolation>(sampler.interpolation);
225228
} else {
226-
ret.animator.translation = make_interpolator<glm::vec3>(times, vec);
229+
ret.transform.translation = make_interpolator<glm::vec3>(times, vec);
230+
ret.transform.translation.interpolation = static_cast<Interpolation>(sampler.interpolation);
227231
}
228232
break;
229233
}
@@ -232,7 +236,8 @@ Animation to_animation(gltf2cpp::Animation const& animation, std::span<gltf2cpp:
232236
auto vec = std::vector<glm::quat>{};
233237
vec.resize(values.size() / 4);
234238
std::memcpy(vec.data(), values.data(), values.size_bytes());
235-
ret.animator.rotation = make_interpolator<glm::quat>(times, vec);
239+
ret.transform.rotation = make_interpolator<glm::quat>(times, vec);
240+
ret.transform.rotation.interpolation = static_cast<Interpolation>(sampler.interpolation);
236241
break;
237242
}
238243
case Path::eWeights: {

lib/scene/src/scene.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ Texture Scene::make_texture(Image::View image) const { return Texture{m_gfx, def
159159

160160
void Scene::tick(float dt) {
161161
for (auto& animation : m_storage.resources.animations.view()) {
162-
assert(animation.target < m_storage.resources.nodes.size());
163-
animation.animator.update(m_storage.resources.nodes[animation.target], dt);
162+
if (!animation.transform.target) { continue; }
163+
assert(*animation.transform.target < m_storage.resources.nodes.size());
164+
animation.transform.update(m_storage.resources.nodes[*animation.transform.target], dt);
164165
}
165166
}
166167

0 commit comments

Comments
 (0)