Scaling mesh and skeleton/bones?

Building on top of the resolved question:

In the Youtube video and PG below: If SCALE = 1 (Line 15), things look fine. However, if I try SCALE < 1, the mesh and bones become messed up. If I change Line 69 to use mat instead of mat2, the mesh looks fine, but the bones have a larger scale compared to the mesh.

Is there a way to scale down both the mesh and bones? Thank you all for your help and @Evgeni_Popov if you could please bless us with your expertise again :slight_smile:

PG: https://playground.babylonjs.com/#BCU1XR#7562

You have bones whose scale is not (1,1,1), so you need to take this into account in the calculation. In addition, the scale matrix must be left-multiplied with mat, not right-multiplied:

1 Like

Thank you for helping to look into this, @Evgeni_Popov. In the updated PG, it still seems like the bones have a larger scale than the mesh.

In the screenshots below, SCALE = 1 has the bones and mesh matching nicely. However, SCALE = 0.6 has the bones larger than the mesh.

cc @Cedric, maybe there’s something that doesn’t work with the debug AxisViewer, because it does work when doing it in the inspector:

The bones unexpectedly have the same absolute position despite different scaling (e.g. SCALE = 1, SCALE = 0.6). So it seems that Debug.AxesViewer is working fine. Perhaps the Inspector is showing a different position instead of the bone’s absolute position? Please see the screenshot and PG below showing this:

PG with logging: https://playground.babylonjs.com/#BCU1XR#7568

The absolute positions are the same because you applied the scaling on the mesh, not on the bones. So, from the point of the view of the bones, the scaling is unchanged whatever the value of SCALE is.

I think the debug viewer does not work because the mesh transformation would need to be applied to the bone transformation, but I don’t see a way to do it (axis from the debug viewer have bones as their parent)… cc @Cedric in case he would know.

1 Like

I think the debug viewer does not work because the mesh transformation would need to be applied to the bone transformation

yes, that’s my guess too.

maybe there’s something that doesn’t work with the debug AxisViewer, because it does work when doing it in the inspector:

I guess you’ve tried to use the position gizmo. gizmos have the ability to get the skeleton mesh linked to a bone

2 Likes

Thank you, @Evgeni_Popov and @Cedric !

Would you know how I could change the PG to get the absolute position of the bones to match the scaled down mesh?


const mat2 = scaleMatrix.multiply(mat);

tmpMat.copyFrom(mat2);

// ...

tmpMat.decompose(undefined, rotation, position);

// ...

bone.setAbsolutePosition(position);

I assumed that the SCALE = 0.6 would get baked into position that we set the bone’s absolute position to, though it seems I’m wrong

You simply have to pass the base mesh to getAbsolutePosition, but you must make sure that the world matrix of this mesh is up to date (see line 40):

1 Like

Ah, thank you, @Evgeni_Popov :slight_smile: I’ve added a PointsCloudSystem using the tip you shared above:

PG: https://playground.babylonjs.com/#BCU1XR#7572