There have been a few threads on properly using setUserTransformsWorld and I have gone through all of them. I can’t seem to make anything work that doesn’t have my model end up as a blob on the ground with every joint at (0, 0, 0). I have a model and skeleton that looks like this:
Then I use the following code:
In graphics state initialize
// Setup the avatar
avatarNode = (Node) assetManager.loadModel("Models/BaseBody/BaseBody.mesh.j3o");
Material matAvatar = new Material(assetManager, "MatDefs/Lighting.j3md");
matAvatar.setTexture("DiffuseMap", assetManager.loadTexture("Textures/flatGrey.png"));
avatarNode.setMaterial(matAvatar);
animControl = avatarNode.getControl(AnimControl.class);
animControl.setEnabled(false);
avatarNode.scale(2.2f);
rootNode.attachChild(avatarNode);
boneList = new TreeSet<String>();
// Setup the skeleton
skeleton = animControl.getSkeleton();
skelDebug = new SkeletonDebugger("skeleton", skeleton);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.getAdditionalRenderState().setWireframe(true);
mat.setColor("Color", ColorRGBA.Green);
mat.getAdditionalRenderState().setDepthTest(false);
skelDebug.setMaterial(mat);
avatarNode.attachChild(skelDebug);
Note that I grab the AnimControl and disable it so I can take control of the bones.
update loop
@Override
public void update(float tpf) {
super.update(tpf);
Bone rootBone[] = skeleton.getRoots();
List<Bone> bones = new ArrayList<Bone>(rootBone[0].getChildren());
for(Bone bone : bones) {
bone.setUserControl(true);
Vector3f worldPos = bone.getWorldBindPosition();
Quaternion worldRot = bone.getWorldBindRotation();
bone.setUserTransformsWorld(worldPos, worldRot);
bone.updateWorldVectors();
}
}
Here, all I do is loop through all the bones in the skeleton, grab the world bind position and world bind rotation and set the bone to the rotation and position. When I do this, I get the following:
In every thread, people have recommended looking at KinematicRagdollControl.java because this shows how to use setUserTransformsWorld. I have examined this code and run it, but I can’t see what I am doing differently. One part of KinematicRagdollControl that is a bit hard for me to parse is the use of TempVars which appears to be a way to store variables you want to use in multiple threads. The boneList that is extracted from this variable is kind of an unknown to me. Does anyone have any insights to what I might be doing wrong?