Skip to content

[GSoC 19] Export Animation for Web using Lottie - #756

Merged
morevnaproject merged 62 commits into
synfig:masterfrom
AnishGG:lottie_exporter
Aug 23, 2019
Merged

morevnaproject merged 62 commits into
synfig:masterfrom
AnishGG:lottie_exporter

Conversation

@AnishGG

@AnishGG AnishGG commented Mar 8, 2019 •

Copy link
Copy Markdown
Member

Google Summer of Code 2019

Student: Anish Gulati(@AnishGG)
Mentors: Konstantin Dmitriev(@morevnaproject), Artem Konoplin(@ice0)
Project: Export Animation for Web

Feature: #704

Description

Created a plugin which allows export of Synfig format animations(.sif/.sifz) to Lottie JSON format. Lottie is a library that renders animations natively on mobile and on the web.
To access this plugin, there is new menu entry "Plugins" - "Export to Lottie". Choosing this will export the currently opened file to Lottie format. After the export, we will have 3 files:

FILE.html
FILE.json
FILE.log
  • To play the file on a local browser, just open FILE.html with any browser like Firefox or Google Chrome.
  • FILE.json is the main file where the Lottie format animation resides. An alternative to play this file is using an online code editor like codepen.io. Here is an example implementation. FILE.json can be directly played using lottiefiles.com.
  • FILE.log stores all the logs after the export. If a layer is not active/supported, it will be notified in the logs.

front_end
Currently plugin is capable to export most main graphic elements, with animation applied to their parameters (various types of interpolations supported), some converters can be applied to parameters (see detailed list of supported layers and parameters below). There is a partial support for exporting bones.

Demonstration

Here is a video by @morevnaproject demonstrating the export process:

Example 1
IDemonstration video 1

Example 2
IDemonstration video 2

Supported Layers

  • Star Layer
  • Circle Layer
  • Rectangle Layer
  • Simple Circle Layer
  • Solid Color Layer
  • Import Image Layer
  • Region Layer
  • Polygon Layer
  • Outline Layer
  • Rotate Layer
  • Scale Layer
  • Translate Layer
  • Group Layer
  • Switch group Layer
  • Skeleton Layer [WIP]

Supported Convert methods

  • Average
  • Composite
  • Linear
  • Radial Composite
  • Scale
  • Subtract
  • Switch
  • Weighted Average
  • Bone Link

Limitations

  • Layers like region, outline, and polygon are exported frame-by-frame because there is no exact alternative provided by Lottie and hence the animations tend to lag on larger displays(lottie calculates animation in real time provided the data). If this project is a success, we will be happy to ask Lottie developers to extend support for these layers.
  • Animation of addition/deletion of bline points is supported yet. Lottie does not provides this, hence this will have to be implemented from the base. I will be aiming at providing support to this in the upcoming months.
  • Exporting Bones (Skeleton) animation is not complete yet.

TODO

  • Finalize support for bones (allow to attach groups and spline vertices to bones).
  • Add support for Gradients.
  • Add support for Advanced Outline Layer.

See full list of pending issues here.

Code Contributions

Development Notes

@morevnaproject morevnaproject changed the title Add lottie-convertor plugin for star layer [WIP] Add lottie-convertor plugin for star layer Mar 8, 2019
@morevnaproject

Copy link
Copy Markdown
Member

@AnishGG Great! I did a quick overview and it looks good so far! I will test it tomorrow.

P.S. Marked this issue as [WIP] and leaving it open for now. So, you can push more commits in the same branch when you get done with animation thing - it will get updated automatically.

Keep up the good work! ^__^

@AnishGG

AnishGG commented Mar 9, 2019 •

Copy link
Copy Markdown
Member Author

@morevnaproject, Does the ordering of the star layers depend on the value of z_depth?
I made three stars layers, in the synfig studio it is showing the z_depth parameter as 0, 1, 2. But when I save it in .sif format, all the z_depth parameters have value equal to 0.
Is it a bug or the layer ordering depends on the order they are present in the .sif format file?
Here is the .sif xml file.
Here is the screenshot for the above
Screenshot from 2019-03-09 14-29-07

@morevnaproject

Copy link
Copy Markdown
Member

@AnishGG Yes, the values in Z-Depth column of Layers Panel indicate order of layers. They are given as reference only.

You can notice each layer also has Z-Depth parameter, which allows to set a shift of layer's depth, relatively to its place in the stack of layers.

Positive values of layer's Z-Depth parameter mean that layer is moved lower in stack. Negative values mean that layer is raised upper.

By default this value is = 0 (so, layer has no shift by default).

For details see https://wiki.synfig.org/Z_Depth_Parameter.

@morevnaproject

Copy link
Copy Markdown
Member

Hey, I tested and it's so cool! ^__^

screenshot_011

@morevnaproject

Copy link
Copy Markdown
Member

Regarding the layout: wouldn't it be reasonable to merge both shapes into single layer? I wonder, if that will make any impact on speed.

@AnishGG

AnishGG commented Mar 9, 2019

Copy link
Copy Markdown
Member Author

Regarding the layout: wouldn't it be reasonable to merge both shapes into single layer? I wonder, if that will make any impact on speed.

I didn't catch up. merge both shapes into single layer, do you mean both stars in a single layer?
If yes, I guess lottie does not have that feature. I tried doing that but only of the stars would get rendered then.
Regarding the speed part, yes it might have an impact on speed, but I 'll have to figure out how lottie is rendering all the layers.

@morevnaproject

Copy link
Copy Markdown
Member

I didn't catch up. merge both shapes into single layer, do you mean both stars in a single layer?

Yes, if we have two star layers (Synfig layers), then in Lottie they can use one layer (Lottie layer here), which includes several shapes.

I did some experimenting and found that this is possible, BUT in this case all stars will share the same fill color. Here is an example - https://gist.github.com/morevnaproject/f4686b5b0868447af64f5b620d0ad669

screenshot_001

I am not sure if we need this now, but we can consider this for future optimization.

@morevnaproject

Copy link
Copy Markdown
Member

One more note: if you look at screenshot in #756 (comment), then you might notice the stars in Synfig and in browser has slightly different colors. This is because Synfig internally uses gamma value = 2.2. Exporter should handle that and do proper correction for colors.

Please check this post on the hints how to deal with gamma - https://forums.synfig.org/t/hack-to-import-gimp-palette/1882/5?u=konstantindmitriev

@AnishGG

AnishGG commented Mar 11, 2019

Copy link
Copy Markdown
Member Author

One more note: if you look at screenshot in #756 (comment), then you might notice the stars in Synfig and in browser has slightly different colors. This is because Synfig internally uses gamma value = 2.2. Exporter should handle that and do proper correction for colors.

Please check this post on the hints how to deal with gamma - https://forums.synfig.org/t/hack-to-import-gimp-palette/1882/5?u=konstantindmitriev

Sure, I will do the correction for color calculation as per the gamma value.

@AnishGG

AnishGG commented Mar 11, 2019

Copy link
Copy Markdown
Member Author

I didn't catch up. merge both shapes into single layer, do you mean both stars in a single layer?

Yes, if we have two star layers (Synfig layers), then in Lottie they can use one layer (Lottie layer here), which includes several shapes.

I did some experimenting and found that this is possible, BUT in this case all stars will share the same fill color. Here is an example - https://gist.github.com/morevnaproject/f4686b5b0868447af64f5b620d0ad669

screenshot_001

I am not sure if we need this now, but we can consider this for future optimization.

Oh, I was trying to fit more than 1 star in a single layer plus more than 1 fills also. That might be the reason the star was not rendering.
In future we might use this somehow for optimization, like may be for all the layers with same fills. I will check this out.

@AnishGG

AnishGG commented Mar 16, 2019

Copy link
Copy Markdown
Member Author

@morevnaproject, the color correction as per the gamma value has been done.🙂 Please have a look at it.
The animation part is not working properly yet. For now this is only the initial version. I will keep you posted regarding the progress.
This is the link that I am referring for the animation part.

@morevnaproject

Copy link
Copy Markdown
Member

Yes, I've tested it already. Thank you for keeping me updated! ^__^

@AnishGG

AnishGG commented Mar 18, 2019

Copy link
Copy Markdown
Member Author

@morevnaproject, TCB only animations are now working. Please have a look at this. ^_^

@AnishGG

AnishGG commented Apr 10, 2019

Copy link
Copy Markdown
Member Author

@morevnaproject, So I modularized the code written till now. I am able to run this code properly using command line interface. But I am facing issues in Makefile.am while installing it as a plugin.
Please guide me regarding the Makefiles part.
Here is the error I am getting when this plugin is run:
Screenshot from 2019-04-11 01-23-04

I think I need to add SUBDIRS in this Makefile. But I am not able to figure what will be written in the Makefile.am for the helpers directory or any other subdirectory.

@AnishGG

AnishGG commented Apr 11, 2019

Copy link
Copy Markdown
Member Author

@morevnaproject, I tried using SUBDIRS, but in the final build the sub-directories are not getting created.
Could you point out where am I making a mistake as I am not that well versed with Makefiles.
Thanks

@AnishGG

AnishGG commented Apr 11, 2019

Copy link
Copy Markdown
Member Author

I have observed that instead of installing the lottie-exporter/helpers/ files to the corresponding path, the Makefile is installing it to build/share/doc/synfigstudio.
Any suggestions on to why this could be happening would be highly apprecited.

Here is the expanded output:
Making install in helpers
make[3]: Entering directory '/home/anishg/GSOC/try/synfig/_debug/synfig-studio/plugins/lottie-exporter/helpers'
make[4]: Entering directory '/home/anishg/GSOC/try/synfig/_debug/synfig-studio/plugins/lottie-exporter/helpers'
make[4]: Nothing to be done for 'install-exec-am'.
/bin/mkdir -p '/home/anishg/GSOC/try/synfig/_debug/build/share/doc/synfigstudio'
/usr/bin/install -c -m 644 /home/anishg/GSOC/try/synfig/synfig-studio/plugins/lottie-exporter/helpers/transform.py '/home/anishg/GSOC/try/synfig/_debug/build/share/doc/synfigstudio'

@AnishGG

AnishGG commented Apr 11, 2019

Copy link
Copy Markdown
Member Author

Please guide me regarding the Makefiles part.
Here is the error I am getting when this plugin is run:

Fixed ^__^

@morevnaproject

Copy link
Copy Markdown
Member

Awesome!

@AnishGG

AnishGG commented Apr 18, 2019 •

Copy link
Copy Markdown
Member Author

Just keeping the discussion alive and posting the progress here.
This is how a star layer with animation when converted to lottie looks like as of now:
Test file: lottie-test.sif

Synfig Studio
synfig_studio

Lottie Web Animation
lottie

P.S. The FPS of my screen-recorder is bad, hence the bad quality.

@AnishGG AnishGG changed the title [WIP] Add lottie-convertor plugin for star layer [WIP] Add lottie-converter plugin for star layer Apr 28, 2019
@morevnaproject

Copy link
Copy Markdown
Member

Looks impressive! keep up the good work! ^__^

@AnishGG

AnishGG commented May 17, 2019

Copy link
Copy Markdown
Member Author

Things not supported by lottie:

  1. Animation of polygon/star parameter
  2. Animation of z-depth parameter.
  3. TCB interpolation of color parameter.

Currently, I am devising an algorithm for the first point. I have ideas to make the third point work in lottie format, but I am keeping it for later.
But I have no clue how to deal with the second point(z-depth animation). Any suggestions or ideas on this point are welcome ^_^. So I am leaving this point as of now.
Also I will start working with other layers.
@morevnaproject could you test this layer? Please inform if anything seems off

@morevnaproject

Copy link
Copy Markdown
Member

But I have no clue how to deal with the second point(z-depth animation).

If this is not supported by Lottie, then I suggest just drop this. This is a format limitation that is beyond of our scope.

BTW, it would be nice to keep track of unsupported features in some document. ^__^

@AnishGG

AnishGG commented May 18, 2019

Copy link
Copy Markdown
Member Author

BTW, it would be nice to keep track of unsupported features in some document. ^__^

Sure, I will update the documentation in a day or two.

If this is not supported by Lottie, then I suggest just drop this. This is a format limitation that is beyond of our scope.

Okay, I will leave it for now.
Just thinking out loudly 😛 : If this project goes on well and good, we could even ask lottie developers to add support for some Synfig dedicated features. For example: z-depth animation.

@morevnaproject

Copy link
Copy Markdown
Member

Just thinking out loudly: If this project goes on well and good, we could even ask lottie developers to add support for some Synfig dedicated features. For example: z-depth animation.

Oh, yeah! That would be absolutely awesome!

@AnishGG AnishGG changed the title [WIP] Add lottie-converter plugin for star layer [WIP] Add lottie-converter plugin for below mentioned layers May 18, 2019
@AnishGG

AnishGG commented May 21, 2019

Copy link
Copy Markdown
Member Author

@morevnaproject, Circle layer is now complete.
I am waiting for your reviews on it. ^_^
Now I will get started with the rectangle layer.

@morevnaproject

Copy link
Copy Markdown
Member

I have created a repository for Lottie exporter tests - https://github.com/synfig/synfig-tests-regressions/tree/master/export/lottie

The idea is to automate verification of how exporting works. I am not aiming at "full-featured" test suite. Just simple check if Lottie exporting fails (python error) will be enough. I plan to add this to Travis CI checks. ^__^

@AnishGG

AnishGG commented Aug 10, 2019

Copy link
Copy Markdown
Member Author

I have created a repository for Lottie exporter tests - https://github.com/synfig/synfig-tests-regressions/tree/master/export/lottie

The idea is to automate verification of how exporting works. I am not aiming at "full-featured" test suite. Just simple check if Lottie exporting fails (python error) will be enough. I plan to add this to Travis CI checks. ^__^

This is amazing!
I have a local testing script available to me and somewhere near 25 test files. I generally run these tests locally before pushing a commit. Will see if I can do the same with travis.

@morevnaproject

Copy link
Copy Markdown
Member

@AnishGG

I have a local testing script available to me and somewhere near 25 test files.

Can you please submit them to https://github.com/synfig/synfig-tests-regressions via PR? ^__^

@AnishGG

AnishGG commented Aug 11, 2019

Copy link
Copy Markdown
Member Author

@AnishGG

I have a local testing script available to me and somewhere near 25 test files.

Can you please submit them to https://github.com/synfig/synfig-tests-regressions via PR? ^__^

Yes I will do that shortly.

@AnishGG AnishGG changed the title [WIP] Add lottie-converter plugin for below mentioned layers [GSoC 19] Export Animation for Web: Add lottie-converter plugin Aug 22, 2019
@morevnaproject morevnaproject changed the title [GSoC 19] Export Animation for Web: Add lottie-converter plugin [GSoC 19] Export Animation for Web using Lottie Aug 23, 2019
morevnaproject added a commit that referenced this pull request Aug 23, 2019
Added support for converts:
- Add
- Linear
- Radial Composite
- Scale
- Subtract
- Switch
- Weighted Average
- Bone Link (WIP)

Added support for exported values.

Added support for bones (WIP).
@morevnaproject
morevnaproject merged commit d298820 into synfig:master Aug 23, 2019
@morevnaproject

Copy link
Copy Markdown
Member

@AnishGG Merged into master now. Thank you! ^__^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants