Added LockTranslationNode.
parent
d006b43d04
commit
554125dde2
|
@ -48,6 +48,7 @@ add_library(AnimTestbedCode OBJECT
|
|||
src/AnimNodes/AnimSamplerNode.cc
|
||||
src/AnimNodes/SpeedScaleNode.cc
|
||||
src/AnimNodes/BlendNode.cc
|
||||
src/AnimNodes/LockTranslationNode.cc
|
||||
src/AnimationController.cc
|
||||
3rdparty/imgui/imgui.cpp
|
||||
3rdparty/imgui/imgui_draw.cpp
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
//
|
||||
// Created by martin on 16.11.21.
|
||||
//
|
||||
|
||||
#include "LockTranslationNode.h"
|
||||
|
||||
#include <imgui.h>
|
||||
#include "ozz/base/maths/soa_transform.h"
|
||||
|
||||
void LockTranslationNode::Evaluate(
|
||||
ozz::vector<ozz::math::SoaTransform>* local_matrices) {
|
||||
m_input->Evaluate(local_matrices);
|
||||
ozz::math::SoaFloat3 translation = (*local_matrices)[m_locked_bone_index].translation;
|
||||
float x[4];
|
||||
float y[4];
|
||||
float z[4];
|
||||
_mm_store_ps(x, translation.x);
|
||||
_mm_store_ps(y, translation.y);
|
||||
_mm_store_ps(z, translation.z);
|
||||
|
||||
if (m_lock_x) {
|
||||
x[0] = 0.f;
|
||||
}
|
||||
|
||||
if (m_lock_y) {
|
||||
y[0] = 0.f;
|
||||
}
|
||||
|
||||
if (m_lock_z) {
|
||||
z[0] = 0.f;
|
||||
}
|
||||
|
||||
translation.x = _mm_load_ps(x);
|
||||
translation.y = _mm_load_ps(y);
|
||||
translation.z = _mm_load_ps(z);
|
||||
|
||||
//translation = ozz::math::SoaFloat3::zero();
|
||||
// ozz::math::SetX(translation, 0.f);
|
||||
// ozz::math::SetZ(translation, 0.f);
|
||||
(*local_matrices)[m_locked_bone_index].translation = translation;
|
||||
}
|
||||
|
||||
void LockTranslationNode::DrawDebugUi() {
|
||||
const ozz::animation::Skeleton& skeleton = m_animation_controller->m_skinned_mesh->m_skeleton;
|
||||
ozz::span<const char* const> joint_names = skeleton.joint_names();
|
||||
|
||||
const char* items[255] = {0};
|
||||
int item_current = 0;
|
||||
for (int i = 0; i < joint_names.size(); i++) {
|
||||
items[i] = joint_names[i];
|
||||
}
|
||||
|
||||
ImGui::Combo("Bone", &m_locked_bone_index, items, joint_names.size());
|
||||
ImGui::Checkbox("Lock X", &m_lock_x);
|
||||
ImGui::Checkbox("Lock Y", &m_lock_y);
|
||||
ImGui::Checkbox("Lock Z", &m_lock_z);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// Created by martin on 16.11.21.
|
||||
//
|
||||
|
||||
#ifndef ANIMTESTBED_LOCKBONES_H
|
||||
#define ANIMTESTBED_LOCKBONES_H
|
||||
|
||||
#include "../AnimNode.h"
|
||||
|
||||
struct LockTranslationNode : public AnimNode {
|
||||
LockTranslationNode(AnimationController* animation_controller)
|
||||
: AnimNode(animation_controller),
|
||||
m_input(nullptr),
|
||||
m_locked_bone_index(0),
|
||||
m_lock_x(false),
|
||||
m_lock_y(false),
|
||||
m_lock_z(false) {}
|
||||
|
||||
virtual ~LockTranslationNode() {}
|
||||
|
||||
AnimNode* m_input;
|
||||
int m_locked_bone_index;
|
||||
bool m_lock_x;
|
||||
bool m_lock_y;
|
||||
bool m_lock_z;
|
||||
|
||||
virtual void Reset() { m_current_time = 0.f; }
|
||||
|
||||
virtual void UpdateIsSynced(bool is_synced) override {
|
||||
m_is_time_synced = is_synced;
|
||||
|
||||
m_input->UpdateIsSynced(m_is_time_synced);
|
||||
}
|
||||
|
||||
virtual void EvalAnimDuration() override {
|
||||
m_anim_duration = m_input->m_anim_duration;
|
||||
}
|
||||
|
||||
virtual void UpdateTime(float dt) { m_input->UpdateTime(dt); }
|
||||
|
||||
virtual void Evaluate(
|
||||
ozz::vector<ozz::math::SoaTransform>* local_matrices) override;
|
||||
|
||||
virtual void GetInputNodes(
|
||||
std::vector<AnimNode*>& input_nodes) const override {
|
||||
input_nodes.push_back(m_input);
|
||||
};
|
||||
|
||||
virtual void DrawDebugUi() override;
|
||||
};
|
||||
|
||||
#endif //ANIMTESTBED_LOCKBONES_H
|
|
@ -5,7 +5,6 @@
|
|||
#include "AnimationController.h"
|
||||
|
||||
#include <imgui.h>
|
||||
#include <ozz/animation/runtime/blending_job.h>
|
||||
#include <ozz/animation/runtime/local_to_model_job.h>
|
||||
#include <ozz/animation/runtime/sampling_job.h>
|
||||
|
||||
|
@ -13,6 +12,7 @@
|
|||
|
||||
#include "AnimNodes/AnimSamplerNode.h"
|
||||
#include "AnimNodes/BlendNode.h"
|
||||
#include "AnimNodes/LockTranslationNode.h"
|
||||
#include "AnimNodes/SpeedScaleNode.h"
|
||||
#include "SkinnedMesh.h"
|
||||
|
||||
|
@ -54,7 +54,12 @@ AnimationController::AnimationController(SkinnedMesh* skinned_mesh)
|
|||
speed_node1->m_input_node = blend_node;
|
||||
m_anim_nodes.push_back(speed_node1);
|
||||
|
||||
m_output_node = 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_output_node = lock_node;
|
||||
|
||||
UpdateOrderedNodes();
|
||||
|
||||
|
|
Loading…
Reference in New Issue