Behaviour of computeWorldMatrix() is confusing for nodes with parents

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.

2 Likes

Well it should work as you expected it to work so let me check what is happening :slight_smile:

Ok I want to salute the high quality of your question and your analysis. I was able to fix the bug in a matter of a few minutes thanks to your fantastic repro

It will be fixed in the next nightly (in a couple of hours)

Thanks a ton @lguminski

1 Like

You’re welcome @Deltakosh . I am happy that I could contribute to this great product

1 Like