Mesh world scaling

Hi, I have a mesh which has many parents. Each parent has a unique set of transforms. How do I get the mesh scaling in the world which accounts for all the parent scaling transforms?

I think it is in here but I’m not sure how to pull it out:
var matrix = mesh.getWorldMatrix();

I guess I could run up the chain of parents and multiply the scalings but I think there is already a built in or easier way to do it.

Thanks

The scale is usually stored as the length of the 1st 3 columns in the matrix: extracting scale vector from a transformation matrix? - Graphics and GPU Programming - GameDev.net

You could use the method decompose on the matrix to extract scale rotation and position easily in babylon.

Is this the way to use decompose to get scaling?:

var matrix = mesh.getWorldMatrix();
var scale = new BABYLON.Vector3()
matrix.decompose(scale);
console.log("scale " + scale);

You have the good code for this but you need to run it once the matrix has been computed and cached e.g. after the first frame it is rendered:

https://playground.babylonjs.com/#25JTIX

Or you could force computing the matrix beforehand:

https://playground.babylonjs.com/#25JTIX#1

Ah that probably explains why I didn’t always seem to be getting accurate values.

Thanks

I found that I needed to run up the parent chain and computeWorldMatrix to get it to work as I scaled a parent node:

var mesh_holder = mesh;
while (mesh_holder.parent != null) {
mesh_holder = mesh_holder.parent;
mesh_holder.computeWorldMatrix(true);
}
mesh.computeWorldMatrix(true);
var matrix = mesh.getWorldMatrix();
var scale = new BABYLON.Vector3()
matrix.decompose(scale);
console.log("scale " + scale);

1 Like