computeWorldMatrix is skipped before the first render

Hello.

I found a bug while running and editing the example code.

On the below code, I expected sphere’s position will be (1, 1, 0), but it becomes (1, 0, 0), which ignores code setting sphere’s y position to 1.

sphere.position.y = 1;
sphere.translate(new BABYLON.Vector3(1, 0, 0), 1, BABYLON.Space.WORLD)

It appears that modifying the position directly without using a setter before the first render skips the code to calculate the _worldMatrix, so translate will works like (0, 0, 0) + (1, 0, 0).
(seems like the code on line 1044 of transformNode.ts doing this)

This is easily solved by updating position with setter, but I think this should be fixed because there are a lot of example codes that use it this way.

reproducible playground: https://playground.babylonjs.com/#Y33FFK#1

Thanks!

Welcome aboard!

This is for performance and architectural reasons. The x/y/z properties are in the Vector3 class, which doesn’t know the TransformNode class, so it can’t trigger a recalculation of the world matrix. But even if it were possible, we wouldn’t do it, because calculating the world matrix is quite heavy, so we only do it once as part of the loop rendering.

It’s the user’s responsibility to call mesh.computeWorldMatrix(true) to force a matrix recalculation if they need the matrix to be updated at a particular time before the system does it itself.

Thanks for your quick response.