Radium Engine  1.5.0
SkinningComponent.hpp
1 #pragma once
2 
3 #include <Core/Animation/HandleWeight.hpp>
4 #include <Core/Animation/Pose.hpp>
5 #include <Core/Animation/SkinningData.hpp>
6 #include <Core/Asset/HandleData.hpp>
7 #include <Core/Geometry/TopologicalMesh.hpp>
8 #include <Core/Geometry/TriangleMesh.hpp>
9 #include <Core/Math/DualQuaternion.hpp>
10 #include <Core/Utils/Index.hpp>
11 
12 #include <Engine/Data/Material.hpp>
13 #include <Engine/Scene/Component.hpp>
14 #include <Engine/Scene/ComponentMessenger.hpp>
15 
16 namespace Ra {
17 namespace Engine {
18 namespace Scene {
19 
34 class RA_ENGINE_API SkinningComponent : public Component
35 {
36  public:
38  enum SkinningType {
39  LBS = 0,
40  DQS,
41  COR,
42  };
43 
46  APPROX = 0,
47  GEOMETRIC
48  };
49 
51  enum WeightType {
52  STANDARD = 0
53  };
54 
55  SkinningComponent( const std::string& name, SkinningType type, Entity* entity ) :
56  Component( name, entity ),
57  m_skinningType( type ),
58  m_normalSkinning( APPROX ),
59  m_isReady( false ),
60  m_forceUpdate( false ),
61  m_weightBone( 0 ),
62  m_weightType( STANDARD ),
63  m_showingWeights( false ) {}
64 
65  ~SkinningComponent() override {}
66 
69 
70  virtual void initialize() override;
72 
75 
78  void handleSkinDataLoading( const Core::Asset::HandleData* data, const std::string& meshName );
80 
83 
85  void skin();
86 
88  void endSkinning();
89 
91  void setSkinningType( SkinningType type );
92 
94  inline SkinningType getSkinningType() const { return m_skinningType; }
95 
97  void setNormalSkinning( NormalSkinning normalSkinning );
98 
100  inline NormalSkinning getNormalSkinning() const { return m_normalSkinning; }
102 
105 
107  const std::string& getMeshName() const;
108 
111  void setMeshName( const std::string& name ) { m_meshName = name; }
112 
114  const std::string& getSkeletonName() const;
115 
117  const Core::Animation::SkinningRefData* getSkinningRefData() const { return &m_refData; }
118 
120  const Core::Animation::SkinningFrameData* getSkinningFrameData() const { return &m_frameData; }
122 
125 
127  void showWeights( bool on );
128 
130  bool isShowingWeights();
131 
133  void showWeightsType( WeightType type );
134 
136  WeightType getWeightsType();
137 
139  void setWeightBone( uint bone );
141 
144  void setPerBoneWeight( std::map<std::string, std::vector<std::pair<uint, Scalar>>>&& w ) {
145  m_loadedWeights = w;
146  }
147 
152  void setPerBoneMatrix( std::map<std::string, Core::Transform>&& m ) {
153  m_loadedBindMatrices = m;
154  }
155 
156  private:
158  void setupIO( const std::string& id );
159 
161  void createWeightMatrix();
162 
163  private:
164  template <typename T>
165  using Getter = typename ComponentMessenger::CallbackTypes<T>::Getter;
166 
167  template <typename T>
168  using ReadWrite = typename ComponentMessenger::CallbackTypes<T>::ReadWrite;
169 
171  std::string m_meshName;
172 
174  std::string m_skelName;
175 
178 
181 
183  Getter<Core::Animation::Skeleton> m_skeletonGetter;
184 
186  SkinningType m_skinningType;
187 
189  NormalSkinning m_normalSkinning;
190 
192  bool m_isReady;
193 
195  bool m_forceUpdate;
196 
198  Getter<Core::Utils::Index> m_renderObjectReader;
199 
201  bool m_meshIsPoly { false };
202 
204  bool m_meshIsQuad { false };
205 
207  ReadWrite<Core::Geometry::TriangleMesh> m_triMeshWriter;
208 
210  ReadWrite<Core::Geometry::PolyMesh> m_polyMeshWriter;
211 
213  ReadWrite<Core::Geometry::QuadMesh> m_quadMeshWriter;
214 
217 
221  std::map<std::string, std::vector<std::pair<uint, Scalar>>> m_loadedWeights;
222 
226  std::map<std::string, Core::Transform> m_loadedBindMatrices;
227 
229  std::shared_ptr<Data::Material> m_baseMaterial;
230 
232  std::shared_ptr<Data::Material> m_weightMaterial;
233 
235  Core::Vector3Array m_baseUV;
236 
238  Core::Vector3Array m_weightsUV;
239 
241  uint m_weightBone;
242 
244  WeightType m_weightType;
245 
247  bool m_showingWeights;
248 };
249 
250 } // namespace Scene
251 } // namespace Engine
252 } // 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
The SkinningComponent class is responsible for applying Geometric Skinning Methods on an animated obj...
void setPerBoneMatrix(std::map< std::string, Core::Transform > &&m)
SkinningType
The Geometric Skinning Method.
@ COR
Center of Rotation skinning.
void setMeshName(const std::string &name)
SkinningType getSkinningType() const
Returns the current skinning method.
const Core::Animation::SkinningRefData * getSkinningRefData() const
Returns the reference skinning data.
NormalSkinning getNormalSkinning() const
Returns the current method used to skin the normal, tangent and binormal vectors.
const Core::Animation::SkinningFrameData * getSkinningFrameData() const
Returns the current Pose data.
void setPerBoneWeight(std::map< std::string, std::vector< std::pair< uint, Scalar >>> &&w)
NormalSkinning
How to skin the normal, tangent and binormal vectors.
Definition: Cage.cpp:3
Skinning data that get set at startup including the "reference state".
std::function< T *(void)> ReadWrite
Function pointer for a read/write getter.
std::function< const T *(void)> Getter
Function pointer for a getter function.