RavEngine
Loading...
Searching...
No Matches
AnimationAsset.hpp
1#pragma once
2#include "Ref.hpp"
3#include "Map.hpp"
4#include "SpinLock.hpp"
5#include <ozz/base/containers/vector.h>
6#include <ozz/animation/runtime/sampling_job.h>
7#include <ozz/base/memory/unique_ptr.h>
8#include "Function.hpp"
9#include "mathtypes.hpp"
10
11namespace ozz::animation {
12 struct Skeleton;
13 struct Animation;
14}
15
16namespace ozz::math {
17 struct SoaTransform;
18}
19
20namespace RavEngine{
21
22 class SkeletonAsset;
23
27struct IAnimGraphable{
35 virtual bool Sample(float t, float start,
36 float speed,
37 bool looping,
38 ozz::vector<ozz::math::SoaTransform>& output,
39 ozz::animation::SamplingJob::Context& cache,
40 const ozz::animation::Skeleton* skeleton) const = 0;
41
42
50 void SampleDirect(float t, const ozz::animation::Animation* anim, ozz::animation::SamplingJob::Context& cache, ozz::vector<ozz::math::SoaTransform>& locals) const;
51};
52
56class AnimationAsset : public IAnimGraphable{
57 //duration
58 //clip data
59 ozz::unique_ptr<ozz::animation::Animation> anim;
60public:
61 AnimationAsset(const std::string& name);
62
69 bool Sample(float t, float start, float speed, bool looping, ozz::vector<ozz::math::SoaTransform>&, ozz::animation::SamplingJob::Context& cache, const ozz::animation::Skeleton* skeleton) const override;
70
74 constexpr inline const decltype(anim)& GetAnim() const{
75 return anim;
76 }
77
78 float duration_seconds;
79 float tps;
80};
81
82class BoneTransforms{
84public:
85 BoneTransforms(decltype(transforms) t) : transforms(t){}
86
87
88 struct SingleTransform{
90 vector3 translation, scale;
91 };
92
93 SingleTransform GetBone(uint32_t index) const;
94 void SetBone(uint32_t index, const SingleTransform&);
95};
96
100class CustomSkeletonAnimation : public IAnimGraphable {
101 Function<bool(BoneTransforms, const ozz::animation::Skeleton*, float, float, float, bool)> mutateBonesHook;
102 bool Sample(float t, float start, float speed, bool looping, ozz::vector<ozz::math::SoaTransform>&, ozz::animation::SamplingJob::Context& cache, const ozz::animation::Skeleton* skeleton) const override;
103public:
108 CustomSkeletonAnimation(const decltype(mutateBonesHook)& hook) : mutateBonesHook(hook) {}
109};
110
111struct CustomSkeletonAnimationFunction {
112
122 virtual bool operator()(BoneTransforms transforms, const ozz::animation::Skeleton* skeleton, float t, float start, float end, bool loop) = 0;
123};
124
128class AnimationAssetSegment : public IAnimGraphable{
129public:
130 float start_ticks, end_ticks;
131 Ref<AnimationAsset> anim_asset;
132
138 AnimationAssetSegment(decltype(anim_asset) asset, float start, float end = 0) : anim_asset(asset), start_ticks(start), end_ticks(end){}
139
140 bool Sample(float global_time, float last_globalplaytime, float speed, bool looping, ozz::vector<ozz::math::SoaTransform>&, ozz::animation::SamplingJob::Context& cache, const ozz::animation::Skeleton* skeleton) const override;
141};
142
143class AnimationClip : public IAnimGraphable{
144 struct Sampler{
145 float influence;
146 ozz::vector<ozz::math::SoaTransform> locals;
147 };
148 locked_hashmap<Ref<IAnimGraphable>,Sampler, SpinLock> influence;
149public:
154 inline void SetAnimationInfluence(Ref<IAnimGraphable> asset, float inf = 1){
155 influence[asset].influence = inf;
156 }
157
162 inline void RemoveAnimation(Ref<IAnimGraphable> asset){
163 influence.erase(asset);
164 }
165
166 inline void Clear(){
167 influence.clear();
168 }
169
170 inline bool IsEmpty() const{
171 return influence.empty();
172 }
173
180 bool Sample(float t, float start, float speed, bool looping, ozz::vector<ozz::math::SoaTransform>&, ozz::animation::SamplingJob::Context& cache, const ozz::animation::Skeleton* skeleton) const override;
181
182};
183}
Definition animation.h:62
Definition skeleton.h:61
GLM_FUNC_DECL qua< T, Q > rotation(vec< 3, T, Q > const &orig, vec< 3, T, Q > const &dest)
Definition quaternion.inl:122
Definition Animation.hpp:6
Definition type_quat.hpp:20
Definition qualifier.hpp:35
Definition span.h:37