ScaleGizmo snapping issue

Using snapDistance on the scaleGizmo does not seem to be very precise.
I have set the snapDistance to 0.1, and when dragging the gizmo back and forth, the scale value of the attached mesh becomes a value like 1.1213525, basically a value with a lot of decimals, as where I would expect it to be a value like 1.1 instead.

edit: this issue seems to also occur for the rotationGizmo

PG: https://playground.babylonjs.com/#KNX2RS#1

cc @Cedric to have a look, through, this might be just a limitation of precision in javascript, since the language cannot represent many numbers exactly

It looks a bit weird. I’ll take a look.

Hi @DukeVen
This is a difference with scaling because the scaling is applied to current values.
for example, with a snap of 0.1, a box of size 1 is scaled to 0.9 then scaled to 1.1. This will give a box size of 0.99, not 1. 1 * 0.9 = 0.9. 0.9 * 1.1 = 0.99. Scaling is relative. The more back and forth scaling applied, the more decimals you’ll get without being able to be a 0.9 or 1.1 precisely.

I tried with the rotation gizmo. There is some float precision issues (like -6.09e-7 instead of 0) but that’s expected.

2 Likes

Thank you for the clarification.
Is there any way to achieve “proper” snapping without decimals being added? So basically Incremental Snapping- scaling in increments of 0.1 units for example.

you can adjust scaling to the nearest value you want in onDragEndObservable

The issue here is that after the onDragEndObservable event is triggered, the mesh’s scaling doesn’t precisely match the scaling while you were dragging the scale gizmo.

Maybe add the option of incremental snapping as a feature request?
=> gizmoManager.gizmos.positionGizmo.incrementalSnapping = true

I’ll be glad to review your PR if you are thinking of a cool addition.

1 Like