touch-orbit

touchOrbit(camera) gives an ArcRotateCamera the view controls people expect from a 3D viewer, on every device. <tosi-b3d>'s default camera and orbitCam both call it; call it yourself on an ArcRotateCamera you build.

orbit pan zoom
mouse drag shift-drag, right-drag, ctrl-drag wheel
trackpad click-drag two-finger drag pinch
touch one finger two fingers together pinch

Returns a function that restores Babylon's handlers.

Two fingers: pan OR zoom, decided once

The decision is pure (no Babylon, no DOM), so it is tested without a touchscreen. Babylon's ArcRotateCamera does both on every two-finger move by default, with zoom driven by the change in SQUARED finger distance. Real fingers never keep their spacing exactly, so a two-finger drag reads mostly as zoom. Its other mode calls a gesture a pinch only if the spacing jumps far in one event early on, so a slow, deliberate pinch becomes a pan.

The rule here: compare how far the fingers have SPREAD (net change in spacing since the gesture began) with how far their centroid has TRAVELLED (net, likewise), until the two together pass decidePx. Then lock: whichever is larger wins for the rest of the gesture. Net, not summed per event, because summed jitter reads as spreading. A gesture never changes its mind mid-stroke, because that reads as the camera fighting you.

Zoom is NATURAL: the radius scales by previous spacing / spacing, so what is under your fingers stays under them. Pan is in pixels, converted to world units at the target's depth as above.