Added test which creates skeleton and animation during runtime.

AnimGraphEditor
Martin Felis 2022-04-13 11:14:29 +02:00
parent eeef635c64
commit b518220576
5 changed files with 131 additions and 0 deletions

View File

@ -92,15 +92,25 @@ target_link_libraries(AnimTestbed AnimTestbedCode glfw ozz_base ozz_geometry ozz
# Tests # Tests
add_executable(runtests) add_executable(runtests)
set(ozz_offline_test_objs
3rdparty/ozz-animation/src/animation/offline/skeleton_builder.cc
3rdparty/ozz-animation/src/animation/offline/raw_skeleton.cc
3rdparty/ozz-animation/src/animation/offline/animation_builder.cc
3rdparty/ozz-animation/src/animation/offline/raw_animation.cc
)
target_sources(runtests PRIVATE target_sources(runtests PRIVATE
tests/AnimGraphResourceTests.cc tests/AnimGraphResourceTests.cc
tests/AnimGraphEvalTests.cc
tests/SyncTrackTests.cc tests/SyncTrackTests.cc
tests/main.cc tests/main.cc
${ozz_offline_test_objs}
) )
target_include_directories( target_include_directories(
runtests runtests
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/ozz-animation/src>
${ThirdPartyIncludeDeps} ${ThirdPartyIncludeDeps}
) )

121
tests/AnimGraphEvalTests.cc Normal file
View File

@ -0,0 +1,121 @@
//
// Created by martin on 04.02.22.
//
#include "AnimGraph/AnimGraph.h"
#include "AnimGraph/AnimGraphEditor.h"
#include "AnimGraph/AnimGraphResource.h"
#include "catch.hpp"
#include "ozz/animation/offline/animation_builder.h"
#include "ozz/animation/offline/raw_animation.h"
#include "ozz/animation/offline/raw_skeleton.h"
#include "ozz/animation/offline/skeleton_builder.h"
#include "ozz/animation/runtime/animation.h"
#include "ozz/base/io/archive.h"
#include "ozz/base/io/stream.h"
#include "ozz/base/log.h"
struct SimpleAnimFixture {
ozz::unique_ptr<ozz::animation::Skeleton> skeleton = nullptr;
ozz::animation::offline::RawAnimation raw_animation_translation_x;
ozz::unique_ptr<ozz::animation::Animation> animation_translate_x = nullptr;
ozz::animation::offline::RawAnimation raw_animation_translation_y;
ozz::unique_ptr<ozz::animation::Animation> animation_translate_y = nullptr;
ozz::vector<ozz::math::SoaTransform> animation_output;
ozz::animation::SamplingCache sampling_cache;
SimpleAnimFixture() {
createSkeleton();
createAnimations();
animation_output.resize(skeleton->num_soa_joints());
sampling_cache.Resize(skeleton->num_joints());
}
void createSkeleton() {
using namespace ozz::animation::offline;
RawSkeleton raw_skeleton;
RawSkeleton::Joint raw_joint;
raw_joint.name = "Bone0";
raw_joint.transform.translation.x = 1.f;
raw_joint.transform.translation.y = 2.f;
raw_joint.transform.translation.z = 3.f;
raw_skeleton.roots.push_back(raw_joint);
SkeletonBuilder skeleton_builder;
skeleton = skeleton_builder(raw_skeleton);
}
void createAnimations() {
using namespace ozz::animation::offline;
raw_animation_translation_x.name = "TranslationX";
RawAnimation::JointTrack bone0_track;
RawAnimation::JointTrack::Translations bone0_translations;
// animation_translate_x
RawAnimation::TranslationKey translation_key;
translation_key.time = 0.f;
translation_key.value = ozz::math::Float3(0.f, 0.f, 0.f);
bone0_translations.push_back(translation_key);
translation_key.time = 1.f;
translation_key.value = ozz::math::Float3(1.f, 6.f, 9.f);
bone0_translations.push_back(translation_key);
bone0_track.translations = bone0_translations;
raw_animation_translation_x.tracks.push_back(bone0_track);
raw_animation_translation_x.duration = 1.f;
REQUIRE(raw_animation_translation_x.Validate());
AnimationBuilder animation_builder;
animation_translate_x = animation_builder(raw_animation_translation_x);
// animation_translate_y
raw_animation_translation_y.name = "TranslationY";
bone0_translations.clear();
translation_key.time = 0.f;
translation_key.value = ozz::math::Float3(0.f, 0.f, 0.f);
bone0_translations.push_back(translation_key);
translation_key.time = 1.f;
translation_key.value = ozz::math::Float3(0.f, 1.f, 0.f);
bone0_translations.push_back(translation_key);
bone0_track.translations = bone0_translations;
raw_animation_translation_y.tracks.push_back(bone0_track);
raw_animation_translation_y.duration = 1.f;
REQUIRE(raw_animation_translation_y.Validate());
animation_translate_y = animation_builder(raw_animation_translation_y);
}
};
TEST_CASE_METHOD(
SimpleAnimFixture,
"Create Animations",
"[AnimGraphEvalTests]") {
using namespace ozz::animation::offline;
ozz::animation::SamplingJob sampling_job;
sampling_job.animation = animation_translate_x.get();
sampling_job.cache = &sampling_cache;
sampling_job.ratio = 1.f;
sampling_job.output = make_span(animation_output);
REQUIRE(sampling_job.Run());
RawAnimation::TranslationKey& translation_key =
raw_animation_translation_x.tracks[0].translations.back();
ozz::math::SoaFloat3& sampled_translation = animation_output[0].translation;
CHECK(
sampled_translation.x[0] == Approx(translation_key.value.x).margin(0.01));
CHECK(
sampled_translation.y[0] == Approx(translation_key.value.y).margin(0.01));
CHECK(
sampled_translation.z[0] == Approx(translation_key.value.z).margin(0.01));
}

BIN
tests/data/run.anim.ozz Normal file

Binary file not shown.

BIN
tests/data/skeleton.ozz Normal file

Binary file not shown.

BIN
tests/data/walk.anim.ozz Normal file

Binary file not shown.