Can't update TransformNode.worldMatrix

Hi guys!

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:

image
What? :slight_smile: Light? EDIT: Seems like a bug just in the docs.

Thank you!

From my observations something happened here after the 5th of February.

1 Like

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). :thinking:

2 Likes

Making the parent’s children dirty seems to fix the issue for a possible workaround at least…

2 Likes

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 :sunglasses:

Who’s da maaaan? @Blake is da maaan!
Thanks dude!

2 Likes

@sebavan what will be the final code for this? Will this be “fixed” or will you guys leave it as is?

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. :slight_smile:
PG: https://playground.babylonjs.com/#THAB7N#9

2 Likes

Hi!
There is another solution to this. Using matrix.decompose(scaling, rotation, position) and setting the position, rotation and scaling values on the TransformNode.

2 Likes

It is supposed to work like that :slight_smile:
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)

4 Likes

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)

3 Likes

Thanks @Deltakosh!

1 Like

@Deltakosh need your advice here :slight_smile:

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);
}

Thanks!

1 Like

Yes definitely the only way is to decompose the matrix into scaling, position and rotation :slight_smile:

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 :slight_smile:

1 Like

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 :slight_smile:
Thanks a lot!

3 Likes