Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture altas import breaking sometimes - Cutting off sprite #41414

Closed
Giwayume opened this issue Aug 21, 2020 · 10 comments · Fixed by #55095
Closed

Texture altas import breaking sometimes - Cutting off sprite #41414

Giwayume opened this issue Aug 21, 2020 · 10 comments · Fixed by #55095

Comments

@Giwayume
Copy link
Contributor

Giwayume commented Aug 21, 2020

Godot version:
3.2.3.rc3

OS/device including version:
Windows 7

Issue description:
I have a specific set of images where changing their import settings to texture atlas causes them to be cut off in the atlas.

Steps to reproduce:
Check the reproduction project. All I did was select all the images and re-import them as an atlas file. Import mode doesn't make a difference. The result looks like this where half the sprite is cut off:

atlas

Minimal reproduction project:
atlas-bug.zip

@Rubonnek
Copy link
Member

Rubonnek commented Aug 21, 2020

@Giwayume please include proper steps on how to reproduce the issue. We can't help otherwise.

@Giwayume
Copy link
Contributor Author

Giwayume commented Aug 21, 2020

@Rubonnek
I have provided the steps. Import the images in the provided minimal production project as a single TextureAtlas. It breaks. That's all the steps. Did you download the reproduction project?

I'm not going to walk through creating the images, that is infeasible. All you need to know is I've provided you sample images that cause the TextureAtlas to not function properly.

Is there something that isn't clear about creating a TextureAtlas from images? I wouldn't know how to go into more detail on this, short of pointing you to a tutorial.

@Rubonnek
Copy link
Member

@Giwayume you are right, never mind -- I thought the instructions were cut off somewhere because the images under the die and idle folders are shown already malformed through the Editor and I thought that perhaps a step was missing. I wasn't aware Godot strictly uses the corresponding .stex file after importing several images as a TextureAtlas either -- I'm not familiar how the import process works under the hood.

I wasn't able to reproduce this exact problem, but after deleting all the .import files, as well as res://.import from the provided project, and attempting to create a new TextureAtlas from a couple of the these images I'm getting a empty image instead on a 3.2 build at commit 9bf5a0b which is definitely a bug too.

@Giwayume
Copy link
Contributor Author

attempting to create a new TextureAtlas from a couple of the these images I'm getting a empty image instead on a 3.2 build at commit 9bf5a0b which is definitely a bug too.

I would assume if you selected all of the images and imported them into the atlas you should see the same generated atlas image I uploaded above?

@Rubonnek
Copy link
Member

Rubonnek commented Aug 21, 2020

I would assume if you selected all of the images and imported them into the atlas you should see the same generated atlas image I uploaded above?

I also attempted attempted that and I still got a fully transparent atlas instead. On my end it seems that for any set of images I try, I will still get an empty one but of correct size. I'm not sure what's going on here, but I'm also running Godot in Linux for what it's worth.

@Calinou
Copy link
Member

Calinou commented Nov 17, 2021

@Giwayume Did you find a solution to this issue, or can you still reproduce this on 3.4?

@Giwayume
Copy link
Contributor Author

Oh, I assumed at some point it started working because I have gotten past this point in my project, so I closed it. But no, looks like I never set up the atlas for this character. It's still broken in 3.4.

This is especially weird, since the atlas works great for literally every other sprite I've created.

@Giwayume Giwayume reopened this Nov 17, 2021
@Calinou Calinou changed the title Texture altas import breaking sometimes - Cutting off sprite - 3.2.3.rc3 Texture altas import breaking sometimes - Cutting off sprite Nov 17, 2021
@Rubonnek
Copy link
Member

Rubonnek commented Nov 17, 2021

For what is worth, and for future reference to anyone stumbling upon this issue, as a workaround I wrote an EditorImportPlugin for GDX Texture Packer GUI some time ago.

The workflow to get the AtlasTextures would be a bit different since you'd have to first build the atlas with the GDX Texture Packer instead, then drop the spritesheet along with the associated .atlas file into the Godot project so that the importer can generate a set of AtlasTexture resources you can use.

I've been meaning to document the whole process in the plugin repository for a while but never got around to it. Maybe I will soon.

@Giwayume
Copy link
Contributor Author

My first thought is maybe Image::get_used_rect() is failing somehow, but I recreated the bounding boxes in GIMP using the numbers it outputs during (Re)import and they're correct.

image

image

Actually now that I look at it, the atlas region and margin appear to be correct if the atlas image itself didn't cut off the sprite.

image

This must be a problem when the importer draws the image to the atlas itself. We can assume the image data in memory is correct because it generated a good bounding box.

@Giwayume
Copy link
Contributor Author

Giwayume commented Nov 18, 2021

Ok I don't fully understand this code but I kinda see the problem.

https://github.com/godotengine/godot/blob/3.4/editor/import/resource_importer_texture_atlas.cpp#L134

In this line, "xf" starts at the left margin in the original sprite frame (source) image. Which in my case is a 512x512 image with the eyeball in the middle and a lot of empty space around it. This 512x512 dimension is set to the src_width and src_height variables respectively.

image

The variables width and height in this function refer to the final atlas texture's width and height, which is 256x252 in this case. So the entire generated texture atlas (256x252) is smaller than a single source animation frame (512x512). That exposes this bug.

It looks like in this loop it's limiting by the generated atlas's width when it's actually looping through the source image's pixels.

for (int xi = (xf > 0 ? int(xf) : 0); xi < (xt < width ? xt : width - 1); xi++) {

So instead it should limit by the source image's width.

for (int xi = (xf > 0 ? int(xf) : 0); xi < (xt < src_width ? xt : src_width - 1); xi++) {

This indeed produces the correct results. And it makes sense why the images were getting cut off before.

image

I don't yet know the full implications of changing this line, though. The code doesn't seem to crash when I regenerate another atlas where the atlas size is much larger than a source animation frame size.

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

Successfully merging a pull request may close this issue.

4 participants