Hello,
first of all this is not necessarily a bug, perhaps just an undocumented feature. So I am sorry if I am taking your time in vain. Nevertheless discovering this behaviour required lots of debugging and from my perspective as a user is very confusing.
Consider the following:
Given: Two meshes. box1 and box2 where box2.parent = box1
Action: box1 position has been updated
Expected: the world matrix of the last box in the chain (box2) is no longer valid, so box2.computeWorldMatrix(true) should update it
Result: works as expected
now a second case:
Given: A longer chain (four meshes, where box2.parent = box1, box3.parent = box2 and box4.parent = box3)
Action: box1 position has been updated
Expected: the world matrix of the last box in the chain (box4) is no longer valid, so box4.computeWorldMatrix(true) should update it
Result: it doesn’t work. box4.absolutePosition is invalid, which means that its worldMatrix has not been updated
I did more testing as it turns out, after a change of position of box1, it is necessary to run computeWorldMatrix()
on every box in the chain, or computeWorldMatrix(true)
on every second box. Only then the change propagates to box4.
https://playground.babylonjs.com/#ZPVQMN#3
Note that this behaviour does not affect rendering because Scene._evaluateActiveMeshes()
function updates world matrix of all meshes in the scene before rendering (as explained by @Evgeni_Popov Problems with getWorldMatrix - positions not updated - #4 by Evgeni_Popov), but if a user needs to perform some calculations based on world matrices earlier, the result can be wrong. And this is what happened to me.
I suspect that this behaviour is caused by the fact that the force flag does not propagate to parent (see code Babylon.js/transformNode.ts at 4.2.0 · BabylonJS/Babylon.js · GitHub )
but like I said, I am not sure if this is a bug or intentional, just undocumented.