Defold now has TexturePacker support

Manual: TexturePacker documentation
GitHub: GitHub - defold/extension-texturepacker: Adds support for the TexturePacker atlas format

We have now added support for packed atlases, via the TexturePacker tool.

Packed atlases refers to the images being tightly packed, using polygonal shapes, in order to fit more images into a single texture page. There are several benefits to this.

  • Less overdraw with empty texels (via polygonal shapes)
  • Smaller memory footprint on GPU
  • Smaller download sizes

We have introduced two new file formats:

  • .tpinfo: The data describing the image layouts
  • .tpatlas: The data describing the flipbook animations in an atlas

Extension

This is implemented as an editor/pipeline extension (i.e. not runtime), and you’ll need to add the extension to the dependencies in game.project.

As usual, pick the latest release from the releases pages.

TexturePacker setup

To keep setup information in one place, we’ll refer to the extension manual on how to set this up.

Data format

While we used TexturePacker as a base implementation, we also intended these new data formats to be used by potential other exporters.

The formats are defined text (using the Protobuf format), and you can find the definitions (.proto) here.

Using these formats, you can write an exporter from other tools, or write your own scripts to generate a packed atlas.

Future

While this support was a heavily requested feature, we realize not everyone can afford a TexturePacker license. So we plan to make similar functionality available to our users within our own ecosystem.
We are currently doing experiments along this route and we hope to do some testing this year.

33 Likes

Great to see this! Will help a ton when optimization really matters!

5 Likes

I believe I mentioned this before but I have a modified version of free-texure-packer that works well. This is basically a trimmed down version of TP

5 Likes

I am Andreas from CodeAndWeb, the Developers of TexturePacker.

I absolutely love that you’ve integrated the support for our Polygon Packer. This is really a huge advantage over rectangular packed sprite sheets - both in terms of sprite sheet size (memory usage) and performance. :smiley:

We decided to integrate the exporter into TexturePacker directly, so that it’ll works out of the box with the next update!

About affording TexturePacker:

  • Pay once and use it forever - no subscription. The license contains updates for 1 year, after that you can continue to use the latest release within that period - or get an update license.
  • Free support: Send us a mail and we’ll help you with all TexturePacker related problems.
  • We offer a 50% discount for a single user license to independent developers - with this, you can get a license for less than 23$ or 25€.

We keep on improving it with new features and bug fixes - since 14 years! Many users bought the tool a long time ago and still use it after years.

19 Likes

I’ve just uploaded TexturePacker 7.3.0 - it now contains the Defold exporter.

No need for manual installation of the exporter!

Some hints for all users:

  • The default packing mode is set to MaxRects - this is a fast packing algorithm. The sprites are all represented as polygons but the layout is rectangle based.
  • If you want to further reduce the sprite sheet size, set Layout → Algorithm = Polygon. It’s a bit slower but usually results in better packing.

@Mathias_Westerdahl You are enforcing power-of-2 sized textures. Is this really needed? Or would a multiple of 8 suffice - this should work on all modern devices and allow all kinds of hardware compression.

11 Likes

The power-of-two is an old requirement, and I don’t think any of our platforms actually require it anymore.
We will have to investigate and test a bit before removing that constraint though.
Perhaps better to do it later on, when we’ll add pivot support as well.

7 Likes

Ok - perfect. Let me know when you want to do that. You can contact me directly at support at codeandweb.com . I can then directly integrate the updated exporter.

2 Likes

There seems to be some issues with importing atlas exported in MaxRects mode. On the screenshot you can see that some trim polygons didn’t match the images, maybe not rotated 90 degrees or something like that.

3 Likes

Is it rendering in the engine ok, or is it wrong there as well?

As far as I can see both in the editor and in runtime.

Here you can see how the first sprite in the animation is marked up incorrectly.


2024-04-26_13-19-15

With Polygon algorithm all seems correct:

3 Likes

Then I wonder if it’s due to the exprter itswlf.
Would it be possible to share the .tps project and images with me?

2 Likes

Also, which trim modes are supported?
I see trim mode trim does not any affect to viewport, just rendering empty space instead a sprite.

and only polygon outline trim mode is workable:

done

2 Likes

I guess there’s a difference in the TP exporter when the trim mode is used. I would have thought it would generate a polygon anyways. But I’ll debug some more to see what I can find out.

1 Like

I have 2 PR’s coming up for the rotation issue:

I also added a ticket for adding box packing (Trim mode):

4 Likes

I have pushed a fix to the extension-texturepacker, and also to our dev branch:

If you can help verify the fix, we should be able to move that PR into a hotfix for 1.8.0

2 Likes

Unfortunately I’m not able to test the changes, maybe I’m getting something plugged in wrong.
I downloaded 1.8.1 version of Defold. Attached to the project https://github.com/defold/extension-texturepacker/archive/refs/heads/main.zip instead of version 1.0.
Installed a custom exporter in Texture Packer. But I’m not sure if this is the correct version. The framework menu shows one version of Defold, (could be an embedded version?).

Defold:

Yeah, it might be the embedded version in TP.
When exporting, the “.tpinfo” file should contain a new version number “1.1”.
You could try temporarily moving the embedded exporter in the TP installation?

I tried it. The polygons have changed, but there are still shifts relative to the original

2 Likes

Thanks for testing, then I have some more work to do :thinking: