Can you please check this? Why can’t I update the worldMatrix on a TransformNode?
EDIT: @sebavan was already writing about issues we may have when updating worldMatrices of a parent however @labris is working on a YUKA example and this was clearly working on 5.2.2022 but now it isn’t.
Also this:
What? Light? EDIT: Seems like a bug just in the docs.
It seems the issue goes all the way back to v4 even. After commenting out the new markAsUpdated() calls I tested in v4.2.1 and the behavior is the same (changing the parent world matrix has no effect).
Yep, I’ve tried v4 too. I am curious whether there is a way to make it working as it was until 5th of February so @labris can lay back with a smile on his face
Also found if you just increment the parent’s _childUpdateId that seems to fix the issue as well, since isSynchronizedWithParent will then return false. Still hacky and hopefully can be fixed internally, but better than looping over all the children to set _isDirty least.
PG: https://playground.babylonjs.com/#THAB7N#9
Hi!
There is another solution to this. Using matrix.decompose(scaling, rotation, position) and setting the position, rotation and scaling values on the TransformNode.
It is supposed to work like that
The world matrix is a by product (an output if you prefer). You cannot update it directly (because for perf reasons we consider it readonly)
Yes this is the supposed way of working with it to keep performance / stability and making sure the values are correct (because updating only the world matrix will end up in a complete mess between the WM and position/rotation/scaling)
If the matrix becomes read-only in the future we can’t rely on modifying the matrix itself anymore so the question is will the code below be the most performant or any other tricks in your magic hat? I started to write a YUKA+BJS TypeScript Starter project for the masses so the example is in TS.
type FlatMatrix4x4 = [
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number
]
private _sync(entity: YUKA.GameEntity, renderComponent: TransformNode) {
// typeof entity.worldMatrix.elements is number[]
Matrix.FromValues(...(entity.worldMatrix.elements as FlatMatrix4x4)).decomposeToTransformNode(renderComponent);
}
Yes definitely the only way is to decompose the matrix into scaling, position and rotation
But technically you also need to get the local matrix so you need to get the entity world matrix, multiply it byt the inveser of parent matrix and then decompose
I use top level TransformNodes with YUKA so I don’t have to deal with parents and achieve maximum performance with no extra code when decomposing but this information is golden to me
Thanks a lot!