The built-in wiring: enableCustomization
The fastest way to get gestures is ARView.enableCustomization(). It
attaches a gesture controller to the view's overlay and wires the gestures
to the active model:
const cleanup = ar.enableCustomization({
// REQUIRED: which model the first tap places. A plain URL string
// works; pass a function and it is called on the placing tap, so the
// model placed can follow the user's current selection.
modelUrl: () => currentModelUrl,
onTap: () => console.log('placed'),
onScale: (factor) => console.log('scale is now', factor),
onRotate: (radians) => console.log('rotationY is now', radians),
});
// Later, to detach:
cleanup();| Gesture | Effect |
|---|---|
| One-finger tap | Places the current modelUrl at the tap point when nothing is placed yet. Once a model is placed, taps do nothing: dragging is the move gesture |
| Pinch (two fingers, in/out) | Scales the active model, ARView.setScale clamps to [0.1, 5] |
| Twist (two fingers, rotate) | Rotates the active model around Y |
| Drag (one finger) | Drags the active model across surfaces: the engine re-aims a hit test at your finger every frame, so the model stays under it, and one final move lands it exactly on the release point. Passing over a spot with no surface is silent; the model stays at its last good position |
Note
modelUrl accepts a plain URL string or a () => string function.
The function form is called on the placing tap; use it when the model
to place can change between placements (the example app reads the latest
selected product from a ref). A plain string always places the same
model. (Before 1.1.0 only the function form worked; a string threw a
TypeError inside the tap handler.)
Overlay elements marked with data-ui are ignored by the gesture layer,
so your buttons and sheets never double as scene gestures.
The standalone controller
For custom interactions, use the exported controller directly. It is framework-agnostic Pointer Events code and knows nothing about AR:
import { createARGestureController } from 'reticlexr';
const gestures = createARGestureController({
element: document.querySelector('#ar-overlay'), // required
onTap: ({ x, y }) => { /* pointerup point, px */ },
onDrag: ({ dx, dy, x, y }) => { /* per-move deltas, px */ },
onPinch: ({ factor, center }) => { /* factor is incremental */ },
onRotate: ({ delta, center }) => { /* delta in radians, incremental */ },
tapMaxDuration: 260, // ms: longer presses are not taps
tapMaxDistance: 12, // px: further movement is not a tap
preventDefault: true,
ignoreSelector: '[data-ui]',
});
// When the view goes away:
gestures.destroy();Payload semantics worth knowing:
onPinch'sfactoris incremental, relative to the previous move event, not the gesture start. Multiply your running scale by it.onRotate'sdeltais likewise incremental, in radians, wrapped to ±π.- A tap is a pointer down/up pair within
tapMaxDurationandtapMaxDistance. One known quirk: apointercancel(system gesture, notification) that happens to be short and stationary is currently treated as a completed tap and can place a model.
Driving transforms yourself
If you bypass enableCustomization, the facade exposes the same
operations the gestures use:
ar.setScale(1.4); // clamped to [0.1, 5], applied uniformly
ar.rotateBy(Math.PI / 8); // accumulates rotationY, radiansOne scale range everywhere since 1.1.0: [0.1, 5], enforced by the engine itself (the facade and the native registry use the same limits). In v1.0.0 the layers disagreed: facade [0.1, 5], engine unclamped, native [0.25, 3].