1 #ifndef DALI_SCENE3D_LOADER_ANIMATION_DEFINITION_H
2 #define DALI_SCENE3D_LOADER_ANIMATION_DEFINITION_H
4 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali-scene3d/public-api/api.h>
25 #include <dali-scene3d/public-api/loader/animated-property.h>
27 namespace Dali::Scene3D::Loader
30 * @brief Animation handle + name + definition of properties.
33 class DALI_SCENE3D_API AnimationDefinition
36 // For Animations created in the SDK.
37 static const float DEFAULT_DURATION_SECONDS;
39 // For parsing Animations from dli, when duration was not defined.
40 static const float MIN_DURATION_SECONDS;
43 * @brief Saves the original end action of @a anim, sets the end action to Discard, then stops
44 * the animation and returns the end action.
47 static Animation::EndAction StopForModification(Animation& anim);
50 AnimationDefinition();
52 AnimationDefinition(AnimationDefinition&& other);
54 AnimationDefinition& operator=(AnimationDefinition&& other);
57 * @brief Registers the properties against the given @a animation.
59 * @a getActor will be used to obtain the Actors for each AnimatedProperty.
62 void Animate(Animation& animation, AnimatedProperty::GetActor getActor);
65 * @brief Creates a new Animation and Animates() its properties.
67 * @a getActor will be used to obtain the Actors for each AnimatedProperty.
70 Animation ReAnimate(AnimatedProperty::GetActor getActor);
73 * @brief Set the name of the animation.
76 * @param[in] name The name of the animation.
78 void SetName(const std::string& name);
81 * @brief Get the name of the animation.
84 * @return The name of the animation.
86 const std::string& GetName() const;
89 * @brief Set the duration of the animation in seconds.
92 * @param[in] duration The duration of the animation in seconds.
94 void SetDuration(float duration);
97 * @brief Get the duration of the animation in seconds.
100 * @return The duration of the animation in seconds.
102 float GetDuration() const;
105 * @brief Set the number of times to loop the animation.
108 * @param[in] loopCount The number of times to loop the animation. Use -1 for infinite looping.
110 void SetLoopCount(int32_t loopCount);
113 * @brief Get the number of times to loop the animation.
116 * @return The number of times to loop the animation. Use -1 for infinite looping.
118 int GetLoopCount() const;
121 * @brief Set what should happen when an animation is disconnected from an object.
124 * @param[in] disconnectAction What should happen when an animation is disconnected from an object.
126 void SetDisconnectAction(Animation::EndAction disconnectAction);
129 * @brief Get what should happen when an animation is disconnected from an object.
132 * @return What should happen when an animation is disconnected from an object.
134 Animation::EndAction GetDisconnectAction() const;
137 * @brief Set what should happen when an animation reaches its end.
140 * @param[in] endAction What should happen when an animation reaches its end.
142 void SetEndAction(Animation::EndAction endAction);
145 * @brief Get what should happen when an animation reaches its end.
148 * @return What should happen when an animation reaches its end.
150 Animation::EndAction GetEndAction() const;
153 * @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.
156 * @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.
158 void SetSpeedFactor(float speedFactor);
161 * @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.
164 * @return The speed factor for this animation. 1.0 is normal speed, 2.0 is double speed, 0.5 is half speed, etc.
166 float GetSpeedFactor() const;
169 * @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
172 * @param[in] playRange A range within which to play this animation. x = start time in seconds, y = end time in seconds
174 void SetPlayRange(const Vector2& playRange);
177 * @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
180 * @return A range within which to play this animation. x = start time in seconds, y = end time in seconds
182 Vector2 GetPlayRange() const;
185 * @brief Reserves Animated property vector's size
188 * @param[in] size The size to reserve property
190 void ReserveSize(uint32_t size);
193 * @brief Retrieves the number of animated properties' count
196 * @return The count of animated properties.
198 uint32_t GetPropertyCount() const;
201 * @brief Add a property that will be animated by this AnimationDefinition
204 * @param[in] index The index the property will be stored.
205 * @param[in] property The property that will be animated by this AnimationDefinition
207 void SetProperty(uint32_t index, AnimatedProperty&& property);
210 * @brief Retrieves animated property at the index
213 * @param[in] index The index of property to be retrieved.
215 AnimatedProperty& GetPropertyAt(uint32_t index);
218 * @brief Retrieves animated property at the index
221 * @param[in] index The index of property to be retrieved.
223 const AnimatedProperty& GetPropertyAt(uint32_t index) const;
228 float mDuration = DEFAULT_DURATION_SECONDS;
229 int32_t mLoopCount = 1;
230 Animation::EndAction mDisconnectAction = Animation::BAKE_FINAL;
231 Animation::EndAction mEndAction = Animation::BAKE;
232 float mSpeedFactor = 1.f;
233 Vector2 mPlayRange = Vector2{0.f, 1.f};
235 std::vector<AnimatedProperty> mProperties;
238 struct AnimationGroupDefinition
241 std::vector<std::string> mAnimations;
244 } // namespace Dali::Scene3D::Loader
246 #endif // DALI_SCENE3D_LOADER_ANIMATION_DEFINITION_H