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

Modification stack to nodes #63588

Closed
wants to merge 2 commits into from

Conversation

fire
Copy link
Member

@fire fire commented Jul 28, 2022

@Calinou Calinou added this to the 4.0 milestone Jul 28, 2022
@fire fire force-pushed the modification-stack-to-nodes branch 3 times, most recently from 0eabe5d to 878a688 Compare July 28, 2022 22:16
scene/3d/skeleton_modification_3d_fabrik.cpp Outdated Show resolved Hide resolved
core/object/worker_thread_pool.cpp Outdated Show resolved Hide resolved
scene/3d/skeleton_modification_3d.h Outdated Show resolved Hide resolved
scene/2d/skeleton_modification_2d.h Outdated Show resolved Hide resolved
@akien-mga
Copy link
Member

CC @TwistedTwigleg

@fire
Copy link
Member Author

fire commented Aug 23, 2022

@lyuma is working on the pr, so the current code isn't accurate. The proposal is still broadly accurate.

@TwistedTwigleg
Copy link
Contributor

TwistedTwigleg commented Aug 25, 2022

I don’t have the time to review the PR, but I agree with the general change (not that my agreement is needed - it’s all Godot code now 🙂 ). Moving it to nodes is MUCH closer to my original GSoC proposal and based on the work I did for my IK plugin for Godot 3.0, it is much more stable and easier to maintain as well. It should also make the workflow less confusing and reduce the number of clicks to get something working on screen.

Now just need to make those Bone3D nodes and have the modification nodes use the Bone3D nodes to fully fit the original proposal 😉

In all seriousness though - I think the general change is good. It will make the modification stack completely unnecessary and I think that is where a lot of the pain came from. It also will untie it from the Skeleton3D node code, making the modifications standalone.

Also, and I know I do not say this enough: Huge thanks to everyone who has continued to work on the IK stuff! I haven’t had any time and energy at all to work on much in spare time as of late and so I’m glad and thankful that others have continued to work on it and improve it.

@fire
Copy link
Member Author

fire commented Sep 1, 2022

The git branches for this work is at https://github.com/lyuma/godot/tree/modification-stack-to-nodes-wip-full and https://github.com/lyuma/godot/tree/modification-stack-to-nodes-wip

@lyuma lyuma force-pushed the modification-stack-to-nodes branch from e109244 to 28012bb Compare September 4, 2022 02:32
@lyuma
Copy link
Contributor

lyuma commented Sep 4, 2022

@TwistedTwigleg I've updated this PR with a mostly feature-complete PR. This is now a two-commit PR. The reason is I don't know how to preserve the rename metadata if I make it all in one commit since so much code was rewritten, so it makes review easier to do it this way.

I haven't tested anything at all. There is likely a lot that could have broken, but the existing implementation already has many features broken during alpha.

As a future PR, there are still some methods that I would like to clean up in BoneAttachment3D related to update order and the pose_updated notification. I also find the external_skeleton feature to be confusing.

Regarding what is in this update... I added documentation for all the new and renamed methods/members.

@TokageItLab I addressed the biggest feedback items.
I removed the following functions:

    void clear_bones_local_pose_override();
    Transform3D get_bone_local_pose_override(int p_bone) const;
    void set_bone_local_pose_override(int p_bone, const Transform3D &p_pose, real_t p_amount, bool p_persistent = false);

    void update_bone_rest_forward_vector(int p_bone, bool p_force_update = false);
    void update_bone_rest_forward_axis(int p_bone, bool p_force_update = false);
    Vector3 get_bone_axis_forward_vector(int p_bone);
    int get_bone_axis_forward_enum(int p_bone);

    Basis global_pose_z_forward_to_bone_forward(int p_bone_idx, Basis p_basis);

    // Modifications
#ifndef _3D_DISABLED
    Ref<SkeletonModificationStack3D> get_modification_stack();
    void set_modification_stack(Ref<SkeletonModificationStack3D> p_stack);
    void execute_modifications(real_t p_delta, int p_execution_mode);
#endif // _3D_DISABLED

get_bone_rest_forward_vector and global_pose_z_forward_to_bone_forward were migrated to SkeletonModification3D as helper functions.

I have made all calculations strictly based on get_bone_pose and set_bone_pose. Modification nodes do not depend on skeleton update or dirty and ignore global pose override.

I have removed bone_property_suffixes and used a const_cast to permit calling into GDScript from _validate_property. I would rather _validate_property be exposed the same way as get_property_list and others, but this should be good enough for now.

@lyuma lyuma force-pushed the modification-stack-to-nodes branch from 28012bb to 71756ad Compare September 4, 2022 02:52
@lyuma lyuma marked this pull request as ready for review September 4, 2022 02:53
@lyuma lyuma requested a review from a team as a code owner September 4, 2022 02:53
@lyuma lyuma requested review from a team as code owners September 4, 2022 02:53
@lyuma lyuma force-pushed the modification-stack-to-nodes branch 2 times, most recently from c979e91 to 62d8e79 Compare September 4, 2022 03:07
@lyuma lyuma force-pushed the modification-stack-to-nodes branch from c398e5e to a886e81 Compare September 6, 2022 16:01
@lyuma lyuma marked this pull request as draft September 12, 2022 21:44
@lyuma
Copy link
Contributor

lyuma commented Sep 13, 2022

I have decided to mark this as draft so that we can focus on other more pressing priorities for 4.0 beta, and fix some of the design issues with this that came up during testing.

For now, I will submit a new PR that marks all of the existing SkeletonModification resources and SkeletonModificationStack as Deprecated (planned to move to modification nodes) and unexposes some skeleton APIs only being used by the modifications such as "global_pose_z_forward_to_bone_forward" so it will be easier to remove

@fire
Copy link
Member Author

fire commented Sep 13, 2022

We're also marking SkeletonIK to Deprecated too?

@ghost
Copy link

ghost commented Sep 15, 2022

please add this issue too #54891

@Riteo
Copy link
Contributor

Riteo commented Oct 15, 2022

What's the status of this PR? It'd be great to see this before 4.0 stable if this level of API breaking is accepted. Right now IK is unusable.

Copy link
Contributor

@RedMser RedMser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some initial testing (after fixing merge conflicts) and the new system is a lot more intuitive to use and set up. Great work!

I only tested FABRIK in 3D so far, but it seems like the math is no longer correct, as the target node is not being reached anymore:
22-10-18_00-30-50_godot windows editor dev x86_64_Warbler

It looks like the algorithm results in global transform per bone, but is applied in local space (see how each bone rotates by 90°):
image

Let me know if you need a simple repro project.

if (!_cache_bone(fabrik_data_chain[i].bone_idx, fabrik_data_chain[i].bone_name)) {
ret.append(vformat("Joint %d bone %s was not found.", i, fabrik_data_chain[i].bone_name));
}
if (!_cache_target(fabrik_data_chain[i].tip_cache, fabrik_data_chain[i].tip_node, fabrik_data_chain[i].tip_bone)) {
Copy link
Contributor

@RedMser RedMser Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having any tip node/bone selected should not show a warning if automatic length calculation is successful.

origin_global_pose = origin_global_pose_trans;

final_joint_idx = fabrik_data_chain.size() - 1;
real_t target_distance = fabrik_transforms[final_joint_idx].origin.distance_to(target_global_pose.origin);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When creating a new FABRIK3D node, assigning skeleton, then assigning target node, I get following error + a crash on this line:

ERROR: Index p_index = 4294967295 is out of bounds (count = 0).
   at: LocalVector<struct Transform3D,unsigned int,0,0>::operator [] (B:\Godot\core/templates/local_vector.h:168)
[1] SkeletonModification3DFABRIK::execute (B:\Godot\scene\3d\skeleton_modification_3d_fabrik.cpp:549)

@lufog
Copy link
Contributor

lufog commented Dec 18, 2022

I guess this will close #65265 unless it's an inspector-specific bug.

(funny, on first attempt to send a message, I got the error You can't comment at this time., and on second attempt it was sent twice)

@lyuma
Copy link
Contributor

lyuma commented Jan 14, 2023

I have repurposed this PR into #71137 and removed SkeletonModificationStack3D, so we will not port to nodes in time for 4.0.

2D modification stack works and will not be removed for now.

3D modification stack will hopefully return in a future 4.x in a different form. Stay tuned.

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

Successfully merging this pull request may close these issues.

Remove SkeletonModificationStack and convert IK solvers to nodes.
10 participants