Radium Engine  1.5.0
SkeletonComponent.hpp
1 #pragma once
2 
3 #include <Core/Animation/HandleWeight.hpp>
4 #include <Core/Animation/KeyFramedValue.hpp>
5 #include <Core/Animation/Skeleton.hpp>
6 #include <Core/Asset/AnimationData.hpp>
7 #include <Core/Asset/HandleData.hpp>
8 
9 #include <Engine/Scene/Component.hpp>
10 
11 namespace Ra {
12 namespace Engine {
13 namespace Data {
14 class BlinnPhongMaterial;
15 class Mesh;
16 } // namespace Data
17 namespace Rendering {
18 class RenderObject;
19 class RenderTechnique;
20 } // namespace Rendering
21 
22 namespace Scene {
23 
24 class SkeletonBasedAnimationSystem;
25 
41 class RA_ENGINE_API SkeletonComponent : public Component
42 {
43  public:
44  friend class SkeletonBasedAnimationSystem;
45 
47  using Animation = std::vector<Core::Animation::KeyFramedValue<Core::Transform>>;
48 
49  SkeletonComponent( const std::string& name, Entity* entity );
50  ~SkeletonComponent() override;
51  SkeletonComponent( const SkeletonComponent& ) = delete;
52  SkeletonComponent& operator=( const SkeletonComponent& ) = delete;
53 
56 
57  void initialize() override { setupIO(); }
58 
59  bool canEdit( const Core::Utils::Index& roIdx ) const override;
60 
61  Core::Transform getTransform( const Core::Utils::Index& roIdx ) const override;
62  Core::Transform getBoneTransform( uint boneIdx,
64 
65  void setTransform( const Core::Utils::Index& roIdx, const Core::Transform& transform ) override;
66  void setBoneTransform( uint boneIdx,
67  const Core::Transform& transform,
70 
73 
75  void handleSkeletonLoading( const Core::Asset::HandleData* data );
76 
78  void handleAnimationLoading( const std::vector<Core::Asset::AnimationData*>& data );
80 
83 
85  inline const std::string& getSkelName() const { return m_skelName; }
86 
88  void setSkeleton( const Core::Animation::Skeleton& skel );
89 
91  inline const Core::Animation::Skeleton* getSkeleton() { return &m_skel; }
92 
94  inline size_t getAnimationCount() const { return m_animations.size(); }
95 
97  inline const Animation& getAnimation( const size_t i ) const { return m_animations[i]; }
98 
100  inline Animation& getAnimation( const size_t i ) { return m_animations[i]; }
101 
103  Animation& addNewAnimation();
104 
106  void removeAnimation( const size_t i );
107 
109  void useAnimation( const size_t i );
110 
112  size_t getAnimationId() const;
114 
117 
119  void update( Scalar time );
120 
122  Scalar getAnimationTime() const;
123 
125  std::pair<Scalar, Scalar> getAnimationTimeInterval() const;
126 
128  void setSpeed( const Scalar value );
129 
131  Scalar getSpeed() const;
132 
134  void autoRepeat( const bool status );
135 
137  bool isAutoRepeat() const;
138 
140  void pingPong( const bool status );
141 
143  bool isPingPong() const;
145 
148 
151  void setXray( bool on ) const;
152 
154  bool isXray() const;
155 
157  void toggleSkeleton( const bool status );
158 
160  bool isShowingSkeleton() const;
161 
163  const std::map<Core::Utils::Index, uint>* getBoneRO2idx() const;
164 
166  void updateDisplay();
167 
169  void setManipulationScheme( const Core::Animation::Skeleton::Manipulation& scheme );
170 
172  Core::Animation::Skeleton::Manipulation getManipulationScheme();
174 
175  private:
177  void setupSkeletonDisplay();
178 
180  void printSkeleton( const Core::Animation::Skeleton& skeleton );
181 
184 
186  void setupIO();
187 
189  const Core::Animation::RefPose* getRefPoseOutput() const;
190 
192  const Animation* getAnimationOutput() const;
193 
195  const Scalar* getTimeOutput() const;
196 
198  const bool* getWasReset() const;
200 
201  private:
203  std::string m_skelName;
204 
207 
209  Core::Animation::RefPose m_refPose;
210 
212  std::vector<Animation> m_animations;
213 
215  size_t m_animationID { 0 };
216 
218  Scalar m_animationTime { 0_ra };
219 
221  Scalar m_speed { 1_ra };
222 
224  bool m_autoRepeat { false };
225 
227  bool m_pingPong { false };
228 
230  bool m_wasReset { false };
231 
233  std::vector<Rendering::RenderObject*> m_boneDrawables;
234 
236  std::map<Core::Utils::Index, uint> m_boneMap;
237 
239  static std::shared_ptr<Data::Mesh> s_boneMesh;
240 
242  static std::shared_ptr<Data::BlinnPhongMaterial> s_boneMaterial;
243 
245  static std::shared_ptr<Rendering::RenderTechnique> s_boneRenderTechnique;
246 };
247 
248 } // namespace Scene
249 } // namespace Engine
250 } // namespace Ra
A component is an element that can be updated by a system. It is also linked to some other components...
Definition: Component.hpp:31
An entity is an scene element. It ties together components with a transform.
Definition: Entity.hpp:23
size_t getAnimationCount() const
Return the number of animations.
Animation & getAnimation(const size_t i)
Return the i -th animation.
void initialize() override
Pure virtual method to be overridden by any component. When this method is called you are guaranteed ...
const std::string & getSkelName() const
Returns the name of the skeleton.
std::vector< Core::Animation::KeyFramedValue< Core::Transform > > Animation
Animations are lists of keyframed transforms (one per bone).
const Animation & getAnimation(const size_t i) const
Return the i -th animation.
const Core::Animation::Skeleton * getSkeleton()
Returns the animation skeleton.
Definition: Cage.cpp:3