Pose with bones

Hi, I would like to modify the pose of avatar through the bones.
I try to modify skeleton bones with setPosition, setScale and setRotation with values that my code read from json the mesh not changed correctly, but if I load the mesh with new pose directly it work corretly.

could someone help me?

thanks

Hello maybe you could share a repro in the playground?

Hi,
I can’t share the code quickly on the playground,
but I describe the tasks performed:

  • I exported a babylon file avatar from blender
  • I loaded avatar whit babylonjs api (fig 1)
  • Through the movement of the bones I would like to change the pose of the avatar as fig 2. To do this it is necessary to modify 5 bones
  • The new values ​​of the vectors of bones are reading by json eg:

var obj = {
“bone”: “Pelvis.L”,
“rotation”: {
“x”: -0.7229200640202624,
“y”: 0.01198242879947844,
“z”: 0.01944017995363767,
“w”: 0.690553618966869
},
“position”: {
“x”: 0,
“y”: 0.10249999910593033,
“z”: 0
}
“scale”: {
“x”: 1,
“y”: 1,
“z”: 1
}
}…

  • So for every bone found in the json
    I set the new values ​​of the vectors:

Object.keys(obj).forEach((key) => {
if (key === ‘position’) {
mesh.skeleton.bones[i].setPosition(obj[key]);
}
if (key === ‘scale’) {
mesh.skeleton.bones[i].setScale(obj[key]);
}
if (key === ‘rotation’) {
mesh.skeleton.bones[i].setRotationQuaternion(obj[key]);
}
});

  • The avatar assumes a position as Fig 3 but it is not the position that I expect (note the level of the feet).
  • The correct position should be that of fig 2

If I load directly the pose of figure 2 from the babylon file exported from the blender, it work fine

Fig 1:


Fig 2:
Fig 3:

Well it is impossible to tell without a repro. It depends on so many factors like the mesh itself, the hierarchy etc…

I don’t consider myself an expert on the mathematics of @JCPalmer 's exporter, but I’m curious when I look at your code above I see numbers like this “0.10249999910593033”. That is a lot of decimal places. I don’t see anything like that in my .babylon files - everything is usually about 4 decimal places.

Could your five bones be amplifying tiny differences in decimal places as you change them?

Stay Safe, gryff :slight_smile:

Hi, I tried to set 4 decimal places as recommended by @gryff but the result is the same.

However I have created two repo in the playground for @Deltakosh :

  1. https://playground.babylonjs.com/#A1YWY7#63 :
    here you see the code implemented to move the bone to change the pose of the mesh

  2. https://playground.babylonjs.com/#PHBVM1#7 :
    here you see the correct pose that I would like

pinging @Cedric to see if he can help

Hey @robgua

When I have issues with pose and skeleton, I always refer to my check list :

  • Are my values local or world space
  • Do I set local or world space
  • when using local space, am I using the same hierarchy?
  • is the parent the same?
  • is the bone parent world matrix the same when I calculate the local transform and when I apply it?
  • if I apply a rotation on a single axis (like 90deg) do I have the result that I’m expecting? same for other axis
  • when in doubt, use axis tripod debug draw. Do I have the same thing in my DCC?

Skeletal animation and poses can be tricky. it’s very important to check and double check your data. even the most obvious thing should be checked.

1 Like