@realitycollective/webxr-interactions 0.1.1-preview.2 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -2
- package/README.md +17 -2
- package/dist/behaviours/behaviour.d.ts +17 -1
- package/dist/behaviours/behaviour.js +12 -2
- package/dist/behaviours/behaviour.js.map +1 -1
- package/dist/behaviours/grab.d.ts +1 -0
- package/dist/behaviours/grab.js +10 -4
- package/dist/behaviours/grab.js.map +1 -1
- package/dist/contract-cases.js +84 -0
- package/dist/contract-cases.js.map +1 -1
- package/dist/descriptor.d.ts +7 -1
- package/dist/descriptor.js.map +1 -1
- package/dist/gaze.d.ts +50 -0
- package/dist/gaze.js +162 -0
- package/dist/gaze.js.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/math.d.ts +8 -0
- package/dist/math.js +17 -0
- package/dist/math.js.map +1 -1
- package/dist/memory-physics.d.ts +41 -0
- package/dist/memory-physics.js +168 -0
- package/dist/memory-physics.js.map +1 -0
- package/dist/memory-ports.d.ts +55 -0
- package/dist/memory-ports.js +128 -0
- package/dist/memory-ports.js.map +1 -0
- package/dist/near-pointer-contract-cases.d.ts +16 -0
- package/dist/near-pointer-contract-cases.js +283 -0
- package/dist/near-pointer-contract-cases.js.map +1 -0
- package/dist/near-pointer.d.ts +88 -0
- package/dist/near-pointer.js +114 -0
- package/dist/near-pointer.js.map +1 -0
- package/dist/physics-contract-cases.d.ts +11 -0
- package/dist/physics-contract-cases.js +229 -0
- package/dist/physics-contract-cases.js.map +1 -0
- package/dist/physics.d.ts +148 -0
- package/dist/physics.js +35 -0
- package/dist/physics.js.map +1 -0
- package/dist/ports.d.ts +15 -0
- package/dist/ports.js.map +1 -1
- package/dist/release-velocity.d.ts +58 -0
- package/dist/release-velocity.js +89 -0
- package/dist/release-velocity.js.map +1 -0
- package/dist/runtime.d.ts +129 -4
- package/dist/runtime.js +362 -40
- package/dist/runtime.js.map +1 -1
- package/dist/trace-synthetic.d.ts +12 -0
- package/dist/trace-synthetic.js +194 -0
- package/dist/trace-synthetic.js.map +1 -0
- package/dist/trace.d.ts +215 -0
- package/dist/trace.js +350 -0
- package/dist/trace.js.map +1 -0
- package/package.json +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -4,10 +4,31 @@ Change log for the Reality Collective WebXR Interaction Extensions packages. All
|
|
|
4
4
|
|
|
5
5
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Preview builds are not listed separately. The entry for a version accumulates while its previews are published, and is dated when that version is released.
|
|
6
6
|
|
|
7
|
-
## [0.1.1]
|
|
7
|
+
## [0.1.1] - 2026-10-01
|
|
8
8
|
|
|
9
9
|
### Added
|
|
10
10
|
|
|
11
|
+
- Native parity round (Pale Signal handover of 29 September 2026): everything IWSDK delivers through its engine for the mechanics the Pale Signal web build uses, restated as core rules every binding runs, with the native contract stating what a host reports.
|
|
12
|
+
- `@realitycollective/webxr-interactions` - the grab lifecycle for hands is stated where it was implied: a hand's `select` is the runtime's binary pinch gesture and its `squeeze` 0 (the `@realitycollective/webxr-input` contract, IWSDK's `useHandPinchForGrab` over the browser's `selectstart`/`selectend`), so the core's 0.7/0.3 thresholds start a grab on the pinch and end it on the frame the pinch ends. `holderPoint` (the point a dial, slide or hinge tracks while held) is the GRIP first, as IWSDK's grab pointer is built on `xrOrigin.gripSpaces` and moves a held object with it, then the fingertip, then the ray origin; a closed hand's fingertip barely moves around a wheel's axis, which is why the native handwheel did not turn. `release-velocity.ts` (`ReleaseVelocityTracker`, `RELEASE_WINDOW_SECONDS` 1/60): the throw is the held OBJECT's velocity over IWSDK's physics step, angular from the orientation delta over the same step, which is what Havok gives a body IWSDK drives by target transform and releases; `GrabBehaviour` records the poses it writes and hands `endHold` that, zeros on a synthesised release (`InteractorInfo.synthesized`). `surfacePointOnSphere` and a `hitTesterContractCases()` case: `hitProximity`'s point is the surface point nearest the query, never the centre, so the touch cursor sits on the object; every platform's tester now reports it.
|
|
13
|
+
- `@realitycollective/webxr-interactions` - one pointer decision per source across interactables AND UI panels, as IWSDK's `MultiPointer` runs over every pointer-event object: `InteractionRuntime` takes `pointers` (a `PointerArbiter` from `@realitycollective/webxr-input`, shared with the UI Extensions hosts) and offers its touch, grab and ray candidates to it under `INTERACTIONS_POINTER_SET`; a panel nearer than an object takes the ray, a fingertip on a panel retires the ray over an object and the reverse, and `PointerVisuals` name the target kind, id and distance. `POINTER_PRIORITY`, `pickActivePointer`, `PointerCandidate`, `PointerVisuals` and `pointerVisualsFor` now live in `@realitycollective/webxr-input` and are re-exported unchanged. Two `nearPointerContractCases()` prove the arbitration on every platform's hit tester.
|
|
14
|
+
- `@realitycollective/webxr-interactions` - pointer display is app configuration through the core: `InteractionRuntime` takes `pointerDisplay` (`PointerDisplay` or a partial `PointerDisplayConfig`, IWSDK 1.0.0's look by default: ray while hitting, cursors on objects and panels), exposes `getPointerDisplay()` for run-time changes, and publishes `onPointerDrawing` / `getPointerDrawing`, the per-source `PointerDrawing` resolved from the arbiter's decision under the settings. `getPointerArbiter()` and `isSelecting()` are public.
|
|
15
|
+
- `@realitycollective/threejs-interactions` (reused by `@realitycollective/xrblocks-interactions`) - `ThreePointerVisuals` draws the drawing: IWSDK's ray shader and stub (3 cm from the hand to `min(0.3 m, the hit)`, 1 mm, white, blue while selecting) and the disc at the hit; `createThreeInteractions({ pointerVisuals: { scene }, pointers, pointerDisplay })` and `connectXRBlocksInteractions` take the same options.
|
|
16
|
+
- `@realitycollective/babylon-interactions` - `BabylonPointerVisuals` draws the same drawing through a structural kit of the app's own `MeshBuilder`, `StandardMaterial`, `Color3` and `Quaternion`; `createBabylonInteractions({ pointerVisuals: { kit }, pointers, pointerDisplay })`.
|
|
17
|
+
- `@realitycollective/iwsdk-interactions` - `IWSDKPointerVisuals` applies the app's settings to IWSDK's own `RayPointer` (`rayDisplayMode`, length) and `CursorVisual`, and enforces the core's drawing where a setting hides what IWSDK would show; `registerInteractions({ pointers, pointerDisplay, pointerVisuals })`.
|
|
18
|
+
- `@realitycollective/webxr-interactions` - the trace suite (G6): `trace.ts` (`rc-trace.v1`, `TraceRecorder`, `TraceInputProvider`, `replayTrace`, `compareOutcomes`, `traceParityCases`, `TRACE_TOLERANCES`) replays a recorded session's input through a binding's own ports and compares press and grab timing, values, poses and release velocity with the reference within stated tolerances; `memory-ports.ts` (`MemoryHitTester`, `MemoryTransformPort`) are the engine-free reference ports that pass both shared suites; `trace-synthetic.ts` scripts the playground mechanics through the core so the pipeline is proved on every platform before a person records on a Quest 3 (`iwsdk-interactions/test/trace-parity.test.ts` replays the synthetic traces on all five platforms, and recorded ones from the folder `RC_TRACES_DIR` names).
|
|
19
|
+
- The playground (`demos/playground`) runs on IWSDK, three.js, Babylon and XR Blocks from one launch screen with one descriptor, one pointer display and a Record button that downloads a trace; the native harness (`harness/native`) is a project for the WebXR-to-native conversion pipeline that runs every suite this family ships against a host on the device (`kits`), plays the same stations there (`play`) and records a native trace (`trace`), and `npm run harness:compile` typechecks it, bundles it through the pipeline's gates and compiles it to Hermes bytecode. CI compiles the harness and never runs it; native builds run only on a developer's machine or a headset.
|
|
20
|
+
- `@realitycollective/native-interactions` - `NativeInputHost.sample()` states what a hand and a controller report for `select` and `squeeze`, with the OpenXR source and resting values (a hand: binary pinch from `XR_FB_hand_tracking_aim` or `XR_EXT_hand_interaction`, squeeze 0; a controller: trigger and grip values), and the binding forces a hand's squeeze to 0. `applyPointerVisuals` hands the host `NativePointerVisuals`, the resolved drawing (stub from `rayFrom` to `rayTo`, radius, colour, disc radius, opacity, offset) plus the decision (`activePointer`, `targetKind`, `targetId`, `hitDistance`), so a panel cursor reaches the host through the same member and no shell hook decides a display mode; `applyPointerDisplay` carries the settings on every change. Every query considers registered interactables only, never scenery, and `hitProximity`'s point is the surface point nearest the query; the test host gains `placeScenery` and `pointerDisplay`. Kit cases: a hand's select is 0 or 1 and its squeeze 0; the pointer display is the app's and the host draws what it is handed; queries never answer with scenery enclosing the hand; the drawing case now covers a panel cursor and a ray told off. `createNativeInteractions({ pointers, pointerDisplay })`.
|
|
21
|
+
- `@realitycollective/webxr-interactions` - the near-pointer rule, IWSDK 1.0.0's pointer stack restated as one core decision every binding runs (`near-pointer.ts`, `NEAR_POINTER_DEFAULTS`): a fingertip (or a controller's ray origin) within 0.15 m of a target's surface owns the source as the touch pointer (hysteresis out to 0.2 m), presses at 0.02 m arriving from outside and releases on the way out, never pressing from inside or behind; the grip is a 0.07 m grab sphere; per source the first of touch, grab, ray with a candidate is the active pointer, locked while it presses or grabs; and `InteractionRuntime` publishes per-source `PointerVisuals` (`onPointerVisuals`, `getPointerVisuals`, `getActivePointer`): the ray and its cursor show only while the ray owns the source or nothing does, with the cursor at the active pointer's hit. `InteractableDescriptor.pokeRadius` is now the touch hover enter distance for that target (default 0.15 m, was a 0.05 m proximity trigger). `nearPointerContractCases()` is the shared suite, run on every platform's hit tester.
|
|
22
|
+
- `@realitycollective/webxr-interactions` - the physics contract (`physics.ts`): `PhysicsFacility`, the platform physics behind one set of semantics and IWSDK 1.0.0's defaults (`PHYSICS_DEFAULTS`: gravity `[0, -9.81, 0]`, 60 steps per second with interpolation, a dynamic body with no damping and gravity factor 1, an auto shape with density 1, restitution 0 and friction 0.5), static and kinematic states, suspend for a hold, resume with the release velocity, teleport with velocity cleared. `physicsFacilityContractCases()` proves a facility falls and rests, bounces, holds, throws, teleports and disposes; `MemoryPhysicsFacility` is the engine-free reference. Every binding names a default engine and takes an app's own facility instead: `createThreeInteractions({ physics: { rapier } })` (Rapier, `RapierPhysicsFacility`, proved against the real engine), `connectXRBlocksInteractions({ physics: { rapier } })` (the Rapier XR Blocks bundles), `registerInteractions` (Havok through IWSDK's components, `IWSDKPhysicsFacility`), `createBabylonInteractions({ physics: { kit } })` (Havok, `BabylonPhysicsFacility`, proved against a fake), and the native `physics` slice (`NativePhysicsHost`, Jolt on Quest and Android, RealityKit on visionOS, with every obligation stated in `native-types.ts` and the whole shared suite in the host conformance kit). A registered object with a body drives the held pose through its facility; `register` takes `body` and `shape` specs.
|
|
23
|
+
- `@realitycollective/native-interactions` - `NativeInputHost.applyPointerVisuals(sourceId, visuals)`: the host is told each frame whether to draw a source's ray and where its cursor sits, and draws exactly that; the earlier rule that the host draws a cursor at every ray hit is withdrawn. The kit gains `input/the ray and cursor are drawn exactly as told`, the whole `nearPointerContractCases()` suite over the host's own queries, and the physics cases.
|
|
24
|
+
- `@realitycollective/iwsdk-interactions` - `test/near-pointer-reference.test.ts` reads the touch and grab constants off IWSDK 1.0.0's own pointer classes and drives the core touch machine beside `@pmndrs/pointer-events`' press rule, recording the one frame they differ on by design (a fingertip first seen inside the press band).
|
|
25
|
+
- `@realitycollective/xrblocks-interactions` - the provider reads the XR Blocks camera's head pose through real three.js scratch objects; a plain object handed to `getWorldPosition` threw against the real camera.
|
|
26
|
+
- Eye gaze and pinch, on every platform, following Meta IWSDK 1.0.0's gaze-and-pinch interaction (the primary input on Meta VR Glasses). The provider half of the rule is `@realitycollective/webxr-input` 0.1.7's `EyeGazeInput`; this repository applies it in every provider and adds the targeting half to the core. `@realitycollective/webxr-interactions` - `HitTester` gains an optional `hitCone(ray, halfAngle, maxLength)`, IWSDK's `GazeConecaster` query (a target the ray reaches wins outright, otherwise the nearest to the axis within the cone, the nearer on a tie within half a degree), with `coneHitForSpheres` for sphere-based testers and `GazeConsensus`, the time-weighted dwell vote over IWSDK's 0.15 s window. `InteractionRuntime` takes `eyeGaze` options (`EYE_GAZE_DEFAULTS`: 5 degree cone, 30 m, 0.15 s, suppression on, follow the hand on) and, when the provider reports `capabilities.eyeGaze`, targets the gaze source through the cone and the consensus, targets nothing while a hand's near pointer is hovering or grabbing, satisfies `gaze.required` and dwell from the eye gaze, presses or grabs the gazed target when the owning hand pinches, and from the next frame drives the gaze source's ray from the pinching hand aimed at the gaze hit (`selectorPose`), so `onSample` listeners such as the pointer bridge and every behaviour see a drag that follows the hand. `hitTesterContractCases()` gains five `hitCone` cases that run when a tester has one. Without `eyeGaze` nothing changes: a gaze-kind source still targets by plain ray as head gaze does.
|
|
27
|
+
- `@realitycollective/iwsdk-interactions` - `IWSDKInputProvider` reports `eyeGaze` when the session carries a gaze input source, reads IWSDK's own sampled eye pose (`xrOrigin.eyeSpace` while `gazeOrigin` is `"tracked"`) and applies `EyeGazeInput`, so it hands far targeting to gaze exactly when IWSDK's `GazePointer` does; `EntityHitTester` answers `hitCone` over its spheres. `test/gaze-reference.test.ts` drives IWSDK's `FilteredEyeGaze` and `GazeConecaster` side by side with the core's filter and consensus.
|
|
28
|
+
- `@realitycollective/threejs-interactions` (reused by `@realitycollective/xrblocks-interactions`) - `WebXRInputProvider` finds the `targetRayMode === "gaze"` source, poses it against the reference space and applies `EyeGazeInput`; `ThreeHitTester.hitCone` tries the raycast first and then the cone over the registered roots' bounding spheres.
|
|
29
|
+
- `@realitycollective/babylon-interactions` - `BabylonInputProvider` reads the `xr-eye-tracking` feature (`WebXREyeTracking.getEyeGaze()`) when the app enabled it and applies `EyeGazeInput`; `BabylonHitTester.hitCone` runs the cone over its spheres.
|
|
30
|
+
- `@realitycollective/native-interactions` - `NativeInputFacts.eyeTracking` (an eye-gaze source is present: OpenXR `XR_EXT_eye_gaze_interaction` bound and active) and `NativeInputHost.getEyeGazePose()` (this frame's gaze target-ray pose, world space, or null) let a native host report the facts while the binding applies the rule: `eyeGaze` is derived, far rays are dropped, the pinch selects, and the selector pose is built from the hand's ray. The `interactions` slice gains an optional `hitCone` the host answers over its own scene, forwarded by `NativeHitTester`. The host conformance kit gains `input/eye gaze` cases: a host that reports eye tracking must pose the gaze, and a hidden target never answers a cone query.
|
|
31
|
+
|
|
11
32
|
- `@realitycollective/webxr-interactions` - three `hitTesterContractCases()` that hold every platform to IWSDK's hit-test semantics: `hitProximity` reports the distance to the target's SURFACE, clamped at zero (a point 3 cm outside a 10 cm target reports 0.03 within 1 mm, not 0.13); it misses a target whose surface is farther than the query radius; and a ray that passes a target farther than its radius misses it. Every platform in the repository already passed them. The `HitTester` and `TransformPort.setEffect` docs now state those semantics, and the effect rule: `scale` multiplies the rest scale, `emissive` adds to the base intensity, and the last write wins.
|
|
12
33
|
- `@realitycollective/native-interactions` - `nativeInteractionsHostConformanceCases()`, the host conformance kit a native app runs on its device against its real slices: the core's whole `hitTesterContractCases()` run against the host itself, the 0.1 m default target radius, the release velocity reaching `endHold`, live-session capabilities, presence hiding the models only per side, `"auto"` following the live modality, and presence never hiding the cursors. The host provides the test readbacks of the new `NativeInteractionsTestHost` type. The kit fails a host that measures proximity to a target's centre, ignores the radius it is handed, loses a release velocity, or draws the wrong presence.
|
|
13
34
|
- `@realitycollective/webxr-interactions` - shared conformance suites for `HitTester` and `TransformPort`, `hitTesterContractCases()` and `transformPortContractCases()`, alongside the existing `inputProviderContractCases()` from `@realitycollective/webxr-input`. Runner-free data, the same pattern as WebXR-UIExtensions' `windowHostContractCases()`: each case throws a plain `Error` naming what a platform's ray/proximity query or transform read/write broke, and asserts only what `ports.ts` documents - a ray or proximity query answers null or an id with a positive distance and a point near the query, the nearer of two targets wins, an offset round-trips, `getWorldPose()` is finite with a unit quaternion, `getRestWorldPose()` is the registration pose and stays put, `getWorldPose()` follows `setLocalOffset`, `setLocalRotation` and `setWorldPose` from that rest frame, every returned tuple is a fresh value the caller owns and no tuple passed in is kept, and the optional `setEffect` accepts its shape without throwing. Each platform's subject starts away from the origin and turned, so a port that ignores its rest frame fails. Run against all five platforms in `packages/iwsdk-interactions/test/port-parity.test.ts`, next to the provider parity suite; every platform passes every case.
|
|
@@ -27,6 +48,8 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
|
|
27
48
|
|
|
28
49
|
### Changed
|
|
29
50
|
|
|
51
|
+
- Every package now requires `@realitycollective/webxr-input` at `^0.1.8-preview.0` rather than `^0.1.7`: the pointer arbiter and the pointer display the code above uses exist only from that release, so an older Input fails at install rather than at run time.
|
|
52
|
+
|
|
30
53
|
- The reference is now IWSDK 1.0. `@realitycollective/iwsdk-interactions` peers on `@iwsdk/core` and `@iwsdk/xr-input` `>=1.0.0 <2.0.0` (was `>=0.5.0 <0.6.0`) and is built and tested against 1.0.0. The per-frame visibility write the presence code works around is unchanged in 1.0.
|
|
31
54
|
- `@realitycollective/threejs-interactions`, `@realitycollective/babylon-interactions` and `@realitycollective/xrblocks-interactions` - a controller's `indexTip` is its ray origin, as IWSDK's input rig makes it, so a controller pokes buttons and interactables as a fingertip does. Before this only a tracked hand carried an index tip on these three platforms, and controllers could not poke at all.
|
|
32
55
|
- **Breaking for native hosts:** `@realitycollective/native-interactions` now derives and decides what the IWSDK provider derives and decides, and a native host reports facts rather than conclusions. What a host must absorb:
|
|
@@ -37,9 +60,13 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
|
|
37
60
|
- `@realitycollective/native-interactions` - `NativeInputProvider` samples no sources while the session lacks focus, as IWSDK's provider samples none unless its visibility state is `Visible`; clamps a pulse's intensity to 0..1, as IWSDK does; takes `nativeGrab` as IWSDK's provider does; and has a `dispose()`, which `NativeInteractions.dispose()` calls.
|
|
38
61
|
- `@realitycollective/webxr-interactions` - `TransformPort.getWorldPose()` is the LIVE world pose on every platform, and the new required `getRestWorldPose()` returns the rest pose captured at registration, in world space. The core only said "current world pose", and the platforms disagreed: the three.js, IWSDK and XR Blocks ports returned the rest pose, while the Babylon.js port returned the live one. The same behaviour therefore acted differently by platform. The hinge, slide and dial behaviours measure the hand against the rest pose, so they now call `getRestWorldPose()`. Grab and toss scoring keep `getWorldPose()` and now see where the object really is. `ports.ts` also states tuple ownership for `TransformPort` and `HitTester`: every returned tuple is fresh and owned by the caller, and a tuple passed in is read during the call and not kept. Every platform already met the ownership rule; the suites now hold them to it. The native `interactions` slice gains `getRestWorldPose(targetId)`, which the native app must implement. This adds a required member to `TransformPort`, so a port written outside this repository must implement it.
|
|
39
62
|
- `@realitycollective/xrblocks-interactions` - the structural slices `XBVec3Like`, `XBQuatLike`, `XBRayLike` and `XBControllerLike` are exported, under the same `XB` prefix as `XBRaySourceLike`, `XBDirectTouchLike` and `XBFrameLike` whose fields they type. They were module-private, so a consumer building a fake frame for a test had nothing to name, and TypeDoc reported each as referenced but undocumented.
|
|
63
|
+
- Dependencies on other Reality Collective repositories now follow one rule, checked by `scripts/rc-dependencies.mjs`. Going into `main`, each names the release npm tags `latest` and never a preview. Going into any other branch, each names the newest version on npm, release or preview. The rule covers every `package.json` in the repository (published packages, demos, harnesses and examples) and every copy `package-lock.json` records. A range passes only when its lowest version is the target, so `^0.1.8` passes for 0.1.8 and `^0.1.4` does not. CI runs it before the install, against the branch a pull request targets, and the publish workflow runs it before publishing. `release.mjs status` reports it. `release.mjs prepare` stops before cutting a release when a dependency names an unreleased preview of another repository, because that repository has to release first, and moves any range that is only behind. Other dependencies are out of scope. The script stays identical across the Reality Collective repositories.
|
|
40
64
|
|
|
41
65
|
### Fixed
|
|
42
66
|
|
|
67
|
+
- `@realitycollective/iwsdk-interactions` - `register` and the physics facility no longer throw in a world created with `features.physics` off. IWSDK registers `PhysicsBody` and `PhysicsShape` only when physics is on, and elics throws when an entity is asked about a component its world never registered, so the first registration in such an app failed with "Cannot read properties of null (reading 'words')". The binding now treats an unregistered component as absent; a test drives a real elics world with physics off.
|
|
68
|
+
- The playground's XR Blocks page drew nothing on a desktop: XR Blocks appends its canvas after the full-height container, below the visible page. The playground now moves it into the container.
|
|
69
|
+
|
|
43
70
|
- `@realitycollective/threejs-interactions`, `@realitycollective/iwsdk-interactions` and `@realitycollective/xrblocks-interactions` - `getWorldPose()` returned the pose captured at registration, not where the object was. Toss scoring therefore read a thrown ball at its registered position until the app called `recaptureRest()`, and a second grab of an object moved without a recapture took its hold offset from the old position. `getWorldPose()` now returns the live pose, as the Babylon.js port already did.
|
|
44
71
|
- `@realitycollective/webxr-interactions` - `InteractableDescriptor.pokeRadius` had no effect. The value was stored on the registration and documented as the poke trigger radius, but the proximity query always used the 5 cm default, so an interactable asking for a wider or narrower poke got the default. The runtime now queries once per source at the largest radius any enabled interactable registered, and accepts the nearest hit only when it lies inside that interactable's own radius. One query per source is kept deliberately; the trade is that a farther interactable with a larger radius is not found behind a nearer one with a smaller radius, because the hit tester returns only the nearest. Covered by a runtime test that failed before the change.
|
|
45
72
|
- CI - the staging deploy published under `--branch=pr-<number>` while the `-test` Pages project's production branch is `staging`, so only `pr-<n>.webxr-interactions-test.pages.dev` aliases were ever created and the project's root URL was a 404. It now deploys as `staging` on every pull request and on every push to `development`, so `webxr-interactions-test.pages.dev` serves the newest preview build, the same arrangement WebXR-UIExtensions already had.
|
|
@@ -98,5 +125,5 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
|
|
98
125
|
- All five packages depend on `@realitycollective/webxr-input`, released independently from the [WebXR-Input](https://github.com/realitycollective/WebXR-Input) repository. That package must be published before this one.
|
|
99
126
|
- The interaction packages themselves carry no IWSDK coupling beyond the adapter: `webxr-interactions` is engine-free, and `threejs-interactions` and `xrblocks-interactions` peer only on three.js.
|
|
100
127
|
|
|
101
|
-
[0.1.1]: https://github.com/realitycollective/WebXR-Interactions/
|
|
128
|
+
[0.1.1]: https://github.com/realitycollective/WebXR-Interactions/releases/tag/v0.1.1
|
|
102
129
|
[0.1.0]: https://github.com/realitycollective/WebXR-Interactions/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Two words are used throughout. An **interactable** is an object that can be inte
|
|
|
8
8
|
npm install @realitycollective/webxr-interactions
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
> You usually do **not** install this directly. Install an adapter for your engine instead. Each adapter re-exports everything here, so your app depends on one package: [`threejs-interactions`](https://www.npmjs.com/package/@realitycollective/threejs-interactions) · [`iwsdk-interactions`](https://www.npmjs.com/package/@realitycollective/iwsdk-interactions) · [`xrblocks-interactions`](https://www.npmjs.com/package/@realitycollective/xrblocks-interactions)
|
|
11
|
+
> You usually do **not** install this directly. Install an adapter for your engine instead. Each adapter re-exports everything here, so your app depends on one package: [`threejs-interactions`](https://www.npmjs.com/package/@realitycollective/threejs-interactions) · [`iwsdk-interactions`](https://www.npmjs.com/package/@realitycollective/iwsdk-interactions) · [`xrblocks-interactions`](https://www.npmjs.com/package/@realitycollective/xrblocks-interactions) · [`babylon-interactions`](https://www.npmjs.com/package/@realitycollective/babylon-interactions) · [`native-interactions`](https://www.npmjs.com/package/@realitycollective/native-interactions)
|
|
12
12
|
|
|
13
13
|
## What it provides
|
|
14
14
|
|
|
@@ -16,10 +16,19 @@ npm install @realitycollective/webxr-interactions
|
|
|
16
16
|
| --- | --- |
|
|
17
17
|
| **Behaviours** | Ready-made interaction types: `press` (with an optional latching mode that stays down until pressed again), `pulse`, `hinge`, `dial`, `slide`, `grab`, and `tossScore` for throw-and-catch scoring |
|
|
18
18
|
| **Gaze** | Optional look-to-activate. Require the user to be looking before an object responds, or let a sustained look trigger the press by itself |
|
|
19
|
+
| **Eye gaze and pinch** | With a provider that reports `capabilities.eyeGaze`, the runtime targets the gaze source through a 5 degree cone (`HitTester.hitCone`) and a 0.15 s dwell consensus, targets nothing while a near pointer is active, presses or grabs on the owning hand's pinch, and drives a gaze-started drag from the hand (IWSDK 1.0.0 gaze-and-pinch, on every platform) |
|
|
19
20
|
| **Targeting** | Picks one target per hand, trying the platform's own answer first, then a close-range touch, then a pointing ray. A short delay stops the target flickering between two objects on a boundary |
|
|
20
21
|
| **Capability checks** | If the headset cannot do what a behaviour needs, the behaviour switches itself off and reports `behaviourDisabled`, rather than silently doing nothing |
|
|
21
22
|
| **Events** | The core never calls into your code. It emits events and you subscribe |
|
|
22
23
|
| **Feedback** | The core asks for a haptic pulse or a sound. Playing it is your app's job. `routeHapticsToProvider` is an opt-in helper that sends those requests straight to the controller |
|
|
24
|
+
| **Pointer arbitration** | One decision per hand across interactables and UI panels: pass a `PointerArbiter` from `@realitycollective/webxr-input` as `pointers` to this setup and to the UI Extensions host. `INTERACTIONS_POINTER_SET`, `NEAR_POINTER_DEFAULTS`, `nearPointerContractCases()` |
|
|
25
|
+
| **Pointer display** | The ray line and cursor disc as app configuration, IWSDK's look by default: the `pointerDisplay` option, `getPointerDisplay()`, `onPointerDrawing()`. Every binding draws the same drawing |
|
|
26
|
+
| **Physics** | `PhysicsFacility`, one contract for the platform physics behind grab, throw and rest, with IWSDK's defaults (`PHYSICS_DEFAULTS`) and `physicsFacilityContractCases()`. Every binding ships one: Rapier (three.js and XR Blocks), IWSDK's own, Babylon Physics V2, the native host's |
|
|
27
|
+
| **Held pose and throws** | `TransformPort.beginHold()` / `endHold(release)`: a grabbed object follows exactly while held and leaves with the object's own velocity over IWSDK's physics step (`ReleaseVelocityTracker`, `RELEASE_WINDOW_SECONDS`). `holderPoint` is the grip first, so hands drive a dial, slide or hinge as controllers do |
|
|
28
|
+
| **Recorded-trace parity** | `TraceRecorder`, `TraceInputProvider`, `replayTrace`, `compareOutcomes`, `traceParityCases()` and `TRACE_TOLERANCES`: an input session recorded on the reference replays through every binding with the same outcome. `synthesizeTrace` builds a synthetic one |
|
|
29
|
+
| **In-memory ports** | `MemoryHitTester`, `MemoryTransformPort` and `MemoryPhysicsFacility`: a complete engine-free host for tests, tools and the trace suite |
|
|
30
|
+
| **Conformance suites** | `hitTesterContractCases()`, `transformPortContractCases()`, `nearPointerContractCases()`, `physicsFacilityContractCases()`, plus `inputProviderContractCases()` from `@realitycollective/webxr-input`, shipped as data so any binding proves itself in its own test runner |
|
|
31
|
+
| **Platforms** | three.js (raw WebXR), Meta IWSDK (the reference), Google XR Blocks, Babylon.js and native hosts (OpenXR on Quest, visionOS). IWSDK is the reference behaviour; every other binding runs the same core rules |
|
|
23
32
|
|
|
24
33
|
All input arrives through the shared [`@realitycollective/webxr-input`](https://www.npmjs.com/package/@realitycollective/webxr-input) types, so the same core runs on any runtime that has an adapter.
|
|
25
34
|
|
|
@@ -29,6 +38,12 @@ All input arrives through the shared [`@realitycollective/webxr-input`](https://
|
|
|
29
38
|
- **Events out, never callbacks in.** The core never reaches into your objects.
|
|
30
39
|
- **Fail loudly, not silently.** A behaviour the hardware cannot support reports `behaviourDisabled` instead of quietly doing nothing.
|
|
31
40
|
|
|
41
|
+
## One pointer decision, and the pointer's look
|
|
42
|
+
|
|
43
|
+
Which pointer owns a hand (touch, grab or ray) is decided ONCE per source across interactables and UI panels, by the `PointerArbiter` from `@realitycollective/webxr-input` (IWSDK's `MultiPointer` over every pointer-event object). Pass one arbiter to the Interactions setup (`pointers`) and to the UI Extensions host, so a fingertip on a panel retires the ray over an object and the cursor is reported on panels too. What is drawn for a pointer is the app's `pointerDisplay` (`PointerDisplay`, IWSDK's look by default: the ray while hitting, drawn as a stub to 0.3 m; cursors on objects and panels), settable at run time; the runtime publishes `onPointerDrawing`, which every binding's renderer draws and the native host is handed.
|
|
44
|
+
|
|
45
|
+
Throws follow the object: the release velocity is the held object's velocity over IWSDK's physics step (`release-velocity.ts`). Parity with the web is measured by replaying recorded input traces (`trace.ts`) through every binding.
|
|
46
|
+
|
|
32
47
|
## Conformance suites
|
|
33
48
|
|
|
34
49
|
Every adapter implements `HitTester` and `TransformPort` (see `ports.ts`) against its own scene graph, so this package ships the checks as data rather than as tests: `hitTesterContractCases()` and `transformPortContractCases()`, alongside `inputProviderContractCases()` from [`@realitycollective/webxr-input`](https://www.npmjs.com/package/@realitycollective/webxr-input) for `InputProvider`. Each case throws a plain `Error` naming the rule a platform broke, so any test runner can host it - an adapter written outside this repository runs the same suite its own way. All three run against every platform in `packages/iwsdk-interactions/test/`, next to each other: `provider-parity.test.ts` for `InputProvider`, `port-parity.test.ts` for `HitTester` and `TransformPort`.
|
|
@@ -37,7 +52,7 @@ Every adapter implements `HitTester` and `TransformPort` (see `ports.ts`) agains
|
|
|
37
52
|
|
|
38
53
|
## Live demo
|
|
39
54
|
|
|
40
|
-
The interaction playground - the full station set, mouse-capable on desktop, VR button for headsets: **[webxr-interactions.pages.dev](https://webxr-interactions.pages.dev)**
|
|
55
|
+
The interaction playground - the full station set on every platform (IWSDK, three.js, Babylon.js and XR Blocks), mouse-capable on desktop, VR button for headsets: **[webxr-interactions.pages.dev](https://webxr-interactions.pages.dev)**
|
|
41
56
|
|
|
42
57
|
## Documentation
|
|
43
58
|
|
|
@@ -36,6 +36,12 @@ export interface InteractorInfo {
|
|
|
36
36
|
angularVelocity?: Vec3Tuple;
|
|
37
37
|
select: number;
|
|
38
38
|
squeeze: number;
|
|
39
|
+
/**
|
|
40
|
+
* True on a release the runtime synthesised because the source was lost,
|
|
41
|
+
* the target unregistered or disabled, or the runtime disposed: no hand
|
|
42
|
+
* let go. A grab behaviour then hands its port zeros instead of a throw.
|
|
43
|
+
*/
|
|
44
|
+
synthesized?: true;
|
|
39
45
|
}
|
|
40
46
|
/** Everything a behaviour can reach during a tick or a routed moment. */
|
|
41
47
|
export interface BehaviourContext {
|
|
@@ -68,5 +74,15 @@ export interface Behaviour {
|
|
|
68
74
|
/** Current logical 0..1 value (state snapshots, HUDs). */
|
|
69
75
|
getValue(): number;
|
|
70
76
|
}
|
|
71
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* The point a hand-driven behaviour (dial, slide, hinge) tracks while a
|
|
79
|
+
* holder grabs it: the GRIP, as IWSDK moves a held object with its grab
|
|
80
|
+
* pointer, which is built on `xrOrigin.gripSpaces[side]` (`@iwsdk/xr-input`
|
|
81
|
+
* `grab-pointer.js`; `@pmndrs/handle` then moves the object with that
|
|
82
|
+
* pointer). Never the index fingertip: with a closed hand the fingertip
|
|
83
|
+
* curls into the palm and barely moves around a wheel's axis, which is why
|
|
84
|
+
* the native handwheel would not turn (Pale Signal handover, G2). A source
|
|
85
|
+
* with no grip (a desktop pointer) falls back to its fingertip, then its
|
|
86
|
+
* ray origin.
|
|
87
|
+
*/
|
|
72
88
|
export declare function holderPoint(holder: InteractorInfo): Vec3Tuple | undefined;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* The point a hand-driven behaviour (dial, slide, hinge) tracks while a
|
|
3
|
+
* holder grabs it: the GRIP, as IWSDK moves a held object with its grab
|
|
4
|
+
* pointer, which is built on `xrOrigin.gripSpaces[side]` (`@iwsdk/xr-input`
|
|
5
|
+
* `grab-pointer.js`; `@pmndrs/handle` then moves the object with that
|
|
6
|
+
* pointer). Never the index fingertip: with a closed hand the fingertip
|
|
7
|
+
* curls into the palm and barely moves around a wheel's axis, which is why
|
|
8
|
+
* the native handwheel would not turn (Pale Signal handover, G2). A source
|
|
9
|
+
* with no grip (a desktop pointer) falls back to its fingertip, then its
|
|
10
|
+
* ray origin.
|
|
11
|
+
*/
|
|
2
12
|
export function holderPoint(holder) {
|
|
3
|
-
return holder.
|
|
13
|
+
return holder.gripPose?.position ?? holder.indexTip ?? holder.ray?.origin;
|
|
4
14
|
}
|
|
5
15
|
//# sourceMappingURL=behaviour.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"behaviour.js","sourceRoot":"","sources":["../../src/behaviours/behaviour.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"behaviour.js","sourceRoot":"","sources":["../../src/behaviours/behaviour.ts"],"names":[],"mappings":"AA0FA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,MAAsB;IAChD,OAAO,MAAM,CAAC,QAAQ,EAAE,QAAQ,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC;AAC5E,CAAC","sourcesContent":["/**\n * The behaviour contract - a mechanism attached to an interactable.\n *\n * Behaviours are pure state machines: they receive routed input moments\n * (press/grab transitions), tick from `update(dt)`, and write their output\n * through the interactable's {@link TransformPort}. They declare:\n *\n * - `ownership` - who owns the transform (the formalised pale-signal\n * driven / dragged / handDriven / native models), so a binder knows\n * without reading code;\n * - `requires` / `requiresAnyOf` - the input capabilities they need;\n * capability negotiation disables unsatisfiable behaviours VISIBLY\n * (a `behaviourDisabled` event with the unmet list), never silently.\n */\nimport type {\n InputCapabilityRequirement,\n InputSourceKind,\n PoseTuple,\n RayTuple,\n Vec3Tuple,\n} from \"@realitycollective/webxr-input\";\nimport type { InteractionEvent } from \"../events.js\";\nimport type { FeedbackIntent } from \"../feedback.js\";\nimport type { TransformPort } from \"../ports.js\";\n\n/** Who owns the interactable's transform while this behaviour is active. */\nexport type TransformOwnership = \"driven\" | \"dragged\" | \"handDriven\" | \"native\";\n\n/** The slice of a live interactor a behaviour may consume. */\nexport interface InteractorInfo {\n id: string;\n kind: InputSourceKind;\n ray?: RayTuple;\n gripPose?: PoseTuple;\n indexTip?: Vec3Tuple;\n /**\n * Grip velocity, present on the same terms as `InputSourceSnapshot`'s -\n * the runtime's `VelocityTracker` fills it when the provider does not.\n * `onGrabEnd`'s release throw reads these; absent on a synthesized\n * release (source lost, target unregistered, runtime disposed), which\n * behaves as zero.\n */\n linearVelocity?: Vec3Tuple;\n angularVelocity?: Vec3Tuple;\n select: number;\n squeeze: number;\n /**\n * True on a release the runtime synthesised because the source was lost,\n * the target unregistered or disabled, or the runtime disposed: no hand\n * let go. A grab behaviour then hands its port zeros instead of a throw.\n */\n synthesized?: true;\n}\n\n/** Everything a behaviour can reach during a tick or a routed moment. */\nexport interface BehaviourContext {\n dt: number;\n interactableId: string;\n transform: TransformPort | undefined;\n emit(event: Omit<InteractionEvent, \"interactableId\">): void;\n feedback(intent: Omit<FeedbackIntent, \"interactableId\">): void;\n /** LIVE world pose of another registered interactable (toss scoring). */\n getWorldPose(interactableId: string): PoseTuple | undefined;\n}\n\nexport interface Behaviour {\n readonly kind: string;\n readonly ownership: TransformOwnership;\n /** ALL of these must be satisfied. */\n readonly requires: readonly InputCapabilityRequirement[];\n /** For each group, AT LEAST ONE must be satisfied. */\n readonly requiresAnyOf?: readonly (readonly InputCapabilityRequirement[])[];\n /** True when this behaviour makes the interactable a grab target. */\n readonly grabbable: boolean;\n\n onPressStart?(ctx: BehaviourContext, interactor: InteractorInfo): void;\n onPressEnd?(ctx: BehaviourContext, interactor: InteractorInfo): void;\n onGrabStart?(ctx: BehaviourContext, interactor: InteractorInfo): void;\n onGrabEnd?(ctx: BehaviourContext, interactor: InteractorInfo): void;\n\n /**\n * Per-frame tick. `holder` is set while a grab interactor holds this\n * interactable (grab-family behaviours consume it; others ignore it).\n */\n update(ctx: BehaviourContext, holder?: InteractorInfo): void;\n\n /** Current logical 0..1 value (state snapshots, HUDs). */\n getValue(): number;\n}\n\n/**\n * The point a hand-driven behaviour (dial, slide, hinge) tracks while a\n * holder grabs it: the GRIP, as IWSDK moves a held object with its grab\n * pointer, which is built on `xrOrigin.gripSpaces[side]` (`@iwsdk/xr-input`\n * `grab-pointer.js`; `@pmndrs/handle` then moves the object with that\n * pointer). Never the index fingertip: with a closed hand the fingertip\n * curls into the palm and barely moves around a wheel's axis, which is why\n * the native handwheel would not turn (Pale Signal handover, G2). A source\n * with no grip (a desktop pointer) falls back to its fingertip, then its\n * ray origin.\n */\nexport function holderPoint(holder: InteractorInfo): Vec3Tuple | undefined {\n return holder.gripPose?.position ?? holder.indexTip ?? holder.ray?.origin;\n}\n"]}
|
|
@@ -12,6 +12,7 @@ export declare class GrabBehaviour implements Behaviour {
|
|
|
12
12
|
private held;
|
|
13
13
|
private offsetPosition;
|
|
14
14
|
private offsetQuaternion;
|
|
15
|
+
private readonly release;
|
|
15
16
|
constructor(_config?: Omit<GrabConfig, "kind">, fulfilment?: GrabFulfilment);
|
|
16
17
|
setFulfilment(fulfilment: GrabFulfilment): void;
|
|
17
18
|
onGrabStart(ctx: BehaviourContext, interactor: InteractorInfo): void;
|
package/dist/behaviours/grab.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { quatConjugate, quatMultiply, vAdd, vApplyQuat, vSub } from "../math.js";
|
|
2
|
+
import { ReleaseVelocityTracker } from "../release-velocity.js";
|
|
2
3
|
export class GrabBehaviour {
|
|
3
4
|
kind = "grab";
|
|
4
5
|
ownership;
|
|
@@ -8,6 +9,7 @@ export class GrabBehaviour {
|
|
|
8
9
|
held = false;
|
|
9
10
|
offsetPosition = [0, 0, 0];
|
|
10
11
|
offsetQuaternion = [0, 0, 0, 1];
|
|
12
|
+
release = new ReleaseVelocityTracker();
|
|
11
13
|
constructor(_config = {}, fulfilment = "poseOnly") {
|
|
12
14
|
this.fulfilment = fulfilment;
|
|
13
15
|
this.ownership = fulfilment === "native" ? "native" : "handDriven";
|
|
@@ -17,6 +19,7 @@ export class GrabBehaviour {
|
|
|
17
19
|
}
|
|
18
20
|
onGrabStart(ctx, interactor) {
|
|
19
21
|
this.held = true;
|
|
22
|
+
this.release.reset();
|
|
20
23
|
if (this.fulfilment === "poseOnly") {
|
|
21
24
|
ctx.transform?.beginHold?.();
|
|
22
25
|
if (interactor.gripPose && ctx.transform) {
|
|
@@ -25,6 +28,8 @@ export class GrabBehaviour {
|
|
|
25
28
|
const invGrip = quatConjugate(grip.quaternion);
|
|
26
29
|
this.offsetPosition = vApplyQuat(vSub(object.position, grip.position), invGrip);
|
|
27
30
|
this.offsetQuaternion = quatMultiply(invGrip, object.quaternion);
|
|
31
|
+
// The pose at pick-up is the first sample the throw is measured from.
|
|
32
|
+
this.release.record(object, 0);
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
ctx.emit({ type: "grabStart", behaviourKind: this.kind, interactorId: interactor.id });
|
|
@@ -43,11 +48,11 @@ export class GrabBehaviour {
|
|
|
43
48
|
// runtime disposed) - see the file comment and `InteractorInfo`'s.
|
|
44
49
|
// The object then resumes at rest rather than flying off on a
|
|
45
50
|
// disconnect it had nothing to do with.
|
|
46
|
-
ctx.transform?.endHold?.(
|
|
47
|
-
linearVelocity:
|
|
48
|
-
|
|
49
|
-
});
|
|
51
|
+
ctx.transform?.endHold?.(interactor.synthesized
|
|
52
|
+
? { linearVelocity: [0, 0, 0], angularVelocity: [0, 0, 0] }
|
|
53
|
+
: this.release.release());
|
|
50
54
|
}
|
|
55
|
+
this.release.reset();
|
|
51
56
|
ctx.emit({ type: "grabEnd", behaviourKind: this.kind, interactorId: interactor.id });
|
|
52
57
|
ctx.feedback({
|
|
53
58
|
cue: "drop",
|
|
@@ -69,6 +74,7 @@ export class GrabBehaviour {
|
|
|
69
74
|
quaternion: quatMultiply(grip.quaternion, this.offsetQuaternion),
|
|
70
75
|
};
|
|
71
76
|
transform.setWorldPose(pose);
|
|
77
|
+
this.release.record(pose, ctx.dt);
|
|
72
78
|
}
|
|
73
79
|
getValue() {
|
|
74
80
|
return this.held ? 1 : 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grab.js","sourceRoot":"","sources":["../../src/behaviours/grab.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"grab.js","sourceRoot":"","sources":["../../src/behaviours/grab.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Grab - pick up and carry an object.\n *\n * Two fulfilments, chosen by capability negotiation at bind time:\n * - `\"poseOnly\"` - the behaviour owns the carry: on grab it captures the\n * offset between the holder's grip and the object, then follows the grip\n * each frame via `setWorldPose`. On a host with no physics the object\n * stays where it is dropped. On one with physics the engine still owns\n * the simulation; this behaviour only suspends and resumes it (see\n * below).\n * - `\"native\"` - the engine owns carry/throw (e.g. IWSDK grabbables +\n * physics); the behaviour only mirrors transitions into core events.\n *\n * On a `poseOnly` host whose object has physics, \"the behaviour owns the\n * carry\" also means the behaviour owns suspending and resuming it:\n * `onGrabStart` calls `ctx.transform.beginHold()` so the follow above does\n * not fight the solver, and `onGrabEnd` calls `endHold()` with the release\n * velocity so a throw carries through. Both are optional on `TransformPort`\n * and simply do not exist on a host with no physics, so this costs a host\n * without one nothing.\n *\n * The release velocity is the core throw rule (`release-velocity.ts`): the\n * velocity of the OBJECT the carry wrote, over IWSDK's physics step of\n * 1/60 s, angular from the orientation delta over the same step. This is\n * what IWSDK's grab system and Havok hand a thrown body, so a throw on a\n * pose-only platform leaves the hand at the same speed as on the web. A\n * source that reports its own grip velocity does not override it: the rule\n * is on the object, on every platform alike. A synthesised release (the\n * source was lost, the target unregistered, the runtime disposed) throws\n * nothing: zeros, and the object resumes at rest.\n */\nimport type { PoseTuple } from \"@realitycollective/webxr-input\";\nimport { quatConjugate, quatMultiply, vAdd, vApplyQuat, vSub } from \"../math.js\";\nimport { ReleaseVelocityTracker } from \"../release-velocity.js\";\nimport type { Behaviour, BehaviourContext, InteractorInfo } from \"./behaviour.js\";\n\nexport interface GrabConfig {\n kind: \"grab\";\n}\n\nexport type GrabFulfilment = \"poseOnly\" | \"native\";\n\nexport class GrabBehaviour implements Behaviour {\n readonly kind = \"grab\";\n readonly ownership: \"handDriven\" | \"native\";\n readonly requires = [\"grabs\"] as const;\n readonly grabbable = true;\n\n private fulfilment: GrabFulfilment;\n private held = false;\n private offsetPosition = [0, 0, 0] as [number, number, number];\n private offsetQuaternion = [0, 0, 0, 1] as [number, number, number, number];\n private readonly release = new ReleaseVelocityTracker();\n\n constructor(_config: Omit<GrabConfig, \"kind\"> = {}, fulfilment: GrabFulfilment = \"poseOnly\") {\n this.fulfilment = fulfilment;\n this.ownership = fulfilment === \"native\" ? \"native\" : \"handDriven\";\n }\n\n setFulfilment(fulfilment: GrabFulfilment): void {\n this.fulfilment = fulfilment;\n }\n\n onGrabStart(ctx: BehaviourContext, interactor: InteractorInfo): void {\n this.held = true;\n this.release.reset();\n if (this.fulfilment === \"poseOnly\") {\n ctx.transform?.beginHold?.();\n if (interactor.gripPose && ctx.transform) {\n const object = ctx.transform.getWorldPose();\n const grip = interactor.gripPose;\n const invGrip = quatConjugate(grip.quaternion);\n this.offsetPosition = vApplyQuat(vSub(object.position, grip.position), invGrip);\n this.offsetQuaternion = quatMultiply(invGrip, object.quaternion);\n // The pose at pick-up is the first sample the throw is measured from.\n this.release.record(object, 0);\n }\n }\n ctx.emit({ type: \"grabStart\", behaviourKind: this.kind, interactorId: interactor.id });\n ctx.feedback({\n cue: \"grab\",\n behaviourKind: this.kind,\n sourceId: interactor.id,\n intensity: 0.5,\n durationMs: 30,\n });\n }\n\n onGrabEnd(ctx: BehaviourContext, interactor: InteractorInfo): void {\n this.held = false;\n if (this.fulfilment === \"poseOnly\") {\n // Zero on a synthesized release (source lost, target unregistered,\n // runtime disposed) - see the file comment and `InteractorInfo`'s.\n // The object then resumes at rest rather than flying off on a\n // disconnect it had nothing to do with.\n ctx.transform?.endHold?.(\n interactor.synthesized\n ? { linearVelocity: [0, 0, 0], angularVelocity: [0, 0, 0] }\n : this.release.release(),\n );\n }\n this.release.reset();\n ctx.emit({ type: \"grabEnd\", behaviourKind: this.kind, interactorId: interactor.id });\n ctx.feedback({\n cue: \"drop\",\n behaviourKind: this.kind,\n sourceId: interactor.id,\n intensity: 0.25,\n durationMs: 20,\n });\n }\n\n update(ctx: BehaviourContext, holder?: InteractorInfo): void {\n if (this.fulfilment !== \"poseOnly\" || !this.held || !holder) return;\n const grip = holder.gripPose;\n const transform = ctx.transform;\n if (!grip || !transform?.setWorldPose) return;\n const pose: PoseTuple = {\n position: vAdd(grip.position, vApplyQuat(this.offsetPosition, grip.quaternion)),\n quaternion: quatMultiply(grip.quaternion, this.offsetQuaternion),\n };\n transform.setWorldPose(pose);\n this.release.record(pose, ctx.dt);\n }\n\n getValue(): number {\n return this.held ? 1 : 0;\n }\n}\n"]}
|
package/dist/contract-cases.js
CHANGED
|
@@ -24,6 +24,9 @@ const AWAY_RAY = { origin: [0, 0, 0], direction: [0, 0, 1] };
|
|
|
24
24
|
*/
|
|
25
25
|
/** A surface distance is exact up to 1 mm, the tolerance the master row states. */
|
|
26
26
|
const SURFACE_EPS = 1e-3;
|
|
27
|
+
function degrees(value) {
|
|
28
|
+
return (value * Math.PI) / 180;
|
|
29
|
+
}
|
|
27
30
|
function slack(radius) {
|
|
28
31
|
return radius + 0.05;
|
|
29
32
|
}
|
|
@@ -81,6 +84,21 @@ const HIT_TESTER_CASES = [
|
|
|
81
84
|
assert(inside !== null && inside.distance === 0, `a point inside the target is at distance 0, got ${inside?.distance}`);
|
|
82
85
|
},
|
|
83
86
|
},
|
|
87
|
+
{
|
|
88
|
+
name: "hitProximity's point is the surface point nearest the query point, never the centre",
|
|
89
|
+
run({ hitTester, driver }) {
|
|
90
|
+
// The touch cursor sits at this point (IWSDK's sphere intersector
|
|
91
|
+
// reports the point on the mesh). A host that answered with the centre
|
|
92
|
+
// put the cursor inside the object (Pale Signal handover, G7).
|
|
93
|
+
driver.place("target", [0, 0, -2], 0.1);
|
|
94
|
+
const hit = hitTester.hitProximity([0.13, 0, -2], 0.5);
|
|
95
|
+
assert(hit !== null, "a point 3 cm outside a 10 cm target must be found within 0.5 m");
|
|
96
|
+
assertVec3Close(hit.point, [0.1, 0, -2], 0.02, "the proximity point");
|
|
97
|
+
const above = hitTester.hitProximity([0, 0.15, -2], 0.5);
|
|
98
|
+
assert(above !== null, "a point 5 cm above the target must be found");
|
|
99
|
+
assertVec3Close(above.point, [0, 0.1, -2], 0.02, "the proximity point from above");
|
|
100
|
+
},
|
|
101
|
+
},
|
|
84
102
|
{
|
|
85
103
|
name: "hitProximity misses a target whose surface is farther than the query radius",
|
|
86
104
|
run({ hitTester, driver }) {
|
|
@@ -154,6 +172,69 @@ const HIT_TESTER_CASES = [
|
|
|
154
172
|
}
|
|
155
173
|
},
|
|
156
174
|
},
|
|
175
|
+
{
|
|
176
|
+
name: "hitCone, when present, answers a ray that reaches a target with that target at angular distance zero",
|
|
177
|
+
run({ hitTester, driver }) {
|
|
178
|
+
if (!hitTester.hitCone)
|
|
179
|
+
return;
|
|
180
|
+
driver.place("cone-direct", [0, 0, -2], 0.1);
|
|
181
|
+
const hit = hitTester.hitCone(DOWN_RAY, degrees(5), 30);
|
|
182
|
+
assert(hit !== null, "hitCone answered null for a target on the ray");
|
|
183
|
+
assert(hit.interactableId === "cone-direct", `hitCone named "${hit.interactableId}", expected "cone-direct"`);
|
|
184
|
+
assert(hit.distance > 0 && hit.distance <= 2 + slack(0.1), `hitCone reported distance ${String(hit.distance)}, expected about 2`);
|
|
185
|
+
assert(dist(hit.point, [0, 0, -2]) <= slack(0.1), "hitCone's point is not on the target");
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: "hitCone, when present, finds a target inside the cone that the ray itself misses",
|
|
190
|
+
run({ hitTester, driver }) {
|
|
191
|
+
if (!hitTester.hitCone)
|
|
192
|
+
return;
|
|
193
|
+
// 2 m ahead and 0.2 m to the side: its silhouette (radius 0.1) is about
|
|
194
|
+
// 2.9 degrees off axis, inside a 5 degree cone, outside the ray.
|
|
195
|
+
driver.place("cone-near", [0.2, 0, -2], 0.1);
|
|
196
|
+
assert(hitTester.hitRay(DOWN_RAY) === null, "the ray itself must miss the offset target");
|
|
197
|
+
const hit = hitTester.hitCone(DOWN_RAY, degrees(5), 30);
|
|
198
|
+
assert(hit !== null && hit.interactableId === "cone-near", "hitCone did not find the target inside the cone");
|
|
199
|
+
assert(dist(hit.point, [0.2, 0, -2]) <= slack(0.1), "hitCone's point is not on the target");
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: "hitCone, when present, ignores a target outside the cone and one beyond the length",
|
|
204
|
+
run({ hitTester, driver }) {
|
|
205
|
+
if (!hitTester.hitCone)
|
|
206
|
+
return;
|
|
207
|
+
driver.place("cone-wide", [0.5, 0, -2], 0.1);
|
|
208
|
+
driver.place("cone-far", [0, 0, -40], 0.1);
|
|
209
|
+
assert(hitTester.hitCone(DOWN_RAY, degrees(5), 30) === null, "hitCone answered with a target outside the cone or beyond the length");
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: "hitCone, when present, prefers the target nearer the axis, and the nearer of two on the axis",
|
|
214
|
+
run({ hitTester, driver }) {
|
|
215
|
+
if (!hitTester.hitCone)
|
|
216
|
+
return;
|
|
217
|
+
driver.place("cone-off", [0.15, 0, -2], 0.05);
|
|
218
|
+
driver.place("cone-on", [0.05, 0, -3], 0.05);
|
|
219
|
+
const byAngle = hitTester.hitCone(DOWN_RAY, degrees(8), 30);
|
|
220
|
+
assert(byAngle !== null && byAngle.interactableId === "cone-on", "hitCone did not prefer the target nearer the axis");
|
|
221
|
+
driver.place("cone-nearer", [0, 0, -1], 0.05);
|
|
222
|
+
const nearer = hitTester.hitCone(DOWN_RAY, degrees(8), 30);
|
|
223
|
+
assert(nearer !== null && nearer.interactableId === "cone-nearer", "with two targets on the axis, hitCone did not prefer the nearer");
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: "hitCone, when present, never answers with a target hidden by visible alone, when the driver can toggle it",
|
|
228
|
+
run({ hitTester, driver }) {
|
|
229
|
+
if (!hitTester.hitCone || !driver.setVisible)
|
|
230
|
+
return;
|
|
231
|
+
driver.place("cone-hidden", [0, 0, -2], 0.1);
|
|
232
|
+
driver.setVisible("cone-hidden", false);
|
|
233
|
+
assert(hitTester.hitCone(DOWN_RAY, degrees(5), 30) === null, "hitCone answered with a hidden target");
|
|
234
|
+
driver.setVisible("cone-hidden", true);
|
|
235
|
+
assert(hitTester.hitCone(DOWN_RAY, degrees(5), 30)?.interactableId === "cone-hidden", "hitCone lost the target after it was shown again");
|
|
236
|
+
},
|
|
237
|
+
},
|
|
157
238
|
];
|
|
158
239
|
/**
|
|
159
240
|
* The shared `TransformPort` conformance suite. An adapter's test file is a
|
|
@@ -372,6 +453,9 @@ function assert(condition, message) {
|
|
|
372
453
|
if (!condition)
|
|
373
454
|
throw new Error(message);
|
|
374
455
|
}
|
|
456
|
+
function dist(a, b) {
|
|
457
|
+
return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
|
|
458
|
+
}
|
|
375
459
|
function closeTo(a, b, eps) {
|
|
376
460
|
return Math.abs(a - b) <= eps;
|
|
377
461
|
}
|