Initial works for sampling root node transforms.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#define OZZ_INCLUDE_PRIVATE_HEADER
|
||||
#include "../src/animation/runtime/animation_keyframe.h"
|
||||
#include "catch.hpp"
|
||||
#include "ozzutils.h"
|
||||
|
||||
void get_bone_transform(
|
||||
int i_bone_idx,
|
||||
@@ -41,52 +42,6 @@ void sample_bone_transform(
|
||||
get_bone_transform(i_bone_idx, io_local_matrices, o_transform);
|
||||
}
|
||||
|
||||
void calc_bone_translation(
|
||||
float ratio,
|
||||
int i_bone_idx,
|
||||
const ozz::animation::Animation* i_animation,
|
||||
ozz::math::Transform& o_transform) {
|
||||
int key_idx = 0;
|
||||
const ozz::span<const ozz::animation::Float3Key>& translations =
|
||||
i_animation->translations();
|
||||
|
||||
int key_idx_prev = 0;
|
||||
int key_idx_next = 0;
|
||||
while (key_idx < translations.size()) {
|
||||
key_idx_next = key_idx;
|
||||
if (translations[key_idx].track == i_bone_idx) {
|
||||
if (translations[key_idx].ratio < ratio) {
|
||||
key_idx_prev = key_idx;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
key_idx++;
|
||||
}
|
||||
|
||||
const ozz::animation::Float3Key& key_prev = translations[key_idx_prev];
|
||||
const ozz::animation::Float3Key& key_next = translations[key_idx_next];
|
||||
|
||||
float r = 0.f;
|
||||
if (key_prev.ratio != key_next.ratio) {
|
||||
r = (ratio - key_prev.ratio) / (key_next.ratio - key_prev.ratio);
|
||||
}
|
||||
o_transform.translation.x =
|
||||
ozz::math::HalfToFloat(key_prev.value[0])
|
||||
+ r
|
||||
* (ozz::math::HalfToFloat(key_next.value[0])
|
||||
- ozz::math::HalfToFloat(key_prev.value[0]));
|
||||
o_transform.translation.y =
|
||||
ozz::math::HalfToFloat(key_prev.value[1])
|
||||
+ r
|
||||
* (ozz::math::HalfToFloat(key_next.value[1])
|
||||
- ozz::math::HalfToFloat(key_prev.value[1]));
|
||||
o_transform.translation.z =
|
||||
ozz::math::HalfToFloat(key_prev.value[2])
|
||||
+ r
|
||||
* (ozz::math::HalfToFloat(key_next.value[2])
|
||||
- ozz::math::HalfToFloat(key_prev.value[2]));
|
||||
}
|
||||
|
||||
TEST_CASE("Sample single bone channel", "[AnimSamplerNode]") {
|
||||
SkinnedMesh skinned_mesh;
|
||||
@@ -167,5 +122,5 @@ TEST_CASE("Root Bone Sampling", "[AnimSamplerNode]") {
|
||||
test_node.UpdateTime(0.2f);
|
||||
|
||||
ozz::math::Transform root_transform;
|
||||
// test_node.Evaluate(&skinned_mesh.m_local_matrices, &root_transform);
|
||||
test_node.Evaluate(&skinned_mesh.m_local_matrices, &root_transform);
|
||||
}
|
||||
Reference in New Issue
Block a user