Transition walking-zombie look good.

AnimGraphEditor
Martin Felis 2021-11-19 22:05:59 +01:00
parent db3095fa07
commit 382730960f
6 changed files with 25 additions and 25 deletions

View File

@ -23,10 +23,9 @@ void AnimSamplerNode::SetAnimation(ozz::animation::Animation* animation, const S
void AnimSamplerNode::Evaluate(
ozz::vector<ozz::math::SoaTransform>* local_matrices) {
ozz::animation::SamplingJob sampling_job;
float ratio = m_sync_track.CalcRatioFromSyncTime(m_anim_ratio);
sampling_job.animation = m_animation;
sampling_job.cache = &m_sampling_cache;
sampling_job.ratio = ratio;
sampling_job.ratio = m_anim_ratio;
sampling_job.output = make_span(*local_matrices);
if (!sampling_job.Run()) {
ozz::log::Err() << "Error sampling animation." << std::endl;

View File

@ -38,10 +38,9 @@ struct AnimSamplerNode : public AnimNode {
m_current_time += dt;
if (!m_override_ratio) {
if (m_is_time_synced) {
m_anim_ratio = fmodf((float)m_current_time, 1.0f);
m_current_time = m_anim_ratio;
m_anim_ratio = m_sync_track.CalcRatioFromSyncTime(m_current_time);
} else {
m_anim_ratio = fmodf((float)m_current_time / m_sync_track.m_duration, 1.0f);
m_anim_ratio = fmodf((float)m_current_time / m_animation->duration(), 1.0f);
}
}

View File

@ -49,7 +49,9 @@ void BlendNode::Evaluate(ozz::vector<ozz::math::SoaTransform>* local_matrices) {
}
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::Text("SyncTrack");

View File

@ -45,20 +45,11 @@ struct BlendNode : public AnimNode {
virtual void UpdateTime(float dt) {
if (m_is_time_synced) {
float current_time_absolute = fmodf(m_current_time * m_sync_track.m_duration + dt, 1.0f);
float current_sync_time = m_sync_track.CalcSyncFromAbsTime(current_time_absolute);
m_current_time = m_sync_track.CalcRatioFromSyncTime(current_sync_time);
m_current_time = fmodf(m_current_time + dt, m_sync_track.m_duration);
float current_sync_time = m_sync_track.CalcSyncFromAbsTime(m_current_time);
float time_absolute_A = fmodf (m_input_A->m_current_time * m_input_A->m_sync_track.m_duration, 1.0f);
float sync_time_A = m_input_A->m_sync_track.CalcSyncFromAbsTime(time_absolute_A);
float m_ratio_A = m_input_A->m_sync_track.CalcSyncFromAbsTime(sync_time_A);
float time_absolute_B = fmodf (m_input_B->m_current_time * m_input_B->m_sync_track.m_duration, 1.0f);
float sync_time_B = m_input_B->m_sync_track.CalcSyncFromAbsTime(time_absolute_B);
float m_ratio_B = m_input_B->m_sync_track.CalcSyncFromAbsTime(sync_time_B);
m_input_A->UpdateTime(current_sync_time);
m_input_B->UpdateTime(current_sync_time);
m_input_A->UpdateTime(current_sync_time - m_input_A->m_current_time);
m_input_B->UpdateTime(current_sync_time - m_input_B->m_current_time);
} else {
m_current_time += dt;
m_input_A->UpdateTime(dt);

View File

@ -17,7 +17,7 @@
#include "SkinnedMesh.h"
AnimationController::AnimationController(SkinnedMesh* skinned_mesh)
: m_current_time(0.f), m_paused(false), m_skinned_mesh(skinned_mesh) {
: m_current_time(0.f), m_paused(true), m_skinned_mesh(skinned_mesh) {
const int num_soa_joints = skinned_mesh->m_skeleton.num_soa_joints();
const int num_joints = skinned_mesh->m_skeleton.num_joints();
skinned_mesh->m_local_matrices.resize(num_soa_joints);
@ -32,7 +32,7 @@ AnimationController::AnimationController(SkinnedMesh* skinned_mesh)
AnimSamplerNode* sampler_node1 = new AnimSamplerNode(this);
sampler_node1->m_name = "AnimSampler1";
sampler_node1->SetAnimation(skinned_mesh->m_animations[2], skinned_mesh->m_animation_sync_track[1]);
sampler_node1->SetAnimation(skinned_mesh->m_animations[2], skinned_mesh->m_animation_sync_track[2]);
m_anim_nodes.push_back(sampler_node1);
// SpeedScaleNode* speed_node = new SpeedScaleNode(this);
@ -52,10 +52,11 @@ AnimationController::AnimationController(SkinnedMesh* skinned_mesh)
speed_node1->m_input_node = blend_node;
m_anim_nodes.push_back(speed_node1);
// LockTranslationNode* lock_node = new LockTranslationNode(this);
// lock_node->m_name = "LockNode0";
// lock_node->m_locked_bone_index = 0;
// lock_node->m_input = speed_node1;
LockTranslationNode* lock_node = new LockTranslationNode(this);
lock_node->m_name = "LockNode0";
lock_node->m_locked_bone_index = 0;
lock_node->m_input = speed_node1;
m_anim_nodes.push_back(lock_node);
m_output_node = m_anim_nodes.back();

View File

@ -11,6 +11,14 @@
constexpr int cSyncTrackMaxIntervals = 8;
struct SyncTrack {
SyncTrack() : m_duration(0.f), m_num_intervals(0) {
for (int i = 0; i < cSyncTrackMaxIntervals; i++) {
m_sync_markers[i] = 0.f;
m_interval_ratio[i] = 0.f;
m_interval_ratio[i] = 0.f;
}
}
float m_duration;
int m_num_intervals;
float m_sync_markers[cSyncTrackMaxIntervals];