godotengine / godot-proposals

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

Refactor SkeletonModificationStack2D and SkeletonModifier2D* to Node2Ds #10247

Open beicause opened 3 months ago

beicause commented 3 months ago

Describe the project you are working on

A 2D game with heavy use of 2D skeletons.

Describe the problem or limitation you are having in your project

Current 2D skeleton modifications are resources, which is not a good design and has some bugs (see https://github.com/godotengine/godot/issues?q=is%3Aissue+is%3Aopen+skeleton+modification+2d). And it's not convinent to use or extend them since they are nested resources.

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

As disscussed in https://github.com/godotengine/godot-proposals/issues/4863 and https://github.com/godotengine/godot/pull/71137

In the first place, it was pointed out that the ModificationStack as a resource is out of favor with Godot's design. It should not have an API for IK within the Skeleton class. By separating it from the Skeleton by making it a Node, it may be easier to share settings among multiple Skeletons and prioritize them with animations. At the very least, ModificationStack2D being a Resource is "not make sense" and "needs to be fixed". So, it should still keep being experimental and definitely needs to be ported as a Node in the future.

Refactoring the 2D skeleton modifications to Nodes is expected to fix these bugs above and improve usability, paving the way for future improvements in 2D skeleton modifiers.

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

Remove SkeletonModificationStack2D, implement SkeletonModifier2D that retrieves its Skeleton2D parent and applies modification, like SkeletonModifier3D and PhysicalBoneSimulator3D. And extend it to implement other modifiers such as IK and 2D physical bones.

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

No, this needs lots of work if we start from scratch.

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

Skeleton2D is core.

fire commented 3 months ago

@lyuma @TokageItLab I saw this and thought it would be good to keep on the todo list

TokageItLab commented 3 months ago

I think that SkeletonModificationStack2D cannot be removed during 4.x, as it is probably already used in a good number of projects.

Of course, SkeletonModifier2D can be added, so we will need to work on implementing SkeletonModifier2D to deprecate SkeletonModificationStack2D and removing them in 5.0 sometime in the future.

beicause commented 3 months ago

I have already made an attempt to add 2d skeleton modifier in https://github.com/beicause/godot/commit/e20709b1d737117278eae010d710dca1a8db050c and ported FABR IK and jiggle. Perhaps physical bone and jiggle can be achieved without the need for modifiers. There is a workaround by using RemoteTransform2D to push the transform of physical body to the corresponding bone.

Ughuuu commented 3 days ago

Impressive, are willing to open a PR with this. Either way I might be interested to help on this.