Create skeleton at runtime

hi,

i’m trying to manually create a skeleton at runtime. i made a simple test app to ensure that nothing else is going wrong. when i run the app, i only see two green points: root1 at the origin and root2 a little above it. why are child1 and child2 not visible? what am i doing wrong?

thanks in advance!

[java]
import com.jme3.animation.AnimControl;
import com.jme3.animation.Bone;
import com.jme3.animation.Skeleton;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.debug.SkeletonDebugger;

public class BoneTest extends SimpleApplication {

/**
 * @param args
 */
public static void main(String[] args) {
BoneTest t = new BoneTest();
t.start();
}

@Override
public void simpleInitApp() {
Bone[] bones = new Bone[4];

bones[0] = new Bone("root1");
bones[1] = new Bone("child1");
bones[2] = new Bone("child2");
bones[3] = new Bone("root2");

bones[0].addChild(bones[1]);
bones[0].addChild(bones[2]);

bones[0].setBindTransforms(new Vector3f(), new Quaternion(),
	    new Vector3f());
bones[1].setBindTransforms(new Vector3f(2, 0, 0), new Quaternion(),
	    new Vector3f());
bones[2].setBindTransforms(new Vector3f(0, 0, 2), new Quaternion(),
	    new Vector3f());
bones[3].setBindTransforms(new Vector3f(0, 2, 0), new Quaternion(),
	    new Vector3f());

Skeleton skeleton = new Skeleton(bones);
skeleton.updateWorldVectors();
skeleton.setBindingPose();

AnimControl control = new AnimControl(skeleton);

Node node = new Node();
node.addControl(control);

rootNode.attachChild(node);

SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton",
	control.getSkeleton());
Material mat2 = new Material(assetManager,
	"Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.Green);
mat2.getAdditionalRenderState().setDepthTest(false);
skeletonDebug.setMaterial(mat2);
node.attachChild(skeletonDebug);
}

}
[/java]

Bones in JME are not exactly bones actually.
They are more joints. So basically we don’t have the information of the length of a bone, just the pivot point and original transforms (pos, rot, scale) in model space.
The skeleton debugger just draws lines between joints, but if a bone has no child ( typically your child1 and child2) it’s just represented as a small square.
That maybe why you don’t have what you expect on screen.

so how do i manually move the joints then? i tried setBindPosition, setUserTransform, etc. and none of them changed the skeleton. i also tried animating the bones manually. how are other skeletons manipulated?

you need to toggle user transform on before using the setUserTransforms method
[java]
bone.setUserControl(true);
[/java]

i know, jme3 throws an exception if i don’t. here is the test app with some user transforms. again, nothing changes :’(

[java]
import com.jme3.animation.Bone;
import com.jme3.animation.Skeleton;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.debug.SkeletonDebugger;

public class BoneTest extends SimpleApplication {

/**
 * @param args
 */
public static void main(String[] args) {
BoneTest t = new BoneTest();
t.start();
}

@Override
public void simpleInitApp() {
Bone[] bones = new Bone[4];

bones[0] = new Bone("root1");
bones[1] = new Bone("child1");
bones[2] = new Bone("child2");
bones[3] = new Bone("root2");

bones[0].addChild(bones[1]);
bones[0].addChild(bones[2]);

bones[0].setBindTransforms(new Vector3f(), new Quaternion(),
	new Vector3f());
bones[1].setBindTransforms(new Vector3f(2, 0, 0), new Quaternion(),
	new Vector3f());
bones[2].setBindTransforms(new Vector3f(0, 0, 2), new Quaternion(),
	new Vector3f());
bones[3].setBindTransforms(new Vector3f(0, 2, 0), new Quaternion(),
	new Vector3f());

bones[0].setUserControl(true);
bones[1].setUserControl(true);
bones[2].setUserControl(true);
bones[3].setUserControl(true);

bones[1].setUserTransforms(new Vector3f(20, 0, 0), new Quaternion(),
	new Vector3f());

Skeleton skeleton = new Skeleton(bones);
skeleton.updateWorldVectors();
skeleton.setBindingPose();

bones[1].setUserTransforms(new Vector3f(20, 0, 0), new Quaternion(),
	new Vector3f());

SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton",
	skeleton);
Material mat = new Material(assetManager,
	"Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Green);
mat.getAdditionalRenderState().setDepthTest(false);
skeletonDebug.setMaterial(mat);

Node node = new Node();
node.attachChild(skeletonDebug);
rootNode.attachChild(node);
}

}
[/java]

bones[0].setBindTransforms(new Vector3f(), new Quaternion(),
new Vector3f());
bones[1].setUserTransforms(new Vector3f(20, 0, 0), new Quaternion(),
new Vector3f());

You are setting the scale to 0,0,0. I would expect things to disappear. Is that what happens? I don’t know what a 0,0,0 scale would do in the bind transforms.

of course!!! absolutely my bad :woot: thanks a lot!! resolved!