setWorldPosition for skeleton-bones

I need a getWorldPosition and setWorldPosition for bones in my model.



I already found a way to implement the getter (several ways, actually).

My latest is:



[java]

public Vector3f getBoneWorldPosition(Bone bone) {

return getBoneWorldTransform(model, bone).getTranslation();

}



Transform getBoneWorldTransform(Node model, Bone bone) {

Transform t = new Transform(bone.getLocalPosition(), bone.getLocalRotation());

if (bone.getParent() == null) {

return t.combineWithParent(model.getWorldTransform());

}



return t.combineWithParent(getBoneWorldTransform(model, bone.getParent()));

}

[/java]



But I am going nuts, trying to implement the setter.



Please help me, I’ve been banging my head against the wall for days.

Thanks.

[java]

bone.setUserControl(true);

bone.setWorldTransform(…);

[/java]



?

Thanks for the answer.



But Bone only has

[java]

void setUserTransforms(Vector3f translation, Quaternion rotation, Vector3f scale)

void setUserTransformsWorld(Vector3f translation, Quaternion rotation)

[/java]



setUserTransformsWorld seems to have no effect at all.

I was using setUserTransforms. But I cannot get the math right.



Any ideas on how to get the math right, or approach this differently?



To clarify, I want a method-signature like this:

[java]

void setBonePosition(Bone bone, Vector3f worldTranslation) {

// TODO: move given bone to given world-space position

}

[/java]

setUserTransformsWorld seems to have no effect at all.


It's because you have to call "setUserControl(true);" before that. KinematicRagdollControl.java is a good example.
1 Like

Thanks again for your answer.



I am trying to copy from the ragdoll-code as good as I can.

I have tried both



[java]

bone.setUserControl(true);

bone.setUserTransformsWorld(worldTranslation, bone.getLocalRotation());

[/java]



And the recursive variant

[java]

RagdollUtils.setUserControl(bone, true);

RagdollUtils.setTransform(bone, worldTranslation, Quaternion.ZERO, false, new HashSet<String>());

[/java]



Both have no effect. Do I have to set anything else to make this work?



This is how I get the skeleton:

[java]

skeleton = model.getControl(AnimControl.class).getSkeleton();

[/java]



This is how I get the bone:

[java]

bone = skeleton.getBone(boneName);

[/java]

Try updating the bone like in KinematicRagdollControll.java.

It’s something like ::



[java]

bone.updateWorldVectors()

[/java]

Thanks so much for trying to solve this.



Now I have:

[java]

bone.setUserControl(true);

bone.setUserTransformsWorld(new Vector3f(60f, 0, 0), Quaternion.IDENTITY);

bone.updateWorldVectors();

skeleton.updateWorldVectors(); // <-- this is for additional fun. I tried without it.

[/java]



The model is still not moving :frowning:

It should work. Weeks ago I was playing with bones and I was doing the same you are, and it works for me. What’s your jme version? And does TestBoneRagdoll.java and TestRagdollCharacter work for you? Maybe the problem is your model!?

I am using the Oto Model.

Both tests work for me.

IDE says 3.0 beta (I downloaded a few days ago from the startpage).



The only difference I can spot right now is that Ragdoll is some kind of a control. So it seems to be in some kind of a stack with the Animation and Skeleton Controls (I read a comment about a hack in KinematicRagdollControl).



Is there maybe something I have to configure on the Animation or Skeleton control?

No. I did it without need a control too. I did a testcase when I was learning how to handle bones by hand. I’ve used the Oto model too, and it worked like a charm for me. KinematicRagdollControl.java helped me.

ha I got it. AnimControl was overwriting all my commands.



[java]

model.getControl(AnimControl.class).setEnabled(false);

[/java]



This is really awesome. setUserTransformsWorld does not even move the child bones (which was annoying).

Cool cool cool.