# Quickest Way to calculate scale

If I have a number of nested transformNodes, each has a different scale, mostly smaller as you move deeper into the tree

Is there a built in method of of calculating the overall scale of any target in the structure?

Example say I want 1.1.2, since nested its overall scale is not 0.5 but really 1 multiplied by 0.5 multipled by 0.5 = 0.25
Node 1: Scale Factor (x,y,z) 1
Node 1.1: Scale Factor (x,y,z) 0.5
Node 1.1.1: Scale Factor (x,y,z) 0.2
Node 1.1.2: Scale Factor (x,y,z) 0.5

I could solve this easily with recursion and walking up the tree, but figured there may be a built in method that I was not seeing in the documentation, and I am trying to get better at using built in methods vs just whipping up my own.

Hello the best option is to get `mesh.getWorldMatrix()` and decompose that matrix into your overall scaling value:

Matrix | Babylon.js Documentation

1 Like

I may need some help with this. Having a really off day. .targetTransformNode returns fine, but computerWorldMatrix fatal errors as undefined.

``````                let targetTransformNode = pwtHelp.findNearestTransformParent(targetMesh);
targetTransformNode.computeWorldMaxtix();
let targetScaleMatrix = targetTransformNode.getWorldMatrix();
const values = {
scale: new Vector3()
}
let isValue = targetScaleMatrix.decompose(values.scale);
scaleFactor = values.scale.x;
console.log("Global Scale:");
console.log(scaleFactor);``````

Got it. Thanks

``````            let targetWorldMatrx = targetTransformNode.getWorldMatrix();
let scaleFactorVector3 = new Vector3;
targetWorldMatrx.decompose(scaleFactorVector3);
let scale = scaleFactorVector3.x``````
1 Like