Trim (crop) alpha for sprites in atlases (DEF-2858)

I wanted to make this feature request and found this post:

I am fully agree with @Edgaronfo - would be great to have checkbox in atlas, that crop empty alpha for sprites but save position information (this feature is super useful for frame by frame animations)

NOTE: This feature is on GitHub as https://github.com/defold/defold/issues/3629

14 Likes

I agree that it would be very useful. I’ve created a ticket for this: DEF-2858

3 Likes

Smart trim good feature! yes please.

2 Likes

It sounds quite good on paper but is a little harder to do in a userfriendly way.
Take the running man above as an example. If just trimming everything you don’t control of the center of animation. Unless the legs are equally spread apart (right and left) from the body the animation you will see is gonna be jittery as the body moves back and forth. This assuming that the anchor of the sprite is always in the middle of the sprite image.

So having this feature would need a system of setting anchor points for each image in the atlas as well (or something similar).
Also there are many times where I dont want to trim an image as the empty space is intentional and crucial to me. This means we would need a system to tag which ones that can be trimmed and which not. Any suggestion in how this would be solved in a good user friendly way? ( and that justify the engine work instead of trimming the png’s yourself )

Edit: Ah jumped on the gun a little bit. Storing position of the graphics (or trim info) could be a way to do it.

2 Likes

My ideal tool for texture atlases is TexturePacker.
I think, if it will be made the same way - it would be great.
Texture packer one of the most popular tool.

Texture Packer save size of trimmed alpha and it used when calculating pivot point. That mean that pivot point calculated in center of original image, and then images are trimmed. but they are still using original image pivot (it can be out of bounds the new trimmed image)

In most case this items can be in different atlases. One with trimmed alpha and other where this option turned off.

All this functions already implemented in texturepacker. I already asked about realisation of supporting atlases from the Texture Packer here and @stormarchitextor ask to support here

3 Likes

We really need this feature.
We have many similar animations:

2 Likes

We need too. We used many similar anims in project.

1 Like

How did you make those animations? They would work better as a spine scene animation probably.

Flipbook - it not ptoblem make this animation.

1 Like

Yes please! Good feature! :hugs:

2 Likes

“Polygon sprites” would be even better!

Would also be cool if there could be a “remove quad” on 9 sliced sprites

4 Likes

+1. Need this feature. It will save a lot of space for flipbook animations.

We use tons of graphics with animations. Absolutely critical feature for us.
That was really disappointing to realize that 2D engine doesn’t have a atlas sprite trimming or Texture Packer support.

Any news on how soon it might be added?

1 Like

I actually wrote a Python script to do this for us. It works, but it’s sort of hackish. For example, you can’t preview animations in the editor anymore and you have to have some extra game object nesting.

It would be great to have official support for this.

2 Likes

Thanks! Hope we’ll figure something out. Really don’t wanna get back to Unity.
But, sirsly, no trimming?.. That was shocking, since we already had great impressions on Defold.

As for any news, we’ve just completed the design for the first part (of three) in this feature.
The three parts:

  • Generate convex hulls for sprites (addresses overdraw)
  • Pack using tight rectangles (addresses texture utilisation)
  • TexturePacker support (which is dependent on the first part)

The first part is mostly done, but was done as a “happy path” to try things out. It needs cleanup, and verification. It’s currently in the sprint, but I don’t think it will be done until the 1.2.163 release.

After that, I think starting with the right rect packing will come directly after.

11 Likes

Mathias, thank you for the news!

Just a tiny feedback. We mostly used Texture Packer as a replacement for internal Unity atlases. Defold atlas interface looks great as far we saw it, so adding a trimming algorithm might also replace all that TPscript - > packing -> import process. So in our experience, there’s no urgent need for Texture Packer support if internal packer works well.

Still TP can make some complex atlas packs like diffuse/normal/masks with exact sprite placements.

Thanks again! =)

3 Likes

A few versions have passed. Is the 2nd phase of the trim features still in the plan? Getting an optimized atlas is definitely something useful.

2 Likes

Yes we still want this. But the next thing for us to look into once we’ve shipped an updated Spine extension is the whole vsync+frame cap mess.

7 Likes

That’s perfect! I’m getting one of the new Macbook Pro with the promotion display. I’ll be really curious to see how it behaves (and also will be available if you need to test things around)

2 Likes