Absolute value of `snapDistance` in `onSnapObservable` of `PositionGizmo`

Hello Babylon.js community!

Currently, I am playing around with the PositionGizmo with “snapping” enabled.

I was wondering

  1. how I would know in which direction the gizmo was dragged (positive vs. negative) and
  2. therefore, would like to ask if it is expected that the snapDistance passed by the onSnapObservable seems to be the absolute value (unsigned).
  3. is it true, that the position of the mesh attached to the gizmo is not yet updated in the callback of onSnapObservable?

I think I would have expected that it would return a negative value if the gizmo gets dragged into the “opposite” direction so that I could calculate the new position already in the callback :innocent:.

Please, see this playground and specifically the following part.

gizmo.snapDistance = 0.1;
gizmo.xGizmo.onSnapObservable.add(snap => {
    console.log(
        snap.snapDistance, // Only absolute value of dragDistance
        gizmo.attachedMesh?.position // After first drag, position is still 0,1,0
    )
});

Thanks in advance for your clarification :pray:!

cc @Cedric the Gizmo daddy

Hi @Philippe and welcome to the forum!

  1. you can compute the delta between current and previous position. For now, there is no way to query this value.
  2. yes, it’s a distance value. if a snap is asked to happen every meter, it doesn’t matter which direction
  3. I don’t know actually. callbacks and observable are numerous and happen in different places, so I’m not sure for that one.

Why not using onDragObservable and query the object position ?

Thank you for your reply @Cedric!

I played around with onDragObservable. Interestingly, the dragDistance seems to return a negative number when dragging in the “opposite” direction.

This feels like a tiny inconsistency or do I maybe mix something up :sweat_smile:?

See updated playground.

gizmo.xGizmo.dragBehavior.onDragObservable.add(drag => {
    console.log(
        drag.dragDistance // This distance can be negative
    )
})