Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
AnimationEvaluator.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32/*Code references:
33 http://nolimitsdesigns.com/game-design/open-asset-import-library-animation-loader/
34*/
35
36#pragma once
37#ifndef ANIMATION_EVALUATOR_H_
38#define ANIMATION_EVALUATOR_H_
39
40#include "Bone.h"
41#include <assimp/anim.h>
43
44namespace Divide {
45
46class ByteBuffer;
47
52 U64 _nameKey = 0ULL;
53 string _name = "";
58};
59
61{
63
64 void matrices(const Container& matricesIn) { _matrices = matricesIn; }
65 const Container& matrices() const noexcept { return _matrices; }
66 [[nodiscard]] size_t count() const noexcept { return _matrices.size(); }
67
68private:
70};
71
72class GFXDevice;
74 public:
75 struct FrameIndex {
79 };
80
81 public:
82 AnimEvaluator() = default;
83
84 explicit AnimEvaluator(const aiAnimation* pAnim, U32 idx) noexcept;
85
86 void evaluate(D64 dt, Bone* skeleton);
87
88 [[nodiscard]] FrameIndex frameIndexAt(D64 elapsedTimeS) const noexcept;
89
90 [[nodiscard]] U32 frameCount() const noexcept { return to_U32(_transforms.size()); }
91
92 [[nodiscard]] vector<BoneTransform>& transforms() noexcept { return _transforms; }
93
94 [[nodiscard]] const vector<BoneTransform>& transforms() const noexcept { return _transforms; }
95
96 [[nodiscard]] BoneTransform& transforms(const U32 frameIndex) {
97 assert(frameIndex < to_U32(_transforms.size()));
98 return _transforms[frameIndex];
99 }
100
101 [[nodiscard]] const BoneTransform& transforms(const U32 frameIndex) const {
102 assert(frameIndex < to_U32(_transforms.size()));
103 return _transforms[frameIndex];
104 }
105
106 [[nodiscard]] BoneTransform& transforms(const D64 elapsedTime, I32& resultingFrameIndex) {
107 resultingFrameIndex = frameIndexAt(elapsedTime)._curr;
108 return transforms(to_U32(resultingFrameIndex));
109 }
110
111 [[nodiscard]] BoneTransform& transforms(const D64 elapsedTime) {
112 I32 resultingFrameIndex = 0;
113 return transforms(elapsedTime, resultingFrameIndex);
114 }
115
116 [[nodiscard]] const BoneTransform& transforms(const D64 elapsedTime, I32& resultingFrameIndex) const {
117 resultingFrameIndex = frameIndexAt(elapsedTime)._curr;
118 return transforms(to_U32(resultingFrameIndex));
119 }
120
121 [[nodiscard]] const BoneTransform& transforms(const D64 elapsedTime) const {
122 I32 resultingFrameIndex = 0;
123 return transforms(elapsedTime, resultingFrameIndex);
124 }
125
126 bool initBuffers(GFXDevice& context);
127
128 static void save(const AnimEvaluator& evaluator, ByteBuffer& dataOut);
129 static void load(AnimEvaluator& evaluator, ByteBuffer& dataIn);
130
131 PROPERTY_RW(D64, ticksPerSecond, 0.0);
132 PROPERTY_RW(bool, playAnimationForward, true);
133 PROPERTY_R_IW(D64, duration, 0.0);
134 PROPERTY_R_IW(string, name, "");
135
136 [[nodiscard]] inline ShaderBuffer* boneBuffer() const { return _boneBuffer.get(); }
137
138 protected:
145 ShaderBuffer_uptr _boneBuffer = nullptr;
147};
148
149}; // namespace Divide
150
151#endif
vector< BoneTransform > & transforms() noexcept
bool initBuffers(GFXDevice &context)
FrameIndex frameIndexAt(D64 elapsedTimeS) const noexcept
ShaderBuffer_uptr _boneBuffer
GPU buffer to hold bone transforms.
BoneTransform & transforms(const U32 frameIndex)
const BoneTransform & transforms(const U32 frameIndex) const
PROPERTY_RW(D64, ticksPerSecond, 0.0)
static void save(const AnimEvaluator &evaluator, ByteBuffer &dataOut)
U32 frameCount() const noexcept
const vector< BoneTransform > & transforms() const noexcept
vector< AnimationChannel > _channels
vector that holds all bone channels
PROPERTY_RW(bool, playAnimationForward, true)
void evaluate(D64 dt, Bone *skeleton)
PROPERTY_R_IW(D64, duration, 0.0)
vector< BoneTransform > _transforms
Array to return transformations results inside.
PROPERTY_R_IW(string, name, "")
const BoneTransform & transforms(const D64 elapsedTime, I32 &resultingFrameIndex) const
BoneTransform & transforms(const D64 elapsedTime, I32 &resultingFrameIndex)
vector< vec3< U32 > > _lastPositions
BoneTransform & transforms(const D64 elapsedTime)
const BoneTransform & transforms(const D64 elapsedTime) const
ShaderBuffer * boneBuffer() const
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
bool load() override
constexpr U32 to_U32(const T value)
int32_t I32
eastl::vector< Type > vector
Definition: Vector.h:42
double D64
uint32_t U32
uint64_t U64
vector< aiVectorKey > _positionKeys
vector< aiQuatKey > _rotationKeys
vector< aiVectorKey > _scalingKeys
size_t count() const noexcept
void matrices(const Container &matricesIn)
vector< mat4< F32 > > Container
const Container & matrices() const noexcept