Renamed AnimData to Pose.

This commit is contained in:
Martin Felis 2025-03-19 21:43:01 +01:00
parent f52b19a8d2
commit 86ea476881
10 changed files with 70 additions and 66 deletions

View File

@ -15,9 +15,9 @@ bool AnimGraphBlendTree::Init(AnimGraphContext& context) {
}
}
for (size_t i = 0; i < m_animdata_blocks.size(); i++) {
for (size_t i = 0; i < m_pose_blocks.size(); i++) {
int num_soa_joints = context.m_skeleton->num_soa_joints();
m_animdata_blocks[i]->m_local_matrices.resize(num_soa_joints);
m_pose_blocks[i]->m_local_matrices.resize(num_soa_joints);
}
return true;

View File

@ -13,8 +13,6 @@
// AnimGraph (Runtime)
//
struct AnimGraphBlendTree : public AnimNode {
AnimData m_local_transforms;
std::vector<AnimNode*> m_nodes;
std::vector<AnimNode*> m_eval_ordered_nodes;
std::vector<std::vector<AnimGraphConnection> > m_node_input_connections;
@ -30,7 +28,7 @@ struct AnimGraphBlendTree : public AnimNode {
return m_node_input_connections[0];
}
std::vector<AnimData*> m_animdata_blocks;
std::vector<Pose*> m_pose_blocks;
NodeDescriptorBase* m_node_descriptor = nullptr;
char* m_input_buffer = nullptr;
char* m_output_buffer = nullptr;
@ -67,10 +65,10 @@ struct AnimGraphBlendTree : public AnimNode {
void PropagateTimeToNodeInputs(const AnimNode* node);
void dealloc() {
for (size_t i = 0; i < m_animdata_blocks.size(); i++) {
m_animdata_blocks[i]->m_local_matrices.vector::~vector();
for (size_t i = 0; i < m_pose_blocks.size(); i++) {
m_pose_blocks[i]->m_local_matrices.vector::~vector();
}
m_animdata_blocks.clear();
m_pose_blocks.clear();
m_node_input_connections.clear();
m_node_output_connections.clear();

View File

@ -25,26 +25,26 @@
struct AnimGraph;
struct AnimNode;
struct AnimData {
struct Pose {
ozz::vector<ozz::math::SoaTransform> m_local_matrices;
};
struct AnimDataRef {
AnimData* ptr = nullptr;
Pose* ptr = nullptr;
};
struct AnimDataAllocator {
struct AnimDataList {
AnimData* m_anim_data = nullptr;
AnimDataList* next = nullptr;
struct PoseList {
Pose* m_anim_data = nullptr;
PoseList* next = nullptr;
};
std::list<AnimData*> m_anim_data_list;
std::list<Pose*> m_anim_data_list;
size_t m_num_allocations = 0;
~AnimDataAllocator() {
while (!m_anim_data_list.empty()) {
AnimData* front = m_anim_data_list.front();
Pose* front = m_anim_data_list.front();
#ifdef ANIM_DATA_ALLOCATOR_DEBUG
std::cout << "about to delete with size "
<< front->m_anim_data->m_local_matrices.size()
@ -55,9 +55,9 @@ struct AnimDataAllocator {
}
}
AnimData* allocate(ozz::animation::Skeleton* skeleton) {
Pose* allocate(ozz::animation::Skeleton* skeleton) {
if (m_anim_data_list.empty()) {
AnimData* result = new AnimData();
Pose* result = new Pose();
result->m_local_matrices.resize(skeleton->num_soa_joints());
#ifdef ANIM_DATA_ALLOCATOR_DEBUG
std::cout << "Allocated with size " << result->m_local_matrices.size()
@ -67,7 +67,7 @@ struct AnimDataAllocator {
return result;
}
AnimData* result = m_anim_data_list.front();
Pose* result = m_anim_data_list.front();
m_anim_data_list.pop_front();
#ifdef ANIM_DATA_ALLOCATOR_DEBUG
@ -78,7 +78,7 @@ struct AnimDataAllocator {
return result;
}
void free(AnimData* anim_data) {
void free(Pose* anim_data) {
#ifdef ANIM_DATA_ALLOCATOR_DEBUG
std::cout << "Storing buffer with size "
<< anim_data->m_local_matrices.size() << " " << anim_data
@ -238,7 +238,7 @@ SocketType GetSocketType() {
return SocketType::SocketTypeBool;
}
if constexpr (std::is_same<T, AnimData>::value) {
if constexpr (std::is_same<T, Pose>::value) {
return SocketType::SocketTypeAnimation;
}

View File

@ -18,9 +18,9 @@ struct AnimNode;
// Blend2Node
//
struct Blend2Node : public AnimNode {
AnimData* i_input0 = nullptr;
AnimData* i_input1 = nullptr;
AnimData* o_output = nullptr;
Pose* i_input0 = nullptr;
Pose* i_input1 = nullptr;
Pose* o_output = nullptr;
float* i_blend_weight = nullptr;
bool m_sync_blend = false;
@ -77,8 +77,8 @@ struct NodeDescriptor<Blend2Node> : public NodeDescriptorBase {
// SpeedScaleNode
//
struct SpeedScaleNode : public AnimNode {
AnimData* i_input = nullptr;
AnimData* o_output = nullptr;
Pose* i_input = nullptr;
Pose* o_output = nullptr;
float* i_speed_scale = nullptr;
void UpdateTime(float time_last, float time_now) override {
@ -114,7 +114,7 @@ struct NodeDescriptor<SpeedScaleNode> : public NodeDescriptorBase {
// AnimSamplerNode
//
struct AnimSamplerNode : public AnimNode {
AnimData* o_output = nullptr;
Pose* o_output = nullptr;
std::string m_filename;
ozz::animation::SamplingJob::Context m_sampling_context;
ozz::animation::Animation* m_animation = nullptr;
@ -144,8 +144,8 @@ struct NodeDescriptor<AnimSamplerNode> : public NodeDescriptorBase {
// LockTranslationNode
//
struct LockTranslationNode : public AnimNode {
AnimData* i_input = nullptr;
AnimData* o_output = nullptr;
Pose* i_input = nullptr;
Pose* o_output = nullptr;
int m_locked_bone_index = 0;
bool m_lock_x = false;
bool m_lock_y = false;

View File

@ -86,7 +86,7 @@ Socket sJsonToSocket(const json& json_data) {
}
} else if (type_string == "Animation") {
result.m_type = SocketType::SocketTypeAnimation;
result.m_type_size = sizeof(AnimData);
result.m_type_size = sizeof(Pose);
} else if (type_string == "Int") {
result.m_type = SocketType::SocketTypeInt;
result.m_type_size = sizeof(int);
@ -1242,9 +1242,8 @@ void BlendTreeResource::CreateBlendTreeConnectionInstances(
&instance.m_connection_data_storage[socket_data_offset];
if (source_socket->m_type == SocketType::SocketTypeAnimation) {
instance.m_animdata_blocks.push_back(
(AnimData*)(&instance
.m_connection_data_storage[socket_data_offset]));
instance.m_pose_blocks.push_back(
(Pose*)(&instance.m_connection_data_storage[socket_data_offset]));
}
}

View File

@ -75,8 +75,7 @@ struct BlendTreeResource : AnimGraphResource {
m_virtual_socket_accessor = VirtualAnimNodeDescriptorFactory("BlendTree");
InitGraphConnectors();
RegisterBlendTreeOutputSocket<AnimData>(
AnimGraphResource::DefaultAnimOutput);
RegisterBlendTreeOutputSocket<Pose>(AnimGraphResource::DefaultAnimOutput);
}
~BlendTreeResource() { ClearAllNodes(); }

View File

@ -491,7 +491,7 @@ int main() {
AnimGraphBlendTree anim_graph;
AnimGraphContext anim_graph_context;
AnimData anim_graph_output;
Pose anim_graph_output;
anim_graph_output.m_local_matrices.resize(
skinned_mesh.m_skeleton.num_soa_joints());
AnimGraphEditorClear();

View File

@ -121,18 +121,18 @@ TEST_CASE_METHOD(
sampled_translation.z[0] == Approx(translation_key.value.z).margin(0.01));
}
TEST_CASE("AnimDataPlacementNew", "[AnimGraphEval]") {
int anim_data_size = sizeof(AnimData);
char* buf = new char[anim_data_size];
TEST_CASE("PosePlacementNew", "[AnimGraphEval]") {
int pose_size = sizeof(Pose);
char* buf = new char[pose_size];
AnimData* anim_data_newed = new AnimData;
anim_data_newed->m_local_matrices.resize(2);
delete anim_data_newed;
Pose* pose_newed = new Pose;
pose_newed->m_local_matrices.resize(2);
delete pose_newed;
AnimData* anim_data_ptr = new (buf) AnimData;
anim_data_ptr->m_local_matrices.resize(4);
anim_data_ptr->m_local_matrices.resize(0);
anim_data_ptr->m_local_matrices.vector::~vector();
Pose* pose_ptr = new (buf) Pose;
pose_ptr->m_local_matrices.resize(4);
pose_ptr->m_local_matrices.resize(0);
pose_ptr->m_local_matrices.vector::~vector();
delete[] buf;
}
@ -214,7 +214,7 @@ TEST_CASE_METHOD(
*blend_tree.GetGraphInputs()[0].m_reference.ptr_ptr
== &graph_float_input);
AnimData graph_anim_output;
Pose graph_anim_output;
graph_anim_output.m_local_matrices.resize(skeleton->num_joints());
blend_tree.SetOutput("Output", &graph_anim_output);

View File

@ -41,7 +41,7 @@ class SimpleAnimSamplerBlendTreeResourceFixture
std::string("media/Walking-loop.ozz"));
AnimNodeResource* graph_node = blend_tree_resource->GetGraphOutputNode();
graph_node->m_virtual_socket_accessor->RegisterInput<AnimData>(
graph_node->m_virtual_socket_accessor->RegisterInput<Pose>(
"GraphOutput",
nullptr);
@ -161,14 +161,14 @@ class EmbeddedBlendTreeGraphResource : public BlendTreeResourceFixture {
// Embedded: outputs
AnimNodeResource* embedded_outputs =
embedded_blend_tree_resource->GetGraphOutputNode();
embedded_outputs->m_virtual_socket_accessor->RegisterInput<AnimData>(
embedded_outputs->m_virtual_socket_accessor->RegisterInput<Pose>(
"AnimOutput",
nullptr);
// Embedded: inputs
AnimNodeResource* embedded_inputs =
embedded_blend_tree_resource->GetGraphInputNode();
embedded_inputs->m_virtual_socket_accessor->RegisterOutput<AnimData>(
embedded_inputs->m_virtual_socket_accessor->RegisterOutput<Pose>(
"AnimInput",
nullptr);
@ -267,7 +267,7 @@ class EmbeddedTreeBlend2GraphResource : public BlendTreeResourceFixture {
embedded_blend_tree_resource->m_name = "EmbeddedTreeBlend2GraphResource";
// Embedded: inputs
embedded_blend_tree_resource->RegisterBlendTreeInputSocket<AnimData>(
embedded_blend_tree_resource->RegisterBlendTreeInputSocket<Pose>(
"AnimInput");
embedded_blend_tree_resource->RegisterBlendTreeInputSocket<float>(
"BlendWeight");
@ -482,7 +482,7 @@ TEST_CASE_METHOD(
REQUIRE(anim_sampler_walk->m_animation != nullptr);
// Ensure that outputs are properly propagated.
AnimData output;
Pose output;
output.m_local_matrices.resize(skeleton.num_soa_joints());
anim_graph_blend_tree.SetOutput(
AnimGraphResource::DefaultAnimOutput,
@ -764,9 +764,8 @@ TEST_CASE_METHOD(
CHECK(blend2_instance->i_input0 == anim_sampler_walk->o_output);
CHECK(blend2_instance->i_input1 == anim_sampler_run->o_output);
AnimData* graph_output =
static_cast<AnimData*>(blend_tree_graph.GetOutputPtr<AnimData>(
AnimGraphResource::DefaultAnimOutput));
Pose* graph_output = blend_tree_graph.GetOutputPtr<Pose>(
AnimGraphResource::DefaultAnimOutput);
CHECK(
graph_output->m_local_matrices.size()

View File

@ -8,26 +8,34 @@
TEST_CASE("Descriptor Access", "[NodeDescriptorTests]") {
Blend2Node blend2Node;
NodeDescriptor<Blend2Node> blend2Descriptor (&blend2Node);
NodeDescriptor<Blend2Node> blend2Descriptor(&blend2Node);
CHECK(blend2Descriptor.m_inputs.size() == 3);
CHECK(*blend2Descriptor.m_inputs[0].m_reference.ptr_ptr == blend2Node.i_input0);
CHECK(*blend2Descriptor.m_inputs[1].m_reference.ptr_ptr == blend2Node.i_input1);
CHECK(*blend2Descriptor.m_inputs[2].m_reference.ptr_ptr == blend2Node.i_blend_weight);
CHECK(
*blend2Descriptor.m_inputs[0].m_reference.ptr_ptr == blend2Node.i_input0);
CHECK(
*blend2Descriptor.m_inputs[1].m_reference.ptr_ptr == blend2Node.i_input1);
CHECK(
*blend2Descriptor.m_inputs[2].m_reference.ptr_ptr
== blend2Node.i_blend_weight);
CHECK(blend2Descriptor.m_inputs[0].m_type_size == sizeof(AnimData));
CHECK(blend2Descriptor.m_inputs[0].m_type_size == sizeof(Pose));
CHECK(blend2Descriptor.m_inputs[2].m_type_size == 4);
CHECK(blend2Descriptor.m_outputs.size() == 1);
CHECK(*blend2Descriptor.m_outputs[0].m_reference.ptr_ptr == blend2Node.o_output);
CHECK(
*blend2Descriptor.m_outputs[0].m_reference.ptr_ptr
== blend2Node.o_output);
CHECK(blend2Descriptor.m_properties.size() == 1);
CHECK(blend2Descriptor.m_properties[0].m_reference.ptr == &blend2Node.m_sync_blend);
CHECK(
blend2Descriptor.m_properties[0].m_reference.ptr
== &blend2Node.m_sync_blend);
// Check we can properly update inputs
CHECK(blend2Node.i_input0 == nullptr);
AnimData some_anim_data;
blend2Descriptor.SetInput("Input0", &some_anim_data);
CHECK(blend2Node.i_input0 == &some_anim_data);
Pose pose;
blend2Descriptor.SetInput("Input0", &pose);
CHECK(blend2Node.i_input0 == &pose);
// Check we properly can set properties
CHECK(blend2Node.m_sync_blend == false);
@ -41,6 +49,7 @@ TEST_CASE("Descriptor Access", "[NodeDescriptorTests]") {
blend2Descriptor.UpdateFlags();
Socket* weight_input_socket = blend2Descriptor.GetInputSocket("Weight");
CHECK(weight_input_socket != nullptr);
CHECK(weight_input_socket->m_flags & SocketFlagAffectsTime == SocketFlagAffectsTime);
CHECK(
weight_input_socket->m_flags
& SocketFlagAffectsTime == SocketFlagAffectsTime);
}