CoaTools import

Hi guys!
I wonder, if someone is interested to write a script for importing JSON format generated by COA Tools?

Short explanation:

COA Tools is used to export layered artwork from Krita/GIMP to separate (cropped) PNG images + it creates a JSON file, which contains information how those layers are located relatively to each other.

The information from JSON file allows to automatically assemble those exported PNGs in Blender/Godot or other software.

We need this script as we want it to use during production of Pepper&Carrot Episode 4.
Help is much appreciated!

@Glax @bazza @BobSynfig @veermetri05

1 Like

I would like to work on this, but I am not sure if importer plugins are supported in stable version (1.4.2). This might be possible in development version (1.5.1). I will try to get the development version.

Will you be using development version ?

Till when should I complete the script ? (any deadline ?)

2 Likes

Thank you!

Yes, we are using latest development version. :slight_smile:

It would be cool to have something by Monday (January 10th). :slight_smile:

Hi @veermetri05! How is it going, any news? :slight_smile:

I am trying to understand the JSON file, some fields like tiles_x, tiles_y, children, frame_index, type, doesn’t seem useful, or are they ?

One thing I noticed is, if more than one image have same z-index we should put them in Switch Group Layer. I will write a simple script so that it can import with necessary information and will ignore the things that I didn’t understand.

@KonstantinDmitriev if you have anything exported to the JSON format and files, that you would use please provide it here so that I can work with real examples.

1 Like

I have examples from Pepper & Carrot project, will send them soon.
In the meantime here are some test files from Krita Batch Exporter (which is also exports to CoaTools) - Test files for COATools Export · Issue #44 · GDQuest/krita-batch-exporter · GitHub

Quick example from Pepper&Carrot - pepper-ep3-004.zip

I am not sure about tiles_x and tiles_y, never used them…

Probably it is for spritesheet.
tile x and tile y would be the sprite size and frame index the sprite index in the sheet.

Yeah, I saw the video (Devlog by the developer), I didn’t know anything about it, I have worked on script.

I am having problem with Python, whenever I run any plugin I get this error
(Synfig 1.5.1, Windows 11, I think this happens with development version)
image

I have setup the SYNFIG_PYTHON_BINARY path variable. And then this error started.
(I have set to python3 exe)

I will test this later on Ubuntu VM.

@KonstantinDmitriev I have wrote this script, hopefully it works (still need a lot of work), this can now only import images and arranges them on their position. I have decided to put the image in single groups, and have enabled lock selection by default.
The control handles are at the top left of the sprite (image), I will work on that so that the control duck would be on the center.

coaTools.zip (1.7 KB)

I tested it on my Ubuntu VM, one thing I understood is importer plugin don’t import but open files from other format, so initially I thought the data will be appended in already existing which is not true, so now some changes need to be done in case of canvas view-box.

One important thing I forgot to mention is that my plugin requires pillow package in python, I don’t know how to package the program to have all the dependency, sorry for that

Also it also have some problems with path which I fixed, if any problems please report I will fix as soon as possible.
coaTools(pathFix).zip (2.3 KB)

3 Likes

Hi @veermetri05! Thank you so much! For some reason I didn’t received notifications about the replies in this topic. :sweat:

Will test it and report back. Thank you so much!

I have tested and it works! -

It even correctly handled Cyrillic characters in my test file. :slight_smile:

Though, I found one issue, which turned to be related with tile_x and tile_y parameters.
Here is a sample file - 005.zip (21.7 KB)
It is imported like this -

I figured out that importer should split the image into tiles and put the tile pieces into switch group.

That’s all so far. Thank you so much for the great work!

2 Likes

I’ve just found one more issue, the layers are stacked in the wrong order when importing this file - 001.zip (2.3 MB)

Here is a video demonstrating the problem -

1 Like

I put all the layers in a list, so that I can reverse it, but stupidly I just forgot to reverse the list.

coaTools(reverseListFix).zip (2.2 KB)

I will take a look into this and will soon post a solution, seems a little difficult, like where should we store the spliced images ? Or maybe not split the images at all but create a rectangular revealing mask and duplicate the layer n times and mask the layer. Duplicating the layer seems good, and not hard, I will go by this approach
1.duplicate the layer based on the tiles
2.Create rectangular revealing mask around each tile
3.Put them in a switch layer with proper positioning.

1 Like

Yes, I think this will be good solution!

Thank you! :slight_smile:

@veermetri05
I still have strange situation with order of layers.

Here are 2 sample CoaTools scenes for import:

Both files are imported into Blender correctly (both have correct layer order) -

…but here is how they are imported into Synfig with the latest version of the plugin (one file imported with correct layer order, other file is imported reversed) -

I guess, the layer order works somehow different, maybe it depends on order of items in JSON file?

Just in case if you need, here I am attaching code of plugin that I used for importing in Blender - coa_tools.zip (593.8 KB)

Thanks for detailed explanations.
I figured out why this occurs, I have to reorder them based on the z parameter and then reverse them.

coaTools.zip (2.2 KB)

I still need to implement the tiles.

They have provided the z parameter in JSON, which I didn’t previously consider.

JSON does preserve the order, but the exporter work different maybe, the Krita exporter might export in correct format, while GIMP exporter might not do so, that’s why they have the z parameter.

1 Like

Great, the order issue is fixed now! Thank you!

I suggest to create a PR on GitHub to include this plugin into Synfig. Can you do that, please?

Hi @veermetri05 ! How are you? If you need any help with preparing the PR - let me know, I will be happy to assist. :slight_smile: