Gizmo location with setPivotPoint

Hi,

I noticed that if I modify the pivot point of a mesh with setPivotPoint the gizmos location does not update but their behavior does.

Example: Babylon.js Playground
In this playground I would expect that the rotation gizmo of the right sphere would be placed at the pivot point (red dot) instead of the center of the object. The current placement makes the rotation kinda inconvenient.

Of course I could create a parent node at the desired pivot location and use the gizmo of this node instead. However this might not always be feasible or desired.

Question:
I would like to know if this is intentionally or a bug.
If its a Bug I`ll happily try to look into the code and see if I could create a PR on that topic.

Related PR
I’ve seen following pull request (Fix issue with Gizmo+Pivot by CedricGuillemet · Pull Request #10976 · BabylonJS/Babylon.js · GitHub) where an issue with setPivotPoint and gizmo was fixed. But this PR only adjusted the translation / roation in regards to the pivot matrix. Not the visualization itself.

cc @Cedric, I don’t know if it’s expected or a bug.

That’s expected. Gizmos are placed at local origin and rotation happens around pivot.
It can make sense to also have a different placement for gizmo (at origin or on pivot) but in order to keep back compatibility, it needs a new flag.

looking at this :

I think it ‘only’ needs to have this._rootMesh.position to be set when attaching node/mesh.
Special care needs to be taken when auto scaling is on or off as position is recomputed here:

EDIT: yes, a bug has been fixed in 2021 for that. check your PG with babylon 4.2.1 and you’ll see the pivot offset accumulate each frame with mouse input.

1 Like

Thanks for the update. I understand that changing the behavior directly is not desired because of back compatibility.

If you like I would look into it and create a PR for adding an additional flag within the GizmoManager to define where the Gizmo should be placed [origin (default) or pivot]

2 Likes

I think the change should happen in gizmo.ts so any gizmo will benefit.
Thank you for taking care of that !

2 Likes

Created a PR for this topic: Add anchor options for gizmos by MBecherKurz · Pull Request #13933 · BabylonJS/Babylon.js · GitHub

@Cedric While testing the new feature I noticed that the BoundingBoxGizmo does not handle the pivot point as I would expect. As you can see in the video I can move the sphere around by rotating the object back and forth. Is this the expected behavior? I`m not sure if this only applies to a custom set pivot point or also to offcentered origin positions.

1 Like

Doesn’t look like an expected behavior to me. can you please share your PG?

Sure: https://playground.babylonjs.com/#QMK5Z2#1

Thanks! I’m adding that issue to my todo list

2 Likes
2 Likes