@realitycollective/babylon-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 +6 -3
- package/dist/babylon-types.d.ts +104 -0
- package/dist/babylon-types.js +2 -0
- package/dist/babylon-types.js.map +1 -1
- package/dist/hit-tester.d.ts +6 -0
- package/dist/hit-tester.js +25 -2
- package/dist/hit-tester.js.map +1 -1
- package/dist/host.d.ts +63 -3
- package/dist/host.js +49 -2
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/physics-facility.d.ts +77 -0
- package/dist/physics-facility.js +199 -0
- package/dist/physics-facility.js.map +1 -0
- package/dist/pointer-visuals.d.ts +105 -0
- package/dist/pointer-visuals.js +149 -0
- package/dist/pointer-visuals.js.map +1 -0
- package/dist/provider.d.ts +16 -1
- package/dist/provider.js +49 -4
- package/dist/provider.js.map +1 -1
- package/dist/transform-port.d.ts +30 -2
- package/dist/transform-port.js +23 -0
- package/dist/transform-port.js.map +1 -1
- package/package.json +7 -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 @@ npm install @realitycollective/babylon-interactions
|
|
|
8
8
|
|
|
9
9
|
It re-exports everything from the core, so this is the only interaction package your app needs.
|
|
10
10
|
|
|
11
|
-
> **
|
|
11
|
+
> **Maturity.** Written against the documented Babylon API and covered by structural fakes; the interaction playground runs it in a real Babylon scene on desktop. No headset pass yet. The physics facility fails 7 of the 10 shared physics cases against a real Havok plugin (`test/physics-facility-havok.test.ts`), so treat physics on Babylon as experimental.
|
|
12
12
|
|
|
13
13
|
## What it binds
|
|
14
14
|
|
|
@@ -20,6 +20,9 @@ It re-exports everything from the core, so this is the only interaction package
|
|
|
20
20
|
| **Desktop** | `scene.onPointerObservable` as a pointer fallback, so the same scene is testable without a headset |
|
|
21
21
|
| **Haptics** | Through the motion controller's `pulse` |
|
|
22
22
|
| **No @babylonjs/core dependency** | It matches the shape of the Babylon API in TypeScript rather than importing Babylon, so an upstream release cannot break your install |
|
|
23
|
+
| **Pointer visuals** | `BabylonPointerVisuals` draws the app's `pointerDisplay` through a structural kit of your own `MeshBuilder`, `StandardMaterial`, `Color3` and `Quaternion`: `createBabylonInteractions({ pointerVisuals: { kit }, pointers, pointerDisplay })` |
|
|
24
|
+
| **Physics** | `BabylonPhysicsFacility` over Physics V2 (`physics: { kit }`), and `BabylonTransformPort`'s held pose over a node's `physicsBody` (`physicsMotionTypes`) |
|
|
25
|
+
| **Eye gaze** | `BabylonInputProvider` reads the `xr-eye-tracking` feature when the app enabled it and applies the shared gaze-and-pinch rule |
|
|
23
26
|
|
|
24
27
|
## Usage
|
|
25
28
|
|
|
@@ -52,7 +55,7 @@ interactions.setPickWithRay((origin, direction, maxDistance) => {
|
|
|
52
55
|
- **Rotations need a quaternion.** A node whose `rotationQuaternion` is null is still driven by Euler angles. Set `node.rotationQuaternion = Quaternion.Identity()` before registering it, or pass `createQuaternion` to `register`, otherwise the first rotation write stores a plain object that Babylon cannot use.
|
|
53
56
|
- **Presence** shows and hides what Babylon built: motion controller root meshes and hand meshes. Babylon picks the visual per input source, so there is no hands/controllers switch - `setPresenceModality` always returns false.
|
|
54
57
|
- **Desktop grip.** The pointer fallback puts its grip one metre along the pointer ray, matching the three.js adapter, so grab, hinge, dial and slide follow the cursor on desktop. Set `desktopGripDistance` near the distance of the things being manipulated; at 0 the grip sits on the camera and a drag reports camera motion only.
|
|
55
|
-
- **Held pose.** A node with a Physics V2 `physicsBody`, registered with `physicsMotionTypes` (Babylon's own `PhysicsMotionType.ANIMATED`/`.DYNAMIC` - this package holds no Babylon values, only shapes), grows `beginHold`/`endHold`: while held it switches to `ANIMATED` and follows `setWorldPose` exactly, ignoring gravity and collisions; on release it goes back to `DYNAMIC` with the grabbing hand's velocity, so a throw carries through; a `setWorldPose` while not held teleports and clears velocity. A node with no `physicsBody`, or a construction with no `physicsMotionTypes`, gets neither member and behaves exactly as before. This
|
|
58
|
+
- **Held pose.** A node with a Physics V2 `physicsBody`, registered with `physicsMotionTypes` (Babylon's own `PhysicsMotionType.ANIMATED`/`.DYNAMIC` - this package holds no Babylon values, only shapes), grows `beginHold`/`endHold`: while held it switches to `ANIMATED` and follows `setWorldPose` exactly, ignoring gravity and collisions; on release it goes back to `DYNAMIC` with the grabbing hand's velocity, so a throw carries through; a `setWorldPose` while not held teleports and clears velocity. A node with no `physicsBody`, or a construction with no `physicsMotionTypes`, gets neither member and behaves exactly as before. The physics half is written from the Babylon Physics V2 documentation. This repository installs neither `@babylonjs/core` nor `@babylonjs/havok`, so CI checks it against structural fakes only. With both installed, `test/physics-facility-havok.test.ts` runs the shared physics suite against real Havok; the maturity note above says where that stands. Confirm it in your own scene before relying on it.
|
|
56
59
|
|
|
57
60
|
## Peer dependency
|
|
58
61
|
|
|
@@ -60,7 +63,7 @@ None. Babylon is matched structurally, not imported, so any Babylon version whos
|
|
|
60
63
|
|
|
61
64
|
## Live demo
|
|
62
65
|
|
|
63
|
-
The interaction playground - the
|
|
66
|
+
The interaction playground - the same station set on every platform; add `?engine=babylon` for this adapter: **[webxr-interactions.pages.dev](https://webxr-interactions.pages.dev)**
|
|
64
67
|
|
|
65
68
|
## Documentation
|
|
66
69
|
|
package/dist/babylon-types.d.ts
CHANGED
|
@@ -82,6 +82,13 @@ export interface BabylonTransformNodeLike {
|
|
|
82
82
|
physicsBody?: BabylonPhysicsBodyLike;
|
|
83
83
|
/** `AbstractMesh.material` - a multi-material mesh's first slot is what `setEffect`'s emissive pulse lights. */
|
|
84
84
|
material?: BabylonMaterialLike | BabylonMaterialLike[] | null;
|
|
85
|
+
/**
|
|
86
|
+
* `AbstractMesh.getTotalVertices()` - absent, or zero, on a plain
|
|
87
|
+
* `TransformNode` with no geometry of its own. `BabylonPhysicsFacility`'s
|
|
88
|
+
* `"auto"` shape reads this to tell a real mesh from an empty node, the
|
|
89
|
+
* same distinction `RapierPhysicsFacility` makes from an object's bounds.
|
|
90
|
+
*/
|
|
91
|
+
getTotalVertices?(): number;
|
|
85
92
|
}
|
|
86
93
|
/**
|
|
87
94
|
* Structural slice of Babylon's `PhysicsBody` (Physics V2, Havok or any
|
|
@@ -99,12 +106,97 @@ export interface BabylonTransformNodeLike {
|
|
|
99
106
|
* node-drives-physics - Babylon reads the node's transform instead of
|
|
100
107
|
* writing it. Held, released and reset all briefly need the second
|
|
101
108
|
* direction, so the port toggles it around each of the three.
|
|
109
|
+
*
|
|
110
|
+
* The read/damping/gravity/target members below back `BabylonPhysicsFacility`
|
|
111
|
+
* (`physics-facility.ts`), which needs a body's current state and the
|
|
112
|
+
* ability to teleport it, not only switch it - `BabylonTransformPort`'s own
|
|
113
|
+
* physicsMotionTypes hold does not need them.
|
|
102
114
|
*/
|
|
103
115
|
export interface BabylonPhysicsBodyLike {
|
|
104
116
|
disablePreStep: boolean;
|
|
117
|
+
/** `PhysicsBody.shape` - `Nullable<PhysicsShape>`, the collider driving this body; settable to swap it. */
|
|
118
|
+
shape?: BabylonPhysicsShapeLike | null;
|
|
105
119
|
setMotionType(motionType: unknown): void;
|
|
120
|
+
/** `PhysicsBody.getMotionType()` - the value last given to `setMotionType`. */
|
|
121
|
+
getMotionType(): unknown;
|
|
106
122
|
setLinearVelocity(velocity: BabylonVector3Like): void;
|
|
123
|
+
/** `PhysicsBody.getLinearVelocity()` - metres per second, world space. */
|
|
124
|
+
getLinearVelocity(): BabylonVector3Like;
|
|
107
125
|
setAngularVelocity(velocity: BabylonVector3Like): void;
|
|
126
|
+
/** `PhysicsBody.getAngularVelocity()` - radians per second, world space. */
|
|
127
|
+
getAngularVelocity(): BabylonVector3Like;
|
|
128
|
+
/** `PhysicsBody.setGravityFactor()` - multiplier on the world's gravity for this body. */
|
|
129
|
+
setGravityFactor(factor: number): void;
|
|
130
|
+
/** `PhysicsBody.setLinearDamping()` - fraction of linear velocity lost per second. */
|
|
131
|
+
setLinearDamping(damping: number): void;
|
|
132
|
+
/** `PhysicsBody.setAngularDamping()` - fraction of angular velocity lost per second. */
|
|
133
|
+
setAngularDamping(damping: number): void;
|
|
134
|
+
/**
|
|
135
|
+
* `PhysicsBody.setTargetTransform()` - Babylon's teleport for a body: sets
|
|
136
|
+
* where the body (and, for an `ANIMATED` one, its kinematic target) is
|
|
137
|
+
* next, in world space, independent of the node's own parent frame.
|
|
138
|
+
*/
|
|
139
|
+
setTargetTransform(position: BabylonVector3Like, rotation: BabylonQuaternionLike): void;
|
|
140
|
+
/** `PhysicsBody.dispose()` - releases the body's Havok handle. */
|
|
141
|
+
dispose(): void;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Structural slice of Babylon's `PhysicsShape` (a `PhysicsShapeSphere`,
|
|
145
|
+
* `PhysicsShapeBox`, `PhysicsShapeCapsule` or `PhysicsShapeMesh` - every
|
|
146
|
+
* kind shares this surface). `material` is a plain data object Havok reads
|
|
147
|
+
* each step, not a class - Babylon's own `PhysicsShape.material` setter
|
|
148
|
+
* takes the same shape.
|
|
149
|
+
*/
|
|
150
|
+
export interface BabylonPhysicsShapeLike {
|
|
151
|
+
material: {
|
|
152
|
+
friction: number;
|
|
153
|
+
restitution: number;
|
|
154
|
+
};
|
|
155
|
+
/** Kilograms per cubic metre; `PhysicsBody`'s mass follows from it. */
|
|
156
|
+
density: number;
|
|
157
|
+
/** `PhysicsShape.dispose()` - releases the shape's Havok handle. */
|
|
158
|
+
dispose(): void;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The Havok-era Physics V2 constructors and values `BabylonPhysicsFacility`
|
|
162
|
+
* needs, handed over by the app exactly as `BabylonTransformPortOptions.physicsMotionTypes`
|
|
163
|
+
* already does for the two motion types it reads - this package has no
|
|
164
|
+
* `@babylonjs/core` dependency to import them from.
|
|
165
|
+
*/
|
|
166
|
+
export interface BabylonPhysicsKitLike {
|
|
167
|
+
PhysicsBody: new (node: BabylonTransformNodeLike, motionType: unknown, startsAsleep: boolean, scene: BabylonSceneLike) => BabylonPhysicsBodyLike;
|
|
168
|
+
PhysicsShapeSphere: new (center: BabylonVector3Like, radius: number, scene: BabylonSceneLike) => BabylonPhysicsShapeLike;
|
|
169
|
+
PhysicsShapeBox: new (center: BabylonVector3Like, rotation: BabylonQuaternionLike, extents: BabylonVector3Like, scene: BabylonSceneLike) => BabylonPhysicsShapeLike;
|
|
170
|
+
/** `pointA`/`pointB` are the capsule's two hemisphere centres along its axis. */
|
|
171
|
+
PhysicsShapeCapsule: new (pointA: BabylonVector3Like, pointB: BabylonVector3Like, radius: number, scene: BabylonSceneLike) => BabylonPhysicsShapeLike;
|
|
172
|
+
/** For an `"auto"` shape over a node with geometry - see `getTotalVertices` above. */
|
|
173
|
+
PhysicsShapeMesh: new (mesh: BabylonTransformNodeLike, scene: BabylonSceneLike) => BabylonPhysicsShapeLike;
|
|
174
|
+
PhysicsMotionType: {
|
|
175
|
+
STATIC: unknown;
|
|
176
|
+
ANIMATED: unknown;
|
|
177
|
+
DYNAMIC: unknown;
|
|
178
|
+
};
|
|
179
|
+
Vector3: new (x: number, y: number, z: number) => BabylonVector3Like;
|
|
180
|
+
Quaternion: new (x: number, y: number, z: number, w: number) => BabylonQuaternionLike;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Structural slice of Babylon's `IPhysicsEngine` - the plugin-level physics
|
|
184
|
+
* world (Havok, or another plugin behind the same API) a scene owns once the
|
|
185
|
+
* app calls `scene.enablePhysics(...)`.
|
|
186
|
+
*/
|
|
187
|
+
export interface BabylonPhysicsEngineLike {
|
|
188
|
+
setGravity(gravity: BabylonVector3Like): void;
|
|
189
|
+
gravity: BabylonVector3Like;
|
|
190
|
+
/**
|
|
191
|
+
* Babylon's own per-frame physics step, called internally by
|
|
192
|
+
* `Scene.render()` once physics is enabled - not part of the public API,
|
|
193
|
+
* named here only so `BabylonPhysicsFacility.step` can advance the
|
|
194
|
+
* simulation directly where nothing drives a render loop (a test, or an
|
|
195
|
+
* app that ticks physics outside Babylon's own loop). Babylon normally
|
|
196
|
+
* steps physics itself; a facility never needs to call this in a real
|
|
197
|
+
* running scene with a render loop.
|
|
198
|
+
*/
|
|
199
|
+
_step?(dtSeconds: number): void;
|
|
108
200
|
}
|
|
109
201
|
/** Structural slice of Babylon's `Camera`. */
|
|
110
202
|
export interface BabylonCameraLike {
|
|
@@ -160,6 +252,8 @@ export interface BabylonSceneLike {
|
|
|
160
252
|
pick?(x: number, y: number): BabylonPickingInfoLike | null;
|
|
161
253
|
activeCamera?: BabylonCameraLike | null;
|
|
162
254
|
getEngine?(): BabylonEngineLike;
|
|
255
|
+
/** `Scene.getPhysicsEngine()` - null until the app calls `scene.enablePhysics(...)`. */
|
|
256
|
+
getPhysicsEngine?(): BabylonPhysicsEngineLike | null;
|
|
163
257
|
}
|
|
164
258
|
/** Structural slice of one `WebXRControllerComponent` reading. */
|
|
165
259
|
export interface BabylonMotionControllerComponentLike {
|
|
@@ -222,6 +316,16 @@ export interface BabylonXRExperienceLike {
|
|
|
222
316
|
}
|
|
223
317
|
/** The name Babylon registers hand tracking under in the features manager. */
|
|
224
318
|
export declare const HAND_TRACKING_FEATURE = "xr-hand-tracking";
|
|
319
|
+
/** The name Babylon registers eye tracking under in the features manager (`WebXREyeTracking.Name`). */
|
|
320
|
+
export declare const EYE_TRACKING_FEATURE = "xr-eye-tracking";
|
|
321
|
+
/**
|
|
322
|
+
* Structural slice of `WebXREyeTracking`: `isEyeGazeValid` says the runtime
|
|
323
|
+
* posed the gaze this frame, `getEyeGaze()` is the gaze ray, world space.
|
|
324
|
+
*/
|
|
325
|
+
export interface BabylonEyeTrackingLike {
|
|
326
|
+
isEyeGazeValid?: boolean;
|
|
327
|
+
getEyeGaze(): BabylonRayLike | null | undefined;
|
|
328
|
+
}
|
|
225
329
|
/** Index fingertip joint, as WebXR and Babylon both spell it. */
|
|
226
330
|
export declare const INDEX_TIP_JOINT = "index-finger-tip";
|
|
227
331
|
/** Copy a Babylon vector into a tuple. */
|
package/dist/babylon-types.js
CHANGED
|
@@ -10,6 +10,8 @@ export const POINTER_EVENT_TYPES = {
|
|
|
10
10
|
};
|
|
11
11
|
/** The name Babylon registers hand tracking under in the features manager. */
|
|
12
12
|
export const HAND_TRACKING_FEATURE = "xr-hand-tracking";
|
|
13
|
+
/** The name Babylon registers eye tracking under in the features manager (`WebXREyeTracking.Name`). */
|
|
14
|
+
export const EYE_TRACKING_FEATURE = "xr-eye-tracking";
|
|
13
15
|
/** Index fingertip joint, as WebXR and Babylon both spell it. */
|
|
14
16
|
export const INDEX_TIP_JOINT = "index-finger-tip";
|
|
15
17
|
// ---------------------------------------------------------------------------
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babylon-types.js","sourceRoot":"","sources":["../src/babylon-types.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AA+HnE;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AW,CAAC,IAA8B;IACxD,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAC3C,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5D,CAAC","sourcesContent":["/**\n * The shape of the Babylon.js API this adapter reads, written out here\n * rather than imported.\n *\n * `@babylonjs/core` is NOT a dependency of this package, in the same way\n * the XR Blocks adapter does not depend on `xrblocks`. Babylon ships one\n * large package on a fast release train, and an adapter that imported it\n * would drag a version choice into every consumer and break on an upstream\n * rename. Matching the shape instead means an app installs whatever Babylon\n * it already uses and passes its objects straight in.\n *\n * The trade for that is honesty about provenance: these declarations were\n * written from the Babylon 7 documentation, not verified against an\n * installed package, so members a version might not carry are optional and\n * read defensively. Nothing here is required to be a Babylon object - a\n * plain object with the same members works, which is what the tests use.\n *\n * Coordinates: Babylon is LEFT-handed and a node's forward is +Z, where\n * three.js and raw WebXR use -Z. That difference is applied in one place\n * (`nodeForward`) so it is stated once.\n */\nimport type { PoseTuple, QuatTuple, Vec3Tuple } from \"@realitycollective/webxr-input\";\nimport { vApplyQuat } from \"@realitycollective/webxr-interactions\";\n\n/** Structural slice of Babylon's `Vector3`. */\nexport interface BabylonVector3Like {\n x: number;\n y: number;\n z: number;\n}\n\n/** Structural slice of Babylon's `Quaternion`. */\nexport interface BabylonQuaternionLike {\n x: number;\n y: number;\n z: number;\n w: number;\n}\n\n/** Structural slice of Babylon's `Ray`. */\nexport interface BabylonRayLike {\n origin: BabylonVector3Like;\n direction: BabylonVector3Like;\n}\n\n/**\n * Structural slice of Babylon's `Observable<T>`. The observer handle is\n * opaque - it is only ever handed straight back to `remove`.\n */\nexport interface BabylonObservableLike<T> {\n add(callback: (eventData: T) => void): unknown;\n remove(observer: unknown): boolean;\n}\n\n/**\n * Structural slice of Babylon's `StandardMaterial`/`PBRMaterial` emissive\n * channel - written from the Babylon 7 documentation, on the same honesty\n * terms as the rest of this file. `emissiveColor` is common to both;\n * `emissiveIntensity` is a PBRMaterial-only scalar multiplier over it -\n * `StandardMaterial` has no such field, so it is absent there and\n * `BabylonTransformPort.setEffect` only scales `emissiveColor` for one.\n */\nexport interface BabylonMaterialLike {\n emissiveColor?: BabylonVector3Like;\n /** PBRMaterial only - StandardMaterial carries no separate intensity. */\n emissiveIntensity?: number;\n}\n\n/**\n * Structural slice of Babylon's `TransformNode`, plus the two members\n * `AbstractMesh` adds that this adapter reads (`isVisible`, `material`).\n *\n * `parent` is `unknown` on purpose: Babylon types it as `Nullable<Node>`,\n * and `Node` carries none of the transform members, so anything narrower\n * would refuse a real Babylon node. Read it through `parentOf`.\n */\nexport interface BabylonTransformNodeLike {\n position: BabylonVector3Like;\n rotationQuaternion?: BabylonQuaternionLike | null;\n scaling?: BabylonVector3Like;\n parent?: unknown;\n getAbsolutePosition(): BabylonVector3Like;\n absoluteRotationQuaternion?: BabylonQuaternionLike;\n computeWorldMatrix?(force?: boolean): unknown;\n setEnabled?(value: boolean): void;\n isEnabled?(checkAncestors?: boolean): boolean;\n isVisible?: boolean;\n /** Present only on a node Physics V2 has a body for - see {@link BabylonPhysicsBodyLike}. */\n physicsBody?: BabylonPhysicsBodyLike;\n /** `AbstractMesh.material` - a multi-material mesh's first slot is what `setEffect`'s emissive pulse lights. */\n material?: BabylonMaterialLike | BabylonMaterialLike[] | null;\n}\n\n/**\n * Structural slice of Babylon's `PhysicsBody` (Physics V2, Havok or any\n * other plugin behind the same API) - present on `BabylonTransformNodeLike`\n * only when the node has one. Written from the Babylon 7 Physics V2\n * documentation, on the same honesty terms as the rest of this file: this\n * package has no `@babylonjs/core` (or `@babylonjs/havok`) dependency to\n * verify it against, so `BabylonTransformPort`'s held-pose behaviour is\n * unverified against a live Babylon scene, and the maintainer should\n * confirm it there before shipping.\n *\n * `disablePreStep` is Babylon's switch for which way a body and its node\n * agree on the truth: `false` (the default) is physics-drives-node - the\n * simulation writes the node's transform every step; `true` is\n * node-drives-physics - Babylon reads the node's transform instead of\n * writing it. Held, released and reset all briefly need the second\n * direction, so the port toggles it around each of the three.\n */\nexport interface BabylonPhysicsBodyLike {\n disablePreStep: boolean;\n setMotionType(motionType: unknown): void;\n setLinearVelocity(velocity: BabylonVector3Like): void;\n setAngularVelocity(velocity: BabylonVector3Like): void;\n}\n\n/** Structural slice of Babylon's `Camera`. */\nexport interface BabylonCameraLike {\n globalPosition?: BabylonVector3Like;\n absoluteRotation?: BabylonQuaternionLike;\n position?: BabylonVector3Like;\n getForwardRay?(length?: number): BabylonRayLike;\n}\n\n/** Structural slice of Babylon's `Engine` - only the frame delta is read. */\nexport interface BabylonEngineLike {\n getDeltaTime(): number;\n}\n\n/** Structural slice of Babylon's `PickingInfo`. */\nexport interface BabylonPickingInfoLike {\n hit?: boolean;\n distance?: number;\n pickedPoint?: BabylonVector3Like | null;\n pickedMesh?: BabylonTransformNodeLike | null;\n ray?: BabylonRayLike | null;\n}\n\n/**\n * Structural slice of Babylon's `PointerInfo`. `type` is one of the\n * `PointerEventTypes` constants - see {@link POINTER_EVENT_TYPES}.\n */\nexport interface BabylonPointerInfoLike {\n type: number;\n event?: { clientX?: number; clientY?: number; button?: number };\n pickInfo?: BabylonPickingInfoLike | null;\n}\n\n/**\n * The `PointerEventTypes` values this adapter reacts to. Babylon defines\n * them as one bit per event; these three are unchanged across 5, 6 and 7.\n */\nexport const POINTER_EVENT_TYPES = {\n down: 1,\n up: 2,\n move: 4,\n} as const;\n\n/** Structural slice of Babylon's `Scene`. */\nexport interface BabylonSceneLike {\n /**\n * Babylon defaults to a left-handed system with forward +Z. A scene that\n * sets this flag is right-handed and its nodes face -Z; the adapter reads\n * it once at construction.\n */\n useRightHandedSystem?: boolean;\n onBeforeRenderObservable?: BabylonObservableLike<unknown>;\n onPointerObservable?: BabylonObservableLike<BabylonPointerInfoLike>;\n pick?(x: number, y: number): BabylonPickingInfoLike | null;\n activeCamera?: BabylonCameraLike | null;\n getEngine?(): BabylonEngineLike;\n}\n\n/** Structural slice of one `WebXRControllerComponent` reading. */\nexport interface BabylonMotionControllerComponentLike {\n value?: number;\n pressed?: boolean;\n}\n\n/** Structural slice of Babylon's `WebXRAbstractMotionController`. */\nexport interface BabylonMotionControllerLike {\n getComponentOfType?(type: string): BabylonMotionControllerComponentLike | null;\n getMainComponent?(): BabylonMotionControllerComponentLike | null;\n pulse?(value: number, duration: number): Promise<unknown>;\n rootMesh?: BabylonTransformNodeLike | null;\n}\n\n/** Structural slice of Babylon's `WebXRInputSource`. */\nexport interface BabylonXRControllerLike {\n uniqueId: string;\n inputSource: {\n handedness?: string;\n hand?: unknown;\n gamepad?: { hapticActuators?: readonly unknown[] } | null;\n };\n pointer: BabylonTransformNodeLike;\n grip?: BabylonTransformNodeLike | null;\n motionController?: BabylonMotionControllerLike | null;\n onMotionControllerInitObservable?: BabylonObservableLike<unknown>;\n}\n\n/** Structural slice of Babylon's `WebXRInput`. */\nexport interface BabylonXRInputLike {\n controllers: readonly BabylonXRControllerLike[];\n onControllerAddedObservable?: BabylonObservableLike<BabylonXRControllerLike>;\n onControllerRemovedObservable?: BabylonObservableLike<BabylonXRControllerLike>;\n}\n\n/** Structural slice of one tracked hand from the hand-tracking feature. */\nexport interface BabylonXRHandLike {\n getJointMesh?(jointName: string): BabylonTransformNodeLike | null | undefined;\n handMesh?: BabylonTransformNodeLike | null;\n}\n\n/**\n * Structural slice of `WebXRHandTracking`, the feature the features manager\n * registers under `\"xr-hand-tracking\"`.\n */\nexport interface BabylonHandTrackingLike {\n getHandByControllerId(id: string): BabylonXRHandLike | null | undefined;\n}\n\n/** Structural slice of Babylon's `WebXRDefaultExperience`. */\nexport interface BabylonXRExperienceLike {\n baseExperience?: {\n sessionManager?: {\n session?: unknown;\n onXRSessionInit?: BabylonObservableLike<unknown>;\n onXRSessionEnded?: BabylonObservableLike<unknown>;\n };\n featuresManager?: { getEnabledFeature(featureName: string): unknown };\n };\n input?: BabylonXRInputLike;\n}\n\n/** The name Babylon registers hand tracking under in the features manager. */\nexport const HAND_TRACKING_FEATURE = \"xr-hand-tracking\";\n\n/** Index fingertip joint, as WebXR and Babylon both spell it. */\nexport const INDEX_TIP_JOINT = \"index-finger-tip\";\n\n// ---------------------------------------------------------------------------\n// Conversions. Everything below turns Babylon-shaped objects into the core's\n// tuples, or writes tuples back IN PLACE.\n//\n// In place is deliberate. Babylon caches the previous position/rotation and\n// recomputes the world matrix when the live values differ, so mutating\n// `node.position.x` is seen. Replacing `node.position` with a plain object is\n// not just missed, it breaks Babylon, which calls Vector3 methods on it.\n// ---------------------------------------------------------------------------\n\n/** Copy a Babylon vector into a tuple. */\nexport function toVec3(v: BabylonVector3Like | null | undefined): Vec3Tuple | null {\n return v ? [v.x, v.y, v.z] : null;\n}\n\n/** Copy a Babylon quaternion into a tuple, defaulting to identity. */\nexport function toQuat(q: BabylonQuaternionLike | null | undefined): QuatTuple {\n return q ? [q.x, q.y, q.z, q.w] : [0, 0, 0, 1];\n}\n\n/** Write a tuple into an existing Babylon vector, in place. */\nexport function writeVec3(target: BabylonVector3Like, value: Vec3Tuple): void {\n target.x = value[0];\n target.y = value[1];\n target.z = value[2];\n}\n\n/** Write a tuple into an existing Babylon quaternion, in place. */\nexport function writeQuat(target: BabylonQuaternionLike, value: QuatTuple): void {\n target.x = value[0];\n target.y = value[1];\n target.z = value[2];\n target.w = value[3];\n}\n\n/** A node's world pose: absolute position and absolute rotation. */\nexport function nodeWorldPose(node: BabylonTransformNodeLike): PoseTuple {\n return {\n position: toVec3(node.getAbsolutePosition()) ?? [0, 0, 0],\n quaternion: toQuat(node.absoluteRotationQuaternion),\n };\n}\n\n/**\n * The world-space forward axis for a scene: +Z in Babylon's default\n * left-handed system, the opposite of three.js and of a raw WebXR target\n * ray, and -Z when the scene sets `useRightHandedSystem`.\n */\nexport function defaultForward(rightHanded = false): Vec3Tuple {\n return [0, 0, rightHanded ? -1 : 1];\n}\n\n/**\n * A node's forward direction in world space, honouring the scene's\n * handedness (see {@link defaultForward}).\n */\nexport function nodeForward(node: BabylonTransformNodeLike, rightHanded = false): Vec3Tuple {\n return vApplyQuat(defaultForward(rightHanded), toQuat(node.absoluteRotationQuaternion));\n}\n\n/**\n * The parent of a node, when it is one this adapter can read a world pose\n * from. Babylon types `parent` as `Node`, which has no transform, so a\n * parent that is a bone or a bare node reports null and the caller treats\n * the node as unparented.\n */\nexport function parentOf(node: BabylonTransformNodeLike): BabylonTransformNodeLike | null {\n const parent = node.parent;\n if (!parent || typeof parent !== \"object\") return null;\n const candidate = parent as Partial<BabylonTransformNodeLike>;\n return typeof candidate.getAbsolutePosition === \"function\"\n ? (parent as BabylonTransformNodeLike)\n : null;\n}\n\n/**\n * Is this node currently showing? A node the app disabled or hid is not a\n * hit-test candidate. Absent members mean yes - a fake, or a build that does\n * not carry them, should not silently drop out of targeting.\n */\nexport function nodeShowing(node: BabylonTransformNodeLike): boolean {\n if (node.isVisible === false) return false;\n return node.isEnabled ? node.isEnabled() !== false : true;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"babylon-types.js","sourceRoot":"","sources":["../src/babylon-types.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAsOnE;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,CAAC;IACP,EAAE,EAAE,CAAC;IACL,IAAI,EAAE,CAAC;CACC,CAAC;AAiFX,8EAA8E;AAC9E,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAExD,uGAAuG;AACvG,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAWtD,iEAAiE;AACjE,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAElD,8EAA8E;AAC9E,6EAA6E;AAC7E,0CAA0C;AAC1C,EAAE;AACF,4EAA4E;AAC5E,uEAAuE;AACvE,8EAA8E;AAC9E,yEAAyE;AACzE,8EAA8E;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,CAAC;QACzD,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC;KACpD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,WAAW,GAAG,KAAK;IAChD,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,IAA8B,EAAE,WAAW,GAAG,KAAK;IAC7E,OAAO,UAAU,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC;AAC1F,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,IAA8B;IACrD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACvD,MAAM,SAAS,GAAG,MAA2C,CAAC;IAC9D,OAAO,OAAO,SAAS,CAAC,mBAAmB,KAAK,UAAU;QACxD,CAAC,CAAE,MAAmC;QACtC,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAA8B;IACxD,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAC3C,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5D,CAAC","sourcesContent":["/**\n * The shape of the Babylon.js API this adapter reads, written out here\n * rather than imported.\n *\n * `@babylonjs/core` is NOT a dependency of this package, in the same way\n * the XR Blocks adapter does not depend on `xrblocks`. Babylon ships one\n * large package on a fast release train, and an adapter that imported it\n * would drag a version choice into every consumer and break on an upstream\n * rename. Matching the shape instead means an app installs whatever Babylon\n * it already uses and passes its objects straight in.\n *\n * The trade for that is honesty about provenance: these declarations were\n * written from the Babylon 7 documentation, not verified against an\n * installed package, so members a version might not carry are optional and\n * read defensively. Nothing here is required to be a Babylon object - a\n * plain object with the same members works, which is what the tests use.\n *\n * Coordinates: Babylon is LEFT-handed and a node's forward is +Z, where\n * three.js and raw WebXR use -Z. That difference is applied in one place\n * (`nodeForward`) so it is stated once.\n */\nimport type { PoseTuple, QuatTuple, Vec3Tuple } from \"@realitycollective/webxr-input\";\nimport { vApplyQuat } from \"@realitycollective/webxr-interactions\";\n\n/** Structural slice of Babylon's `Vector3`. */\nexport interface BabylonVector3Like {\n x: number;\n y: number;\n z: number;\n}\n\n/** Structural slice of Babylon's `Quaternion`. */\nexport interface BabylonQuaternionLike {\n x: number;\n y: number;\n z: number;\n w: number;\n}\n\n/** Structural slice of Babylon's `Ray`. */\nexport interface BabylonRayLike {\n origin: BabylonVector3Like;\n direction: BabylonVector3Like;\n}\n\n/**\n * Structural slice of Babylon's `Observable<T>`. The observer handle is\n * opaque - it is only ever handed straight back to `remove`.\n */\nexport interface BabylonObservableLike<T> {\n add(callback: (eventData: T) => void): unknown;\n remove(observer: unknown): boolean;\n}\n\n/**\n * Structural slice of Babylon's `StandardMaterial`/`PBRMaterial` emissive\n * channel - written from the Babylon 7 documentation, on the same honesty\n * terms as the rest of this file. `emissiveColor` is common to both;\n * `emissiveIntensity` is a PBRMaterial-only scalar multiplier over it -\n * `StandardMaterial` has no such field, so it is absent there and\n * `BabylonTransformPort.setEffect` only scales `emissiveColor` for one.\n */\nexport interface BabylonMaterialLike {\n emissiveColor?: BabylonVector3Like;\n /** PBRMaterial only - StandardMaterial carries no separate intensity. */\n emissiveIntensity?: number;\n}\n\n/**\n * Structural slice of Babylon's `TransformNode`, plus the two members\n * `AbstractMesh` adds that this adapter reads (`isVisible`, `material`).\n *\n * `parent` is `unknown` on purpose: Babylon types it as `Nullable<Node>`,\n * and `Node` carries none of the transform members, so anything narrower\n * would refuse a real Babylon node. Read it through `parentOf`.\n */\nexport interface BabylonTransformNodeLike {\n position: BabylonVector3Like;\n rotationQuaternion?: BabylonQuaternionLike | null;\n scaling?: BabylonVector3Like;\n parent?: unknown;\n getAbsolutePosition(): BabylonVector3Like;\n absoluteRotationQuaternion?: BabylonQuaternionLike;\n computeWorldMatrix?(force?: boolean): unknown;\n setEnabled?(value: boolean): void;\n isEnabled?(checkAncestors?: boolean): boolean;\n isVisible?: boolean;\n /** Present only on a node Physics V2 has a body for - see {@link BabylonPhysicsBodyLike}. */\n physicsBody?: BabylonPhysicsBodyLike;\n /** `AbstractMesh.material` - a multi-material mesh's first slot is what `setEffect`'s emissive pulse lights. */\n material?: BabylonMaterialLike | BabylonMaterialLike[] | null;\n /**\n * `AbstractMesh.getTotalVertices()` - absent, or zero, on a plain\n * `TransformNode` with no geometry of its own. `BabylonPhysicsFacility`'s\n * `\"auto\"` shape reads this to tell a real mesh from an empty node, the\n * same distinction `RapierPhysicsFacility` makes from an object's bounds.\n */\n getTotalVertices?(): number;\n}\n\n/**\n * Structural slice of Babylon's `PhysicsBody` (Physics V2, Havok or any\n * other plugin behind the same API) - present on `BabylonTransformNodeLike`\n * only when the node has one. Written from the Babylon 7 Physics V2\n * documentation, on the same honesty terms as the rest of this file: this\n * package has no `@babylonjs/core` (or `@babylonjs/havok`) dependency to\n * verify it against, so `BabylonTransformPort`'s held-pose behaviour is\n * unverified against a live Babylon scene, and the maintainer should\n * confirm it there before shipping.\n *\n * `disablePreStep` is Babylon's switch for which way a body and its node\n * agree on the truth: `false` (the default) is physics-drives-node - the\n * simulation writes the node's transform every step; `true` is\n * node-drives-physics - Babylon reads the node's transform instead of\n * writing it. Held, released and reset all briefly need the second\n * direction, so the port toggles it around each of the three.\n *\n * The read/damping/gravity/target members below back `BabylonPhysicsFacility`\n * (`physics-facility.ts`), which needs a body's current state and the\n * ability to teleport it, not only switch it - `BabylonTransformPort`'s own\n * physicsMotionTypes hold does not need them.\n */\nexport interface BabylonPhysicsBodyLike {\n disablePreStep: boolean;\n /** `PhysicsBody.shape` - `Nullable<PhysicsShape>`, the collider driving this body; settable to swap it. */\n shape?: BabylonPhysicsShapeLike | null;\n setMotionType(motionType: unknown): void;\n /** `PhysicsBody.getMotionType()` - the value last given to `setMotionType`. */\n getMotionType(): unknown;\n setLinearVelocity(velocity: BabylonVector3Like): void;\n /** `PhysicsBody.getLinearVelocity()` - metres per second, world space. */\n getLinearVelocity(): BabylonVector3Like;\n setAngularVelocity(velocity: BabylonVector3Like): void;\n /** `PhysicsBody.getAngularVelocity()` - radians per second, world space. */\n getAngularVelocity(): BabylonVector3Like;\n /** `PhysicsBody.setGravityFactor()` - multiplier on the world's gravity for this body. */\n setGravityFactor(factor: number): void;\n /** `PhysicsBody.setLinearDamping()` - fraction of linear velocity lost per second. */\n setLinearDamping(damping: number): void;\n /** `PhysicsBody.setAngularDamping()` - fraction of angular velocity lost per second. */\n setAngularDamping(damping: number): void;\n /**\n * `PhysicsBody.setTargetTransform()` - Babylon's teleport for a body: sets\n * where the body (and, for an `ANIMATED` one, its kinematic target) is\n * next, in world space, independent of the node's own parent frame.\n */\n setTargetTransform(position: BabylonVector3Like, rotation: BabylonQuaternionLike): void;\n /** `PhysicsBody.dispose()` - releases the body's Havok handle. */\n dispose(): void;\n}\n\n/**\n * Structural slice of Babylon's `PhysicsShape` (a `PhysicsShapeSphere`,\n * `PhysicsShapeBox`, `PhysicsShapeCapsule` or `PhysicsShapeMesh` - every\n * kind shares this surface). `material` is a plain data object Havok reads\n * each step, not a class - Babylon's own `PhysicsShape.material` setter\n * takes the same shape.\n */\nexport interface BabylonPhysicsShapeLike {\n material: { friction: number; restitution: number };\n /** Kilograms per cubic metre; `PhysicsBody`'s mass follows from it. */\n density: number;\n /** `PhysicsShape.dispose()` - releases the shape's Havok handle. */\n dispose(): void;\n}\n\n/**\n * The Havok-era Physics V2 constructors and values `BabylonPhysicsFacility`\n * needs, handed over by the app exactly as `BabylonTransformPortOptions.physicsMotionTypes`\n * already does for the two motion types it reads - this package has no\n * `@babylonjs/core` dependency to import them from.\n */\nexport interface BabylonPhysicsKitLike {\n PhysicsBody: new (\n node: BabylonTransformNodeLike,\n motionType: unknown,\n startsAsleep: boolean,\n scene: BabylonSceneLike,\n ) => BabylonPhysicsBodyLike;\n PhysicsShapeSphere: new (center: BabylonVector3Like, radius: number, scene: BabylonSceneLike) => BabylonPhysicsShapeLike;\n PhysicsShapeBox: new (\n center: BabylonVector3Like,\n rotation: BabylonQuaternionLike,\n extents: BabylonVector3Like,\n scene: BabylonSceneLike,\n ) => BabylonPhysicsShapeLike;\n /** `pointA`/`pointB` are the capsule's two hemisphere centres along its axis. */\n PhysicsShapeCapsule: new (\n pointA: BabylonVector3Like,\n pointB: BabylonVector3Like,\n radius: number,\n scene: BabylonSceneLike,\n ) => BabylonPhysicsShapeLike;\n /** For an `\"auto\"` shape over a node with geometry - see `getTotalVertices` above. */\n PhysicsShapeMesh: new (mesh: BabylonTransformNodeLike, scene: BabylonSceneLike) => BabylonPhysicsShapeLike;\n PhysicsMotionType: { STATIC: unknown; ANIMATED: unknown; DYNAMIC: unknown };\n Vector3: new (x: number, y: number, z: number) => BabylonVector3Like;\n Quaternion: new (x: number, y: number, z: number, w: number) => BabylonQuaternionLike;\n}\n\n/**\n * Structural slice of Babylon's `IPhysicsEngine` - the plugin-level physics\n * world (Havok, or another plugin behind the same API) a scene owns once the\n * app calls `scene.enablePhysics(...)`.\n */\nexport interface BabylonPhysicsEngineLike {\n setGravity(gravity: BabylonVector3Like): void;\n gravity: BabylonVector3Like;\n /**\n * Babylon's own per-frame physics step, called internally by\n * `Scene.render()` once physics is enabled - not part of the public API,\n * named here only so `BabylonPhysicsFacility.step` can advance the\n * simulation directly where nothing drives a render loop (a test, or an\n * app that ticks physics outside Babylon's own loop). Babylon normally\n * steps physics itself; a facility never needs to call this in a real\n * running scene with a render loop.\n */\n _step?(dtSeconds: number): void;\n}\n\n/** Structural slice of Babylon's `Camera`. */\nexport interface BabylonCameraLike {\n globalPosition?: BabylonVector3Like;\n absoluteRotation?: BabylonQuaternionLike;\n position?: BabylonVector3Like;\n getForwardRay?(length?: number): BabylonRayLike;\n}\n\n/** Structural slice of Babylon's `Engine` - only the frame delta is read. */\nexport interface BabylonEngineLike {\n getDeltaTime(): number;\n}\n\n/** Structural slice of Babylon's `PickingInfo`. */\nexport interface BabylonPickingInfoLike {\n hit?: boolean;\n distance?: number;\n pickedPoint?: BabylonVector3Like | null;\n pickedMesh?: BabylonTransformNodeLike | null;\n ray?: BabylonRayLike | null;\n}\n\n/**\n * Structural slice of Babylon's `PointerInfo`. `type` is one of the\n * `PointerEventTypes` constants - see {@link POINTER_EVENT_TYPES}.\n */\nexport interface BabylonPointerInfoLike {\n type: number;\n event?: { clientX?: number; clientY?: number; button?: number };\n pickInfo?: BabylonPickingInfoLike | null;\n}\n\n/**\n * The `PointerEventTypes` values this adapter reacts to. Babylon defines\n * them as one bit per event; these three are unchanged across 5, 6 and 7.\n */\nexport const POINTER_EVENT_TYPES = {\n down: 1,\n up: 2,\n move: 4,\n} as const;\n\n/** Structural slice of Babylon's `Scene`. */\nexport interface BabylonSceneLike {\n /**\n * Babylon defaults to a left-handed system with forward +Z. A scene that\n * sets this flag is right-handed and its nodes face -Z; the adapter reads\n * it once at construction.\n */\n useRightHandedSystem?: boolean;\n onBeforeRenderObservable?: BabylonObservableLike<unknown>;\n onPointerObservable?: BabylonObservableLike<BabylonPointerInfoLike>;\n pick?(x: number, y: number): BabylonPickingInfoLike | null;\n activeCamera?: BabylonCameraLike | null;\n getEngine?(): BabylonEngineLike;\n /** `Scene.getPhysicsEngine()` - null until the app calls `scene.enablePhysics(...)`. */\n getPhysicsEngine?(): BabylonPhysicsEngineLike | null;\n}\n\n/** Structural slice of one `WebXRControllerComponent` reading. */\nexport interface BabylonMotionControllerComponentLike {\n value?: number;\n pressed?: boolean;\n}\n\n/** Structural slice of Babylon's `WebXRAbstractMotionController`. */\nexport interface BabylonMotionControllerLike {\n getComponentOfType?(type: string): BabylonMotionControllerComponentLike | null;\n getMainComponent?(): BabylonMotionControllerComponentLike | null;\n pulse?(value: number, duration: number): Promise<unknown>;\n rootMesh?: BabylonTransformNodeLike | null;\n}\n\n/** Structural slice of Babylon's `WebXRInputSource`. */\nexport interface BabylonXRControllerLike {\n uniqueId: string;\n inputSource: {\n handedness?: string;\n hand?: unknown;\n gamepad?: { hapticActuators?: readonly unknown[] } | null;\n };\n pointer: BabylonTransformNodeLike;\n grip?: BabylonTransformNodeLike | null;\n motionController?: BabylonMotionControllerLike | null;\n onMotionControllerInitObservable?: BabylonObservableLike<unknown>;\n}\n\n/** Structural slice of Babylon's `WebXRInput`. */\nexport interface BabylonXRInputLike {\n controllers: readonly BabylonXRControllerLike[];\n onControllerAddedObservable?: BabylonObservableLike<BabylonXRControllerLike>;\n onControllerRemovedObservable?: BabylonObservableLike<BabylonXRControllerLike>;\n}\n\n/** Structural slice of one tracked hand from the hand-tracking feature. */\nexport interface BabylonXRHandLike {\n getJointMesh?(jointName: string): BabylonTransformNodeLike | null | undefined;\n handMesh?: BabylonTransformNodeLike | null;\n}\n\n/**\n * Structural slice of `WebXRHandTracking`, the feature the features manager\n * registers under `\"xr-hand-tracking\"`.\n */\nexport interface BabylonHandTrackingLike {\n getHandByControllerId(id: string): BabylonXRHandLike | null | undefined;\n}\n\n/** Structural slice of Babylon's `WebXRDefaultExperience`. */\nexport interface BabylonXRExperienceLike {\n baseExperience?: {\n sessionManager?: {\n session?: unknown;\n onXRSessionInit?: BabylonObservableLike<unknown>;\n onXRSessionEnded?: BabylonObservableLike<unknown>;\n };\n featuresManager?: { getEnabledFeature(featureName: string): unknown };\n };\n input?: BabylonXRInputLike;\n}\n\n/** The name Babylon registers hand tracking under in the features manager. */\nexport const HAND_TRACKING_FEATURE = \"xr-hand-tracking\";\n\n/** The name Babylon registers eye tracking under in the features manager (`WebXREyeTracking.Name`). */\nexport const EYE_TRACKING_FEATURE = \"xr-eye-tracking\";\n\n/**\n * Structural slice of `WebXREyeTracking`: `isEyeGazeValid` says the runtime\n * posed the gaze this frame, `getEyeGaze()` is the gaze ray, world space.\n */\nexport interface BabylonEyeTrackingLike {\n isEyeGazeValid?: boolean;\n getEyeGaze(): BabylonRayLike | null | undefined;\n}\n\n/** Index fingertip joint, as WebXR and Babylon both spell it. */\nexport const INDEX_TIP_JOINT = \"index-finger-tip\";\n\n// ---------------------------------------------------------------------------\n// Conversions. Everything below turns Babylon-shaped objects into the core's\n// tuples, or writes tuples back IN PLACE.\n//\n// In place is deliberate. Babylon caches the previous position/rotation and\n// recomputes the world matrix when the live values differ, so mutating\n// `node.position.x` is seen. Replacing `node.position` with a plain object is\n// not just missed, it breaks Babylon, which calls Vector3 methods on it.\n// ---------------------------------------------------------------------------\n\n/** Copy a Babylon vector into a tuple. */\nexport function toVec3(v: BabylonVector3Like | null | undefined): Vec3Tuple | null {\n return v ? [v.x, v.y, v.z] : null;\n}\n\n/** Copy a Babylon quaternion into a tuple, defaulting to identity. */\nexport function toQuat(q: BabylonQuaternionLike | null | undefined): QuatTuple {\n return q ? [q.x, q.y, q.z, q.w] : [0, 0, 0, 1];\n}\n\n/** Write a tuple into an existing Babylon vector, in place. */\nexport function writeVec3(target: BabylonVector3Like, value: Vec3Tuple): void {\n target.x = value[0];\n target.y = value[1];\n target.z = value[2];\n}\n\n/** Write a tuple into an existing Babylon quaternion, in place. */\nexport function writeQuat(target: BabylonQuaternionLike, value: QuatTuple): void {\n target.x = value[0];\n target.y = value[1];\n target.z = value[2];\n target.w = value[3];\n}\n\n/** A node's world pose: absolute position and absolute rotation. */\nexport function nodeWorldPose(node: BabylonTransformNodeLike): PoseTuple {\n return {\n position: toVec3(node.getAbsolutePosition()) ?? [0, 0, 0],\n quaternion: toQuat(node.absoluteRotationQuaternion),\n };\n}\n\n/**\n * The world-space forward axis for a scene: +Z in Babylon's default\n * left-handed system, the opposite of three.js and of a raw WebXR target\n * ray, and -Z when the scene sets `useRightHandedSystem`.\n */\nexport function defaultForward(rightHanded = false): Vec3Tuple {\n return [0, 0, rightHanded ? -1 : 1];\n}\n\n/**\n * A node's forward direction in world space, honouring the scene's\n * handedness (see {@link defaultForward}).\n */\nexport function nodeForward(node: BabylonTransformNodeLike, rightHanded = false): Vec3Tuple {\n return vApplyQuat(defaultForward(rightHanded), toQuat(node.absoluteRotationQuaternion));\n}\n\n/**\n * The parent of a node, when it is one this adapter can read a world pose\n * from. Babylon types `parent` as `Node`, which has no transform, so a\n * parent that is a bone or a bare node reports null and the caller treats\n * the node as unparented.\n */\nexport function parentOf(node: BabylonTransformNodeLike): BabylonTransformNodeLike | null {\n const parent = node.parent;\n if (!parent || typeof parent !== \"object\") return null;\n const candidate = parent as Partial<BabylonTransformNodeLike>;\n return typeof candidate.getAbsolutePosition === \"function\"\n ? (parent as BabylonTransformNodeLike)\n : null;\n}\n\n/**\n * Is this node currently showing? A node the app disabled or hid is not a\n * hit-test candidate. Absent members mean yes - a fake, or a build that does\n * not carry them, should not silently drop out of targeting.\n */\nexport function nodeShowing(node: BabylonTransformNodeLike): boolean {\n if (node.isVisible === false) return false;\n return node.isEnabled ? node.isEnabled() !== false : true;\n}\n"]}
|
package/dist/hit-tester.d.ts
CHANGED
|
@@ -52,6 +52,12 @@ export declare class BabylonHitTester implements HitTester {
|
|
|
52
52
|
getNode(id: string): BabylonTransformNodeLike | undefined;
|
|
53
53
|
hitRay(ray: RayTuple): InteractableHit | null;
|
|
54
54
|
hitProximity(point: Vec3Tuple, radius: number): InteractableHit | null;
|
|
55
|
+
/**
|
|
56
|
+
* The eye-gaze cone (`ports.ts`, `hitCone`) over the registered spheres,
|
|
57
|
+
* the core's `coneHitForSpheres`. With an app-supplied `pickWithRay`, a
|
|
58
|
+
* mesh the ray itself reaches wins first, as it does for `hitRay`.
|
|
59
|
+
*/
|
|
60
|
+
hitCone(ray: RayTuple, halfAngle: number, maxLength: number): InteractableHit | null;
|
|
55
61
|
/** The registered interactable a picked node belongs to, if any. */
|
|
56
62
|
private ownerOf;
|
|
57
63
|
}
|
package/dist/hit-tester.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rayPointDistance, } from "@realitycollective/webxr-interactions";
|
|
1
|
+
import { surfacePointOnSphere, coneHitForSpheres, rayPointDistance, } from "@realitycollective/webxr-interactions";
|
|
2
2
|
import { nodeShowing, parentOf, toVec3 } from "./babylon-types.js";
|
|
3
3
|
const DEFAULT_RADIUS = 0.1;
|
|
4
4
|
const DEFAULT_MAX_RAY_DISTANCE = 100;
|
|
@@ -70,11 +70,34 @@ export class BabylonHitTester {
|
|
|
70
70
|
continue;
|
|
71
71
|
const distance = Math.hypot(at[0] - point[0], at[1] - point[1], at[2] - point[2]) - targetRadius;
|
|
72
72
|
if (distance <= radius && (best === null || distance < best.distance)) {
|
|
73
|
-
|
|
73
|
+
// The surface point nearest the fingertip, where the touch cursor sits.
|
|
74
|
+
best = { interactableId: id, distance: Math.max(0, distance), point: surfacePointOnSphere(at, targetRadius, point) };
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
return best;
|
|
77
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* The eye-gaze cone (`ports.ts`, `hitCone`) over the registered spheres,
|
|
81
|
+
* the core's `coneHitForSpheres`. With an app-supplied `pickWithRay`, a
|
|
82
|
+
* mesh the ray itself reaches wins first, as it does for `hitRay`.
|
|
83
|
+
*/
|
|
84
|
+
hitCone(ray, halfAngle, maxLength) {
|
|
85
|
+
if (this.pickWithRay) {
|
|
86
|
+
const direct = this.hitRay(ray);
|
|
87
|
+
if (direct && direct.distance <= maxLength)
|
|
88
|
+
return direct;
|
|
89
|
+
}
|
|
90
|
+
const spheres = [];
|
|
91
|
+
for (const [id, { node, radius }] of this.entries) {
|
|
92
|
+
if (!nodeShowing(node))
|
|
93
|
+
continue;
|
|
94
|
+
const center = toVec3(node.getAbsolutePosition());
|
|
95
|
+
if (center)
|
|
96
|
+
spheres.push({ id, center, radius });
|
|
97
|
+
}
|
|
98
|
+
const hit = coneHitForSpheres(ray, spheres, halfAngle, maxLength);
|
|
99
|
+
return hit ? { interactableId: hit.interactableId, distance: hit.distance, point: hit.point } : null;
|
|
100
|
+
}
|
|
78
101
|
/** The registered interactable a picked node belongs to, if any. */
|
|
79
102
|
ownerOf(node) {
|
|
80
103
|
let current = node;
|
package/dist/hit-tester.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hit-tester.js","sourceRoot":"","sources":["../src/hit-tester.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,gBAAgB,GAGjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAiC,MAAM,oBAAoB,CAAC;AA+BlG,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,MAAM,OAAO,gBAAgB;IACV,OAAO,GAAG,IAAI,GAAG,EAA8D,CAAC;IAChF,MAAM,GAAG,IAAI,GAAG,EAAoC,CAAC;IACrD,aAAa,CAAS;IACtB,cAAc,CAAS;IAChC,WAAW,CAA4B;IAE/C,YAAY,UAAmC,EAAE;QAC/C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,cAAc,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,wBAAwB,CAAC;QACzE,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC;IACjD,CAAC;IAED,mEAAmE;IACnE,cAAc,CAAC,IAA+B;QAC5C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,QAAQ,CAAC,EAAU,EAAE,IAA8B,EAAE,MAAe;QAClE,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACpB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE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,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACtE,IAAI,GAAG,EAAE,cAAc,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;YAC5E,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oEAAoE;IAC5D,OAAO,CAAC,IAA8B;QAC5C,IAAI,OAAO,GAAoC,IAAI,CAAC;QACpD,OAAO,OAAO,EAAE,CAAC;YACf,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACpC,IAAI,EAAE,KAAK,SAAS;gBAAE,OAAO,EAAE,CAAC;YAChC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["/**\n * BabylonHitTester - resolves the core's ray and proximity queries against\n * registered Babylon nodes.\n *\n * The default test needs no Babylon raycaster: each registered node carries\n * a radius, and a query is a sphere test against the node's absolute\n * position. That is the same model the IWSDK adapter uses, and it is enough\n * for buttons, levers, dials and grabbables, which are small next to the\n * distance they are pointed at from.\n *\n * An app that wants mesh-accurate picking supplies `pickWithRay`, typically\n * a one-line wrapper over `scene.pickWithRay`. Whatever mesh it returns is\n * mapped back to an interactable id through the registration map, walking up\n * parents so a pick on a child mesh still resolves to the registered root.\n */\nimport type { RayTuple, Vec3Tuple } from \"@realitycollective/webxr-input\";\nimport {\n rayPointDistance,\n type HitTester,\n type InteractableHit,\n} from \"@realitycollective/webxr-interactions\";\nimport { nodeShowing, parentOf, toVec3, type BabylonTransformNodeLike } from \"./babylon-types.js\";\n\n/** What an app's mesh-accurate pick reports back. */\nexport interface BabylonPickResult {\n /** The node that was hit. Mapped to an interactable through registration. */\n mesh: BabylonTransformNodeLike | null | undefined;\n /** Distance from the ray origin, in metres. */\n distance: number;\n /** World-space hit point. */\n point: Vec3Tuple;\n}\n\n/**\n * A mesh-accurate pick supplied by the app - `scene.pickWithRay` with a Ray\n * built from these arguments. Return null for a miss.\n */\nexport type BabylonPickWithRay = (\n origin: Vec3Tuple,\n direction: Vec3Tuple,\n maxDistance: number,\n) => BabylonPickResult | null;\n\nexport interface BabylonHitTesterOptions {\n /** Targeting radius for a node registered without one. Default 0.1 m. */\n defaultRadius?: number;\n /** Ray length handed to `pickWithRay`, in metres. Default 100. */\n maxRayDistance?: number;\n /** Optional mesh-accurate pick. Absent, the sphere test is used. */\n pickWithRay?: BabylonPickWithRay;\n}\n\nconst DEFAULT_RADIUS = 0.1;\nconst DEFAULT_MAX_RAY_DISTANCE = 100;\n\nexport class BabylonHitTester implements HitTester {\n private readonly entries = new Map<string, { node: BabylonTransformNodeLike; radius: number }>();\n private readonly byNode = new Map<BabylonTransformNodeLike, string>();\n private readonly defaultRadius: number;\n private readonly maxRayDistance: number;\n private pickWithRay: BabylonPickWithRay | null;\n\n constructor(options: BabylonHitTesterOptions = {}) {\n this.defaultRadius = options.defaultRadius ?? DEFAULT_RADIUS;\n this.maxRayDistance = options.maxRayDistance ?? DEFAULT_MAX_RAY_DISTANCE;\n this.pickWithRay = options.pickWithRay ?? null;\n }\n\n /** Supply or replace the mesh-accurate pick after construction. */\n setPickWithRay(pick: BabylonPickWithRay | null): void {\n this.pickWithRay = pick;\n }\n\n register(id: string, node: BabylonTransformNodeLike, radius?: number): void {\n this.unregister(id);\n this.entries.set(id, { node, radius: radius ?? this.defaultRadius });\n this.byNode.set(node, id);\n }\n\n unregister(id: string): void {\n const entry = this.entries.get(id);\n if (entry) this.byNode.delete(entry.node);\n this.entries.delete(id);\n }\n\n getNode(id: string): BabylonTransformNodeLike | undefined {\n return this.entries.get(id)?.node;\n }\n\n hitRay(ray: RayTuple): InteractableHit | null {\n // An app-supplied pick REPLACES the sphere test for rays - it does not\n // sit in front of it. A miss, or a hit on scenery, is the answer: the\n // app's own pick already said what the ray reached first, and testing\n // spheres behind it would target something the ray never got to.\n // Proximity queries stay on the sphere test either way.\n if (this.pickWithRay) {\n const picked = this.pickWithRay(ray.origin, ray.direction, this.maxRayDistance);\n if (!picked?.mesh) return null;\n const id = this.ownerOf(picked.mesh);\n return id === null\n ? null\n : { interactableId: id, distance: picked.distance, point: picked.point };\n }\n\n let best: InteractableHit | null = null;\n for (const [id, { node, radius }] of this.entries) {\n if (!nodeShowing(node)) continue;\n const point = toVec3(node.getAbsolutePosition());\n if (!point) continue;\n const { distance, t } = rayPointDistance(ray, point);\n if (t > 0 && distance <= radius && (best === null || t < best.distance)) {\n best = { interactableId: id, distance: t, point };\n }\n }\n return best;\n }\n\n hitProximity(point: Vec3Tuple, radius: number): InteractableHit | null {\n let best: InteractableHit | null = null;\n for (const [id, { node, radius: targetRadius }] of this.entries) {\n if (!nodeShowing(node)) continue;\n const at = toVec3(node.getAbsolutePosition());\n if (!at) continue;\n const distance =\n Math.hypot(at[0] - point[0], at[1] - point[1], at[2] - point[2]) - targetRadius;\n if (distance <= radius && (best === null || distance < best.distance)) {\n best = { interactableId: id, distance: Math.max(0, distance), point: at };\n }\n }\n return best;\n }\n\n /** The registered interactable a picked node belongs to, if any. */\n private ownerOf(node: BabylonTransformNodeLike): string | null {\n let current: BabylonTransformNodeLike | null = node;\n while (current) {\n const id = this.byNode.get(current);\n if (id !== undefined) return id;\n current = parentOf(current);\n }\n return null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hit-tester.js","sourceRoot":"","sources":["../src/hit-tester.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GAIjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAiC,MAAM,oBAAoB,CAAC;AA+BlG,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,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ChC,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,IAAI,SAAS;gBAAE,OAAO,MAAM,CAAC;QAC5D,CAAC;QACD,MAAM,OAAO,GAAmB,EAAE,CAAC;QACnC,KAAK,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;gBAAE,SAAS;YACjC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC;YAClD,IAAI,MAAM;gBAAE,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACnD,CAAC;QACD,MAAM,GAAG,GAAG,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QAClE,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,GAAG,CAAC,cAAc,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACvG,CAAC;IAED,oEAAoE;IAC5D,OAAO,CAAC,IAA8B;QAC5C,IAAI,OAAO,GAAoC,IAAI,CAAC;QACpD,OAAO,OAAO,EAAE,CAAC;YACf,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACpC,IAAI,EAAE,KAAK,SAAS;gBAAE,OAAO,EAAE,CAAC;YAChC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["/**\n * BabylonHitTester - resolves the core's ray and proximity queries against\n * registered Babylon nodes.\n *\n * The default test needs no Babylon raycaster: each registered node carries\n * a radius, and a query is a sphere test against the node's absolute\n * position. That is the same model the IWSDK adapter uses, and it is enough\n * for buttons, levers, dials and grabbables, which are small next to the\n * distance they are pointed at from.\n *\n * An app that wants mesh-accurate picking supplies `pickWithRay`, typically\n * a one-line wrapper over `scene.pickWithRay`. Whatever mesh it returns is\n * mapped back to an interactable id through the registration map, walking up\n * parents so a pick on a child mesh still resolves to the registered root.\n */\nimport type { RayTuple, Vec3Tuple } from \"@realitycollective/webxr-input\";\nimport {\n surfacePointOnSphere,\n coneHitForSpheres,\n rayPointDistance,\n type HitTester,\n type InteractableHit,\n type SphereTarget,\n} from \"@realitycollective/webxr-interactions\";\nimport { nodeShowing, parentOf, toVec3, type BabylonTransformNodeLike } from \"./babylon-types.js\";\n\n/** What an app's mesh-accurate pick reports back. */\nexport interface BabylonPickResult {\n /** The node that was hit. Mapped to an interactable through registration. */\n mesh: BabylonTransformNodeLike | null | undefined;\n /** Distance from the ray origin, in metres. */\n distance: number;\n /** World-space hit point. */\n point: Vec3Tuple;\n}\n\n/**\n * A mesh-accurate pick supplied by the app - `scene.pickWithRay` with a Ray\n * built from these arguments. Return null for a miss.\n */\nexport type BabylonPickWithRay = (\n origin: Vec3Tuple,\n direction: Vec3Tuple,\n maxDistance: number,\n) => BabylonPickResult | null;\n\nexport interface BabylonHitTesterOptions {\n /** Targeting radius for a node registered without one. Default 0.1 m. */\n defaultRadius?: number;\n /** Ray length handed to `pickWithRay`, in metres. Default 100. */\n maxRayDistance?: number;\n /** Optional mesh-accurate pick. Absent, the sphere test is used. */\n pickWithRay?: BabylonPickWithRay;\n}\n\nconst DEFAULT_RADIUS = 0.1;\nconst DEFAULT_MAX_RAY_DISTANCE = 100;\n\nexport class BabylonHitTester implements HitTester {\n private readonly entries = new Map<string, { node: BabylonTransformNodeLike; radius: number }>();\n private readonly byNode = new Map<BabylonTransformNodeLike, string>();\n private readonly defaultRadius: number;\n private readonly maxRayDistance: number;\n private pickWithRay: BabylonPickWithRay | null;\n\n constructor(options: BabylonHitTesterOptions = {}) {\n this.defaultRadius = options.defaultRadius ?? DEFAULT_RADIUS;\n this.maxRayDistance = options.maxRayDistance ?? DEFAULT_MAX_RAY_DISTANCE;\n this.pickWithRay = options.pickWithRay ?? null;\n }\n\n /** Supply or replace the mesh-accurate pick after construction. */\n setPickWithRay(pick: BabylonPickWithRay | null): void {\n this.pickWithRay = pick;\n }\n\n register(id: string, node: BabylonTransformNodeLike, radius?: number): void {\n this.unregister(id);\n this.entries.set(id, { node, radius: radius ?? this.defaultRadius });\n this.byNode.set(node, id);\n }\n\n unregister(id: string): void {\n const entry = this.entries.get(id);\n if (entry) this.byNode.delete(entry.node);\n this.entries.delete(id);\n }\n\n getNode(id: string): BabylonTransformNodeLike | undefined {\n return this.entries.get(id)?.node;\n }\n\n hitRay(ray: RayTuple): InteractableHit | null {\n // An app-supplied pick REPLACES the sphere test for rays - it does not\n // sit in front of it. A miss, or a hit on scenery, is the answer: the\n // app's own pick already said what the ray reached first, and testing\n // spheres behind it would target something the ray never got to.\n // Proximity queries stay on the sphere test either way.\n if (this.pickWithRay) {\n const picked = this.pickWithRay(ray.origin, ray.direction, this.maxRayDistance);\n if (!picked?.mesh) return null;\n const id = this.ownerOf(picked.mesh);\n return id === null\n ? null\n : { interactableId: id, distance: picked.distance, point: picked.point };\n }\n\n let best: InteractableHit | null = null;\n for (const [id, { node, radius }] of this.entries) {\n if (!nodeShowing(node)) continue;\n const point = toVec3(node.getAbsolutePosition());\n if (!point) continue;\n const { distance, t } = rayPointDistance(ray, point);\n if (t > 0 && distance <= radius && (best === null || t < best.distance)) {\n best = { interactableId: id, distance: t, point };\n }\n }\n return best;\n }\n\n hitProximity(point: Vec3Tuple, radius: number): InteractableHit | null {\n let best: InteractableHit | null = null;\n for (const [id, { node, radius: targetRadius }] of this.entries) {\n if (!nodeShowing(node)) continue;\n const at = toVec3(node.getAbsolutePosition());\n if (!at) continue;\n const distance =\n Math.hypot(at[0] - point[0], at[1] - point[1], at[2] - point[2]) - targetRadius;\n if (distance <= radius && (best === null || distance < best.distance)) {\n // The surface point nearest the fingertip, where the touch cursor sits.\n best = { interactableId: id, distance: Math.max(0, distance), point: surfacePointOnSphere(at, targetRadius, point) };\n }\n }\n return best;\n }\n\n /**\n * The eye-gaze cone (`ports.ts`, `hitCone`) over the registered spheres,\n * the core's `coneHitForSpheres`. With an app-supplied `pickWithRay`, a\n * mesh the ray itself reaches wins first, as it does for `hitRay`.\n */\n hitCone(ray: RayTuple, halfAngle: number, maxLength: number): InteractableHit | null {\n if (this.pickWithRay) {\n const direct = this.hitRay(ray);\n if (direct && direct.distance <= maxLength) return direct;\n }\n const spheres: SphereTarget[] = [];\n for (const [id, { node, radius }] of this.entries) {\n if (!nodeShowing(node)) continue;\n const center = toVec3(node.getAbsolutePosition());\n if (center) spheres.push({ id, center, radius });\n }\n const hit = coneHitForSpheres(ray, spheres, halfAngle, maxLength);\n return hit ? { interactableId: hit.interactableId, distance: hit.distance, point: hit.point } : null;\n }\n\n /** The registered interactable a picked node belongs to, if any. */\n private ownerOf(node: BabylonTransformNodeLike): string | null {\n let current: BabylonTransformNodeLike | null = node;\n while (current) {\n const id = this.byNode.get(current);\n if (id !== undefined) return id;\n current = parentOf(current);\n }\n return null;\n }\n}\n"]}
|
package/dist/host.d.ts
CHANGED
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
* `scene.onBeforeRenderObservable` and the engine's own frame delta.
|
|
12
12
|
* Without it, call `update(dt)` yourself with seconds.
|
|
13
13
|
*/
|
|
14
|
-
import { InteractionRuntime, type DwellConfig, type InteractableDescriptor } from "@realitycollective/webxr-interactions";
|
|
15
|
-
import type
|
|
14
|
+
import { InteractionRuntime, type DwellConfig, type InteractableDescriptor, type PhysicsBodySpec, type PhysicsFacility, type PhysicsShapeSpec, type PointerArbiter, type PointerDisplay, type PointerDisplayConfig } from "@realitycollective/webxr-interactions";
|
|
15
|
+
import { type BabylonPhysicsKitLike, type BabylonTransformNodeLike } from "./babylon-types.js";
|
|
16
16
|
import { BabylonHitTester, type BabylonHitTesterOptions, type BabylonPickWithRay } from "./hit-tester.js";
|
|
17
|
+
import { BabylonPointerVisuals, type BabylonPointerVisualsKit } from "./pointer-visuals.js";
|
|
17
18
|
import { BabylonTransformPort, type BabylonTransformPortOptions } from "./transform-port.js";
|
|
18
19
|
import { BabylonInputProvider, type BabylonProviderOptions } from "./provider.js";
|
|
19
20
|
export interface BabylonInteractionsOptions extends BabylonProviderOptions, BabylonHitTesterOptions {
|
|
@@ -24,21 +25,80 @@ export interface BabylonInteractionsOptions extends BabylonProviderOptions, Baby
|
|
|
24
25
|
* `update` from its own loop.
|
|
25
26
|
*/
|
|
26
27
|
attachToScene?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The pointer arbiter shared with the UI Extensions window host
|
|
30
|
+
* (`connectUIExtensions({ pointers })`), so one decision per source covers
|
|
31
|
+
* panels and interactables, as IWSDK's `MultiPointer` does. Omit when the
|
|
32
|
+
* app has no panels.
|
|
33
|
+
*/
|
|
34
|
+
pointers?: PointerArbiter;
|
|
35
|
+
/**
|
|
36
|
+
* The app's pointer display settings: ray never, always or while hitting;
|
|
37
|
+
* cursors on objects and on panels; the ray and cursor look. Defaults are
|
|
38
|
+
* IWSDK 1.0.0's. Change them at run time through
|
|
39
|
+
* `runtime.getPointerDisplay().set(...)`.
|
|
40
|
+
*/
|
|
41
|
+
pointerDisplay?: PointerDisplay | Partial<PointerDisplayConfig>;
|
|
42
|
+
/**
|
|
43
|
+
* Draw the ray stub and the cursor disc for every source, IWSDK's look,
|
|
44
|
+
* into `options.scene`, exactly as the core decides them each frame. Pass
|
|
45
|
+
* `{ kit }`, the Babylon constructors the renderer builds its meshes from.
|
|
46
|
+
* Omit to draw nothing (an app that draws its own reads
|
|
47
|
+
* `runtime.onPointerDrawing`).
|
|
48
|
+
*/
|
|
49
|
+
pointerVisuals?: {
|
|
50
|
+
kit: BabylonPointerVisualsKit;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The platform's physics. Havok (Physics V2) is the named default engine
|
|
54
|
+
* for Babylon: pass `{ kit }`, the Havok-era values from
|
|
55
|
+
* `BabylonPhysicsKitLike`, and the binding builds a `BabylonPhysicsFacility`
|
|
56
|
+
* over `options.scene`. Pass any `PhysicsFacility` instead to replace the
|
|
57
|
+
* default engine with your own. Omit it and no node can carry a body:
|
|
58
|
+
* `register` with a `body` or `shape` then throws.
|
|
59
|
+
*/
|
|
60
|
+
physics?: PhysicsFacility | {
|
|
61
|
+
kit: BabylonPhysicsKitLike;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Step the facility from `update(dt)`. Default true. Pass false when the
|
|
65
|
+
* app steps its physics world itself - or lets Babylon's own render loop
|
|
66
|
+
* do it, since Babylon normally steps physics from `scene.render()`.
|
|
67
|
+
*/
|
|
68
|
+
stepPhysics?: boolean;
|
|
27
69
|
}
|
|
28
70
|
export interface BabylonRegisterOptions extends BabylonTransformPortOptions {
|
|
29
71
|
/** Targeting radius for the sphere hit-tester. Default 0.1 m. */
|
|
30
72
|
targetRadius?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Give the node a physics body with these settings (defaults are the
|
|
75
|
+
* core's: dynamic, no damping, gravity factor 1). Needs `physics` on the
|
|
76
|
+
* setup. With a body, the port applies the held-pose rule through it.
|
|
77
|
+
*/
|
|
78
|
+
body?: PhysicsBodySpec;
|
|
79
|
+
/** The body's collider (default `"auto"`: the node's own geometry). Implies `body`. */
|
|
80
|
+
shape?: PhysicsShapeSpec;
|
|
31
81
|
}
|
|
32
82
|
export declare class BabylonInteractions {
|
|
33
83
|
readonly runtime: InteractionRuntime;
|
|
34
84
|
readonly provider: BabylonInputProvider;
|
|
35
85
|
readonly hitTester: BabylonHitTester;
|
|
86
|
+
/** The platform's physics, when the setup was given one. */
|
|
87
|
+
readonly physics: PhysicsFacility | null;
|
|
88
|
+
/** The ray and cursor renderer, when the setup was given `pointerVisuals`. */
|
|
89
|
+
readonly pointerVisuals: BabylonPointerVisuals | null;
|
|
90
|
+
private readonly stepPhysics;
|
|
36
91
|
private readonly ports;
|
|
92
|
+
private readonly nodes;
|
|
37
93
|
private detachScene;
|
|
38
94
|
constructor(options: BabylonInteractionsOptions);
|
|
39
95
|
/** Supply or replace the app's mesh-accurate pick. */
|
|
40
96
|
setPickWithRay(pick: BabylonPickWithRay | null): void;
|
|
41
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Register an interactable with its Babylon node. With `body` or `shape`
|
|
99
|
+
* the node gets a physics body in the facility at its current world pose,
|
|
100
|
+
* and its port drives the held-pose rule through it.
|
|
101
|
+
*/
|
|
42
102
|
register(descriptor: InteractableDescriptor, node: BabylonTransformNodeLike, options?: BabylonRegisterOptions): BabylonTransformPort;
|
|
43
103
|
unregister(id: string): void;
|
|
44
104
|
getPort(id: string): BabylonTransformPort | undefined;
|