Lottie to Synfig conversion script

Not sure if it’s of interest, but I wrote a script that converts from lottie json into synfig animations.

The code is https://gitlab.com/mattia.basaglia/tgs/ (the script itself is bin/lottie2sif.py)

It doesn’t support all the features in the format but it’s enough to be usable.

Kind of interesting that using my scripts to convert svg to lottie and from lottie to synfig for certain things gives a better result than synfig’s built in svg importer.

3 Likes

That’s absolutely cool, thank you!

It would be nice to implement some changes in Synfig code to allow open Lottie files simply via File -> Open (and internally use this python script). :slight_smile:

Ideally, it would be nice to have a system of python plugins, which allow to handle import/export into various formats. This

It worth to investigate how Inkscape handles that…

1 Like

In the past I’ve used boost::python to embed scripts in my applications, it has a smart system to link C++ classes and objects to the python scripts allowing for communication between the python script and the C++ app.

For importing files, probably the best option though is just to have the script to generate the sif xml as a string or a temporary file.
Linking the plugin with an open file dialog shouldn’t be too hard as long as there’s a way to add metadata to the plugin that tells which file extensions it can load.

1 Like

I’ve improved a bit my converter, now it converts simple shapes like ellipses, rects, and stars into blines so they show up correctly in synfig.

1 Like

Yes, that will work. Actually, this is how Synfig’s SVG import module works - synfig/synfig-core/src/modules/mod_svg/svg_parser.cpp at master · synfig/synfig · GitHub with only difference it is written in C++).

In perfect case it would be nice to have some GUI settings for import/export (i.e for Lottie export we might want some options at some point).

In simplest implementation it is possible to write a synfig-core module in C++ (like mod_svg linked above), which calls a Python script. For having GUI options it will require to add code into synfig-studio, which actually interferes with a concept of “module in synfig-core”.

So, it’s best to think how to organize import/export (conversion) routines in synfig-studio (synfig-core doesn’t needs it anyway).

This is just I am thinking aloud. ^___^

btw, does the sif file format support specifying bezier tangents in cartesian coordinates?

Currently I’m converting them from cartesian (the way they are stored in lottie) to polar, but that creates some artefacts on animated regions, when the value from one waypoint is close to 180 degrees and the value on the next waypoint becomes -180, making that tangent spin around like crazy.

So, as part of the same project, I made a script that allows to convert between the file formats my framework supports.

I can now make a direct comparison between loading svg into synfig.
From the same SVG file, on the left is the file as imported by synfig, on the right my conversion script

Screenshot_20190718_143942

Colors are a bit different, I think the default importer assumes I have a gamma of 2.2, while my converter keeps RGB values the same, so it works with a gamma near 1.

I also tried with inkscape’s sif export but it causes inkscape to crash and the generated sif file is invalid (some issue about a blurred layer).

Some issues I’ve found with synfig’s built-in SVG importer:

  • ellipses are missing, and paths using ellipse arcs are broken
    • I assume this is because synfig doesn’t properly convert ellipses to bezier
  • some paths have the wrong bezier tangents
  • some lines have the wrong width
  • inkscape layer names aren’t preserved (not part of SVG proper but a bit unfortunate)
3 Likes

Another update, I’ve added support for approximating easing values.

I also have experimented with inkscape extensions, looks like for import/export they have an XML which defines the UI for a dialog where you can define extra options for the file format, then passes them to a script on the command line, for both import and export the script is given a file name on the command line and outputs the result to stdout.

4 Likes

This thread is about importing lottie into synfig, looks like you’re having issues with the export instead?
Lottie export is being discussed here: GSOC-2019::Export Animation for Web

Yes I think I confused the post, thanks.