118 lines
3.7 KiB
C++
118 lines
3.7 KiB
C++
![]() |
//
|
||
|
// Created by martin on 11.04.25.
|
||
|
//
|
||
|
|
||
|
#include "TestAnimData.h"
|
||
|
|
||
|
#include <iostream>
|
||
|
|
||
|
#include "ozz/animation/offline/animation_builder.h"
|
||
|
#include "ozz/animation/offline/raw_animation.h"
|
||
|
#include "ozz/animation/offline/raw_skeleton.h"
|
||
|
#include "ozz/base/io/archive.h"
|
||
|
#include "ozz/base/log.h"
|
||
|
|
||
|
namespace TestAnimData {
|
||
|
|
||
|
SingleBoneSkeleton::SingleBoneSkeleton() {
|
||
|
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);
|
||
|
|
||
|
// SingleBoneSkeleton Animations
|
||
|
ozz::animation::offline::RawAnimation raw_animation_translation_x;
|
||
|
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, 0.f, 0.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;
|
||
|
if (!raw_animation_translation_x.Validate()) {
|
||
|
std::cerr << "Error: could animation raw data invalid!" << std::endl;
|
||
|
}
|
||
|
|
||
|
AnimationBuilder animation_builder;
|
||
|
animation_translate_x = animation_builder(raw_animation_translation_x);
|
||
|
|
||
|
animation_translate_x_resource.m_animation = animation_translate_x.get();
|
||
|
SaveAnimation("single_bone_translation_z.ozz", animation_translate_x.get());
|
||
|
animation_translate_x_resource.m_name = "single_bone_translation_z";
|
||
|
animation_translate_x_resource.m_filename = "single_bone_translation_z.ozz";
|
||
|
|
||
|
// animation_translate_y
|
||
|
ozz::animation::offline::RawAnimation raw_animation_translation_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;
|
||
|
if (!raw_animation_translation_y.Validate()) {
|
||
|
std::cerr << "Error: could animation raw data invalid!" << std::endl;
|
||
|
}
|
||
|
|
||
|
animation_translate_y = animation_builder(raw_animation_translation_y);
|
||
|
|
||
|
animation_translate_y_resource.m_animation = animation_translate_y.get();
|
||
|
SaveAnimation("single_bone_translation_y.ozz", animation_translate_y.get());
|
||
|
animation_translate_y_resource.m_name = "single_bone_translation_y";
|
||
|
animation_translate_y_resource.m_filename = "single_bone_translation_y.ozz";
|
||
|
}
|
||
|
|
||
|
bool SingleBoneSkeleton::SaveSkeleton(
|
||
|
const char* filename,
|
||
|
ozz::animation::Skeleton* skeleton) {
|
||
|
assert(false);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool SingleBoneSkeleton::SaveAnimation(
|
||
|
const char* filename,
|
||
|
ozz::animation::Animation* animation) {
|
||
|
ozz::io::File file(filename, "wb");
|
||
|
if (!file.opened()) {
|
||
|
ozz::log::Err() << "Failed to create animation file " << filename << "."
|
||
|
<< std::endl;
|
||
|
delete animation;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
ozz::io::OArchive archive(&file);
|
||
|
|
||
|
archive << *animation;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
} // namespace TestAnimData
|