Most basic skeleton example

I’m trying to work out how to create the simplest example of a working skeleton that is not imported from a pre-created model. (aka Created purely in code js/ts). No fancy humanoid! I just want two bones that are bound to a two boxes or a single cylinder mesh to form a finger or worm.

Here is what I have so far:

 let s = new BABYLON.Skeleton("skeletontest", "skeletonID", scene);
 let bone1 = new BABYLON.Bone("bone1", s, null)
 let bone2 = new BABYLON.Bone("bone2", s, bone1)

With just this, the skeleton is in the scene debugger, in the skeletons drop down, but I’m unable to get the skeleton debug “lines” to visually appear, so something is missing. Help! Is this because the bones need to be bound to a mesh first in order to show up in debug? Or perhaps, the bone needs position and rotation, but I can’t find examples of how to set this. The bone constructor takes a lot of different types of matrices, but I can’t find examples of how to set them. Please educate me on what the Bone constructor’s API means (what’s the difference between localMatrix, restPost matrix and baseMatrix?).

So first step, try to get my skeleton to show up in debugger. 2nd step, try to learn to layout my bones in 3d space using the proper matrices. Step 3, try to bind the bones to the vertices of the mesh I want to deform.

I can’t even get step 1 to work. Any advice?

cc @bghgary but I also recommend checking out some resources on how bone animation works overrall: LearnOpenGL - Skeletal Animation, Tutorial 38 - Skeletal Animation With Assimp (, OpenGL Skeletal Animation Tutorial #1 - YouTube

Doing this by hand is difficult, especially with so many vertices for the cylinder.

Here is the most basic one I can come up with:

You are missing a few things.

  1. The mesh.skeleton needs to be assigned to the skeleton.
  2. The localMatrix parameter of the bone is not actually optional. You must pass at least this parameter or the baseMatrix parameter for the bone to compute its matrices. We should probably update the documentation for the constructor.
  3. There must be bone indices (called MatricesIndices in Babylon.js) and bone weights (called MatricesWeights in Babylon.js) attributes for each vertex in the skinned mesh.

This just makes everything identity, so the bones don’t actually do anything, but this is where you can start.

I would suggest you start with a simpler mesh geometry to understand what is happening. Learning from the skinning section in glTF tutorials may help.


Doing this by hand is difficult, especially with so many vertices for the cylinder.

How about just a box then? Can I assign the north face to one bone and the south face to another bone?

Thanks for the playground, how can I get the skeleton to show up in the bone debugger?

You must bind bones to vertices, not faces. “Bones” are really just an abstraction for matrices; they describe a transformation that should be applied to the vertex. Once a skeleton is bound to the mesh (it has been “skinned”) the vertices will be transformed in the same way that the bones they’ve been mapped to are.

If affected by multiple bones, the bone weights will be used to compute a single transformation matrix for the vertex, factoring in each bone with its respective weight. Animations may however override these (IIRC).

For a better explanation, see this video: How It Works - Skeletons!

For what it’s worth, I agree that the Bone constructor’s arguments are very confusing and have in fact stumbled over them myself, as well as seen others face the same issues. Unfortunately, no one has been able to clear up what exactly all those parameters are doing and I didn’t really understand it from the source code, so I’ve been unable to add the relevant information to the documentation myself.


@bghgary @PirateJC I think we have an opportunity here to improve on the Bones documentation :smiley:

1 Like

Yup sounds like it. Added an issue for it: