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.
32 class DALI_SCENE3D_API AnimationDefinition
35 // For Animations created in the SDK.
36 static const float DEFAULT_DURATION_SECONDS;
38 // For parsing Animations from dli, when duration was not defined.
39 static const float MIN_DURATION_SECONDS;
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.
45 static Animation::EndAction StopForModification(Animation& anim);
48 AnimationDefinition();
50 AnimationDefinition(AnimationDefinition&& other);
52 AnimationDefinition& operator=(AnimationDefinition&& other);
55 * @brief Registers the properties against the given @a animation. @a getActor
56 * will be used to obtain the Actors for each AnimatedProperty.
58 void Animate(Animation& animation, AnimatedProperty::GetActor getActor);
61 * @brief Creates a new Animation and Animates() its properties. @a getActor
62 * will be used to obtain the Actors for each AnimatedProperty.
64 Animation ReAnimate(AnimatedProperty::GetActor getActor);
67 * @brief Set the name of the animation.
69 * @param[in] name The name of the animation.
71 void SetName(const std::string& name);
74 * @brief Get the name of the animation.
76 * @return The name of the animation.
78 const std::string& GetName() const;
81 * @brief Set the duration of the animation in seconds.
83 * @param[in] duration The duration of the animation in seconds.
85 void SetDuration(float duration);
88 * @brief Get the duration of the animation in seconds.
90 * @return The duration of the animation in seconds.
92 float GetDuration() const;
95 * @brief Set the number of times to loop the animation.
97 * @param[in] loopCount The number of times to loop the animation. Use -1 for infinite looping.
99 void SetLoopCount(int32_t loopCount);
102 * @brief Get the number of times to loop the animation.
104 * @return The number of times to loop the animation. Use -1 for infinite looping.
106 int GetLoopCount() const;
109 * @brief Set what should happen when an animation is disconnected from an object.
111 * @param[in] disconnectAction What should happen when an animation is disconnected from an object.
113 void SetDisconnectAction(Animation::EndAction disconnectAction);
116 * @brief Get what should happen when an animation is disconnected from an object.
118 * @return What should happen when an animation is disconnected from an object.
120 Animation::EndAction GetDisconnectAction() const;
123 * @brief Set what should happen when an animation reaches its end.
125 * @param[in] endAction What should happen when an animation reaches its end.
127 void SetEndAction(Animation::EndAction endAction);
130 * @brief Get what should happen when an animation reaches its end.
132 * @return What should happen when an animation reaches its end.
134 Animation::EndAction GetEndAction() const;
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.
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.
141 void SetSpeedFactor(float speedFactor);
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.
146 * @return The speed factor for this animation. 1.0 is normal speed, 2.0 is double speed, 0.5 is half speed, etc.
148 float GetSpeedFactor() const;
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
153 * @param[in] playRange A range within which to play this animation. x = start time in seconds, y = end time in seconds
155 void SetPlayRange(const Vector2& playRange);
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
160 * @return A range within which to play this animation. x = start time in seconds, y = end time in seconds
162 Vector2 GetPlayRange() const;
165 * @brief Reserves Animated property vector's size
167 * @param[in] size The size to reserve property
169 void ReserveSize(uint32_t size);
172 * @brief Retrieves the number of animated properties' count
174 * @return The count of animated properties.
176 uint32_t GetPropertyCount();
179 * @brief Add a property that will be animated by this AnimationDefinition
181 * @param[in] index The index the property will be stored.
182 * @param[in] property The property that will be animated by this AnimationDefinition
184 void SetProperty(uint32_t index, AnimatedProperty&& property);
187 * @brief Retrieves animated property at the index
189 * @param[in] index The index of property to be retrieved.
191 const AnimatedProperty& GetPropertyAt(uint32_t index);
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};
203 std::vector<AnimatedProperty> mProperties;
206 struct AnimationGroupDefinition
209 std::vector<std::string> mAnimations;
212 } // namespace Dali::Scene3D::Loader
214 #endif // DALI_SCENE3D_LOADER_ANIMATION_DEFINITION_H