Skylicht Engine
Loading...
Searching...
No Matches
CAnimationClip.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 "pch.h"
28#include "CAnimationTrack.h"
29
30namespace Skylicht
31{
33 {
34 std::string Name;
35 CAnimationData Data;
36 };
37
40 class SKYLICHT_API CAnimationClip
41 {
42 public:
44 std::string AnimName;
45
47 float Duration; // Second
48
50 bool Loop;
51
53 std::vector<SEntityAnim*> AnimInfo;
54
56 std::map<std::string, SEntityAnim*> AnimNameToInfo;
57
58 CAnimationClip()
59 {
60 AnimName = "";
61 Duration = 0.0f;
62 Loop = true;
63 }
64
65 virtual ~CAnimationClip()
66 {
67 releaseAllAnim();
68 }
69
74 {
75 for (SEntityAnim* &i : AnimInfo)
76 {
77 delete i;
78 }
79 AnimInfo.clear();
80 AnimNameToInfo.clear();
81 }
82
87 void addAnim(SEntityAnim* anim)
88 {
89 for (SEntityAnim *&i : AnimInfo)
90 {
91 if (i->Name == anim->Name)
92 {
93 delete i;
94 i = anim;
95 AnimNameToInfo[i->Name] = anim;
96 return;
97 }
98 }
99
100 AnimInfo.push_back(anim);
101 AnimNameToInfo[anim->Name] = anim;
102 }
103
109 {
110 return (int)AnimInfo.size();
111 }
112
119 {
120 return AnimInfo[i];
121 }
122
128 SEntityAnim* getAnimOfEntity(const std::string &sceneNodeName)
129 {
130 return AnimNameToInfo[sceneNodeName];
131 }
132
138 float getRealTimeLength(float baseFps = 30.0f)
139 {
140 return Duration * 1000.0f / baseFps;
141 }
142 };
143
144}
Represents an animation clip containing multiple animation tracks for different entities.
Definition CAnimationClip.h:41
float getRealTimeLength(float baseFps=30.0f)
Gets the real-time length of the clip in milliseconds based on a target FPS.
Definition CAnimationClip.h:138
std::map< std::string, SEntityAnim * > AnimNameToInfo
Map of entity animations indexed by entity name.
Definition CAnimationClip.h:56
float Duration
Duration of the clip in seconds.
Definition CAnimationClip.h:47
SEntityAnim * getAnimOfEntity(const std::string &sceneNodeName)
Gets an entity animation by the name of the scene node/entity.
Definition CAnimationClip.h:128
void addAnim(SEntityAnim *anim)
Adds an entity animation to the clip.
Definition CAnimationClip.h:87
std::string AnimName
The name of the animation clip.
Definition CAnimationClip.h:44
void releaseAllAnim()
Releases and deletes all entity animations in this clip.
Definition CAnimationClip.h:73
SEntityAnim * getAnimOfEntity(int i)
Gets an entity animation by index.
Definition CAnimationClip.h:118
bool Loop
Whether the clip should loop during playback.
Definition CAnimationClip.h:50
int getNodeAnimCount()
Gets the number of entity animations (tracks) in the clip.
Definition CAnimationClip.h:108
std::vector< SEntityAnim * > AnimInfo
List of entity animations (tracks) within this clip.
Definition CAnimationClip.h:53
Container for PRS (Position, Rotation, Scale) animation data.
Definition CAnimationTrack.h:157
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
Definition CAnimationClip.h:33