Compare commits
No commits in common. "b8d863c8e10fdef74619906fa75d5e6da0260ccb" and "6aabe98931e3dd88b89f4e7ac9cd82d9f5b253b9" have entirely different histories.
b8d863c8e1
...
6aabe98931
@ -17,7 +17,7 @@ enum class AnimNodeType { Blend, SpeedScale, AnimSampler };
|
|||||||
struct AnimNode {
|
struct AnimNode {
|
||||||
AnimNode(AnimationController* animation_controller)
|
AnimNode(AnimationController* animation_controller)
|
||||||
: m_animation_controller(animation_controller),
|
: m_animation_controller(animation_controller),
|
||||||
m_time_current(0.f),
|
m_current_time(0.f),
|
||||||
m_is_time_synced(false) {}
|
m_is_time_synced(false) {}
|
||||||
virtual ~AnimNode(){};
|
virtual ~AnimNode(){};
|
||||||
|
|
||||||
@ -27,10 +27,10 @@ struct AnimNode {
|
|||||||
|
|
||||||
// When synced then current time is relative to the node's anim duration.:w
|
// When synced then current time is relative to the node's anim duration.:w
|
||||||
bool m_is_time_synced;
|
bool m_is_time_synced;
|
||||||
float m_time_current;
|
float m_current_time;
|
||||||
SyncTrack m_sync_track;
|
SyncTrack m_sync_track;
|
||||||
|
|
||||||
virtual void Reset() { m_time_current = 0.f; }
|
virtual void Reset() { m_current_time = 0.f; }
|
||||||
|
|
||||||
// Mark current node according to is_synced and propagate flag to animation inputs.
|
// Mark current node according to is_synced and propagate flag to animation inputs.
|
||||||
virtual void UpdateIsSynced(bool is_synced) = 0;
|
virtual void UpdateIsSynced(bool is_synced) = 0;
|
||||||
|
@ -10,18 +10,16 @@
|
|||||||
struct AnimSamplerNode : public AnimNode {
|
struct AnimSamplerNode : public AnimNode {
|
||||||
AnimSamplerNode(AnimationController* animation_controller)
|
AnimSamplerNode(AnimationController* animation_controller)
|
||||||
: AnimNode(animation_controller),
|
: AnimNode(animation_controller),
|
||||||
m_time_prev(0.f),
|
|
||||||
m_override_ratio(false),
|
m_override_ratio(false),
|
||||||
m_anim_ratio(0.f),
|
m_anim_ratio(0.f),
|
||||||
m_root_bone_index(0) {
|
m_root_bone_index(0) {
|
||||||
assert(m_time_current < 100.0f);
|
assert(m_current_time < 100.0f);
|
||||||
m_anim_node_type = AnimNodeType::AnimSampler;
|
m_anim_node_type = AnimNodeType::AnimSampler;
|
||||||
};
|
};
|
||||||
virtual ~AnimSamplerNode() {}
|
virtual ~AnimSamplerNode() {}
|
||||||
|
|
||||||
ozz::animation::Animation* m_animation;
|
ozz::animation::Animation* m_animation;
|
||||||
|
|
||||||
float m_time_prev;
|
|
||||||
bool m_override_ratio;
|
bool m_override_ratio;
|
||||||
float m_anim_ratio;
|
float m_anim_ratio;
|
||||||
float m_anim_ratio_prev;
|
float m_anim_ratio_prev;
|
||||||
@ -42,28 +40,22 @@ struct AnimSamplerNode : public AnimNode {
|
|||||||
virtual void UpdateSyncTrack() override {}
|
virtual void UpdateSyncTrack() override {}
|
||||||
|
|
||||||
virtual void UpdateTime(float dt) override {
|
virtual void UpdateTime(float dt) override {
|
||||||
if (m_override_ratio) {
|
m_current_time += dt;
|
||||||
return;
|
if (!m_override_ratio) {
|
||||||
}
|
if (m_is_time_synced) {
|
||||||
|
m_anim_ratio = m_sync_track.CalcRatioFromSyncTime(m_current_time);
|
||||||
m_time_prev = m_time_current;
|
float prev_sync_time = m_current_time - dt;
|
||||||
m_time_current += dt;
|
if (m_current_time < 0) {
|
||||||
|
prev_sync_time += m_sync_track.m_num_intervals;
|
||||||
if (m_is_time_synced) {
|
}
|
||||||
m_anim_ratio = m_sync_track.CalcRatioFromSyncTime(m_time_current);
|
m_anim_ratio_prev = m_sync_track.CalcRatioFromSyncTime(prev_sync_time);
|
||||||
float prev_sync_time = m_time_current - dt;
|
} else {
|
||||||
if (m_time_current < 0) {
|
m_anim_ratio =
|
||||||
prev_sync_time += m_sync_track.m_num_intervals;
|
fmodf((float)m_current_time / m_animation->duration(), 1.0f);
|
||||||
}
|
m_anim_ratio_prev = fmodf((float)m_current_time / m_animation->duration(), 1.0f);
|
||||||
m_anim_ratio_prev = m_sync_track.CalcRatioFromSyncTime(prev_sync_time);
|
if (m_anim_ratio_prev < 0) {
|
||||||
} else {
|
m_anim_ratio_prev += 1.0f;
|
||||||
m_anim_ratio =
|
}
|
||||||
fmodf((float)m_time_current / m_animation->duration(), 1.0f);
|
|
||||||
m_anim_ratio_prev =
|
|
||||||
fmodf((float)m_time_prev / m_animation->duration(), 1.0f);
|
|
||||||
|
|
||||||
if (m_anim_ratio_prev < 0) {
|
|
||||||
m_anim_ratio_prev += 1.0f;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,12 @@ void BlendNode::Evaluate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BlendNode::DrawDebugUi() {
|
void BlendNode::DrawDebugUi() {
|
||||||
ImGui::SliderFloat("Weight", &m_weight, 0.f, 1.f);
|
if (ImGui::SliderFloat("Weight", &m_weight, 0.f, 1.f)) {
|
||||||
|
m_sync_track = SyncTrack::Blend(
|
||||||
|
m_weight,
|
||||||
|
m_input_A->m_sync_track,
|
||||||
|
m_input_B->m_sync_track);
|
||||||
|
}
|
||||||
ImGui::Checkbox("Sync Inputs", &m_sync_inputs);
|
ImGui::Checkbox("Sync Inputs", &m_sync_inputs);
|
||||||
|
|
||||||
ImGui::Text("SyncTrack");
|
ImGui::Text("SyncTrack");
|
||||||
|
@ -22,7 +22,9 @@ struct BlendNode : public AnimNode {
|
|||||||
ozz::math::Transform m_root_transform_A;
|
ozz::math::Transform m_root_transform_A;
|
||||||
ozz::math::Transform m_root_transform_B;
|
ozz::math::Transform m_root_transform_B;
|
||||||
|
|
||||||
virtual void Reset() { m_time_current = 0.f; }
|
virtual void Reset() {
|
||||||
|
m_current_time = 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void UpdateIsSynced(bool is_synced) override {
|
virtual void UpdateIsSynced(bool is_synced) override {
|
||||||
m_is_time_synced = is_synced;
|
m_is_time_synced = is_synced;
|
||||||
@ -37,28 +39,24 @@ struct BlendNode : public AnimNode {
|
|||||||
|
|
||||||
virtual void UpdateSyncTrack() override {
|
virtual void UpdateSyncTrack() override {
|
||||||
if (m_is_time_synced) {
|
if (m_is_time_synced) {
|
||||||
m_sync_track = SyncTrack::Blend(
|
m_sync_track = SyncTrack::Blend(m_weight, m_input_A->m_sync_track, m_input_B->m_sync_track);
|
||||||
m_weight,
|
|
||||||
m_input_A->m_sync_track,
|
|
||||||
m_input_B->m_sync_track);
|
|
||||||
} else {
|
} else {
|
||||||
assert(false);
|
assert (false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void UpdateTime(float dt) {
|
virtual void UpdateTime(float dt) {
|
||||||
if (m_is_time_synced) {
|
if (m_is_time_synced) {
|
||||||
float sync_time_old = m_sync_track.CalcSyncFromAbsTime(m_time_current);
|
float sync_time_old = m_sync_track.CalcSyncFromAbsTime(m_current_time);
|
||||||
m_time_current = fmodf(m_time_current + dt, m_sync_track.m_duration);
|
m_current_time = fmodf(m_current_time + dt, m_sync_track.m_duration);
|
||||||
float sync_time_dt =
|
float sync_time_dt = m_sync_track.CalcSyncFromAbsTime(m_current_time) - sync_time_old;
|
||||||
m_sync_track.CalcSyncFromAbsTime(m_time_current) - sync_time_old;
|
|
||||||
|
|
||||||
m_input_A->m_time_current = sync_time_old;
|
m_input_A->m_current_time = sync_time_old;
|
||||||
m_input_B->m_time_current = sync_time_old;
|
m_input_B->m_current_time = sync_time_old;
|
||||||
m_input_A->UpdateTime(sync_time_dt);
|
m_input_A->UpdateTime(sync_time_dt);
|
||||||
m_input_B->UpdateTime(sync_time_dt);
|
m_input_B->UpdateTime(sync_time_dt);
|
||||||
} else {
|
} else {
|
||||||
m_time_current += dt;
|
m_current_time += dt;
|
||||||
m_input_A->UpdateTime(dt);
|
m_input_A->UpdateTime(dt);
|
||||||
m_input_B->UpdateTime(dt);
|
m_input_B->UpdateTime(dt);
|
||||||
}
|
}
|
||||||
@ -68,8 +66,7 @@ struct BlendNode : public AnimNode {
|
|||||||
ozz::vector<ozz::math::SoaTransform>* local_matrices,
|
ozz::vector<ozz::math::SoaTransform>* local_matrices,
|
||||||
ozz::math::Transform* root_transform) override;
|
ozz::math::Transform* root_transform) override;
|
||||||
|
|
||||||
virtual void GetInputNodes(
|
virtual void GetInputNodes(std::vector<AnimNode*>& input_nodes) const override {
|
||||||
std::vector<AnimNode*>& input_nodes) const override {
|
|
||||||
input_nodes.push_back(m_input_A);
|
input_nodes.push_back(m_input_A);
|
||||||
input_nodes.push_back(m_input_B);
|
input_nodes.push_back(m_input_B);
|
||||||
};
|
};
|
||||||
|
@ -59,7 +59,12 @@ void BlendSpace1D::Evaluate(
|
|||||||
void BlendSpace1D::DrawDebugUi() {
|
void BlendSpace1D::DrawDebugUi() {
|
||||||
float min_weight = m_input_weights[0];
|
float min_weight = m_input_weights[0];
|
||||||
float max_weight = m_input_weights.back();
|
float max_weight = m_input_weights.back();
|
||||||
ImGui::SliderFloat("Weight", &m_weight, min_weight, max_weight);
|
if (ImGui::SliderFloat("Weight", &m_weight, min_weight, max_weight)) {
|
||||||
|
m_sync_track = SyncTrack::Blend(
|
||||||
|
m_weight,
|
||||||
|
m_input_0->m_sync_track,
|
||||||
|
m_input_1->m_sync_track);
|
||||||
|
}
|
||||||
ImGui::Checkbox("Sync Inputs", &m_sync_inputs);
|
ImGui::Checkbox("Sync Inputs", &m_sync_inputs);
|
||||||
|
|
||||||
ImGui::Text("SyncTrack");
|
ImGui::Text("SyncTrack");
|
||||||
|
@ -29,7 +29,9 @@ struct BlendSpace1D : public AnimNode {
|
|||||||
ozz::math::Transform m_root_transform_0;
|
ozz::math::Transform m_root_transform_0;
|
||||||
ozz::math::Transform m_root_transform_1;
|
ozz::math::Transform m_root_transform_1;
|
||||||
|
|
||||||
virtual void Reset() { m_time_current = 0.f; }
|
virtual void Reset() {
|
||||||
|
m_current_time = 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void UpdateIsSynced(bool is_synced) override {
|
virtual void UpdateIsSynced(bool is_synced) override {
|
||||||
m_is_time_synced = is_synced;
|
m_is_time_synced = is_synced;
|
||||||
@ -38,15 +40,12 @@ struct BlendSpace1D : public AnimNode {
|
|||||||
m_is_time_synced = true;
|
m_is_time_synced = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(m_input_weights.size() > 0);
|
assert (m_input_weights.size() > 0);
|
||||||
assert(
|
assert (m_weight >= m_input_weights[0] && m_weight <= m_input_weights[m_input_weights.size() - 1]);
|
||||||
m_weight >= m_input_weights[0]
|
|
||||||
&& m_weight <= m_input_weights[m_input_weights.size() - 1]);
|
|
||||||
|
|
||||||
int prev_idx = 0;
|
int prev_idx = 0;
|
||||||
for (int next_idx = 1; next_idx < m_input_weights.size(); next_idx++) {
|
for (int next_idx = 1; next_idx < m_input_weights.size(); next_idx++) {
|
||||||
if (m_input_weights[prev_idx] <= m_weight
|
if (m_input_weights[prev_idx] <= m_weight && m_input_weights[next_idx] >= m_weight) {
|
||||||
&& m_input_weights[next_idx] >= m_weight) {
|
|
||||||
m_input_0 = m_inputs[prev_idx];
|
m_input_0 = m_inputs[prev_idx];
|
||||||
m_weight_0 = m_input_weights[prev_idx];
|
m_weight_0 = m_input_weights[prev_idx];
|
||||||
|
|
||||||
@ -66,28 +65,21 @@ struct BlendSpace1D : public AnimNode {
|
|||||||
|
|
||||||
virtual void UpdateSyncTrack() override {
|
virtual void UpdateSyncTrack() override {
|
||||||
if (m_is_time_synced) {
|
if (m_is_time_synced) {
|
||||||
m_sync_track = SyncTrack::Blend(
|
m_sync_track = SyncTrack::Blend(m_normalized_weight, m_input_0->m_sync_track, m_input_1->m_sync_track);
|
||||||
m_normalized_weight,
|
|
||||||
m_input_0->m_sync_track,
|
|
||||||
m_input_1->m_sync_track);
|
|
||||||
} else {
|
} else {
|
||||||
assert(false);
|
assert (false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void UpdateTime(float dt) {
|
virtual void UpdateTime(float dt) {
|
||||||
if (m_is_time_synced) {
|
if (m_is_time_synced) {
|
||||||
float sync_time_old = m_sync_track.CalcSyncFromAbsTime(m_time_current);
|
m_current_time = fmodf(m_current_time + dt, m_sync_track.m_duration);
|
||||||
m_time_current = fmodf(m_time_current + dt, m_sync_track.m_duration);
|
float current_sync_time = m_sync_track.CalcSyncFromAbsTime(m_current_time);
|
||||||
float sync_time_dt =
|
|
||||||
m_sync_track.CalcSyncFromAbsTime(m_time_current) - sync_time_old;
|
|
||||||
|
|
||||||
m_input_0->m_time_current = sync_time_old;
|
m_input_0->UpdateTime(current_sync_time - m_input_0->m_current_time);
|
||||||
m_input_1->m_time_current = sync_time_old;
|
m_input_1->UpdateTime(current_sync_time - m_input_1->m_current_time);
|
||||||
m_input_0->UpdateTime(sync_time_dt);
|
|
||||||
m_input_1->UpdateTime(sync_time_dt);
|
|
||||||
} else {
|
} else {
|
||||||
m_time_current += dt;
|
m_current_time += dt;
|
||||||
m_input_0->UpdateTime(dt);
|
m_input_0->UpdateTime(dt);
|
||||||
m_input_1->UpdateTime(dt);
|
m_input_1->UpdateTime(dt);
|
||||||
}
|
}
|
||||||
@ -97,8 +89,7 @@ struct BlendSpace1D : public AnimNode {
|
|||||||
ozz::vector<ozz::math::SoaTransform>* local_matrices,
|
ozz::vector<ozz::math::SoaTransform>* local_matrices,
|
||||||
ozz::math::Transform* root_transform) override;
|
ozz::math::Transform* root_transform) override;
|
||||||
|
|
||||||
virtual void GetInputNodes(
|
virtual void GetInputNodes(std::vector<AnimNode*>& input_nodes) const override {
|
||||||
std::vector<AnimNode*>& input_nodes) const override {
|
|
||||||
for (int i = 0; i < m_inputs.size(); i++) {
|
for (int i = 0; i < m_inputs.size(); i++) {
|
||||||
input_nodes.push_back(m_inputs[i]);
|
input_nodes.push_back(m_inputs[i]);
|
||||||
}
|
}
|
||||||
@ -107,4 +98,5 @@ struct BlendSpace1D : public AnimNode {
|
|||||||
virtual void DrawDebugUi();
|
virtual void DrawDebugUi();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif //ANIMTESTBED_BLENDSPACE1D_H
|
#endif //ANIMTESTBED_BLENDSPACE1D_H
|
||||||
|
@ -24,7 +24,7 @@ struct LockTranslationNode : public AnimNode {
|
|||||||
bool m_lock_y;
|
bool m_lock_y;
|
||||||
bool m_lock_z;
|
bool m_lock_z;
|
||||||
|
|
||||||
virtual void Reset() { m_time_current = 0.f; }
|
virtual void Reset() { m_current_time = 0.f; }
|
||||||
|
|
||||||
virtual void UpdateIsSynced(bool is_synced) override {
|
virtual void UpdateIsSynced(bool is_synced) override {
|
||||||
m_is_time_synced = is_synced;
|
m_is_time_synced = is_synced;
|
||||||
|
@ -16,7 +16,7 @@ struct SpeedScaleNode : public AnimNode {
|
|||||||
float m_time_scale;
|
float m_time_scale;
|
||||||
AnimNode* m_input_node;
|
AnimNode* m_input_node;
|
||||||
|
|
||||||
virtual void Reset() { m_time_current = 0.f; }
|
virtual void Reset() { m_current_time = 0.f; }
|
||||||
|
|
||||||
virtual void UpdateIsSynced(bool is_synced) override {
|
virtual void UpdateIsSynced(bool is_synced) override {
|
||||||
m_is_time_synced = is_synced;
|
m_is_time_synced = is_synced;
|
||||||
@ -32,10 +32,10 @@ struct SpeedScaleNode : public AnimNode {
|
|||||||
|
|
||||||
virtual void UpdateTime(float dt) {
|
virtual void UpdateTime(float dt) {
|
||||||
if (!m_is_time_synced) {
|
if (!m_is_time_synced) {
|
||||||
m_time_current += dt * m_time_scale;
|
m_current_time += dt * m_time_scale;
|
||||||
m_input_node->UpdateTime(dt * m_time_scale);
|
m_input_node->UpdateTime(dt * m_time_scale);
|
||||||
} else {
|
} else {
|
||||||
m_time_current += dt;
|
m_current_time += dt;
|
||||||
m_input_node->UpdateTime(dt);
|
m_input_node->UpdateTime(dt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,8 +229,8 @@ void AnimationController::DrawDebugUi() {
|
|||||||
ImGui::NextColumn();
|
ImGui::NextColumn();
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
|
|
||||||
ImGui::PushID((void*)&node->m_time_current);
|
ImGui::PushID((void*)&node->m_current_time);
|
||||||
ImGui::Text("%2.3f", node->m_time_current);
|
ImGui::Text("%2.3f", node->m_current_time);
|
||||||
ImGui::NextColumn();
|
ImGui::NextColumn();
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ TEST_CASE("Sample single bone channel", "[AnimSamplerNode]") {
|
|||||||
local_matrices,
|
local_matrices,
|
||||||
root_transform_0);
|
root_transform_0);
|
||||||
|
|
||||||
int n_samples = 53;
|
int n_samples = 20;
|
||||||
for (int i = 0; i <= n_samples; i++) {
|
for (int i = 0; i <= n_samples; i++) {
|
||||||
float ratio = i * 1.f / n_samples;
|
float ratio = i * 1.f / n_samples;
|
||||||
ozz::math::Transform sampled_root_transform;
|
ozz::math::Transform sampled_root_transform;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user