Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
AnimationComponent.cpp
Go to the documentation of this file.
1
2
4
8
11
12namespace Divide {
13
15
18{
19 EditorComponentField vskelField = {};
20 vskelField._name = "Show Skeleton";
21 vskelField._data = &_showSkeleton;
24 vskelField._readOnly = false;
25 _editorComponent.registerField(MOV(vskelField));
26
27 EditorComponentField playAnimationsField = {};
28 playAnimationsField._name = "Play Animations";
29 playAnimationsField._data = &_playAnimations;
30 playAnimationsField._type = EditorComponentFieldType::SWITCH_TYPE;
31 playAnimationsField._basicType = PushConstantType::BOOL;
32 playAnimationsField._readOnly = false;
33 _editorComponent.registerField(MOV(playAnimationsField));
34
35 EditorComponentField animationSpeedField = {};
36 animationSpeedField._name = "Animation Speed";
37 animationSpeedField._data = &_animationSpeed;
38 animationSpeedField._type = EditorComponentFieldType::PUSH_TYPE;
39 animationSpeedField._basicType = PushConstantType::FLOAT;
40 animationSpeedField._range = { 0.01f, 100.0f };
41 animationSpeedField._readOnly = false;
42 _editorComponent.registerField(MOV(animationSpeedField));
43
44 EditorComponentField animationFrameIndexInfoField = {};
45 animationFrameIndexInfoField._name = "Animation Frame Index";
46 animationFrameIndexInfoField._tooltip = " [Curr - Prev - Next]";
47 animationFrameIndexInfoField._dataGetter = [this](void* dataOut) noexcept { *static_cast<vec3<I32>*>(dataOut) = vec3<I32>{ _frameIndex._curr, _frameIndex._prev, _frameIndex._next }; };
48 animationFrameIndexInfoField._type = EditorComponentFieldType::PUSH_TYPE;
49 animationFrameIndexInfoField._basicType = PushConstantType::IVEC3;
50 animationFrameIndexInfoField._readOnly = true;
51 _editorComponent.registerField(MOV(animationFrameIndexInfoField));
52
53
54 _editorComponent.onChangedCbk([this]([[maybe_unused]] std::string_view field) {
55 if (_parentSGN->HasComponents(ComponentType::RENDERING)) {
56 _parentSGN->get<RenderingComponent>()->toggleRenderOption(RenderingComponent::RenderOptions::RENDER_SKELETON, showSkeleton());
57 }
58 });
59}
60
62 _currentTimeStamp = -1.0;
63 _parentTimeStamp = 0.0;
64 _frameIndex = {};
65}
66
68bool AnimationComponent::playAnimation(const string& name) {
69 if (!_animator) {
70 return false;
71 }
72
73 return playAnimation(_animator->animationID(name));
74}
75
78{
79 if (!_animator)
80 {
81 return false;
82 }
83
84 if (pAnimIndex >= _animator->animations().size() && pAnimIndex != U32_MAX)
85 {
86 return false; // no change, or the animations data is out of bounds
87 }
88
89 const U32 oldIndex = animationIndex();
90 _animationIndex = pAnimIndex; // only set this after the checks for good data and the object was actually inserted
91
92 if ( _animationIndex == U32_MAX)
93 {
94 _animationIndex = 0;
95 }
96
98
99 if (oldIndex != _animationIndex )
100 {
101 _parentSGN->getNode<Object3D>().onAnimationChange(_parentSGN, _animationIndex );
102 return true;
103 }
104
105 return false;
106}
107
110{
111 if (!_animator)
112 {
113 return false;
114 }
115
116 const U32 oldIndex = animationIndex();
117 if ( _animationIndex == U32_MAX)
118 {
119 _animationIndex = 0u;
120 }
121
122 _animationIndex = (_animationIndex + 1u) % _animator->animations().size();
123
124 resetTimers();
125
126 return oldIndex != _animationIndex;
127}
128
130{
131 if (!_animator)
132 {
133 return false;
134 }
135
136 const U32 oldIndex = _animationIndex;
137 if ( _animationIndex == 0 || _animationIndex == U32_MAX)
138 {
139 _animationIndex = to_I32(_animator->animations().size());
140 }
141
142 --_animationIndex;
143
144 resetTimers();
145
146 return oldIndex != _animationIndex;
147}
148
150{
151 assert(_animator != nullptr);
152
153 const D64 animTimeStamp = Time::MillisecondsToSeconds<D64>(std::max(_currentTimeStamp, 0.0));
154 // update possible animation
155 return _animator->skeletonLines( _animationIndex, animTimeStamp);
156}
157
159{
160 const AnimEvaluator& anim = getAnimationByIndex( std::min( _previousAnimationIndex, to_U32(_animator->animations().size()) ) );
161 return anim.boneBuffer();
162}
163
164I32 AnimationComponent::frameCount(const U32 animationID) const
165{
166 assert(_animator != nullptr);
167
168 return _animator->frameCount(animationID);
169}
170
172{
173 assert(_animator != nullptr);
174
175 return _animator->boneCount();
176}
177
179{
181}
182
184{
185 assert(_animator != nullptr && animationID != U32_MAX);
186
187 return _animator->animationByIndex(animationID);
188}
189
190} //namespace Divide
#define MOV(...)
ShaderBuffer * boneBuffer() const
AnimEvaluator & getAnimationByIndex(U32 animationID) const
const vector< Line > & skeletonLines() const
AnimationComponent(SceneGraphNode *parentSGN, PlatformContext &context)
ShaderBuffer * getBoneBuffer() const
bool playPreviousAnimation() noexcept
Select previous available animation.
AnimEvaluator::FrameIndex _frameIndex
bool playAnimation(const string &name)
Select an animation by name.
bool playNextAnimation() noexcept
Select next available animation.
D64 _currentTimeStamp
Current animation timestamp for the current SGN.
bool frameTicked() const noexcept
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
constexpr U32 to_U32(const T value)
int32_t I32
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
SGNComponent::Registrar< T, C > BaseComponentType
Definition: SGNComponent.h:207
constexpr U32 U32_MAX
double D64
constexpr I32 to_I32(const T value)
uint32_t U32
DELEGATE_STD< void, void * > _dataGetter
vec2< F32 > _range
Used by slider_type as a min / max range or dropdown as selected_index / count.
EditorComponentFieldType _type