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

Minimum distance of TwoBoneIK sometimes leads to disappearence of bones #4

Closed
pwab opened this issue Sep 13, 2020 · 9 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@pwab
Copy link

pwab commented Sep 13, 2020

I'm not yet sure if the title is correct but I encountered a strange thing where the TwoBoneIK somehow hides the bones if no pose solution can be found and the minimum distance is set to default (which is 6). It looks like that:

VdyEdXLY4Y

Here you can see two TwoBoneIKs trying to reach the target. When getting near the basis the bones disappear (in game and in editor). This can only be reverted by deactivating the SkeletonModification (enabled = off).

Has this something to do with the minimum_distance? Because if I set it to for example 100 the TwoBoneIK is working fine and stops the chain at the distance of 100.


Apart from that: Would it be possible to add a maximum_distance feature working like the minimum one?

@pwab pwab mentioned this issue Sep 13, 2020
21 tasks
@TwistedTwigleg TwistedTwigleg self-assigned this Sep 14, 2020
@TwistedTwigleg TwistedTwigleg added the bug Something isn't working label Sep 14, 2020
@TwistedTwigleg
Copy link
Owner

Just copying my reply from #2 over here, for anyone who hasn't read it yet:

... is a bug with the TwoBoneIK solver. I have a hunch that it occurs when the two bones in the solver are folded into each other completely. I will need to debug this and see if I can fix it.

Also, it probably is related to the minimum distance. When the minimum distance is too small, the bones can fold into themselves and I believe that is causing the issue. One potential solution would be setting the minimum distance to a minimum value based on the lengths of the bones, but ideally I should find a fix that makes it where the issue does not occur regardless of the minimum distance.

Apart from that: Would it be possible to add a maximum_distance feature working like the minimum one?

Sure, it shouldn't be too difficult to add. I'll add a maximum distance property when I'm working on the TwoBoneIK fix!

@pwab
Copy link
Author

pwab commented Sep 14, 2020

One potential solution would be setting the minimum distance to a minimum value based on the lengths of the bones [...]

Well that sounds reasonable. Because there are no solutions below the (bone_length_1 - bone_length_2)-distance. So setting the min value of the minimum_distance to the lowest possible (always updated when the bone lengths have changed) should do the job.
But I don't have taken a look into the code behind so I'm just guessing.

Only one point to add. The solution should be tested with those three configurations:

  • bone_length_1 > bone_length_2
  • bone_length_1 < bone_length_2
  • bone_length_1 == bone_length_2

I could create a test_scene for that.

I'll add a maximum distance property when I'm working on the TwoBoneIK fix!

👌😃

@pwab
Copy link
Author

pwab commented Sep 15, 2020

I was curious how the TwoBoneIK behaves in 3D. At least in the test scene nothing disappears when the bones overlap:

Test_07_TwoBoneIk

@TwistedTwigleg
Copy link
Owner

Interesting. I wonder if the reason is that in 3D it has the benefit of having the pole node to help define the bend axis. That might help give a clue as to why the TwoBoneIK in 2D has the disappearing issue... Something to look into at any rate. Thanks for letting me know! 👍

@pwab
Copy link
Author

pwab commented Sep 16, 2020

I wonder if the reason is that in 3D it has the benefit of having the pole node to help define the bend axis.

At least it adds lots of stability to the result of the pose calculation:

d5ATEg9ZQ6

(Just one note: I changed to auto calculated bone lengths - not that this has changed anything as far as I'm aware of.)

@TwistedTwigleg
Copy link
Owner

I just recently pushed a commit that should fix the issue. The issue turned out to be that the acos function was sometimes returning NaN when the joints were too close together. I added a condition to fix this and now it should work regardless of the minimum distance.

@pwab
Copy link
Author

pwab commented Oct 10, 2020

Issue seems fixed. I tried with different samples and nothing disappeared. 👍


Only thing I've noticed while testing is a lack of some kind of visible border (for debugging) when using the minimum or maximum distance. Something like the circle that is shown when using limited angles which should have the radius of the used parameters.

@pwab pwab closed this as completed Oct 10, 2020
@TwistedTwigleg
Copy link
Owner

TwistedTwigleg commented Oct 11, 2020

I’ll see about adding a line or something for debugging to show the minimum and maximum distances when I rebase with master.

Or maybe a circle or pair of circles? Hmm, will have to experiment!

@pwab
Copy link
Author

pwab commented Oct 11, 2020

A pair of circles seem like a good fit. But it should be distinct from the angle constraints circle. Not easy to get the visuals right here.

Maybe also an Editor switch could be introduced for switching the visibility of the lines on and off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants