move function prototype to animation.h
[platform/core/uifw/lottie-player.git] / README.md
1
2 # rlottie
3
4 [![Build Status](https://travis-ci.org/Samsung/rlottie.svg?branch=master)](https://travis-ci.org/Samsung/rlottie)
5 [![Build status](https://ci.appveyor.com/api/projects/status/n3xonxk1ooo6s7nr?svg=true&passingText=windows%20-%20passing)](https://ci.appveyor.com/project/smohantty/rlottie-mliua)
6 [![Gitter](https://badges.gitter.im/rLottie-dev/community.svg)](https://gitter.im/rLottie-dev/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
7
8 <p align="center">
9   <img width="240" height="240" src="https://github.com/Samsung/rlottie/blob/master/.Gifs/logo.png">
10 </p>
11
12 rlottie is a platform independent standalone c++ library for rendering vector based animations and art in realtime.
13
14 Lottie loads and renders animations and vectors exported in the bodymovin JSON format. Bodymovin JSON can be created and exported from After Effects with [bodymovin](https://github.com/bodymovin/bodymovin), Sketch with [Lottie Sketch Export](https://github.com/buba447/Lottie-Sketch-Export), and from [Haiku](https://www.haiku.ai).
15
16 For the first time, designers can create and ship beautiful animations without an engineer painstakingly recreating it by hand. Since the animation is backed by JSON they are extremely small in size but can be large in complexity!
17
18 Here are small samples of the power of Lottie.
19
20 <p align="center">
21   <img src="https://github.com/Samsung/rlottie/blob/master/.Gifs/1.gif">
22   <img src="https://github.com/Samsung/rlottie/blob/master/.Gifs/2.gif">
23   <img src="https://github.com/airbnb/lottie-ios/blob/master/_Gifs/Examples1.gif">
24 </p>
25
26 ## Contents
27 - [Building Lottie](#building-lottie)
28         - [Meson Build](#meson-build)
29         - [Cmake Build](#cmake-build)
30         - [Test](#test)
31 - [Demo](#demo)
32 - [Previewing Lottie JSON Files](#previewing-lottie-json-files)
33 - [Quick Start](#quick-start)
34 - [Dynamic Property](#dynamic-property)
35 - [Supported After Effects Features](#supported-after-effects-features)
36 - [Issues or Feature Requests?](#issues-or-feature-requests)
37
38 ## Building Lottie
39 rlottie supports [meson](https://mesonbuild.com/) and [cmake](https://cmake.org/) build system. rlottie is written in `C++14`. and has a public header dependency of `C++11`
40
41 ### Meson Build
42 install [meson](http://mesonbuild.com/Getting-meson.html) and [ninja](https://ninja-build.org/) if not already installed.
43
44 Run meson to configure rlottie
45 ```
46 meson build
47 ```
48 Run ninja to build rlottie
49 ```
50 ninja -C build
51 ```
52
53 ### Cmake Build
54
55 Install [cmake](https://cmake.org/download/) if not already installed
56
57 Create a build directory for out of source `build`
58 ```
59 mkdir build
60 ```
61 Run cmake command inside `build` directory to configure rlottie.
62 ```
63 cd build
64 cmake ..
65
66 # install in a different path. eg ~/test/usr/lib
67 cmake -DCMAKE_INSTALL_PREFIX=~/test ..
68
69 # static build
70 cmake -DBUILD_SHARED_LIBS=OFF ..
71 ```
72 Run make to build rlottie
73
74 ```
75 make -j 2
76 ```
77 To install rlottie library
78
79 ```
80 make install
81 ```
82
83 ### Test
84
85 Configure to build test
86 ```
87 meson configure -Dtest=true
88 ```
89 Build test suit
90
91 ```
92 ninja
93 ```
94 Run test suit
95 ```
96 ninja test
97 ```
98 [Back to contents](#contents)
99
100 #
101 ## Demo
102 If you want to see rlottie library in action without building it please visit [rlottie online viewer](http://rlottie.com)
103
104 While building rlottie library it generates a simple lottie to GIF converter which can be used to convert lottie json file to GIF file.
105
106 Run Demo
107 ```
108 lottie2gif [lottie file name]
109 ```
110
111 #
112 ## Previewing Lottie JSON Files
113 Please visit [rlottie online viewer](http://rlottie.com)
114
115 [rlottie online viewer](http://rlottie.com) uses rlottie wasm library to render the resource locally in your browser. To test your JSON resource drag and drop it to the browser window.
116
117 #
118 ## Quick Start
119
120 Lottie loads and renders animations and vectors exported in the bodymovin JSON format. Bodymovin JSON can be created and exported from After Effects with [bodymovin](https://github.com/bodymovin/bodymovin), Sketch with [Lottie Sketch Export](https://github.com/buba447/Lottie-Sketch-Export), and from [Haiku](https://www.haiku.ai).
121
122 You can quickly load a Lottie animation with:
123 ```cpp
124 auto animation = rlottie::Animation::loadFromFile("absolute_path/test.json");
125 ```
126 You can load a lottie animation from raw data with:
127 ```cpp
128 auto animation = rlottie::Animation::loadFromData(std::string(rawData), std::string(cacheKey));
129 ```
130
131 Properties like `frameRate` , `totalFrame` , `duration` can be queried with:
132 ```cpp
133 # get the frame rate of the resource.
134 double frameRate = animation->frameRate();
135
136 #get total frame that exists in the resource
137 size_t totalFrame = animation->totalFrame();
138
139 #get total animation duration in sec for the resource
140 double duration = animation->duration();
141 ```
142 Render a particular frame in a surface buffer `immediately` with:
143 ```cpp
144 rlottie::Surface surface(buffer, width , height , stride);
145 animation->renderSync(frameNo, surface);
146 ```
147 Render a particular frame in a surface buffer `asyncronousely` with:
148 ```cpp
149 rlottie::Surface surface(buffer, width , height , stride);
150 # give a render request
151 std::future<rlottie::Surface> handle = animation->render(frameNo, surface);
152 ...
153 #when the render data is needed
154 rlottie::Surface surface = handle.get();
155 ```
156
157 [Back to contents](#contents)
158
159
160 ## Dynamic Property
161
162 You can update properties dynamically at runtime. This can be used for a variety of purposes such as:
163 - Theming (day and night or arbitrary themes).
164 - Responding to events such as an error or a success.
165 - Animating a single part of an animation in response to an event.
166 - Responding to view sizes or other values not known at design time.
167
168 ### Understanding After Effects
169
170 To understand how to change animation properties in Lottie, you should first understand how animation properties are stored in Lottie. Animation properties are stored in a data tree that mimics the information hierarchy of After Effects. In After Effects a Composition is a collection of Layers that each have their own timelines. Layer objects have string names, and their contents can be an image, shape layers, fills, strokes, or just about anything that is drawable. Each object in After Effects has a name. Lottie can find these objects and properties by their name using a KeyPath.
171
172 ### Usage
173
174 To update a property at runtime, you need 3 things:
175 1. KeyPath
176 2. rLottie::Property
177 3. setValue()
178
179 ### KeyPath
180
181 A KeyPath is used to target a specific content or a set of contents that will be updated. A KeyPath is specified by a list of strings that correspond to the hierarchy of After Effects contents in the original animation.
182 KeyPaths can include the specific name of the contents or wildcards:
183 - Wildcard *
184         - Wildcards match any single content name in its position in the keypath.
185 - Globstar **
186         - Globstars match zero or more layers.
187
188 ### Properties
189
190 `rLottie::Property` is an enumeration of properties that can be set. They correspond to the animatable value in After Effects and the available properties are listed below.
191 ```cpp
192 enum class Property {
193     FillColor,     /*!< Color property of Fill object , value type is rlottie::Color */
194     FillOpacity,   /*!< Opacity property of Fill object , value type is float [ 0 .. 100] */
195     StrokeColor,   /*!< Color property of Stroke object , value type is rlottie::Color */
196     StrokeOpacity, /*!< Opacity property of Stroke object , value type is float [ 0 .. 100] */
197     StrokeWidth,   /*!< stroke with property of Stroke object , value type is float */
198     ...
199 };
200 ```
201
202 ### setValue()
203
204 `setValue()` requires a keypath of string and value. The value can be `Color`, `Size` and `Point` structure or a function that returns them. `Color`, `Size`, and `Point` vary depending on the type of `rLottie::Property`. This value or function(callback) is called and applied to every frame. This value can be set differently for each frame by using the `FrameInfo` argument passed to the function.
205
206
207 ### Usage
208 ```cpp
209 animation->setValue<rlottie::Property::FillColor>("**",rlottie::Color(0, 1, 0));
210 ```
211
212 ```cpp
213 animation->setValue<rlottie::Property::FillColor>("Layer1.Box 1.Fill1",
214     [](const rlottie::FrameInfo& info) {
215          if (info.curFrame() < 15 )
216              return rlottie::Color(0, 1, 0);
217          else {
218              return rlottie::Color(1, 0, 0);
219          }
220      });
221 ```
222
223 [Back to contents](#contents)
224
225 #
226 #
227 ## Supported After Effects Features
228
229 | **Shapes** | **Supported** |
230 |:--|:-:|
231 | Shape | 👍 |
232 | Ellipse | 👍 |
233 | Rectangle | 👍 |
234 | Rounded Rectangle | 👍 |
235 | Polystar | 👍 |
236 | Group | 👍 |
237 | Trim Path (individually) | 👍 |
238 | Trim Path (simultaneously) | 👍 |
239 | **Renderable** | **Supported** |
240 | Fill  | 👍 |
241 | Stroke | 👍 |
242 | Radial Gradient | 👍 |
243 | Linear Gradient | 👍 |
244 | Gradient Stroke | 👍 |
245 | **Transforms** | **Supported** |
246 | Position | 👍 |
247 | Position (separated X/Y) | 👍 |
248 | Scale | 👍 |
249 | Skew | ⛔️ |
250 | Rotation | 👍 |
251 | Anchor Point | 👍 |
252 | Opacity | 👍 |
253 | Parenting | 👍 |
254 | Auto Orient | 👍 |
255 | **Interpolation** | **Supported** |
256 | Linear Interpolation | 👍 |
257 | Bezier Interpolation | 👍 |
258 | Hold Interpolation | 👍 |
259 | Spatial Bezier Interpolation | 👍 |
260 | Rove Across Time | 👍 |
261 | **Masks** | **Supported** |
262 | Mask Path | 👍 |
263 | Mask Opacity | 👍 |
264 | Add | 👍 |
265 | Subtract | 👍 |
266 | Intersect | 👍 |
267 | Lighten | ⛔️ |
268 | Darken | ⛔️ |
269 | Difference | ⛔️ |
270 | Expansion | ⛔️ |
271 | Feather | ⛔️ |
272 | **Mattes** | **Supported** |
273 | Alpha Matte | 👍 |
274 | Alpha Inverted Matte | 👍 |
275 | Luma Matte | 👍 |
276 | Luma Inverted Matte | 👍 |
277 | **Merge Paths** | **Supported** |
278 | Merge | ⛔️ |
279 | Add | ⛔️ |
280 | Subtract | ⛔️ |
281 | Intersect | ⛔️ |
282 | Exclude Intersection | ⛔️ |
283 | **Layer Effects** | **Supported** |
284 | Fill | ⛔️ |
285 | Stroke | ⛔️ |
286 | Tint | ⛔️ |
287 | Tritone | ⛔️ |
288 | Levels Individual Controls | ⛔️ |
289 | **Text** | **Supported** |
290 | Glyphs |  ⛔️ |
291 | Fonts | ⛔️ |
292 | Transform | ⛔️ |
293 | Fill | ⛔️ |
294 | Stroke | ⛔️ |
295 | Tracking | ⛔️ |
296 | Anchor point grouping | ⛔️ |
297 | Text Path | ⛔️ |
298 | Per-character 3D | ⛔️ |
299 | Range selector (Units) | ⛔️ |
300 | Range selector (Based on) | ⛔️ |
301 | Range selector (Amount) | ⛔️ |
302 | Range selector (Shape) | ⛔️ |
303 | Range selector (Ease High) | ⛔️ |
304 | Range selector (Ease Low)  | ⛔️ |
305 | Range selector (Randomize order) | ⛔️ |
306 | expression selector | ⛔️ |
307 | **Other** | **Supported** |
308 | Expressions | ⛔️ |
309 | Images | 👍 |
310 | Precomps | 👍 |
311 | Time Stretch |  👍 |
312 | Time remap |  👍 |
313 | Markers | 👍  |
314
315 #
316 [Back to contents](#contents)
317
318 ## Issues or Feature Requests?
319 File github issues for anything that is broken. Be sure to check the [list of supported features](#supported-after-effects-features) before submitting.  If an animation is not working, please attach the After Effects file to your issue. Debugging without the original can be very difficult. For immidiate assistant or support please reach us in [Gitter](https://gitter.im/rLottie-dev/community#)