Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2848909981 | ||
|
|
ed7c7902ec | ||
|
|
79c878a8e5 | ||
|
|
791bf36b90 | ||
|
|
382730960f | ||
|
|
db3095fa07 | ||
|
|
e2959aaed3 |
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required (VERSION 3.3)
|
cmake_minimum_required (VERSION 3.20)
|
||||||
|
|
||||||
# Defines the project's name
|
# Defines the project's name
|
||||||
project(ozz)
|
project(ozz)
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class StdAllocator {
|
|||||||
StdAllocator(const StdAllocator&) noexcept {}
|
StdAllocator(const StdAllocator&) noexcept {}
|
||||||
|
|
||||||
template <class _Other>
|
template <class _Other>
|
||||||
StdAllocator<value_type>(const StdAllocator<_Other>&) noexcept {}
|
StdAllocator(const StdAllocator<_Other>&) noexcept {}
|
||||||
|
|
||||||
template <class _Other>
|
template <class _Other>
|
||||||
struct rebind {
|
struct rebind {
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ add_library(AnimTestbedCode OBJECT
|
|||||||
src/Camera.c
|
src/Camera.c
|
||||||
src/SkinnedMesh.cc
|
src/SkinnedMesh.cc
|
||||||
src/SkinnedMesh.h
|
src/SkinnedMesh.h
|
||||||
|
src/SyncTrack.cc
|
||||||
|
src/SyncTrack.h
|
||||||
src/AnimNode.cc
|
src/AnimNode.cc
|
||||||
src/AnimNodes/AnimSamplerNode.cc
|
src/AnimNodes/AnimSamplerNode.cc
|
||||||
src/AnimNodes/SpeedScaleNode.cc
|
src/AnimNodes/SpeedScaleNode.cc
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
## Graph
|
||||||
|
|
||||||
|
### 1. Support of math nodes (or non-AnimNodes in general)
|
||||||
|
|
||||||
|
* Enables animators to add custom math for blend inputs or to adjust other inputs (e.g. LookAt or IK
|
||||||
|
targets).
|
||||||
|
|
||||||
|
**Open Issues**
|
||||||
|
|
||||||
|
1. When to do the evaluation? Two types of subgraphs:
|
||||||
|
a) Instant inputs (needed for blend node inputs) that have to be evaluated before
|
||||||
|
UpdateConnections
|
||||||
|
b) Processing nodes, e.g. for extracted bones.
|
||||||
|
|
||||||
|
### 2. Support of multiple output sockets
|
||||||
|
|
||||||
|
* E.g. extract Bone transform
|
||||||
|
|
||||||
|
* Increases Node complexity:
|
||||||
|
* AnimOutput
|
||||||
|
* AnimOutput + Data
|
||||||
|
* Data
|
||||||
|
|
||||||
|
(Data = bool, float, vec3, quat, ...)
|
||||||
|
|
||||||
|
**Open Issues**
|
||||||
|
|
||||||
|
1. Unclear when this is actually needed. Using more specific nodes that perform the desired logic
|
||||||
|
may be better (
|
||||||
|
c.f. https://dev.epicgames.com/documentation/en-us/unreal-engine/animation-blueprint-bone-driven-controller-in-unreal-engine).
|
||||||
|
Likely this is not crucial so should be avoided for now.
|
||||||
|
|
||||||
|
### 3. Multi-skeleton evaluation
|
||||||
|
|
||||||
|
Use case: riding on a horse, interaction between two characters.
|
||||||
+2
-4
@@ -16,8 +16,7 @@ struct AnimNode {
|
|||||||
AnimNode(AnimationController* animation_controller)
|
AnimNode(AnimationController* animation_controller)
|
||||||
: m_animation_controller(animation_controller),
|
: m_animation_controller(animation_controller),
|
||||||
m_current_time(0.f),
|
m_current_time(0.f),
|
||||||
m_is_time_synced(false),
|
m_is_time_synced(false) {}
|
||||||
m_anim_duration(0.f) {}
|
|
||||||
virtual ~AnimNode(){};
|
virtual ~AnimNode(){};
|
||||||
|
|
||||||
AnimNodeType m_anim_node_type;
|
AnimNodeType m_anim_node_type;
|
||||||
@@ -27,7 +26,6 @@ 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_current_time;
|
float m_current_time;
|
||||||
float m_anim_duration;
|
|
||||||
SyncTrack m_sync_track;
|
SyncTrack m_sync_track;
|
||||||
|
|
||||||
virtual void Reset() { m_current_time = 0.f; }
|
virtual void Reset() { m_current_time = 0.f; }
|
||||||
@@ -37,7 +35,7 @@ struct AnimNode {
|
|||||||
|
|
||||||
// Evaluate the animation duration of this node. All input nodes must have already evaluated
|
// Evaluate the animation duration of this node. All input nodes must have already evaluated
|
||||||
// their anim durations.
|
// their anim durations.
|
||||||
virtual void EvalAnimDuration() = 0;
|
virtual void UpdateSyncTrack() = 0;
|
||||||
|
|
||||||
// Evaluate current time and propagate time step to inputs.
|
// Evaluate current time and propagate time step to inputs.
|
||||||
virtual void UpdateTime(float dt) = 0;
|
virtual void UpdateTime(float dt) = 0;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "../SkinnedMesh.h"
|
#include "../SkinnedMesh.h"
|
||||||
|
|
||||||
void AnimSamplerNode::SetAnimation(ozz::animation::Animation* animation) {
|
void AnimSamplerNode::SetAnimation(ozz::animation::Animation* animation, const SyncTrack& sync_track) {
|
||||||
m_animation = animation;
|
m_animation = animation;
|
||||||
|
|
||||||
const SkinnedMesh* skinned_mesh = m_animation_controller->m_skinned_mesh;
|
const SkinnedMesh* skinned_mesh = m_animation_controller->m_skinned_mesh;
|
||||||
@@ -16,6 +16,8 @@ void AnimSamplerNode::SetAnimation(ozz::animation::Animation* animation) {
|
|||||||
const int num_joints = skinned_mesh->m_skeleton.num_joints();
|
const int num_joints = skinned_mesh->m_skeleton.num_joints();
|
||||||
m_local_matrices.resize(num_soa_joints);
|
m_local_matrices.resize(num_soa_joints);
|
||||||
m_sampling_cache.Resize(num_joints);
|
m_sampling_cache.Resize(num_joints);
|
||||||
|
|
||||||
|
m_sync_track = sync_track;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimSamplerNode::Evaluate(
|
void AnimSamplerNode::Evaluate(
|
||||||
@@ -44,8 +46,13 @@ void AnimSamplerNode::DrawDebugUi() {
|
|||||||
|
|
||||||
if (ImGui::Combo("Animation", &item_current, items, anim_count)) {
|
if (ImGui::Combo("Animation", &item_current, items, anim_count)) {
|
||||||
m_animation = skinned_mesh->m_animations[item_current];
|
m_animation = skinned_mesh->m_animations[item_current];
|
||||||
|
m_sync_track = skinned_mesh->m_animation_sync_track[item_current];
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Checkbox("Override", &m_override_ratio);
|
ImGui::Checkbox("Override", &m_override_ratio);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SliderFloat("Ratio", &m_anim_ratio, 0.f, 1.f);
|
ImGui::SliderFloat("Ratio", &m_anim_ratio, 0.f, 1.f);
|
||||||
|
|
||||||
|
ImGui::Text("SyncTrack");
|
||||||
|
m_sync_track.DrawDebugUi();
|
||||||
}
|
}
|
||||||
@@ -25,25 +25,22 @@ struct AnimSamplerNode : public AnimNode {
|
|||||||
ozz::vector<ozz::math::SoaTransform> m_local_matrices;
|
ozz::vector<ozz::math::SoaTransform> m_local_matrices;
|
||||||
ozz::animation::SamplingCache m_sampling_cache;
|
ozz::animation::SamplingCache m_sampling_cache;
|
||||||
|
|
||||||
void SetAnimation(ozz::animation::Animation* animation);
|
void SetAnimation(ozz::animation::Animation* animation, const SyncTrack& sync_track);
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void EvalAnimDuration() override {
|
virtual void UpdateSyncTrack() override {
|
||||||
m_anim_duration = m_animation->duration();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void UpdateTime(float dt) override {
|
virtual void UpdateTime(float dt) override {
|
||||||
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 {
|
||||||
const float duration = m_animation->duration();
|
m_anim_ratio = fmodf((float)m_current_time / m_animation->duration(), 1.0f);
|
||||||
m_anim_ratio = fmodf((float)m_current_time / duration, 1.0f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ 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");
|
||||||
|
m_sync_track.DrawDebugUi();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ struct BlendNode : public AnimNode {
|
|||||||
m_input_A->UpdateIsSynced(m_is_time_synced);
|
m_input_A->UpdateIsSynced(m_is_time_synced);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void EvalAnimDuration() override {
|
virtual void UpdateSyncTrack() override {
|
||||||
if (m_is_time_synced) {
|
if (m_is_time_synced) {
|
||||||
m_anim_duration = (1.0f - m_weight) * m_input_A->m_anim_duration + m_weight * m_input_B->m_anim_duration;
|
m_sync_track = SyncTrack::Blend(m_weight, m_input_A->m_sync_track, m_input_B->m_sync_track);
|
||||||
} else {
|
} else {
|
||||||
assert (false);
|
assert (false);
|
||||||
}
|
}
|
||||||
@@ -45,11 +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 = m_current_time * m_anim_duration + dt;
|
m_current_time = fmodf(m_current_time + dt, m_sync_track.m_duration);
|
||||||
m_current_time = fmodf(current_time_absolute / m_anim_duration, 1.0);
|
float current_sync_time = m_sync_track.CalcSyncFromAbsTime(m_current_time);
|
||||||
|
|
||||||
m_input_A->UpdateTime(m_current_time - m_input_A->m_current_time);
|
m_input_A->UpdateTime(current_sync_time - m_input_A->m_current_time);
|
||||||
m_input_B->UpdateTime(m_current_time - m_input_B->m_current_time);
|
m_input_B->UpdateTime(current_sync_time - m_input_B->m_current_time);
|
||||||
} else {
|
} else {
|
||||||
m_current_time += dt;
|
m_current_time += dt;
|
||||||
m_input_A->UpdateTime(dt);
|
m_input_A->UpdateTime(dt);
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ struct LockTranslationNode : public AnimNode {
|
|||||||
m_input->UpdateIsSynced(m_is_time_synced);
|
m_input->UpdateIsSynced(m_is_time_synced);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void EvalAnimDuration() override {
|
virtual void UpdateSyncTrack() override {
|
||||||
m_anim_duration = m_input->m_anim_duration;
|
m_sync_track = m_input->m_sync_track;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void UpdateTime(float dt) { m_input->UpdateTime(dt); }
|
virtual void UpdateTime(float dt) { m_input->UpdateTime(dt); }
|
||||||
|
|||||||
@@ -14,7 +14,11 @@ void SpeedScaleNode::DrawDebugUi() {
|
|||||||
|
|
||||||
// ensure m_time_scale is positive
|
// ensure m_time_scale is positive
|
||||||
m_time_scale = m_time_scale * (is_negative ? -1.f : 1.f);
|
m_time_scale = m_time_scale * (is_negative ? -1.f : 1.f);
|
||||||
ImGui::SliderFloat("Time Scale", &m_time_scale, 0.01f, 5.f);
|
if (ImGui::SliderFloat("Time Scale", &m_time_scale, 0.01f, 2.f)) {
|
||||||
|
if (fabs(m_time_scale - 1.0) < 0.2) {
|
||||||
|
m_time_scale = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
// and back to the original negative or positive sign
|
// and back to the original negative or positive sign
|
||||||
m_time_scale = m_time_scale * (is_negative ? -1.f : 1.f);
|
m_time_scale = m_time_scale * (is_negative ? -1.f : 1.f);
|
||||||
}
|
}
|
||||||
@@ -23,9 +23,10 @@ struct SpeedScaleNode : public AnimNode {
|
|||||||
m_input_node->UpdateIsSynced(is_synced);
|
m_input_node->UpdateIsSynced(is_synced);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void EvalAnimDuration() override {
|
virtual void UpdateSyncTrack() override {
|
||||||
assert(fabs(m_time_scale) >= 0.01f);
|
assert(fabs(m_time_scale) >= 0.01f);
|
||||||
m_anim_duration = fabsf(m_input_node->m_anim_duration / m_time_scale);
|
m_sync_track = m_input_node->m_sync_track;
|
||||||
|
m_sync_track.m_duration =fabsf(m_input_node->m_sync_track.m_duration / m_time_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void UpdateTime(float dt) {
|
virtual void UpdateTime(float dt) {
|
||||||
|
|||||||
+31
-20
@@ -17,24 +17,22 @@
|
|||||||
#include "SkinnedMesh.h"
|
#include "SkinnedMesh.h"
|
||||||
|
|
||||||
AnimationController::AnimationController(SkinnedMesh* skinned_mesh)
|
AnimationController::AnimationController(SkinnedMesh* skinned_mesh)
|
||||||
: m_current_time(0.f), 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);
|
||||||
skinned_mesh->m_model_matrices.resize(num_joints);
|
skinned_mesh->m_model_matrices.resize(num_joints);
|
||||||
|
|
||||||
m_local_matrices.resize(num_soa_joints);
|
|
||||||
|
|
||||||
ResetAnims();
|
ResetAnims();
|
||||||
|
|
||||||
AnimSamplerNode* sampler_node0 = new AnimSamplerNode(this);
|
AnimSamplerNode* sampler_node0 = new AnimSamplerNode(this);
|
||||||
sampler_node0->m_name = "AnimSampler0";
|
sampler_node0->m_name = "AnimSampler0";
|
||||||
sampler_node0->SetAnimation(skinned_mesh->m_animations[1]);
|
sampler_node0->SetAnimation(skinned_mesh->m_animations[1], skinned_mesh->m_animation_sync_track[1]);
|
||||||
m_anim_nodes.push_back(sampler_node0);
|
m_anim_nodes.push_back(sampler_node0);
|
||||||
|
|
||||||
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]);
|
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);
|
||||||
@@ -46,7 +44,7 @@ AnimationController::AnimationController(SkinnedMesh* skinned_mesh)
|
|||||||
blend_node->m_name = "Blend0";
|
blend_node->m_name = "Blend0";
|
||||||
blend_node->m_input_A = speed_node;
|
blend_node->m_input_A = speed_node;
|
||||||
blend_node->m_input_B = sampler_node1;
|
blend_node->m_input_B = sampler_node1;
|
||||||
blend_node->m_sync_inputs = false;
|
blend_node->m_sync_inputs = true;
|
||||||
m_anim_nodes.push_back(blend_node);
|
m_anim_nodes.push_back(blend_node);
|
||||||
|
|
||||||
SpeedScaleNode* speed_node1 = new SpeedScaleNode(this);
|
SpeedScaleNode* speed_node1 = new SpeedScaleNode(this);
|
||||||
@@ -58,8 +56,9 @@ AnimationController::AnimationController(SkinnedMesh* skinned_mesh)
|
|||||||
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 = lock_node;
|
m_output_node = m_anim_nodes.back();
|
||||||
|
|
||||||
UpdateOrderedNodes();
|
UpdateOrderedNodes();
|
||||||
|
|
||||||
@@ -100,10 +99,8 @@ void AnimationController::UpdateOrderedNodes() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimationController::UpdateBlendLogic() {}
|
|
||||||
|
|
||||||
void AnimationController::UpdateTime(float dt) {
|
void AnimationController::UpdateTime(float dt) {
|
||||||
if (m_output_node == nullptr) {
|
if (m_paused || m_output_node == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +111,7 @@ void AnimationController::UpdateTime(float dt) {
|
|||||||
for (int i = m_ordered_nodes.size() - 1; i >= 0; i--) {
|
for (int i = m_ordered_nodes.size() - 1; i >= 0; i--) {
|
||||||
AnimNode* node = m_ordered_nodes[i];
|
AnimNode* node = m_ordered_nodes[i];
|
||||||
if (node->m_is_time_synced) {
|
if (node->m_is_time_synced) {
|
||||||
node->EvalAnimDuration();
|
node->UpdateSyncTrack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,14 +123,8 @@ void AnimationController::Evaluate() {
|
|||||||
if (m_output_node == nullptr) {
|
if (m_output_node == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_output_node->Evaluate(&m_local_matrices);
|
|
||||||
|
|
||||||
// convert joint matrices from local to model space
|
m_output_node->Evaluate(&m_skinned_mesh->m_local_matrices);
|
||||||
ozz::animation::LocalToModelJob ltm_job;
|
|
||||||
ltm_job.skeleton = &m_skinned_mesh->m_skeleton;
|
|
||||||
ltm_job.input = make_span(m_local_matrices);
|
|
||||||
ltm_job.output = make_span(m_skinned_mesh->m_model_matrices);
|
|
||||||
ltm_job.Run();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void AnimationController::DrawDebugUi() {
|
void AnimationController::DrawDebugUi() {
|
||||||
@@ -143,6 +134,24 @@ void AnimationController::DrawDebugUi() {
|
|||||||
if (ImGui::Button("Reset")) {
|
if (ImGui::Button("Reset")) {
|
||||||
ResetAnims();
|
ResetAnims();
|
||||||
}
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (m_paused) {
|
||||||
|
if (ImGui::Button("Play")) {
|
||||||
|
m_paused = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ImGui::Button("Pause")) {
|
||||||
|
m_paused = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Step")) {
|
||||||
|
bool was_paused = m_paused;
|
||||||
|
m_paused = false;
|
||||||
|
UpdateTime(0.1);
|
||||||
|
Evaluate();
|
||||||
|
m_paused = was_paused;
|
||||||
|
}
|
||||||
|
|
||||||
ImVec2 node_size(200, 100);
|
ImVec2 node_size(200, 100);
|
||||||
for (int i = 0; i < m_ordered_nodes.size(); i++) {
|
for (int i = 0; i < m_ordered_nodes.size(); i++) {
|
||||||
@@ -157,6 +166,8 @@ void AnimationController::DrawDebugUi() {
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::Text ("Node States");
|
||||||
|
|
||||||
ImGui::Columns(4, "Node States"); // 4-ways, with border
|
ImGui::Columns(4, "Node States"); // 4-ways, with border
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
ImGui::Text("Name");
|
ImGui::Text("Name");
|
||||||
@@ -184,8 +195,8 @@ void AnimationController::DrawDebugUi() {
|
|||||||
ImGui::Text(node->m_is_time_synced ? "X" : "-");
|
ImGui::Text(node->m_is_time_synced ? "X" : "-");
|
||||||
ImGui::NextColumn();
|
ImGui::NextColumn();
|
||||||
|
|
||||||
ImGui::PushID((void*)&node->m_anim_duration);
|
ImGui::PushID((void*)&node->m_sync_track.m_duration);
|
||||||
ImGui::Text("%2.3f", node->m_anim_duration);
|
ImGui::Text("%2.3f", node->m_sync_track.m_duration);
|
||||||
ImGui::NextColumn();
|
ImGui::NextColumn();
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ struct AnimationController {
|
|||||||
// Creates a list of nodes where for node at index i for all inputs holds index > i.
|
// Creates a list of nodes where for node at index i for all inputs holds index > i.
|
||||||
void UpdateOrderedNodes();
|
void UpdateOrderedNodes();
|
||||||
|
|
||||||
void UpdateBlendLogic();
|
|
||||||
|
|
||||||
// Updates all nodes.
|
// Updates all nodes.
|
||||||
void UpdateTime(float dt);
|
void UpdateTime(float dt);
|
||||||
|
|
||||||
@@ -34,11 +32,7 @@ struct AnimationController {
|
|||||||
void DrawDebugUi();
|
void DrawDebugUi();
|
||||||
|
|
||||||
float m_current_time;
|
float m_current_time;
|
||||||
|
bool m_paused;
|
||||||
ozz::vector<ozz::math::SoaTransform> m_local_matrices;
|
|
||||||
ozz::vector<ozz::math::SoaTransform> m_local_matrices_blended;
|
|
||||||
|
|
||||||
ozz::animation::SamplingCache m_sampling_cache_A;
|
|
||||||
|
|
||||||
SkinnedMesh* m_skinned_mesh = nullptr;
|
SkinnedMesh* m_skinned_mesh = nullptr;
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -42,8 +42,8 @@ inline void Camera_Init(Camera* camera) {
|
|||||||
camera->pitch = 10 * M_PI / 180.0f;
|
camera->pitch = 10 * M_PI / 180.0f;
|
||||||
|
|
||||||
memcpy(&camera->mtxView, &mtx_identity, sizeof(camera->mtxView));
|
memcpy(&camera->mtxView, &mtx_identity, sizeof(camera->mtxView));
|
||||||
Camera_CalcToMatrix(camera, &camera->mtxView);
|
Camera_CalcToMatrix(camera, &camera->mtxView[0]);
|
||||||
Camera_CalcFromMatrix(camera, &camera->mtxView);
|
Camera_CalcFromMatrix(camera, &camera->mtxView[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera_CalcFromMatrix(Camera* camera, float* mat) {
|
void Camera_CalcFromMatrix(Camera* camera, float* mat) {
|
||||||
@@ -153,6 +153,6 @@ inline void Camera_Update(
|
|||||||
camera->vel[i] = camera->vel[i] * 0.1;
|
camera->vel[i] = camera->vel[i] * 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera_CalcToMatrix(camera, &camera->mtxView);
|
Camera_CalcToMatrix(camera, &camera->mtxView[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-30
@@ -7,7 +7,6 @@
|
|||||||
#include <HandmadeMath.h>
|
#include <HandmadeMath.h>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
|
|
||||||
SkinnedMesh::~SkinnedMesh() {
|
SkinnedMesh::~SkinnedMesh() {
|
||||||
while (m_animations.size() > 0) {
|
while (m_animations.size() > 0) {
|
||||||
ozz::animation::Animation* animation_ptr =
|
ozz::animation::Animation* animation_ptr =
|
||||||
@@ -76,6 +75,7 @@ bool SkinnedMesh::LoadAnimation(const char* filename) {
|
|||||||
|
|
||||||
m_animations.push_back(animation_ptr);
|
m_animations.push_back(animation_ptr);
|
||||||
m_animation_names.push_back(filename);
|
m_animation_names.push_back(filename);
|
||||||
|
m_animation_sync_track.push_back(SyncTrack());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -89,20 +89,7 @@ void SkinnedMesh::SetCurrentAnimation(int index) {
|
|||||||
m_current_animation = m_animations[index];
|
m_current_animation = m_animations[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool LoadMesh (const char* filename);
|
void SkinnedMesh::CalcModelMatrices() {
|
||||||
|
|
||||||
void SkinnedMesh::EvalAnimation(float in_time) {
|
|
||||||
const float anim_duration = m_current_animation->duration();
|
|
||||||
float anim_ratio = fmodf((float)in_time / anim_duration, 1.0f);
|
|
||||||
|
|
||||||
// sample animation
|
|
||||||
ozz::animation::SamplingJob sampling_job;
|
|
||||||
sampling_job.animation = m_current_animation;
|
|
||||||
sampling_job.cache = &m_cache;
|
|
||||||
sampling_job.ratio = anim_ratio;
|
|
||||||
sampling_job.output = make_span(m_local_matrices);
|
|
||||||
sampling_job.Run();
|
|
||||||
|
|
||||||
// convert joint matrices from local to model space
|
// convert joint matrices from local to model space
|
||||||
ozz::animation::LocalToModelJob ltm_job;
|
ozz::animation::LocalToModelJob ltm_job;
|
||||||
ltm_job.skeleton = &m_skeleton;
|
ltm_job.skeleton = &m_skeleton;
|
||||||
@@ -111,27 +98,40 @@ void SkinnedMesh::EvalAnimation(float in_time) {
|
|||||||
ltm_job.Run();
|
ltm_job.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinnedMesh::DrawSkeleton() {
|
void SkinnedMesh::DrawSkeleton() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkinnedMesh::DrawDebugUi() {
|
void SkinnedMesh::DrawDebugUi() {
|
||||||
ImGui::Begin("SkinnedMesh");
|
ImGui::Begin("SkinnedMesh");
|
||||||
|
|
||||||
// ImGui::Checkbox("Time override", &state.time.anim_ratio_ui_override);
|
ImGui::Text("Animations");
|
||||||
|
|
||||||
// const float anim_duration = state.ozz->animation.duration();
|
const char* items[255] = {0};
|
||||||
// if (!state.time.anim_ratio_ui_override) {
|
static int selected = -1;
|
||||||
// state.time.anim_ratio =
|
for (int i = 0; i < m_animations.size(); i++) {
|
||||||
// fmodf((float)state.time.absolute / anim_duration, 1.0f);
|
items[i] = m_animation_names[i].c_str();
|
||||||
// }
|
}
|
||||||
// ImGui::SliderFloat("Time", &state.time.anim_ratio, 0.f, 1.f);
|
|
||||||
|
|
||||||
// ImGui::Text(
|
ImGui::Combo("Animation", &selected, items, m_animations.size());
|
||||||
// "Application average %.3f ms/frame (%.1f FPS)",
|
|
||||||
// 1000.0f / ImGui::GetIO().Framerate,
|
ImGui::Text("Sync Track");
|
||||||
// ImGui::GetIO().Framerate);
|
if (selected >= 0 && selected < m_animations.size()) {
|
||||||
|
m_animation_sync_track[selected].DrawDebugUi();
|
||||||
|
m_override_anim = selected;
|
||||||
|
|
||||||
|
ImGui::Checkbox("Override Animation", &m_sync_track_override);
|
||||||
|
if (m_sync_track_override) {
|
||||||
|
ImGui::SliderFloat("Ratio", &m_override_ratio, 0.f, 1.f);
|
||||||
|
|
||||||
|
ozz::animation::SamplingJob sampling_job;
|
||||||
|
sampling_job.animation = m_animations[selected];
|
||||||
|
sampling_job.cache = &m_cache;
|
||||||
|
sampling_job.ratio = m_override_ratio;
|
||||||
|
sampling_job.output = make_span(m_local_matrices);
|
||||||
|
if (!sampling_job.Run()) {
|
||||||
|
ozz::log::Err() << "Error sampling animation." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
}
|
}
|
||||||
+8
-90
@@ -9,6 +9,7 @@
|
|||||||
#include <cmath> // fmodf
|
#include <cmath> // fmodf
|
||||||
#include <memory> // std::unique_ptr, std::make_unique
|
#include <memory> // std::unique_ptr, std::make_unique
|
||||||
|
|
||||||
|
#include "SyncTrack.h"
|
||||||
#include "ozz/animation/runtime/animation.h"
|
#include "ozz/animation/runtime/animation.h"
|
||||||
#include "ozz/animation/runtime/local_to_model_job.h"
|
#include "ozz/animation/runtime/local_to_model_job.h"
|
||||||
#include "ozz/animation/runtime/sampling_job.h"
|
#include "ozz/animation/runtime/sampling_job.h"
|
||||||
@@ -20,97 +21,10 @@
|
|||||||
#include "ozz/base/maths/soa_transform.h"
|
#include "ozz/base/maths/soa_transform.h"
|
||||||
#include "ozz/base/maths/vec_float.h"
|
#include "ozz/base/maths/vec_float.h"
|
||||||
|
|
||||||
constexpr int cSyncTrackMaxIntervals = 8;
|
|
||||||
|
|
||||||
struct SyncTrack {
|
|
||||||
float m_duration;
|
|
||||||
int m_num_intervals;
|
|
||||||
float m_sync_markers[cSyncTrackMaxIntervals];
|
|
||||||
float m_interval_start[cSyncTrackMaxIntervals];
|
|
||||||
float m_interval_end[cSyncTrackMaxIntervals];
|
|
||||||
float m_interval_durations[cSyncTrackMaxIntervals];
|
|
||||||
|
|
||||||
void CalcIntervals() {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (m_num_intervals == 0) {
|
|
||||||
m_num_intervals = 1;
|
|
||||||
m_interval_start[0] = 0.f;
|
|
||||||
m_interval_end[0] = 1.f;
|
|
||||||
} else {
|
|
||||||
for (i = 0; i < m_num_intervals; i++) {
|
|
||||||
int end_index = i < m_num_intervals - 1 ? i + 1 : 0;
|
|
||||||
|
|
||||||
m_interval_start[i] = m_sync_markers[i];
|
|
||||||
m_interval_end[i] = m_sync_markers[end_index];
|
|
||||||
|
|
||||||
if (m_interval_end[i] > m_interval_start[i]) {
|
|
||||||
m_interval_durations[i] = m_interval_end[i] - m_interval_start[i];
|
|
||||||
} else {
|
|
||||||
m_interval_durations[i] =
|
|
||||||
m_interval_end[i] + (1. - m_interval_start[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float CalcSyncFromAbsTime(float abs_time) {
|
|
||||||
float sync_time = fmodf(abs_time, m_duration) / m_duration;
|
|
||||||
|
|
||||||
int interval_index = 0;
|
|
||||||
while (sync_time >= m_interval_durations[interval_index]) {
|
|
||||||
sync_time -= m_interval_durations[interval_index];
|
|
||||||
interval_index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return float(interval_index)
|
|
||||||
+ sync_time / m_interval_durations[interval_index];
|
|
||||||
}
|
|
||||||
|
|
||||||
float CalcRatioFromSyncTime(float sync_time) {
|
|
||||||
float interval_ratio = fmodf(sync_time, 1.0f);
|
|
||||||
int interval = int(sync_time - interval_ratio);
|
|
||||||
|
|
||||||
return fmodf(
|
|
||||||
m_interval_start[interval]
|
|
||||||
+ m_interval_durations[interval] * interval_ratio,
|
|
||||||
1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static SyncTrack
|
|
||||||
Blend(float weight, const SyncTrack& track_A, const SyncTrack& track_B) {
|
|
||||||
assert(track_A.m_num_intervals == track_B.m_num_intervals);
|
|
||||||
|
|
||||||
SyncTrack result;
|
|
||||||
result.m_num_intervals = track_A.m_num_intervals;
|
|
||||||
|
|
||||||
result.m_duration =
|
|
||||||
(1.0f - weight) * track_A.m_duration + weight * track_B.m_duration;
|
|
||||||
|
|
||||||
for (int i = 0; i < result.m_num_intervals; i++) {
|
|
||||||
result.m_interval_durations[i] =
|
|
||||||
(1.0f - weight) * track_A.m_interval_durations[i]
|
|
||||||
+ weight * track_B.m_interval_durations[i];
|
|
||||||
|
|
||||||
result.m_interval_start[i] =
|
|
||||||
(1.0f - weight) * track_A.m_interval_start[i]
|
|
||||||
+ weight * track_B.m_interval_start[i];
|
|
||||||
|
|
||||||
result.m_interval_end[i] =
|
|
||||||
(1.0f - weight) * track_A.m_interval_end[i]
|
|
||||||
+ weight * track_B.m_interval_end[i];
|
|
||||||
|
|
||||||
result.m_sync_markers[i] =
|
|
||||||
(1.0f - weight) * track_A.m_sync_markers[i]
|
|
||||||
+ weight * track_B.m_sync_markers[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SkinnedMesh {
|
struct SkinnedMesh {
|
||||||
|
SkinnedMesh() : m_sync_track_override(false), m_override_anim(0.f) {}
|
||||||
virtual ~SkinnedMesh();
|
virtual ~SkinnedMesh();
|
||||||
|
|
||||||
bool LoadSkeleton(const char* filename);
|
bool LoadSkeleton(const char* filename);
|
||||||
bool LoadAnimation(const char* filename);
|
bool LoadAnimation(const char* filename);
|
||||||
//bool LoadMesh (const char* filename);
|
//bool LoadMesh (const char* filename);
|
||||||
@@ -123,7 +37,7 @@ struct SkinnedMesh {
|
|||||||
return m_current_animation->duration();
|
return m_current_animation->duration();
|
||||||
};
|
};
|
||||||
|
|
||||||
void EvalAnimation(float in_time);
|
void CalcModelMatrices();
|
||||||
void DrawSkeleton();
|
void DrawSkeleton();
|
||||||
void DrawJoint(int joint_index, int parent_joint_index);
|
void DrawJoint(int joint_index, int parent_joint_index);
|
||||||
|
|
||||||
@@ -138,6 +52,10 @@ struct SkinnedMesh {
|
|||||||
ozz::animation::SamplingCache m_cache;
|
ozz::animation::SamplingCache m_cache;
|
||||||
ozz::vector<ozz::math::SoaTransform> m_local_matrices;
|
ozz::vector<ozz::math::SoaTransform> m_local_matrices;
|
||||||
ozz::vector<ozz::math::Float4x4> m_model_matrices;
|
ozz::vector<ozz::math::Float4x4> m_model_matrices;
|
||||||
|
|
||||||
|
bool m_sync_track_override;
|
||||||
|
int m_override_anim;
|
||||||
|
float m_override_ratio;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //ANIMTESTBED_SKINNEDMESH_H
|
#endif //ANIMTESTBED_SKINNEDMESH_H
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// Created by martin on 19.11.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "SyncTrack.h"
|
||||||
|
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
void SyncTrack::DrawDebugUi() {
|
||||||
|
ImGui::SliderFloat("duration", &m_duration, 0.001f, 10.f);
|
||||||
|
|
||||||
|
ImGui::Text("Marker");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("%d", m_num_intervals);
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("+")) {
|
||||||
|
if (m_num_intervals < cSyncTrackMaxIntervals) {
|
||||||
|
m_num_intervals ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("-")) {
|
||||||
|
if (m_num_intervals > 0) {
|
||||||
|
m_num_intervals --;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Text("Marker:");
|
||||||
|
for (int i = 0; i < m_num_intervals; i++) {
|
||||||
|
ImGui::Text("%2d:", i);
|
||||||
|
ImGui::SameLine();
|
||||||
|
std::ostringstream marker_stream;
|
||||||
|
marker_stream << i;
|
||||||
|
ImGui::SliderFloat(
|
||||||
|
marker_stream.str().c_str(),
|
||||||
|
&m_sync_markers[i],
|
||||||
|
0.f,
|
||||||
|
1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::Button ("Update Intervals")) {
|
||||||
|
CalcIntervals();
|
||||||
|
}
|
||||||
|
}
|
||||||
+156
@@ -0,0 +1,156 @@
|
|||||||
|
//
|
||||||
|
// Created by martin on 19.11.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef ANIMTESTBED_SYNCTRACK_H
|
||||||
|
#define ANIMTESTBED_SYNCTRACK_H
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
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];
|
||||||
|
float m_interval_start[cSyncTrackMaxIntervals];
|
||||||
|
float m_interval_ratio[cSyncTrackMaxIntervals];
|
||||||
|
|
||||||
|
void CalcIntervals() {
|
||||||
|
if (m_num_intervals == 0) {
|
||||||
|
m_num_intervals = 1;
|
||||||
|
m_sync_markers[0] = 0.f;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < m_num_intervals; i++) {
|
||||||
|
assert(m_sync_markers[i] >= 0.f && m_sync_markers[i] <= 1.0f);
|
||||||
|
|
||||||
|
int end_index = i < m_num_intervals - 1 ? i + 1 : 0;
|
||||||
|
|
||||||
|
m_interval_start[i] = m_sync_markers[i];
|
||||||
|
float interval_end = m_sync_markers[end_index];
|
||||||
|
|
||||||
|
if (interval_end < m_interval_start[i]) {
|
||||||
|
interval_end += 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_interval_ratio[i] = interval_end - m_interval_start[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float CalcSyncFromAbsTime(float abs_time) {
|
||||||
|
float sync_time = fmodf(abs_time, m_duration) / m_duration;
|
||||||
|
|
||||||
|
int interval_index = 0;
|
||||||
|
while (sync_time >= m_interval_ratio[interval_index]) {
|
||||||
|
sync_time -= m_interval_ratio[interval_index];
|
||||||
|
interval_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return float(interval_index) + sync_time / m_interval_ratio[interval_index];
|
||||||
|
}
|
||||||
|
|
||||||
|
float CalcRatioFromSyncTime(float sync_time) {
|
||||||
|
float interval_ratio = fmodf(sync_time, 1.0f);
|
||||||
|
int interval = int(sync_time - interval_ratio);
|
||||||
|
|
||||||
|
return fmodf(
|
||||||
|
m_interval_start[interval]
|
||||||
|
+ m_interval_ratio[interval] * interval_ratio,
|
||||||
|
1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const SyncTrack& other) const {
|
||||||
|
bool result = m_duration == other.m_duration
|
||||||
|
&& m_num_intervals == other.m_num_intervals;
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < m_num_intervals; i++) {
|
||||||
|
if ((fabsf(m_interval_start[i] - other.m_interval_start[i]) > 1.0e-5)
|
||||||
|
|| (fabsf(m_interval_ratio[i] - other.m_interval_ratio[i])
|
||||||
|
> 1.0e-5)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SyncTrack CreateFromMarkers(
|
||||||
|
float duration,
|
||||||
|
int n_markers,
|
||||||
|
float markers[cSyncTrackMaxIntervals]) {
|
||||||
|
SyncTrack result;
|
||||||
|
result.m_duration = duration;
|
||||||
|
result.m_num_intervals = n_markers;
|
||||||
|
for (int i = 0; i < n_markers; i++) {
|
||||||
|
result.m_sync_markers[i] = markers[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
result.CalcIntervals();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SyncTrack
|
||||||
|
Blend(float weight, const SyncTrack& track_A, const SyncTrack& track_B) {
|
||||||
|
assert(track_A.m_num_intervals == track_B.m_num_intervals);
|
||||||
|
|
||||||
|
SyncTrack result;
|
||||||
|
result.m_num_intervals = track_A.m_num_intervals;
|
||||||
|
|
||||||
|
result.m_duration =
|
||||||
|
(1.0f - weight) * track_A.m_duration + weight * track_B.m_duration;
|
||||||
|
|
||||||
|
float interval_0_offset =
|
||||||
|
track_B.m_interval_start[0] - track_A.m_interval_start[0];
|
||||||
|
if (interval_0_offset > 0.5f) {
|
||||||
|
interval_0_offset = -fmodf(1.f - interval_0_offset, 1.0f);
|
||||||
|
} else if (interval_0_offset < -0.5) {
|
||||||
|
interval_0_offset = fmodf(1.f + interval_0_offset, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.m_interval_start[0] = fmodf(
|
||||||
|
1.0 + (1.0f - weight) * track_A.m_interval_start[0]
|
||||||
|
+ weight * (track_A.m_interval_start[0] + interval_0_offset),
|
||||||
|
1.0f);
|
||||||
|
result.m_sync_markers[0] = result.m_interval_start[0];
|
||||||
|
|
||||||
|
for (int i = 0; i < result.m_num_intervals; i++) {
|
||||||
|
float interval_duration_A = track_A.m_interval_ratio[i];
|
||||||
|
float interval_duration_B = track_B.m_interval_ratio[i];
|
||||||
|
result.m_interval_ratio[i] =
|
||||||
|
(1.0f - weight) * interval_duration_A + weight * interval_duration_B;
|
||||||
|
|
||||||
|
if (i < cSyncTrackMaxIntervals) {
|
||||||
|
result.m_interval_start[i + 1] =
|
||||||
|
result.m_interval_start[i] + result.m_interval_ratio[i];
|
||||||
|
if (result.m_interval_start[i + 1] > 1.0f) {
|
||||||
|
result.m_interval_start[i + 1] =
|
||||||
|
fmodf(result.m_interval_start[i + 1], 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.m_sync_markers[i + 1] = result.m_interval_start[i + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert (result.m_num_intervals < cSyncTrackMaxIntervals);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawDebugUi();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //ANIMTESTBED_SYNCTRACK_H
|
||||||
+10441
File diff suppressed because it is too large
Load Diff
+53
-7
@@ -17,9 +17,10 @@
|
|||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "SkinnedMesh.h"
|
#include "SkinnedMesh.h"
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
|
#include "embedded_fonts.h"
|
||||||
|
|
||||||
const int Width = 1024;
|
const int Width = 2420;
|
||||||
const int Height = 768;
|
const int Height = 1480;
|
||||||
const int MaxVertices = (1 << 16);
|
const int MaxVertices = (1 << 16);
|
||||||
const int MaxIndices = MaxVertices * 3;
|
const int MaxIndices = MaxVertices * 3;
|
||||||
|
|
||||||
@@ -199,16 +200,40 @@ int main() {
|
|||||||
SkinnedMesh skinned_mesh;
|
SkinnedMesh skinned_mesh;
|
||||||
skinned_mesh.LoadSkeleton("../media/MixamoYBot-skeleton.ozz");
|
skinned_mesh.LoadSkeleton("../media/MixamoYBot-skeleton.ozz");
|
||||||
skinned_mesh.LoadAnimation("../media/Idle-loop.ozz");
|
skinned_mesh.LoadAnimation("../media/Idle-loop.ozz");
|
||||||
|
|
||||||
|
int anim_idx = 0;
|
||||||
|
float idle_markers[] = {0.f, 0.5};
|
||||||
|
skinned_mesh.m_animation_sync_track[anim_idx] = SyncTrack::CreateFromMarkers(skinned_mesh.m_animations[anim_idx]->duration(), 2, idle_markers);
|
||||||
|
|
||||||
|
anim_idx = 1;
|
||||||
skinned_mesh.LoadAnimation("../media/Walking-loop.ozz");
|
skinned_mesh.LoadAnimation("../media/Walking-loop.ozz");
|
||||||
|
float walking_markers[] = {0.293, 0.762};
|
||||||
|
skinned_mesh.m_animation_sync_track[anim_idx] = SyncTrack::CreateFromMarkers(skinned_mesh.m_animations[anim_idx]->duration(), 2, walking_markers);
|
||||||
|
|
||||||
|
anim_idx = 2;
|
||||||
skinned_mesh.LoadAnimation("../media/RunningSlow-loop.ozz");
|
skinned_mesh.LoadAnimation("../media/RunningSlow-loop.ozz");
|
||||||
|
float running_slow_markers[] = {0.315, 0.834};
|
||||||
|
skinned_mesh.m_animation_sync_track[anim_idx] = SyncTrack::CreateFromMarkers(skinned_mesh.m_animations[anim_idx]->duration(), 2, running_slow_markers);
|
||||||
|
|
||||||
|
anim_idx = 3;
|
||||||
skinned_mesh.LoadAnimation("../media/RunningFast-loop.ozz");
|
skinned_mesh.LoadAnimation("../media/RunningFast-loop.ozz");
|
||||||
|
float running_fast_markers[] = {0.403, 0.818};
|
||||||
|
skinned_mesh.m_animation_sync_track[anim_idx] = SyncTrack::CreateFromMarkers(skinned_mesh.m_animations[anim_idx]->duration(), 2, running_fast_markers);
|
||||||
|
|
||||||
|
anim_idx = 4;
|
||||||
skinned_mesh.LoadAnimation("../media/Limping-loop.ozz");
|
skinned_mesh.LoadAnimation("../media/Limping-loop.ozz");
|
||||||
|
float limping_markers[] = {0.757, 0.044};
|
||||||
|
skinned_mesh.m_animation_sync_track[anim_idx] = SyncTrack::CreateFromMarkers(skinned_mesh.m_animations[anim_idx]->duration(), 2, limping_markers);
|
||||||
|
|
||||||
|
anim_idx = 5;
|
||||||
skinned_mesh.LoadAnimation("../media/ZombieWalk-loop.ozz");
|
skinned_mesh.LoadAnimation("../media/ZombieWalk-loop.ozz");
|
||||||
|
float zombiewalk_markers[] = {0.619, 0.};
|
||||||
|
skinned_mesh.m_animation_sync_track[anim_idx] = SyncTrack::CreateFromMarkers(skinned_mesh.m_animations[anim_idx]->duration(), 2, zombiewalk_markers);
|
||||||
|
|
||||||
skinned_mesh.SetCurrentAnimation(0);
|
skinned_mesh.SetCurrentAnimation(0);
|
||||||
|
|
||||||
AnimationController animation_controller (&skinned_mesh);
|
AnimationController animation_controller (&skinned_mesh);
|
||||||
|
|
||||||
// state.ozz = std::make_unique<ozz_t>();
|
|
||||||
state.time.factor = 1.0f;
|
state.time.factor = 1.0f;
|
||||||
|
|
||||||
Camera_Init(&state.camera);
|
Camera_Init(&state.camera);
|
||||||
@@ -217,8 +242,24 @@ int main() {
|
|||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.IniFilename = nullptr;
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||||
io.Fonts->AddFontDefault();
|
io.IniFilename = "ATPImgui.ini";
|
||||||
|
|
||||||
|
ImGui::GetStyle().ScaleAllSizes(2.0);
|
||||||
|
|
||||||
|
//io.Fonts->AddFontDefault();
|
||||||
|
ImFontConfig font_config;
|
||||||
|
font_config.OversampleH = 4;
|
||||||
|
font_config.OversampleV = 4;
|
||||||
|
font_config.GlyphExtraSpacing.x = 1.0f;
|
||||||
|
io.Fonts->AddFontFromMemoryCompressedTTF(
|
||||||
|
// roboto_medium_ttf_compressed_data,
|
||||||
|
// roboto_medium_ttf_compressed_size,
|
||||||
|
droid_sans_ttf_compressed_data,
|
||||||
|
droid_sans_ttf_compressed_size,
|
||||||
|
28,
|
||||||
|
&font_config);
|
||||||
|
|
||||||
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB;
|
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB;
|
||||||
io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
|
io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
|
||||||
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
||||||
@@ -408,11 +449,16 @@ int main() {
|
|||||||
|
|
||||||
|
|
||||||
draw_grid();
|
draw_grid();
|
||||||
|
ImGui::SetNextWindowPos(ImVec2 (600, 60), ImGuiCond_FirstUseEver);
|
||||||
|
ImGui::SetNextWindowSize(ImVec2 (300, 400), ImGuiCond_FirstUseEver);
|
||||||
skinned_mesh.DrawDebugUi();
|
skinned_mesh.DrawDebugUi();
|
||||||
animation_controller.DrawDebugUi();
|
animation_controller.DrawDebugUi();
|
||||||
|
|
||||||
animation_controller.UpdateTime(state.time.frame);
|
if (!skinned_mesh.m_sync_track_override) {
|
||||||
animation_controller.Evaluate();
|
animation_controller.UpdateTime(state.time.frame);
|
||||||
|
animation_controller.Evaluate();
|
||||||
|
}
|
||||||
|
skinned_mesh.CalcModelMatrices();
|
||||||
|
|
||||||
sgl_defaults();
|
sgl_defaults();
|
||||||
sgl_matrix_mode_projection();
|
sgl_matrix_mode_projection();
|
||||||
|
|||||||
+101
-54
@@ -2,7 +2,7 @@
|
|||||||
// Created by martin on 16.11.21.
|
// Created by martin on 16.11.21.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "SkinnedMesh.h"
|
#include "SyncTrack.h"
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
TEST_CASE("Basic", "[SyncTrack]") {
|
TEST_CASE("Basic", "[SyncTrack]") {
|
||||||
@@ -10,21 +10,17 @@ TEST_CASE("Basic", "[SyncTrack]") {
|
|||||||
track_A.m_num_intervals = 2;
|
track_A.m_num_intervals = 2;
|
||||||
track_A.m_duration = 2.0;
|
track_A.m_duration = 2.0;
|
||||||
track_A.m_interval_start[0] = 0.f;
|
track_A.m_interval_start[0] = 0.f;
|
||||||
track_A.m_interval_end[0] = 0.7f;
|
track_A.m_interval_ratio[0] = 0.7;
|
||||||
track_A.m_interval_durations[0] = 0.7;
|
|
||||||
track_A.m_interval_start[1] = 0.7f;
|
track_A.m_interval_start[1] = 0.7f;
|
||||||
track_A.m_interval_end[1] = 1.0f;
|
track_A.m_interval_ratio[1] = 0.3;
|
||||||
track_A.m_interval_durations[1] = 0.3;
|
|
||||||
|
|
||||||
SyncTrack track_B;
|
SyncTrack track_B;
|
||||||
track_B.m_num_intervals = 2;
|
track_B.m_num_intervals = 2;
|
||||||
track_B.m_duration = 1.5;
|
track_B.m_duration = 1.5;
|
||||||
track_B.m_interval_start[0] = 0.0f;
|
track_B.m_interval_start[0] = 0.0f;
|
||||||
track_B.m_interval_end[0] = 0.6f;
|
track_B.m_interval_ratio[0] = 0.6;
|
||||||
track_B.m_interval_durations[0] = 0.6;
|
|
||||||
track_B.m_interval_start[1] = 0.6f;
|
track_B.m_interval_start[1] = 0.6f;
|
||||||
track_B.m_interval_end[1] = 1.0f;
|
track_B.m_interval_ratio[1] = 0.4;
|
||||||
track_B.m_interval_durations[1] = 0.4;
|
|
||||||
|
|
||||||
WHEN("Calculating sync time of track_B at 0.5 duration") {
|
WHEN("Calculating sync time of track_B at 0.5 duration") {
|
||||||
float sync_time_at_0_75 =
|
float sync_time_at_0_75 =
|
||||||
@@ -69,48 +65,16 @@ TEST_CASE("Basic", "[SyncTrack]") {
|
|||||||
WHEN("Blending two synctracks with weight 0.") {
|
WHEN("Blending two synctracks with weight 0.") {
|
||||||
SyncTrack blended = SyncTrack::Blend(0.f, track_A, track_B);
|
SyncTrack blended = SyncTrack::Blend(0.f, track_A, track_B);
|
||||||
|
|
||||||
THEN("Result must equal track_A") {
|
THEN("Result must equal track_A") { REQUIRE(track_A == blended); }
|
||||||
REQUIRE(blended.m_duration == track_A.m_duration);
|
|
||||||
REQUIRE(
|
|
||||||
blended.m_interval_durations[0] == track_A.m_interval_durations[0]);
|
|
||||||
REQUIRE(
|
|
||||||
blended.m_interval_durations[1] == track_A.m_interval_durations[1]);
|
|
||||||
|
|
||||||
REQUIRE(blended.m_sync_markers[0] == track_A.m_sync_markers[0]);
|
|
||||||
REQUIRE(blended.m_sync_markers[1] == track_A.m_sync_markers[1]);
|
|
||||||
|
|
||||||
REQUIRE(blended.m_interval_start[0] == track_A.m_interval_start[0]);
|
|
||||||
REQUIRE(blended.m_interval_start[1] == track_A.m_interval_start[1]);
|
|
||||||
|
|
||||||
REQUIRE(blended.m_interval_end[0] == track_A.m_interval_end[0]);
|
|
||||||
REQUIRE(blended.m_interval_end[1] == track_A.m_interval_end[1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WHEN("Blending two synctracks with weight 1.") {
|
WHEN("Blending two synctracks with weight 1.") {
|
||||||
SyncTrack blended = SyncTrack::Blend(1.f, track_A, track_B);
|
SyncTrack blended = SyncTrack::Blend(1.f, track_A, track_B);
|
||||||
|
|
||||||
THEN("Result must equal track_B") {
|
THEN("Result must equal track_B") { REQUIRE(track_B == blended); }
|
||||||
REQUIRE(blended.m_duration == track_B.m_duration);
|
|
||||||
REQUIRE(
|
|
||||||
blended.m_interval_durations[0] == track_B.m_interval_durations[0]);
|
|
||||||
REQUIRE(
|
|
||||||
blended.m_interval_durations[1] == track_B.m_interval_durations[1]);
|
|
||||||
|
|
||||||
REQUIRE(blended.m_sync_markers[0] == track_B.m_sync_markers[0]);
|
|
||||||
REQUIRE(blended.m_sync_markers[1] == track_B.m_sync_markers[1]);
|
|
||||||
|
|
||||||
REQUIRE(blended.m_interval_start[0] == track_B.m_interval_start[0]);
|
|
||||||
REQUIRE(blended.m_interval_start[1] == track_B.m_interval_start[1]);
|
|
||||||
|
|
||||||
REQUIRE(blended.m_interval_end[0] == track_B.m_interval_end[0]);
|
|
||||||
REQUIRE(blended.m_interval_end[1] == track_B.m_interval_end[1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("Sync Marker Interval Calculation", "[SyncTrack]") {
|
TEST_CASE("Sync Marker Interval Calculation", "[SyncTrack]") {
|
||||||
SyncTrack track_A;
|
SyncTrack track_A;
|
||||||
track_A.m_num_intervals = 2;
|
track_A.m_num_intervals = 2;
|
||||||
@@ -121,13 +85,11 @@ TEST_CASE("Sync Marker Interval Calculation", "[SyncTrack]") {
|
|||||||
WHEN("Calculating intervals") {
|
WHEN("Calculating intervals") {
|
||||||
track_A.CalcIntervals();
|
track_A.CalcIntervals();
|
||||||
|
|
||||||
CHECK(track_A.m_interval_start[0] == 0.9f);
|
CHECK(track_A.m_interval_start[0] == Catch::Detail::Approx(0.9f));
|
||||||
CHECK(track_A.m_interval_end[0] == 0.2f);
|
CHECK(track_A.m_interval_ratio[0] == Catch::Detail::Approx(0.3f));
|
||||||
CHECK(track_A.m_interval_durations[0] == 0.3f);
|
|
||||||
|
|
||||||
CHECK(track_A.m_interval_start[1] == 0.2f);
|
CHECK(track_A.m_interval_start[1] == Catch::Detail::Approx(0.2f));
|
||||||
CHECK(track_A.m_interval_end[1] == 0.9f);
|
CHECK(track_A.m_interval_ratio[1] == Catch::Detail::Approx(0.7f));
|
||||||
CHECK(track_A.m_interval_durations[1] == 0.7f);
|
|
||||||
|
|
||||||
WHEN("Querying ratio at sync time at 1.001") {
|
WHEN("Querying ratio at sync time at 1.001") {
|
||||||
float ratio = track_A.CalcRatioFromSyncTime(1.0001f);
|
float ratio = track_A.CalcRatioFromSyncTime(1.0001f);
|
||||||
@@ -145,11 +107,96 @@ TEST_CASE("Sync Marker Interval Calculation", "[SyncTrack]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WHEN ("Blending with another sync track") {
|
WHEN("Blending sync track with 3 events") {
|
||||||
|
track_A.m_num_intervals = 3;
|
||||||
|
track_A.m_duration = 2.0;
|
||||||
|
track_A.m_sync_markers[0] = 0.;
|
||||||
|
track_A.m_sync_markers[1] = 0.3;
|
||||||
|
track_A.m_sync_markers[2] = 0.9;
|
||||||
|
track_A.CalcIntervals();
|
||||||
|
|
||||||
SyncTrack track_B;
|
SyncTrack track_B;
|
||||||
track_B.m_num_intervals = 2;
|
track_B.m_num_intervals = 3;
|
||||||
track_B.m_duration = 1.0;
|
track_B.m_duration = 1.5;
|
||||||
track_B.m_sync_markers[0] = 0.9;
|
track_B.m_sync_markers[0] = 0.7;
|
||||||
track_B.m_sync_markers[1] = 0.2;
|
track_B.m_sync_markers[1] = 0.9;
|
||||||
|
track_B.m_sync_markers[2] = 0.2;
|
||||||
|
track_B.CalcIntervals();
|
||||||
|
|
||||||
|
WHEN("Calculating A's durations") {
|
||||||
|
CHECK(track_A.m_interval_ratio[0] == Catch::Detail::Approx(0.3));
|
||||||
|
CHECK(track_A.m_interval_ratio[1] == Catch::Detail::Approx(0.6));
|
||||||
|
CHECK(track_A.m_interval_ratio[2] == Catch::Detail::Approx(0.1));
|
||||||
|
}
|
||||||
|
|
||||||
|
WHEN("Calculating B's durations") {
|
||||||
|
CHECK(track_B.m_interval_ratio[0] == Catch::Detail::Approx(0.2));
|
||||||
|
CHECK(track_B.m_interval_ratio[1] == Catch::Detail::Approx(0.3));
|
||||||
|
CHECK(track_B.m_interval_ratio[2] == Catch::Detail::Approx(0.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
WHEN("Blending two synctracks with weight 0.") {
|
||||||
|
SyncTrack blended = SyncTrack::Blend(0.f, track_A, track_B);
|
||||||
|
|
||||||
|
THEN("Result must equal track_A") { REQUIRE(track_A == blended); }
|
||||||
|
}
|
||||||
|
|
||||||
|
WHEN("Blending two synctracks with weight 1.") {
|
||||||
|
SyncTrack blended = SyncTrack::Blend(1.f, track_A, track_B);
|
||||||
|
|
||||||
|
THEN("Result must equal track_B") { REQUIRE(track_B == blended); }
|
||||||
|
}
|
||||||
|
|
||||||
|
WHEN("Blending with weight 0.2") {
|
||||||
|
float weight = 0.2f;
|
||||||
|
SyncTrack blended = SyncTrack::Blend(weight, track_A, track_B);
|
||||||
|
|
||||||
|
REQUIRE(
|
||||||
|
blended.m_duration
|
||||||
|
== (1.0f - weight) * track_A.m_duration
|
||||||
|
+ weight * track_B.m_duration);
|
||||||
|
REQUIRE(
|
||||||
|
blended.m_interval_start[0]
|
||||||
|
== fmodf(
|
||||||
|
(1.0f - weight) * (track_A.m_interval_start[0] + 1.0f)
|
||||||
|
+ weight * (track_B.m_interval_start[0]),
|
||||||
|
1.0f));
|
||||||
|
REQUIRE(
|
||||||
|
blended.m_interval_ratio[1]
|
||||||
|
== (1.0f - weight) * (track_A.m_interval_ratio[1])
|
||||||
|
+ weight * (track_B.m_interval_ratio[1])
|
||||||
|
);
|
||||||
|
REQUIRE(
|
||||||
|
blended.m_interval_ratio[2]
|
||||||
|
== (1.0f - weight) * (track_A.m_interval_ratio[2])
|
||||||
|
+ weight * (track_B.m_interval_ratio[2])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
WHEN("Inverted blending with weight 0.2") {
|
||||||
|
float weight = 0.2f;
|
||||||
|
SyncTrack blended = SyncTrack::Blend(weight, track_B, track_A);
|
||||||
|
|
||||||
|
REQUIRE(
|
||||||
|
blended.m_duration
|
||||||
|
== (1.0f - weight) * track_B.m_duration
|
||||||
|
+ weight * track_A.m_duration);
|
||||||
|
REQUIRE(
|
||||||
|
blended.m_interval_start[0]
|
||||||
|
== fmodf(
|
||||||
|
(1.0f - weight) * (track_B.m_interval_start[0])
|
||||||
|
+ weight * (track_A.m_interval_start[0] + 1.0f),
|
||||||
|
1.0f));
|
||||||
|
REQUIRE(
|
||||||
|
blended.m_interval_ratio[1]
|
||||||
|
== (1.0f - weight) * (track_B.m_interval_ratio[1])
|
||||||
|
+ weight * (track_A.m_interval_ratio[1])
|
||||||
|
);
|
||||||
|
REQUIRE(
|
||||||
|
blended.m_interval_ratio[2]
|
||||||
|
== (1.0f - weight) * (track_B.m_interval_ratio[2])
|
||||||
|
+ weight * (track_A.m_interval_ratio[2])
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user