Gizmos misbehave when operating on child objects with configured pivot

Admittedly, this is an edge case - however the current implementation seems a bit hacky anyway.

The issue:
We have a complex assembly of objects that are tied into a hierarchy, for example MegaParent → Parent → Box
If Box has a pivot set for it, using any attached gizmos will cause the object to rapidly fly away:

(try using gizmo attached to be Green box)

It looks like that that current implementation using Gizmo._handlePivot would handle only some specific cases, but not a hierarchy like in the example.

The core of the problem appears that Gizmo._matrixChanged uses Matrix.decompose to extract position from the local matrix. However, when pivot is set, TransformNode.computeWorldMatrix does not use Matrix.compose - instead it factors in the pivot matrix. Thus decomposing that local matrix will return a different local position and that error will rapidly accumulate.

A potential fix is to remove the position tweak in _handlePivot and handle the “un-compute-world-matrix” better in the _matrixChanged:

I’m not totally sure that fixes it in all cases thus no PR, but a monkey patch like one around line 100+ here seems to work in our case:

cc @Cedric

This is something I’ll definitely take a look at. Thanks.

WIP Fixes and enhancements for gizmos by CedricGuillemet · Pull Request #14316 · BabylonJS/Babylon.js · GitHub

1 Like