@realitycollective/xrblocks-interactions 0.1.0-preview.1 → 0.1.0-preview.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Changelog
2
2
 
3
- Change log for the Reality Collective WebXR Interaction Extensions packages. All four packages are versioned and released together; the version below is the one carried by the `v<version>` release tag.
3
+ Change log for the Reality Collective WebXR Interaction Extensions packages. All five packages are versioned and released together; the version below is the one carried by the `v<version>` release tag.
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
 
@@ -13,15 +13,23 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
13
13
  - `@realitycollective/iwsdk-interactions` - Meta IWSDK adapter: player-rig poses and stateful gamepads as the provider, IWSDK's own targeting (`Pressed` / `Grabbed` tags) forwarded as pre-resolved hints, and native grab fulfilment when the app enables IWSDK grabbing/physics. One-call `registerInteractions(world)` setup.
14
14
  - `@realitycollective/xrblocks-interactions` - EXPERIMENTAL Google XR Blocks adapter, structurally typed against xrblocks v0.20.0 (`Input.getFrame()` ray sources and direct touches, pooled structs copied, no haptics upstream).
15
15
  - `demos/playground` - the standalone interaction playground: the full station set from one portable `InteractionDescriptor`, with client-side audio cues, opt-in controller haptics and client-side toss ballistics.
16
+ - `@realitycollective/webxr-interactions` - per-source velocity. `VelocityTracker` differentiates the grip poses the runtime already samples into linear and angular velocity, and the runtime runs one by default (`velocity: false` turns it off, `{ smoothing }` averages it). A source on its first frame, or one that reappears after dropping out, reports no velocity rather than a jump from its last known pose, and a provider that supplies its own velocity keeps it. Read it from `runtime.onSample(...)` or `runtime.getSource(id)`. `poseVelocity` and `clampDeadzone` join the math helpers.
17
+ - `@realitycollective/webxr-interactions` - `routeAudioToSink`, the audio counterpart to `routeHapticsToProvider`: an opt-in that plays the cues named in a map through a client-supplied sink. Cues absent from the map are ignored, so an app sonifies only the moments it has sounds for.
18
+ - `@realitycollective/iwsdk-interactions` and `@realitycollective/threejs-interactions` - presence control. `setPresenceVisible(target, visible)` shows and hides the hand and controller visuals per side; the IWSDK adapter adds `setPresenceModality(mode)` to force hands or controllers over the automatic choice, and the three.js adapter takes the app's own models through `registerVisual(handedness, root)`. Each provider reports `supportsPresence`; the XR Blocks adapter reports false, since XR Blocks exposes no way to hide its visuals.
19
+ - `@realitycollective/threejs-interactions` - native WebXR pose velocity. Where the browser reports `linearVelocity` or `angularVelocity` with a grip pose (or with the wrist joint a hand falls back to), the provider passes it through on the snapshot and the core's tracker leaves it alone; where it does not, the tracker derives velocity from consecutive poses as before. The desktop mouse source synthesises nothing: its grip rides the camera ray, so the derived velocity is camera motion, and hand mechanics should be gated on `handedness !== "none"`.
20
+ - `@realitycollective/babylon-interactions` - a Babylon.js adapter, the fourth engine. It reads a `WebXRDefaultExperience` (controllers, motion controller trigger and squeeze, hand-tracking joints, session manager) for input, with `scene.onPointerObservable` as the desktop fallback, haptics through the motion controller's `pulse`, and presence over the visuals Babylon builds - motion controller root meshes and hand meshes. Babylon picks the visual per input source, so there is no modality switch. Hit-testing is a sphere test over registered nodes, with an optional `pickWithRay` hook for mesh-accurate targeting; the transform port moves, rotates and scales Babylon nodes from rest. Structurally typed against the Babylon API rather than importing `@babylonjs/core`, as the XR Blocks adapter is, so an upstream release cannot break the install - and so the whole adapter is covered headlessly by structural fakes. Written against the documented Babylon 7 API and not yet exercised against a real Babylon runtime.
21
+ - Tests for `@realitycollective/iwsdk-interactions`, which had none. `@iwsdk/core` imports headlessly in node, so the provider is covered against a structural fake world with no module mocking, and a parity suite instantiates all three providers and checks each one implements the whole `InputProvider` contract. The package's coverage ratchet moves off zero, and the other three ratchets rise to the floor they now measure.
16
22
 
17
23
  ### Changed
18
24
 
25
+ - `@realitycollective/iwsdk-interactions` - `pulse` resolves the side from the handedness recorded while sampling, rather than parsing the source id. Parsing the id remains the fallback for an id the provider did not produce.
26
+
19
27
  - `@realitycollective/iwsdk-interactions` targets **IWSDK 0.5.x**. Its peer range is now `>=0.5.0 <0.6.0` and it is developed and tested against `@iwsdk/core` 0.5.3. The adapter is source-compatible with 0.4.x and needed no code change, but 0.5 is the only line exercised, so it is the only line supported. Every symbol and runtime member the provider uses is present in both, and it already reads `world.input.xr.gamepads` rather than the accessor 0.5 deprecates.
20
28
  - `demos/playground` no longer compiles UIKitML at build time. `@iwsdk/vite-plugin-uikitml` was discontinued at 0.4.2 and only ever did `JSON.stringify(parse(source))`, so the panel is served as `.uikitml` from `public/ui/` and parsed on load. The demo drops that plugin, and its station markup uses `rgba()` rather than `background-opacity`, which the 0.5 parser removed.
21
29
 
22
30
  ### Notes
23
31
 
24
- - All four 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.
32
+ - 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.
25
33
  - 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.
26
34
 
27
35
  [0.1.0]: https://github.com/realitycollective/WebXR-Interactions/commits/main
@@ -82,6 +82,12 @@ export interface XRBlocksContext {
82
82
  };
83
83
  }
84
84
  export declare class XRBlocksInputProvider implements InputProvider {
85
+ /**
86
+ * XR Blocks owns its own controller and hand visuals and exposes no way
87
+ * to hide them, so there is no presence to offer. Becomes
88
+ * `capabilities.presence` at `@realitycollective/webxr-input` 0.1.1.
89
+ */
90
+ readonly supportsPresence = false;
85
91
  private readonly context;
86
92
  private capabilities;
87
93
  private readonly capsListeners;
package/dist/provider.js CHANGED
@@ -26,6 +26,12 @@ import { NO_CAPABILITIES, } from "@realitycollective/webxr-input";
26
26
  const SCRATCH_V = { x: 0, y: 0, z: 0 };
27
27
  const SCRATCH_Q = { x: 0, y: 0, z: 0, w: 1 };
28
28
  export class XRBlocksInputProvider {
29
+ /**
30
+ * XR Blocks owns its own controller and hand visuals and exposes no way
31
+ * to hide them, so there is no presence to offer. Becomes
32
+ * `capabilities.presence` at `@realitycollective/webxr-input` 0.1.1.
33
+ */
34
+ supportsPresence = false;
29
35
  context;
30
36
  capabilities = { ...NO_CAPABILITIES, headPose: true, gaze: true };
31
37
  capsListeners = new Set();
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EACL,eAAe,GAMhB,MAAM,gCAAgC,CAAC;AAuDxC,MAAM,SAAS,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACvC,MAAM,SAAS,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAE7C,MAAM,OAAO,qBAAqB;IACf,OAAO,CAAkB;IAClC,YAAY,GAAsB,EAAE,GAAG,eAAe,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC5E,aAAa,GAAG,IAAI,GAAG,EAAkC,CAAC;IAE3E,YAAY,OAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,qBAAqB,CAAC,QAAwC;QAC5D,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACjC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED,gB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AAI,CAAC;YACzB,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC;gBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAED,WAAW;QACT,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACjE,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACrE,OAAO;YACL,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;YAC9C,UAAU,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;SAC1E,CAAC;IACJ,CAAC;CACF;AAED,SAAS,mBAAmB,CAAC,KAAyB;IACpD,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;AAChE,CAAC;AAED,SAAS,OAAO,CAAC,GAAY;IAI3B,yDAAyD;IACzD,OAAO;QACL,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QAClD,SAAS,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;KAC/D,CAAC;AACJ,CAAC","sourcesContent":["/**\n * XRBlocksInputProvider - EXPERIMENTAL.\n *\n * Binds to the SHAPE of Google XR Blocks (verified against xrblocks\n * v0.20.0 source, 2026-08) without importing `xrblocks`, per the\n * UI Extensions structural-typing convention:\n *\n * - `xb.input.getFrame()` → `{ raySources, directTouches }`. Those slot\n * objects are POOLED AND MUTATED per frame upstream - everything is\n * copied here, never retained.\n * - `RaySourceInput`: `{ controller, sourceType: 'mouse'|'controller-ray'\n * |'hand-ray'|'gaze'|'simulator', ray, selected }` - handedness from\n * `controller.inputSource?.handedness`; analog select only via\n * `controller.gamepad?.buttons[0].value`; squeeze only as the boolean\n * `controller.userData.squeezing`.\n * - `DirectTouchInput`: `{ handIndex (0=left,1=right), point }` - the\n * index-fingertip world position, merged into the matching hand source.\n * - Grip poses are not exposed by the frame struct; the ray pose doubles\n * as the carry pose (XR Blocks keeps grip transforms behind\n * `options.controllers.visualization`).\n * - Gaze rides `sourceType: 'gaze'` and never raw-selects (XR Blocks\n * selects gaze via its own dwell; ours is the core's dwell).\n * - Haptics: none in XR Blocks (verified) - capability stays false.\n */\nimport {\n NO_CAPABILITIES,\n type HeadPose,\n type InputCapabilities,\n type InputProvider,\n type InputSourceSnapshot,\n type Unsubscribe,\n} from \"@realitycollective/webxr-input\";\n\n/** Structural slice of THREE.Vector3 / Quaternion. */\ninterface Vec3Like {\n x: number;\n y: number;\n z: number;\n}\ninterface QuatLike extends Vec3Like {\n w: number;\n}\n\ninterface RayLike {\n origin: Vec3Like;\n direction: Vec3Like;\n}\n\ninterface ControllerLike {\n inputSource?: { handedness?: string };\n gamepad?: { buttons?: ReadonlyArray<{ value: number }> };\n userData?: { squeezing?: boolean; selected?: boolean; id?: number };\n}\n\n/** Structural `RaySourceInput` (xrblocks src/interaction/InteractionTypes.ts). */\nexport interface XBRaySourceLike {\n controller: ControllerLike;\n sourceType: string; // 'mouse' | 'controller-ray' | 'hand-ray' | 'gaze' | 'simulator'\n ray: RayLike;\n selected: boolean;\n}\n\n/** Structural `DirectTouchInput`. */\nexport interface XBDirectTouchLike {\n controller: ControllerLike;\n handIndex: number; // 0 = LEFT, 1 = RIGHT (xrblocks Handedness enum)\n point: Vec3Like;\n selected: boolean;\n}\n\nexport interface XBFrameLike {\n raySources: readonly XBRaySourceLike[];\n directTouches: readonly XBDirectTouchLike[];\n}\n\n/** The slice of the XR Blocks singletons the provider binds to. */\nexport interface XRBlocksContext {\n /** `xb.input` - must expose `getFrame()`. */\n input: { getFrame(): XBFrameLike };\n /** `xb.camera` / `xb.core.camera` - the head pose. */\n camera: {\n getWorldPosition(target: Vec3Like): Vec3Like;\n getWorldQuaternion(target: QuatLike): QuatLike;\n };\n}\n\nconst SCRATCH_V = { x: 0, y: 0, z: 0 };\nconst SCRATCH_Q = { x: 0, y: 0, z: 0, w: 1 };\n\nexport class XRBlocksInputProvider implements InputProvider {\n private readonly context: XRBlocksContext;\n private capabilities: InputCapabilities = { ...NO_CAPABILITIES, headPose: true, gaze: true };\n private readonly capsListeners = new Set<(c: InputCapabilities) => void>();\n\n constructor(context: XRBlocksContext) {\n this.context = context;\n }\n\n getCapabilities(): InputCapabilities {\n return this.capabilities;\n }\n\n onCapabilitiesChanged(listener: (c: InputCapabilities) => void): Unsubscribe {\n this.capsListeners.add(listener);\n return () => this.capsListeners.delete(listener);\n }\n\n onSourcesChanged(): Unsubscribe {\n return () => undefined;\n }\n\n sample(): readonly InputSourceSnapshot[] {\n const frame = this.context.input.getFrame();\n const snapshots: InputSourceSnapshot[] = [];\n const byHandedness = new Map<string, InputSourceSnapshot>();\n\n let sawRay = false;\n let sawTouch = false;\n let sawMouse = false;\n\n for (const source of frame.raySources) {\n if (source.sourceType === \"gaze\") {\n snapshots.push({\n id: \"xb-gaze\",\n kind: \"gaze\",\n handedness: \"none\",\n ray: copyRay(source.ray),\n select: 0, // gaze never raw-selects in XR Blocks\n squeeze: 0,\n });\n continue;\n }\n const handedness = normalizeHandedness(source.controller.inputSource?.handedness);\n const isMouse = source.sourceType === \"mouse\";\n if (isMouse) sawMouse = true;\n else sawRay = true;\n const analog = source.controller.gamepad?.buttons?.[0]?.value;\n const select = analog !== undefined && analog > 0 ? analog : source.selected ? 1 : 0;\n const ray = copyRay(source.ray);\n const snapshot: InputSourceSnapshot = {\n id: isMouse ? \"xb-mouse\" : `xb-${handedness}-${source.sourceType}`,\n kind: isMouse ? \"pointer2d\" : source.sourceType === \"hand-ray\" ? \"hand\" : \"controller\",\n handedness,\n ray,\n // XR Blocks does not expose grip transforms in the frame struct;\n // the ray pose doubles as the carry pose.\n gripPose: { position: ray.origin, quaternion: [0, 0, 0, 1] },\n select,\n squeeze: source.controller.userData?.squeezing ? 1 : 0,\n };\n snapshots.push(snapshot);\n if (handedness !== \"none\") byHandedness.set(handedness, snapshot);\n }\n\n for (const touch of frame.directTouches) {\n sawTouch = true;\n const handedness = touch.handIndex === 0 ? \"left\" : \"right\";\n const existing = byHandedness.get(handedness);\n const tip: [number, number, number] = [touch.point.x, touch.point.y, touch.point.z];\n if (existing) {\n existing.indexTip = tip;\n existing.kind = \"hand\";\n } else {\n snapshots.push({\n id: `xb-${handedness}-touch`,\n kind: \"hand\",\n handedness,\n indexTip: tip,\n gripPose: { position: tip, quaternion: [0, 0, 0, 1] },\n select: touch.selected ? 1 : 0,\n squeeze: 0,\n });\n }\n }\n\n this.refreshCapabilities(sawRay, sawTouch, sawMouse);\n return snapshots;\n }\n\n private refreshCapabilities(rays: boolean, touches: boolean, mouse: boolean): void {\n const next: InputCapabilities = {\n ...NO_CAPABILITIES,\n rays,\n pokes: touches,\n grabs: rays || touches ? \"poseOnly\" : \"none\",\n handJoints: touches,\n pinch: touches,\n gaze: true,\n pointer2d: mouse,\n headPose: true,\n haptics: false, // xrblocks v0.20.0 has no haptics API\n };\n if (JSON.stringify(next) !== JSON.stringify(this.capabilities)) {\n this.capabilities = next;\n for (const listener of [...this.capsListeners]) listener(next);\n }\n }\n\n getHeadPose(): HeadPose {\n const position = this.context.camera.getWorldPosition(SCRATCH_V);\n const quaternion = this.context.camera.getWorldQuaternion(SCRATCH_Q);\n return {\n position: [position.x, position.y, position.z],\n quaternion: [quaternion.x, quaternion.y, quaternion.z, quaternion.w ?? 1],\n };\n }\n}\n\nfunction normalizeHandedness(value: string | undefined): \"left\" | \"right\" | \"none\" {\n return value === \"left\" || value === \"right\" ? value : \"none\";\n}\n\nfunction copyRay(ray: RayLike): {\n origin: [number, number, number];\n direction: [number, number, number];\n} {\n // Upstream slot objects are pooled - copy, never retain.\n return {\n origin: [ray.origin.x, ray.origin.y, ray.origin.z],\n direction: [ray.direction.x, ray.direction.y, ray.direction.z],\n };\n}\n"]}
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EACL,eAAe,GAMhB,MAAM,gCAAgC,CAAC;AAuDxC,MAAM,SAAS,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACvC,MAAM,SAAS,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAE7C,MAAM,OAAO,qBAAqB;IAChC;;;;OAIG;IACM,gBAAgB,GAAG,KAAK,CAAC;IAEjB,OAAO,CAAkB;IAClC,YAAY,GAAsB,EAAE,GAAG,eAAe,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC5E,aAAa,GAAG,IAAI,GAAG,EAAkC,CAAC;IAE3E,YAAY,OAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,qBAAqB,CAAC,QAAwC;QAC5D,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACjC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED,gBAAg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,CAAC;YACzB,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC;gBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAED,WAAW;QACT,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACjE,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACrE,OAAO;YACL,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;YAC9C,UAAU,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;SAC1E,CAAC;IACJ,CAAC;CACF;AAED,SAAS,mBAAmB,CAAC,KAAyB;IACpD,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;AAChE,CAAC;AAED,SAAS,OAAO,CAAC,GAAY;IAI3B,yDAAyD;IACzD,OAAO;QACL,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QAClD,SAAS,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;KAC/D,CAAC;AACJ,CAAC","sourcesContent":["/**\n * XRBlocksInputProvider - EXPERIMENTAL.\n *\n * Binds to the SHAPE of Google XR Blocks (verified against xrblocks\n * v0.20.0 source, 2026-08) without importing `xrblocks`, per the\n * UI Extensions structural-typing convention:\n *\n * - `xb.input.getFrame()` → `{ raySources, directTouches }`. Those slot\n * objects are POOLED AND MUTATED per frame upstream - everything is\n * copied here, never retained.\n * - `RaySourceInput`: `{ controller, sourceType: 'mouse'|'controller-ray'\n * |'hand-ray'|'gaze'|'simulator', ray, selected }` - handedness from\n * `controller.inputSource?.handedness`; analog select only via\n * `controller.gamepad?.buttons[0].value`; squeeze only as the boolean\n * `controller.userData.squeezing`.\n * - `DirectTouchInput`: `{ handIndex (0=left,1=right), point }` - the\n * index-fingertip world position, merged into the matching hand source.\n * - Grip poses are not exposed by the frame struct; the ray pose doubles\n * as the carry pose (XR Blocks keeps grip transforms behind\n * `options.controllers.visualization`).\n * - Gaze rides `sourceType: 'gaze'` and never raw-selects (XR Blocks\n * selects gaze via its own dwell; ours is the core's dwell).\n * - Haptics: none in XR Blocks (verified) - capability stays false.\n */\nimport {\n NO_CAPABILITIES,\n type HeadPose,\n type InputCapabilities,\n type InputProvider,\n type InputSourceSnapshot,\n type Unsubscribe,\n} from \"@realitycollective/webxr-input\";\n\n/** Structural slice of THREE.Vector3 / Quaternion. */\ninterface Vec3Like {\n x: number;\n y: number;\n z: number;\n}\ninterface QuatLike extends Vec3Like {\n w: number;\n}\n\ninterface RayLike {\n origin: Vec3Like;\n direction: Vec3Like;\n}\n\ninterface ControllerLike {\n inputSource?: { handedness?: string };\n gamepad?: { buttons?: ReadonlyArray<{ value: number }> };\n userData?: { squeezing?: boolean; selected?: boolean; id?: number };\n}\n\n/** Structural `RaySourceInput` (xrblocks src/interaction/InteractionTypes.ts). */\nexport interface XBRaySourceLike {\n controller: ControllerLike;\n sourceType: string; // 'mouse' | 'controller-ray' | 'hand-ray' | 'gaze' | 'simulator'\n ray: RayLike;\n selected: boolean;\n}\n\n/** Structural `DirectTouchInput`. */\nexport interface XBDirectTouchLike {\n controller: ControllerLike;\n handIndex: number; // 0 = LEFT, 1 = RIGHT (xrblocks Handedness enum)\n point: Vec3Like;\n selected: boolean;\n}\n\nexport interface XBFrameLike {\n raySources: readonly XBRaySourceLike[];\n directTouches: readonly XBDirectTouchLike[];\n}\n\n/** The slice of the XR Blocks singletons the provider binds to. */\nexport interface XRBlocksContext {\n /** `xb.input` - must expose `getFrame()`. */\n input: { getFrame(): XBFrameLike };\n /** `xb.camera` / `xb.core.camera` - the head pose. */\n camera: {\n getWorldPosition(target: Vec3Like): Vec3Like;\n getWorldQuaternion(target: QuatLike): QuatLike;\n };\n}\n\nconst SCRATCH_V = { x: 0, y: 0, z: 0 };\nconst SCRATCH_Q = { x: 0, y: 0, z: 0, w: 1 };\n\nexport class XRBlocksInputProvider implements InputProvider {\n /**\n * XR Blocks owns its own controller and hand visuals and exposes no way\n * to hide them, so there is no presence to offer. Becomes\n * `capabilities.presence` at `@realitycollective/webxr-input` 0.1.1.\n */\n readonly supportsPresence = false;\n\n private readonly context: XRBlocksContext;\n private capabilities: InputCapabilities = { ...NO_CAPABILITIES, headPose: true, gaze: true };\n private readonly capsListeners = new Set<(c: InputCapabilities) => void>();\n\n constructor(context: XRBlocksContext) {\n this.context = context;\n }\n\n getCapabilities(): InputCapabilities {\n return this.capabilities;\n }\n\n onCapabilitiesChanged(listener: (c: InputCapabilities) => void): Unsubscribe {\n this.capsListeners.add(listener);\n return () => this.capsListeners.delete(listener);\n }\n\n onSourcesChanged(): Unsubscribe {\n return () => undefined;\n }\n\n sample(): readonly InputSourceSnapshot[] {\n const frame = this.context.input.getFrame();\n const snapshots: InputSourceSnapshot[] = [];\n const byHandedness = new Map<string, InputSourceSnapshot>();\n\n let sawRay = false;\n let sawTouch = false;\n let sawMouse = false;\n\n for (const source of frame.raySources) {\n if (source.sourceType === \"gaze\") {\n snapshots.push({\n id: \"xb-gaze\",\n kind: \"gaze\",\n handedness: \"none\",\n ray: copyRay(source.ray),\n select: 0, // gaze never raw-selects in XR Blocks\n squeeze: 0,\n });\n continue;\n }\n const handedness = normalizeHandedness(source.controller.inputSource?.handedness);\n const isMouse = source.sourceType === \"mouse\";\n if (isMouse) sawMouse = true;\n else sawRay = true;\n const analog = source.controller.gamepad?.buttons?.[0]?.value;\n const select = analog !== undefined && analog > 0 ? analog : source.selected ? 1 : 0;\n const ray = copyRay(source.ray);\n const snapshot: InputSourceSnapshot = {\n id: isMouse ? \"xb-mouse\" : `xb-${handedness}-${source.sourceType}`,\n kind: isMouse ? \"pointer2d\" : source.sourceType === \"hand-ray\" ? \"hand\" : \"controller\",\n handedness,\n ray,\n // XR Blocks does not expose grip transforms in the frame struct;\n // the ray pose doubles as the carry pose.\n gripPose: { position: ray.origin, quaternion: [0, 0, 0, 1] },\n select,\n squeeze: source.controller.userData?.squeezing ? 1 : 0,\n };\n snapshots.push(snapshot);\n if (handedness !== \"none\") byHandedness.set(handedness, snapshot);\n }\n\n for (const touch of frame.directTouches) {\n sawTouch = true;\n const handedness = touch.handIndex === 0 ? \"left\" : \"right\";\n const existing = byHandedness.get(handedness);\n const tip: [number, number, number] = [touch.point.x, touch.point.y, touch.point.z];\n if (existing) {\n existing.indexTip = tip;\n existing.kind = \"hand\";\n } else {\n snapshots.push({\n id: `xb-${handedness}-touch`,\n kind: \"hand\",\n handedness,\n indexTip: tip,\n gripPose: { position: tip, quaternion: [0, 0, 0, 1] },\n select: touch.selected ? 1 : 0,\n squeeze: 0,\n });\n }\n }\n\n this.refreshCapabilities(sawRay, sawTouch, sawMouse);\n return snapshots;\n }\n\n private refreshCapabilities(rays: boolean, touches: boolean, mouse: boolean): void {\n const next: InputCapabilities = {\n ...NO_CAPABILITIES,\n rays,\n pokes: touches,\n grabs: rays || touches ? \"poseOnly\" : \"none\",\n handJoints: touches,\n pinch: touches,\n gaze: true,\n pointer2d: mouse,\n headPose: true,\n haptics: false, // xrblocks v0.20.0 has no haptics API\n };\n if (JSON.stringify(next) !== JSON.stringify(this.capabilities)) {\n this.capabilities = next;\n for (const listener of [...this.capsListeners]) listener(next);\n }\n }\n\n getHeadPose(): HeadPose {\n const position = this.context.camera.getWorldPosition(SCRATCH_V);\n const quaternion = this.context.camera.getWorldQuaternion(SCRATCH_Q);\n return {\n position: [position.x, position.y, position.z],\n quaternion: [quaternion.x, quaternion.y, quaternion.z, quaternion.w ?? 1],\n };\n }\n}\n\nfunction normalizeHandedness(value: string | undefined): \"left\" | \"right\" | \"none\" {\n return value === \"left\" || value === \"right\" ? value : \"none\";\n}\n\nfunction copyRay(ray: RayLike): {\n origin: [number, number, number];\n direction: [number, number, number];\n} {\n // Upstream slot objects are pooled - copy, never retain.\n return {\n origin: [ray.origin.x, ray.origin.y, ray.origin.z],\n direction: [ray.direction.x, ray.direction.y, ray.direction.z],\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realitycollective/xrblocks-interactions",
3
- "version": "0.1.0-preview.1",
3
+ "version": "0.1.0-preview.2",
4
4
  "description": "EXPERIMENTAL Google XR Blocks adapter for the Reality Collective Interaction Extensions - maps XR Blocks' input pipeline (Input.getFrame() ray sources + direct touches, Script select events) into the engine-free @realitycollective/webxr-interactions core, reusing the three.js hit-testing/transform machinery. Structurally typed: no xrblocks import. Re-exports the core.",
5
5
  "keywords": [
6
6
  "realitycollective",
@@ -34,8 +34,8 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@realitycollective/webxr-input": "^0.1.0",
37
- "@realitycollective/webxr-interactions": "^0.1.0-preview.1",
38
- "@realitycollective/threejs-interactions": "^0.1.0-preview.1"
37
+ "@realitycollective/webxr-interactions": "^0.1.0-preview.2",
38
+ "@realitycollective/threejs-interactions": "^0.1.0-preview.2"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "three": ">=0.170.0"