Skylicht Engine
Loading...
Searching...
No Matches
CSkeleton.h
1/*
2!@
3MIT License
4
5Copyright (c) 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "CAnimationTimeline.h"
28#include "CAnimationTransformData.h"
29#include "Entity/CEntityPrefab.h"
30#include "Animation/CAnimationClip.h"
31
32namespace Skylicht
33{
49 class SKYLICHT_API CSkeleton
50 {
51 public:
56 {
57 KeyFrame = 0,
59 };
60
65 {
66 DefaultBlending,
69 };
70
71 protected:
74
76 std::vector<CAnimationTransformData*> m_entitiesData;
77
80
83
85 int m_id;
86
89
92
95
98
101
104
105 protected:
106
108 CSkeleton* m_target;
109
111 std::vector<CSkeleton*> m_blending;
112
113 public:
114 CSkeleton(int id);
115
116 virtual ~CSkeleton();
117
123
128
132 void update();
133
138
147 int simulateTransform(float timeSecond, core::matrix4 origin, core::matrix4* transforms, int numTransform);
148
153 void getBoneIdMap(std::map<std::string, int>& bones);
154
159
164
171 void setAnimation(CAnimationClip* clip, bool loop, bool pause = false);
172
181 void setAnimation(CAnimationClip* clip, bool loop, float from, float duration, bool pause = false);
182
187 void setJointWeights(float weight);
188
195 void setJointWeights(const char* name, float weight, bool includeChild = true);
196
202 void getJoints(const char* name, std::vector<CAnimationTransformData*>& joints);
203
209 void setJointWeights(std::vector<CAnimationTransformData*>& joints, float weight);
210
217
222 inline std::vector<CAnimationTransformData*>& getJoints()
223 {
224 return m_entitiesData;
225 }
226
232 {
233 return m_clip;
234 }
235
240 inline int getID()
241 {
242 return m_id;
243 }
244
249 inline bool isEnable()
250 {
251 return m_enable;
252 }
253
258 inline void setEnable(bool b)
259 {
260 m_enable = b;
261 }
262
268 {
269 return m_timeline;
270 }
271
277 {
278 m_animationType = type;
279 }
280
286 {
287 return m_animationType;
288 }
289
295 {
296 m_layerType = type;
297 }
298
304 {
305 return m_layerType;
306 }
307
312 {
314 }
315
320 void setTarget(CSkeleton* skeleton);
321
326 inline CSkeleton* getTarget()
327 {
328 return m_target;
329 }
330
335 inline std::vector<CSkeleton*>& getBlending()
336 {
337 return m_blending;
338 }
339
344 void addBlending(CSkeleton* skeleton);
345
350 void removeBlending(CSkeleton* skeleton);
351
357 void drawDebug(const core::matrix4& transform, const SColor& c);
358
364 void drawDebugDefaultSkeleton(const core::matrix4& transform, const SColor& c);
365
366 protected:
367
372
377
382
386 void doBlending(CSkeleton* skeleton, bool first);
387
391 void doAddtive(CSkeleton* skeleton, bool first);
392
396 void doReplace(CSkeleton* skeleton, bool first);
397 };
398}
Represents an animation clip containing multiple animation tracks for different entities.
Definition CAnimationClip.h:41
Manages the playback state of an animation (current time, speed, loop state).
Definition CAnimationTimeline.h:45
ECS data component that holds animation and transform state for an entity within a skeleton.
Definition CAnimationTransformData.h:38
This object class is created to store data in an array of multiple CEntities.
Definition CEntityPrefab.h:38
void setTarget(CSkeleton *skeleton)
Sets the target skeleton that this skeleton will blend into.
EAnimationType m_animationType
Current operating mode.
Definition CSkeleton.h:97
void doAddtive(CSkeleton *skeleton, bool first)
Performs additive blending from a source layer.
void getBoneIdMap(std::map< std::string, int > &bones)
Builds a map from bone names to bone IDs.
bool m_enable
Whether this skeleton is enabled.
Definition CSkeleton.h:88
CEntityPrefab m_entities
Collection of entities (bones) in this skeleton.
Definition CSkeleton.h:73
EAnimationLayerType
Blending algorithms for layers.
Definition CSkeleton.h:65
@ Replace
Normal linear blending.
Definition CSkeleton.h:67
@ Addtive
Overrides previous layers.
Definition CSkeleton.h:68
CSkeleton * getTarget()
Gets the target skeleton.
Definition CSkeleton.h:326
bool m_needUpdateActivateEntities
Flag to trigger update of activated entities.
Definition CSkeleton.h:91
core::array< CAnimationTransformData * > m_entitiesActivated
List of bones that are currently active (weight > 0).
Definition CSkeleton.h:79
int simulateTransform(float timeSecond, core::matrix4 origin, core::matrix4 *transforms, int numTransform)
Simulates the skeleton at a specific time and returns world matrices.
void notifyUpdateActivateEntities()
Manually notifies the skeleton to refresh its active joint list.
Definition CSkeleton.h:311
CAnimationTimeline & getTimeline()
Gets the animation timeline for this skeleton.
Definition CSkeleton.h:267
void doBlending(CSkeleton *skeleton, bool first)
Performs standard linear blending from a source layer.
void drawDebugDefaultSkeleton(const core::matrix4 &transform, const SColor &c)
Draws the default pose of the skeleton.
CAnimationClip * getCurrentAnimation()
Gets the currently assigned animation clip.
Definition CSkeleton.h:231
int m_id
Unique ID of the skeleton.
Definition CSkeleton.h:85
void setAnimationData()
Internal helper to set up keyframe data for each joint from the current clip.
void setAnimation(CAnimationClip *clip, bool loop, bool pause=false)
Sets an animation clip to play on this skeleton.
EAnimationType getAnimationType()
Gets the current operating mode.
Definition CSkeleton.h:285
void drawDebug(const core::matrix4 &transform, const SColor &c)
Draws the skeleton hierarchy for debugging.
CAnimationTransformData * m_root
Pointer to the root bone data.
Definition CSkeleton.h:82
void getJoints(const char *name, std::vector< CAnimationTransformData * > &joints)
Gets a list of joint data pointers starting from a named joint.
bool isEnable()
Checks if the skeleton is enabled.
Definition CSkeleton.h:249
std::vector< CAnimationTransformData * > m_entitiesData
List of internal animation data for each bone.
Definition CSkeleton.h:76
void setJointWeights(std::vector< CAnimationTransformData * > &joints, float weight)
Sets blending weights for a provided list of joints.
CSkeleton * m_target
For blending: the skeleton that this layer blends into.
Definition CSkeleton.h:108
void applyTransform()
Applies calculated local PRS to the relative matrices of bones.
CAnimationTransformData * getJoint(const char *name)
Gets the joint data for a specific bone name.
void setEnable(bool b)
Sets whether the skeleton is enabled.
Definition CSkeleton.h:258
void initSkeleton(core::array< CEntity * > &entities)
Initializes the skeleton hierarchy from a list of world entities.
void addBlending(CSkeleton *skeleton)
Adds a layer to blend into this skeleton.
CAnimationClip * m_clip
Currently assigned animation clip.
Definition CSkeleton.h:100
void doReplace(CSkeleton *skeleton, bool first)
Performs override (replace) blending from a source layer.
EAnimationType
Operating modes for the skeleton.
Definition CSkeleton.h:56
@ Blending
Standard mode: plays a single animation clip.
Definition CSkeleton.h:58
EAnimationLayerType getLayerType()
Gets the layer blending type.
Definition CSkeleton.h:303
int getID()
Gets the skeleton ID.
Definition CSkeleton.h:240
std::vector< CSkeleton * > & getBlending()
Gets the list of layers (sub-skeletons) blending into this skeleton.
Definition CSkeleton.h:335
void setJointWeights(const char *name, float weight, bool includeChild=true)
Sets the blending weight for a specific joint and its children.
void removeBlending(CSkeleton *skeleton)
Removes a blended layer.
void syncAnimationByTimeScale()
Synchronizes time across multiple blended layers based on the highest weight.
std::vector< CAnimationTransformData * > & getJoints()
Gets the list of all joint data in the skeleton.
Definition CSkeleton.h:222
void setLayerType(EAnimationLayerType type)
Sets the blending algorithm (Replace, Addtive, etc.) for this skeleton layer.
Definition CSkeleton.h:294
std::vector< CSkeleton * > m_blending
List of sub-skeletons (layers) that blend into this skeleton.
Definition CSkeleton.h:111
void updateBlending()
Orchestrates the blending of all attached layers.
void releaseAllEntities()
Releases all bone entities.
void updateTrackKeyFrame()
Evaluates current keyframes and interpolates PRS data for all active joints.
void setAnimation(CAnimationClip *clip, bool loop, float from, float duration, bool pause=false)
Sets an animation clip with a specific range.
CAnimationTimeline m_timeline
Playback state for this skeleton.
Definition CSkeleton.h:94
void setJointWeights(float weight)
Sets the blending weight for ALL joints in the skeleton.
void setAnimationType(EAnimationType type)
Sets the operating mode of the skeleton.
Definition CSkeleton.h:276
void update()
Updates the animation state.
void updateActivateEntities()
Filters and caches bones that are currently contributing to the animation.
EAnimationLayerType m_layerType
Blending type for this skeleton (when used as a layer).
Definition CSkeleton.h:103
Self reallocating template array (like stl vector) with additional features.
Definition irrArray.h:23
Class representing a 32 bit ARGB color.
Definition SColor.h:285
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
CMatrix4< f32 > matrix4
Typedef for f32 matrix.
Definition matrix4.h:2241