Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
AnimationComponent.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of
8this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the Software
14is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_ANIMATION_COMPONENT_H_
34#define DVD_ANIMATION_COMPONENT_H_
35
36#include "SGNComponent.h"
39
40namespace Divide {
41
42class ShaderBuffer;
43class AnimEvaluator;
44class SceneGraphNode;
45
48 public:
49 explicit AnimationComponent(SceneGraphNode* parentSGN, PlatformContext& context);
50
52 bool playAnimation(const string& name);
54 bool playAnimation(U32 pAnimIndex);
56 bool playNextAnimation() noexcept;
58 bool playPreviousAnimation() noexcept;
59
60 [[nodiscard]] I32 frameCount(U32 animationID) const;
61
62 [[nodiscard]] U8 boneCount() const;
63 [[nodiscard]] bool frameTicked() const noexcept;
64
65 [[nodiscard]] const vector<Line>& skeletonLines() const;
66 [[nodiscard]] ShaderBuffer* getBoneBuffer() const;
67
68 [[nodiscard]] AnimEvaluator& getAnimationByIndex(U32 animationID) const;
69
70 void resetTimers() noexcept;
71
72 [[nodiscard]] AnimEvaluator::FrameIndex frameIndex() const noexcept { return _frameIndex; }
73 [[nodiscard]] I32 frameCount() const { return frameCount( animationIndex() ); }
74
75 [[nodiscard]] AnimEvaluator& getCurrentAnimation() const { return getAnimationByIndex(animationIndex()); }
76
77 PROPERTY_R(bool, showSkeleton, false);
78 PROPERTY_RW(F32, animationSpeed, 1.f);
80 POINTER_RW(SceneAnimator, animator, nullptr);
82 PROPERTY_R(U32, animationIndex, U32_MAX);
83 PROPERTY_RW(U32, previousAnimationIndex, U32_MAX);
84
85 void playAnimations(const bool state) noexcept { _playAnimations = state;}
86 [[nodiscard]] bool playAnimations() const noexcept { return _playAnimations && s_globalAnimationState; }
87
88 protected:
89 static void GlobalAnimationState(const bool state) noexcept { s_globalAnimationState = state; }
90 [[nodiscard]] static bool GlobalAnimationState() noexcept { return s_globalAnimationState; }
91
92 protected:
93 AnimEvaluator::FrameIndex _frameIndex = {};
95 D64 _currentTimeStamp = -1.0;
99 D64 _parentTimeStamp = 0.0;
100
101 bool _playAnimations = true;
102
105
106} // namespace Divide
107
108#endif //DVD_ANIMATION_COMPONENT_H_
#define FWD_DECLARE_MANAGED_CLASS(T)
#define END_COMPONENT(Name)
Definition: SGNComponent.h:223
#define BEGIN_COMPONENT(Name, Enum)
Definition: SGNComponent.h:215
static void GlobalAnimationState(const bool state) noexcept
static bool GlobalAnimationState() noexcept
POINTER_RW(SceneAnimator, animator, nullptr)
Pointer to the mesh's animator. Owned by the mesh!
PROPERTY_R(bool, showSkeleton, false)
AnimEvaluator & getCurrentAnimation() const
PROPERTY_RW(U32, previousAnimationIndex, U32_MAX)
PROPERTY_R(U32, animationIndex, U32_MAX)
Current animation index for the current SGN.
bool playAnimations() const noexcept
PROPERTY_RW(F32, animationSpeed, 1.f)
void playAnimations(const bool state) noexcept
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
constexpr U32 U32_MAX
double D64
uint32_t U32