9b8393cb5d6a2068baa21c2e05bb3b993aec6c12
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / animation-definition.h
1 #ifndef DALI_SCENE3D_LOADER_ANIMATION_DEFINITION_H
2 #define DALI_SCENE3D_LOADER_ANIMATION_DEFINITION_H
3 /*
4  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/common/vector-wrapper.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-scene3d/public-api/api.h>
25 #include <dali-scene3d/public-api/loader/animated-property.h>
26
27 namespace Dali::Scene3D::Loader
28 {
29 /**
30  * @brief Animation handle + name + definition of properties.
31  */
32 class DALI_SCENE3D_API AnimationDefinition
33 {
34 public: // STATIC
35   // For Animations created in the SDK.
36   static const float DEFAULT_DURATION_SECONDS;
37
38   // For parsing Animations from dli, when duration was not defined.
39   static const float MIN_DURATION_SECONDS;
40
41   /**
42    * @brief Saves the original end action of @a anim, sets the end action to
43    *  Discard, then stops the animation and returns the end action.
44    */
45   static Animation::EndAction StopForModification(Animation& anim);
46
47 public: // METHODS
48   AnimationDefinition();
49
50   AnimationDefinition(AnimationDefinition&& other);
51
52   AnimationDefinition& operator=(AnimationDefinition&& other);
53
54   /**
55    * @brief Registers the properties against the given @a animation. @a getActor
56    *  will be used to obtain the Actors for each AnimatedProperty.
57    */
58   void Animate(Animation& animation, AnimatedProperty::GetActor getActor);
59
60   /**
61    * @brief Creates a new Animation and Animates() its properties. @a getActor
62    *  will be used to obtain the Actors for each AnimatedProperty.
63    */
64   Animation ReAnimate(AnimatedProperty::GetActor getActor);
65
66   /**
67    * @brief Set the name of the animation.
68    *
69    * @param[in] name The name of the animation.
70    */
71   void SetName(const std::string& name);
72
73   /**
74    * @brief Get the name of the animation.
75    *
76    * @return The name of the animation.
77    */
78   const std::string& GetName() const;
79
80   /**
81    * @brief Set the duration of the animation in seconds.
82    *
83    * @param[in] duration The duration of the animation in seconds.
84    */
85   void SetDuration(float duration);
86
87   /**
88    * @brief Get the duration of the animation in seconds.
89    *
90    * @return The duration of the animation in seconds.
91    */
92   float GetDuration() const;
93
94   /**
95    * @brief Set the number of times to loop the animation.
96    *
97    * @param[in] loopCount The number of times to loop the animation. Use -1 for infinite looping.
98    */
99   void SetLoopCount(int32_t loopCount);
100
101   /**
102    * @brief Get the number of times to loop the animation.
103    *
104    * @return The number of times to loop the animation. Use -1 for infinite looping.
105    */
106   int GetLoopCount() const;
107
108   /**
109    * @brief Set what should happen when an animation is disconnected from an object.
110    *
111    * @param[in] disconnectAction What should happen when an animation is disconnected from an object.
112    */
113   void SetDisconnectAction(Animation::EndAction disconnectAction);
114
115   /**
116    * @brief Get what should happen when an animation is disconnected from an object.
117    *
118    * @return What should happen when an animation is disconnected from an object.
119    */
120   Animation::EndAction GetDisconnectAction() const;
121
122   /**
123    * @brief Set what should happen when an animation reaches its end.
124    *
125    * @param[in] endAction What should happen when an animation reaches its end.
126    */
127   void SetEndAction(Animation::EndAction endAction);
128
129   /**
130    * @brief Get what should happen when an animation reaches its end.
131    *
132    * @return What should happen when an animation reaches its end.
133    */
134   Animation::EndAction GetEndAction() const;
135
136   /**
137    * @brief Set a speed factor for this animation. This can be used to speed up or slow down playback of this animation relative to other animations in a scene.
138    *
139    * @param[in] speedFactor The speed factor for this animation. 1.0 is normal speed, 2.0 is double speed, 0.5 is half speed, etc.
140    */
141   void SetSpeedFactor(float speedFactor);
142
143   /**
144    * @brief Get a speed factor for this animation. This can be used to speed up or slow down playback of this animation relative to other animations in a scene.
145    *
146    * @return The speed factor for this animation. 1.0 is normal speed, 2.0 is double speed, 0.5 is half speed, etc.
147    */
148   float GetSpeedFactor() const;
149
150   /**
151    * @brief Set a range within which to play this animation. This can be used to play only part of an animation or to play it backwards by setting playRange.y < playRange.x
152    *
153    * @param[in] playRange A range within which to play this animation. x = start time in seconds, y = end time in seconds
154    */
155   void SetPlayRange(const Vector2& playRange);
156
157   /**
158    * @brief Get a range within which to play this animation. This can be used to play only part of an animation or to play it backwards by setting playRange.y < playRange.x
159    *
160    * @return A range within which to play this animation. x = start time in seconds, y = end time in seconds
161    */
162   Vector2 GetPlayRange() const;
163
164   /**
165    * @brief Reserves Animated property vector's size
166    *
167    * @param[in] size The size to reserve property
168    */
169   void ReserveSize(uint32_t size);
170
171   /**
172    * @brief Retrieves the number of animated properties' count
173    *
174    * @return The count of animated properties.
175    */
176   uint32_t GetPropertyCount();
177
178   /**
179    * @brief Add a property that will be animated by this AnimationDefinition
180    *
181    * @param[in] index The index the property will be stored.
182    * @param[in] property The property that will be animated by this AnimationDefinition
183    */
184   void SetProperty(uint32_t index, AnimatedProperty&& property);
185
186   /**
187    * @brief Retrieves animated property at the index
188    *
189    * @param[in] index The index of property to be retrieved.
190    */
191   AnimatedProperty& GetPropertyAt(uint32_t index);
192
193 private: // DATA
194   std::string mName;
195
196   float                mDuration         = DEFAULT_DURATION_SECONDS;
197   int32_t              mLoopCount        = 1;
198   Animation::EndAction mDisconnectAction = Animation::BAKE_FINAL;
199   Animation::EndAction mEndAction        = Animation::BAKE;
200   float                mSpeedFactor      = 1.f;
201   Vector2              mPlayRange        = Vector2{0.f, 1.f};
202
203   std::vector<AnimatedProperty> mProperties;
204 };
205
206 struct AnimationGroupDefinition
207 {
208   std::string              mName;
209   std::vector<std::string> mAnimations;
210 };
211
212 } // namespace Dali::Scene3D::Loader
213
214 #endif // DALI_SCENE3D_LOADER_ANIMATION_DEFINITION_H