23#include "aeongames/AeonEngine.hpp"
24#include "aeongames/ProtoBufHelpers.hpp"
25#include "aeongames/ProtoBufUtils.hpp"
26#include "aeongames/Utilities.hpp"
27#include "aeongames/Animation.hpp"
30#pragma warning( push )
31#pragma warning( disable : PROTOBUF_WARNINGS )
33#include "animation.pb.h"
40 Animation::Animation()
49 mVersion = aAnimationMsg.version();
50 mFrameRate = aAnimationMsg.framerate();
51 mDuration = aAnimationMsg.duration();
52 mFrames.reserve ( aAnimationMsg.frame_size() );
53 for (
auto& frame : aAnimationMsg.frame() )
55 mFrames.emplace_back();
56 mFrames.back().reserve ( frame.bone_size() );
57 for (
auto& joint : frame.bone() )
59 mFrames.back().emplace_back (
77 joint.translation().x(),
78 joint.translation().y(),
79 joint.translation().z()
94 Animation::~Animation() =
default;
113 return fmod ( mFrameRate * fmod ( aTime, mDuration ), mFrames.size() );
118 return fmod ( aSample + ( mFrameRate * fmod ( aTime, mDuration ) ), mFrames.size() );
124 double interpolation = modf ( aSample, &frame );
125 auto frame1 =
static_cast<size_t> ( frame );
126 size_t frame2 = ( ( frame1 + 1 ) % mFrames.size() );
127 size_t frame0 = frame1 == 0 ? mFrames.size() - 1 : ( ( frame1 - 1 ) % mFrames.size() );
128 size_t frame3 = ( ( frame1 + 2 ) % mFrames.size() );
130 assert ( ( interpolation >= 0.0 ) && ( interpolation < 1.0 ) &&
"Interpolation out of range [0.0,1.0)." );
131 return Interpolate ( mFrames[frame0][aBoneIndex], mFrames[frame1][aBoneIndex], mFrames[frame2][aBoneIndex], mFrames[frame3][aBoneIndex], interpolation );
Provides the DLL_PROTOBUF export/import macro for protobuf wrapper classes.
DLL double AddTimeToSample(double aSample, double aTime) const
Advance a sample position by a time delta.
DLL double GetDuration() const
Get the total duration of the animation.
DLL double GetSample(double aTime) const
Get a normalized sample position for a given time.
DLL void Unload() final
Unload animation data and free resources.
DLL void LoadFromMemory(const void *aBuffer, size_t aBufferSize) final
Load animation data from a memory buffer.
DLL void LoadFromPBMsg(const AnimationMsg &aAnimationMsg)
Load animation data from a protobuf message.
DLL const Transform GetTransform(size_t aBoneIndex, double aSample) const
Get the transform for a specific bone at a given sample.
DLL uint32_t GetFrameRate() const
Get the frame rate of the animation.
<- This is here just for the literals
DLL const Transform Interpolate(const Transform &aTransform0, const Transform &aTransform1, const Transform &aTransform2, const Transform &aTransform3, double aInterpolation)
Interpolate transforms using spline and mlerp methods.
void LoadFromProtoBufObject(T &aTarget, const void *aBuffer, size_t aBufferSize)
Loads a Protocol Buffer message from a buffer and populates a target object.