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