godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Automatically guess the sprite size instead of defaulting to 4×4 in the SpriteFrames editor #5302

Open Proggle opened 2 years ago

Proggle commented 2 years ago

Describe the project you are working on

A 2d game that uses sprite sheets

Describe the problem or limitation you are having in your project

It's a bit annoying to have to enter the x and y framecounts each time I add a spritesheet.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Instead of defaulting to a fixed 4x4 sheet size, Godot should estimate/guess what the correct size is and default to that instead.

Basically, good chance of saving some time and thought on a task developers do fairly frequently, and if the estimate is wrong it's no worse than the status quo.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I have an unoptimized algorithm here

https://github.com/Proggle/godotSpriteSheetFrameCounter/

It does a decent job of guessing. I originally coded it in MATLAB instead of gdscript, and it's a LOT faster in MATLAB, so I'm sure this code can be dramatically improved.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Nah this is user-facing UI, can't improve that with scripts.

Is there a reason why this should be core and not an add-on in the asset library?

This is about streamlining sprite sheet imports. Can't really do that in a library.

Calinou commented 2 years ago

Related to https://github.com/godotengine/godot-proposals/issues/2588 and https://github.com/godotengine/godot-proposals/issues/2060.

Proggle commented 2 years ago

Have updated my algorithm a bit, giving a weight bonuses to perfect rows and columns of transparency, which seems to significantly improve results. I tested it with 80 random spritesheets I had lying around and it guessed correctly on 75 of them, which is probably a good enough hit ratio to be a useful tool.

I think it should be possible to do something similar for tilesets which don't have transparency (especially if we can assume tiles are virtually always square, and often are sized as powers of 2), but that would require a lot more signal processing tools than gdscript has baked-in. Maybe a stretch goal for someone up for a challenge.

nuckynine commented 1 year ago

Even just saving the last values used for the x and y would greatly simplify using one sheet to generate multiple animations.

Calinou commented 1 year ago

Even just saving the last values used for the x and y would greatly simplify using one sheet to generate multiple animations.

This is already being tracked in https://github.com/godotengine/godot-proposals/issues/2588.

DanielSnd commented 8 months ago

Came here because I was about to start a proposal asking for something similar. I'd be happy with a button in the editor to "guess" the number. I've been working with a bunch of spritesheets with different counts and it's been pretty annoying to manually count visually to input the numbers there where it could be done way easier by code.