Joint world position is incorrect

Hello Guys,
I’m facing an issue with fetching a given Joint’s node world position.
The process is as follows:

  1. I have a model with some joints (a mixamo model)
  2. I would like to place some geometry (for example a Box) in a given Joint (for example: “mixamorig:Head”) world position
  3. I get the main Spatial - OK
  4. Search for the specified Joint’s node in that Spatial - OK
  5. Get the joint’s world translation:
getWorldTranslation()
  1. The vector3f for the world translation is wrong
  2. Do the same again (steps 3-5) - now I get the correct world translation

so to summarize - first time fetching a given joint’s world translation is wrong. From the seconds time and on I’m getting the correct values.

It looks to like a bug…
WDYT?
Thanks!

Code?

This is how I get the joint:

SkinningControl skinningControl = this.skinningControlNode.getControl(SkinningControl.class);
            if (skinningControl != null) {
                Node n= skinningControl.getAttachmentsNode(jointName);
                return n;

            }

It gets the correct Node (I see by the name)
Then when calling getWorldTranslation() for that joint’s node you get some value
If you doing it again, you get another value - the correct value

I will try to write a class with only the relevant code to reproduce the problem

Like literally:

n.getWorldTranslation();
n.getWorldTranslation();

Or:

n.getWorldTranslation(); on one frame
n.getWorldTranslation(); on the next frame


I think it’s related - the first time I’m getting the joint thw world transform is 0,0,0,1

The second time i’m getting the Joint it’s totally different values:

It’s in other frame. I didn’t try calling the getWorldTranslation() twice in my code

…but that’s the way you made it sound.

World translation will not be updated until the frame is done. You could maybe force it by calling update on the control.

…but maybe you are abusing joints for something for which they were not intended?

This is because I’m not a native English speaker.
What happens is that sometime when the game is running and the character is loaded and active (move, animation etc.) I need to display another object in the position of a given joint (not attach, just position. attaching works fine) then I’m looking for the joint’s node, fetch it’s worldTraslation and uses that for placing the other object. as I said, first time doing so gets wrong position, second time - works fine. It’s possible that I’m abusing the joints in some way I dont know but it’s pretty straight forward…
I’ll try to write an isolated program reproducing it.

You may find that your “attached but not attached” objects are always going to be one frame behind.

Why can’t they just be regular attachments?

Here is an isolated source code for reproducing the problem.

I wonder if it’s a bug or is it by design?
for reproducing the issue, put a breakpoint in line 81:

Vector3f pos = n.getWorldTranslation();

Thanks

I don’t know if it’s a bug or by design but until the control actually runs the bones have old positions and the newly created joint bone won’t have been updated yet. So more a matter of “attachment bones were not designed to be used the way you are using them”.

I ask again:

Like, why does n.attachChild(yourThing) not work in this case.

Sometimes if you explain WHY you are trying to do something then it helps a lot more than trying to explain how to levitate out of a room where you are standing in a corner surrounded by paint.

If I attach the spatial to the joint’s node, it will start moving according to the movement of the joint. I just want to place it there not to make it move with the joint. Am I missing something?

When you use the word “move” do you really mean “rotate”?

…I thought moving with the joint was precisely what you wanted.

I simply wanted to place an object in the world position of a given joint.
Is there an alternative way or best practice to fetch the joint’s world position other than using it’s getWorldTranslation() method?

And I’m trying to understand why attachChild() is not doing that.

But alas we are at an impasse because this conversation has become circular and my questions back are not really getting answered. I’m apparently not the right person to help so I’m going to bow out and let someone else try.

I think if you want to do what you are trying to do that you will have to call update on the animation control or call that animated spatial’s updateLogicalState() to force it to update before it wants to.

1 Like

Thanks for the effort. I’ll try using updateLogicalState()

Hi @adi.barda , perhaps you may find it useful to use the Joint.getModelTransform() or Joint.getLocalTransform() methods.

1 Like

Since I think it sounds like you want translation to be updated but not rotation. (even though I asked specifically that and got no reply)

Probably the “JME way” would be to add a control to the joint node that updates the world translation of your spatial. Then you will know it always runs at the right time and will never be a frame behind. You also won’t have to run extra passes of updateLogicalState() just to make things right.

1 Like

I will try anything you say and I’m sure I will find a workaround for getting the correct joint’s world position at any given time but the the purpose of this post is to also to check whether or not JME has a defect when using a joint’s getWorldTranslation() for the first time and if it does have a defect I will report it as an issue on the engine’s GitHub repo.

Here is a video I have recorded reproducing the problem:

I loaded a character and have it moving Left 2 meters for 3 seconds 5 times
After each time, I called the “Head” joint’s getWorldTranslation() method trying to receive it’s position and place there a little spaceship
As demonstrated in the video - calling it for the first time yields a wrong position while calling it every other time will give the correct position.
So again, what do you think? is it a bug and I should create a new issue in GitHub or is it by design?
Thanks for your answers :slight_smile:

I don’t know, maybe you can find something useful in this video that you can use for solve your problem.

1 Like