Transition walking-zombie look good.
parent
db3095fa07
commit
382730960f
|
@ -23,10 +23,9 @@ void AnimSamplerNode::SetAnimation(ozz::animation::Animation* animation, const S
|
||||||
void AnimSamplerNode::Evaluate(
|
void AnimSamplerNode::Evaluate(
|
||||||
ozz::vector<ozz::math::SoaTransform>* local_matrices) {
|
ozz::vector<ozz::math::SoaTransform>* local_matrices) {
|
||||||
ozz::animation::SamplingJob sampling_job;
|
ozz::animation::SamplingJob sampling_job;
|
||||||
float ratio = m_sync_track.CalcRatioFromSyncTime(m_anim_ratio);
|
|
||||||
sampling_job.animation = m_animation;
|
sampling_job.animation = m_animation;
|
||||||
sampling_job.cache = &m_sampling_cache;
|
sampling_job.cache = &m_sampling_cache;
|
||||||
sampling_job.ratio = ratio;
|
sampling_job.ratio = m_anim_ratio;
|
||||||
sampling_job.output = make_span(*local_matrices);
|
sampling_job.output = make_span(*local_matrices);
|
||||||
if (!sampling_job.Run()) {
|
if (!sampling_job.Run()) {
|
||||||
ozz::log::Err() << "Error sampling animation." << std::endl;
|
ozz::log::Err() << "Error sampling animation." << std::endl;
|
||||||
|
|
|
@ -38,10 +38,9 @@ struct AnimSamplerNode : public AnimNode {
|
||||||
m_current_time += dt;
|
m_current_time += dt;
|
||||||
if (!m_override_ratio) {
|
if (!m_override_ratio) {
|
||||||
if (m_is_time_synced) {
|
if (m_is_time_synced) {
|
||||||
m_anim_ratio = fmodf((float)m_current_time, 1.0f);
|
m_anim_ratio = m_sync_track.CalcRatioFromSyncTime(m_current_time);
|
||||||
m_current_time = m_anim_ratio;
|
|
||||||
} else {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,9 @@ void BlendNode::Evaluate(ozz::vector<ozz::math::SoaTransform>* local_matrices) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
|
|
|
@ -45,20 +45,11 @@ struct BlendNode : public AnimNode {
|
||||||
|
|
||||||
virtual void UpdateTime(float dt) {
|
virtual void UpdateTime(float dt) {
|
||||||
if (m_is_time_synced) {
|
if (m_is_time_synced) {
|
||||||
float current_time_absolute = fmodf(m_current_time * m_sync_track.m_duration + dt, 1.0f);
|
m_current_time = fmodf(m_current_time + dt, m_sync_track.m_duration);
|
||||||
float current_sync_time = m_sync_track.CalcSyncFromAbsTime(current_time_absolute);
|
float current_sync_time = m_sync_track.CalcSyncFromAbsTime(m_current_time);
|
||||||
m_current_time = m_sync_track.CalcRatioFromSyncTime(current_sync_time);
|
|
||||||
|
|
||||||
float time_absolute_A = fmodf (m_input_A->m_current_time * m_input_A->m_sync_track.m_duration, 1.0f);
|
m_input_A->UpdateTime(current_sync_time - m_input_A->m_current_time);
|
||||||
float sync_time_A = m_input_A->m_sync_track.CalcSyncFromAbsTime(time_absolute_A);
|
m_input_B->UpdateTime(current_sync_time - m_input_B->m_current_time);
|
||||||
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);
|
|
||||||
} else {
|
} else {
|
||||||
m_current_time += dt;
|
m_current_time += dt;
|
||||||
m_input_A->UpdateTime(dt);
|
m_input_A->UpdateTime(dt);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "SkinnedMesh.h"
|
#include "SkinnedMesh.h"
|
||||||
|
|
||||||
AnimationController::AnimationController(SkinnedMesh* skinned_mesh)
|
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_soa_joints = skinned_mesh->m_skeleton.num_soa_joints();
|
||||||
const int num_joints = skinned_mesh->m_skeleton.num_joints();
|
const int num_joints = skinned_mesh->m_skeleton.num_joints();
|
||||||
skinned_mesh->m_local_matrices.resize(num_soa_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);
|
AnimSamplerNode* sampler_node1 = new AnimSamplerNode(this);
|
||||||
sampler_node1->m_name = "AnimSampler1";
|
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);
|
m_anim_nodes.push_back(sampler_node1);
|
||||||
|
|
||||||
// SpeedScaleNode* speed_node = new SpeedScaleNode(this);
|
// SpeedScaleNode* speed_node = new SpeedScaleNode(this);
|
||||||
|
@ -52,10 +52,11 @@ AnimationController::AnimationController(SkinnedMesh* skinned_mesh)
|
||||||
speed_node1->m_input_node = blend_node;
|
speed_node1->m_input_node = blend_node;
|
||||||
m_anim_nodes.push_back(speed_node1);
|
m_anim_nodes.push_back(speed_node1);
|
||||||
|
|
||||||
// LockTranslationNode* lock_node = new LockTranslationNode(this);
|
LockTranslationNode* lock_node = new LockTranslationNode(this);
|
||||||
// lock_node->m_name = "LockNode0";
|
lock_node->m_name = "LockNode0";
|
||||||
// lock_node->m_locked_bone_index = 0;
|
lock_node->m_locked_bone_index = 0;
|
||||||
// lock_node->m_input = speed_node1;
|
lock_node->m_input = speed_node1;
|
||||||
|
m_anim_nodes.push_back(lock_node);
|
||||||
|
|
||||||
m_output_node = m_anim_nodes.back();
|
m_output_node = m_anim_nodes.back();
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,14 @@
|
||||||
constexpr int cSyncTrackMaxIntervals = 8;
|
constexpr int cSyncTrackMaxIntervals = 8;
|
||||||
|
|
||||||
struct SyncTrack {
|
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;
|
float m_duration;
|
||||||
int m_num_intervals;
|
int m_num_intervals;
|
||||||
float m_sync_markers[cSyncTrackMaxIntervals];
|
float m_sync_markers[cSyncTrackMaxIntervals];
|
||||||
|
|
Loading…
Reference in New Issue