@realitycollective/threejs-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
@@ -11,7 +11,7 @@
11
11
  * Capabilities are derived from the LIVE session (never the requested
12
12
  * config) and re-published on session start/end and input-source changes.
13
13
  */
14
- import { type Camera, type WebXRManager } from "three";
14
+ import { type Camera, type Object3D, type WebXRManager } from "three";
15
15
  import { type HeadPose, type InputCapabilities, type InputProvider, type InputSourceSnapshot, type Unsubscribe } from "@realitycollective/webxr-input";
16
16
  export interface WebXRProviderContext {
17
17
  /** three.js `renderer.xr` (or anything with the same session surface). */
@@ -42,12 +42,20 @@ export interface WebXRProviderContext {
42
42
  */
43
43
  desktopSqueezeButton?: "left" | "right" | "none";
44
44
  }
45
+ /** Which side's visual a presence call targets. `"all"` is both. */
46
+ export type PresenceTarget = "left" | "right" | "none" | "all";
47
+ /**
48
+ * Which family of visuals presence shows. This provider does not build
49
+ * controller or hand models, so it cannot switch between them.
50
+ */
51
+ export type PresenceModality = "hands" | "controllers" | "auto";
45
52
  export declare class WebXRInputProvider implements InputProvider {
46
53
  private readonly context;
47
54
  private capabilities;
48
55
  private readonly capsListeners;
49
56
  private readonly sourceListeners;
50
57
  private readonly selectStates;
58
+ private readonly visuals;
51
59
  private boundSession;
52
60
  private readonly sessionHandlers;
53
61
  private mouseDown;
@@ -79,6 +87,33 @@ export declare class WebXRInputProvider implements InputProvider {
79
87
  private squeezing;
80
88
  private sampleDesktop;
81
89
  getHeadPose(): HeadPose;
90
+ /**
91
+ * Hand the provider the scene object that represents one side's hand or
92
+ * controller, so presence can hide and show it. Nothing here builds those
93
+ * models: a standalone three.js app owns its own, and this is the hook
94
+ * that lets it be driven from the same place as an IWSDK app's.
95
+ *
96
+ * Registering the same side twice replaces the previous root.
97
+ */
98
+ registerVisual(handedness: "left" | "right", root: Object3D): void;
99
+ /**
100
+ * True once a visual has been registered. Becomes `capabilities.presence`
101
+ * at `@realitycollective/webxr-input` 0.1.1.
102
+ */
103
+ get supportsPresence(): boolean;
104
+ /**
105
+ * Show or hide registered visuals. Returns false when the targeted side
106
+ * has no registered visual. `"none"` targets no side, so it reports
107
+ * whether presence is usable at all without changing anything.
108
+ */
109
+ setPresenceVisible(target: PresenceTarget, visible: boolean): boolean;
110
+ /**
111
+ * Always false. Switching between hand and controller models means owning
112
+ * both, and this provider owns neither - the app registered one root per
113
+ * side and decides for itself what that root contains. IWSDK builds both
114
+ * families, so its adapter implements this.
115
+ */
116
+ setPresenceModality(_mode: PresenceModality): boolean;
82
117
  pulse(sourceId: string, intensity: number, durationMs: number): boolean;
83
118
  dispose(): void;
84
119
  }
@@ -11,7 +11,7 @@
11
11
  * Capabilities are derived from the LIVE session (never the requested
12
12
  * config) and re-published on session start/end and input-source changes.
13
13
  */
14
- import { Raycaster, Vector2, Vector3, Quaternion } from "three";
14
+ import { Raycaster, Vector2, Vector3, Quaternion, } from "three";
15
15
  import { NO_CAPABILITIES, } from "@realitycollective/webxr-input";
16
16
  /** Where the desktop fallback puts its synthetic grip along the mouse ray. */
17
17
  const DEFAULT_DESKTOP_GRIP_DISTANCE = 1;
@@ -23,6 +23,7 @@ export class WebXRInputProvider {
23
23
  capsListeners = new Set();
24
24
  sourceListeners = new Set();
25
25
  selectStates = new Map();
26
+ visuals = new Map();
26
27
  boundSession = null;
27
28
  sessionHandlers = [];
28
29
  // Desktop pointer state.
@@ -238,8 +239,10 @@ export class WebXRInputProvider {
238
239
  }
239
240
  if (source.gripSpace) {
240
241
  const gripPose = frame.getPose(source.gripSpace, referenceSpace);
241
- if (gripPose)
242
+ if (gripPose) {
242
243
  snapshot.gripPose = xrPoseToTuple(gripPose);
244
+ applyPoseVelocity(snapshot, gripPose);
245
+ }
243
246
  }
244
247
  if (source.hand) {
245
248
  const joint = source.hand.get("index-finger-tip");
@@ -252,8 +255,10 @@ export class WebXRInputProvider {
252
255
  if (!snapshot.gripPose) {
253
256
  const wrist = source.hand.get("wrist");
254
257
  const wristPose = wrist ? frame.getJointPose?.(wrist, referenceSpace) : undefined;
255
- if (wristPose)
258
+ if (wristPose) {
256
259
  snapshot.gripPose = xrPoseToTuple(wristPose);
260
+ applyPoseVelocity(snapshot, wristPose);
261
+ }
257
262
  }
258
263
  }
259
264
  if ((source.gamepad?.hapticActuators?.length ?? 0) > 0) {
@@ -332,6 +337,54 @@ export class WebXRInputProvider {
332
337
  quaternion: [this.q.x, this.q.y, this.q.z, this.q.w],
333
338
  };
334
339
  }
340
+ // -- presence -----------------------------------------------------------------
341
+ /**
342
+ * Hand the provider the scene object that represents one side's hand or
343
+ * controller, so presence can hide and show it. Nothing here builds those
344
+ * models: a standalone three.js app owns its own, and this is the hook
345
+ * that lets it be driven from the same place as an IWSDK app's.
346
+ *
347
+ * Registering the same side twice replaces the previous root.
348
+ */
349
+ registerVisual(handedness, root) {
350
+ this.visuals.set(handedness, root);
351
+ }
352
+ /**
353
+ * True once a visual has been registered. Becomes `capabilities.presence`
354
+ * at `@realitycollective/webxr-input` 0.1.1.
355
+ */
356
+ get supportsPresence() {
357
+ return this.visuals.size > 0;
358
+ }
359
+ /**
360
+ * Show or hide registered visuals. Returns false when the targeted side
361
+ * has no registered visual. `"none"` targets no side, so it reports
362
+ * whether presence is usable at all without changing anything.
363
+ */
364
+ setPresenceVisible(target, visible) {
365
+ if (target === "none")
366
+ return this.visuals.size > 0;
367
+ let applied = false;
368
+ for (const side of ["left", "right"]) {
369
+ if (target !== "all" && target !== side)
370
+ continue;
371
+ const root = this.visuals.get(side);
372
+ if (!root)
373
+ continue;
374
+ root.visible = visible;
375
+ applied = true;
376
+ }
377
+ return applied;
378
+ }
379
+ /**
380
+ * Always false. Switching between hand and controller models means owning
381
+ * both, and this provider owns neither - the app registered one root per
382
+ * side and decides for itself what that root contains. IWSDK builds both
383
+ * families, so its adapter implements this.
384
+ */
385
+ setPresenceModality(_mode) {
386
+ return false;
387
+ }
335
388
  pulse(sourceId, intensity, durationMs) {
336
389
  const session = this.boundSession;
337
390
  if (!session)
@@ -363,4 +416,22 @@ function xrPoseToTuple(pose) {
363
416
  const o = pose.transform.orientation;
364
417
  return { position: [p.x, p.y, p.z], quaternion: [o.x, o.y, o.z, o.w] };
365
418
  }
419
+ /**
420
+ * Pass the platform's own velocity through when it reports one.
421
+ *
422
+ * `XRPose.linearVelocity` (metres per second) and `angularVelocity` (radians
423
+ * per second about each axis) are optional, and undefined on a user agent that
424
+ * does not compute them. Both are expressed in the reference space the pose was
425
+ * taken in, which is the space the snapshot's grip pose already uses. What is
426
+ * left undefined here is filled in by the core's `VelocityTracker`, which
427
+ * differentiates consecutive grip poses and never overwrites a supplied value.
428
+ */
429
+ function applyPoseVelocity(snapshot, pose) {
430
+ const linear = pose.linearVelocity;
431
+ if (linear)
432
+ snapshot.linearVelocity = [linear.x, linear.y, linear.z];
433
+ const angular = pose.angularVelocity;
434
+ if (angular)
435
+ snapshot.angularVelocity = [angular.x, angular.y, angular.z];
436
+ }
366
437
  //# sourceMappingURL=webxr-provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webxr-provider.js","sourceRoot":"","sources":["../src/webxr-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAkC,MAAM,OAAO,CAAC;AAChG,OAAO,EACL,eAAe,GAOhB,MAAM,gCAAgC,CAAC;AAqCxC,8EAA8E;AAC9E,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAExC,gEAAgE;AAChE,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEnC,MAAM,OAAO,kBAAkB;IACZ,OAAO,CAAuB;IACvC,YAAY,CAAoB;IACvB,aAAa,GAAG,IAAI,GAAG,EAAkC,CAAC;IAC1D,eAAe,GAAG,IAAI,GAAG,EAAc,CAAC;IACxC,YAAY,GAAG,IAAI,GAAG,EAA8B,CAAC;IAC9D,YAAY,GAAqB,IAAI,CAAC;IAC7B,eAAe,GAAmC,EAAE,CAAC;IAEtE,yBAAyB;IACjB,SAAS,GAAG,KAAK,CAAC;IAClB,UAAU,GAAG,KAAK,CAAC;IACV,QAAQ,GAAG,IAAI,OAAO,EAAE,CAAC;IACzB,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;IAC5B,SAAS,CAAc;IACvB,YAAY,CAAS;IACrB,aAAa,CAA4B;IAE1D,SAAS;IACQ,CAAC,GAAG,IAAI,OAAO,EAAE,CAAC;IAClB,CAAC,GAAG,IAAI,UAAU,EAAE,CAAC;IACrB,UAAU,GAAG,IAAI,OAAO,EAAE,CAAC;IAC3B,SAAS,GAAG,IAAI,OAAO,EAAE,CAAC;IAC1B,cAAc,GAAG,IAAI,UAAU,EAAE,C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AC,EAAE,CAAC;AACzE,CAAC","sourcesContent":["/**\n * WebXRInputProvider - the standalone, framework-free input provider.\n *\n * Speaks the browser's OpenXR binding directly: `XRSession` input sources\n * (`targetRaySpace`, `gripSpace`, `hand` joints), `selectstart/selectend`\n * and `squeezestart/squeezeend`, gamepad analog values where present, and\n * haptic actuators. Falls back to a desktop mouse pointer (a ray from the\n * camera through the cursor) when no immersive session is live, so every\n * consumer runs in a flat browser too.\n *\n * Capabilities are derived from the LIVE session (never the requested\n * config) and re-published on session start/end and input-source changes.\n */\nimport { Raycaster, Vector2, Vector3, Quaternion, type Camera, type WebXRManager } from \"three\";\nimport {\n NO_CAPABILITIES,\n type HeadPose,\n type InputCapabilities,\n type InputProvider,\n type InputSourceSnapshot,\n type PoseTuple,\n type Unsubscribe,\n} from \"@realitycollective/webxr-input\";\n\nexport interface WebXRProviderContext {\n /** three.js `renderer.xr` (or anything with the same session surface). */\n xr: Pick<WebXRManager, \"getSession\" | \"getReferenceSpace\" | \"getFrame\">;\n /** The rendering camera - head pose in XR, pointer projection on desktop. */\n camera: Camera;\n /** DOM element for the desktop mouse fallback (canvas). Omit to disable. */\n domElement?: HTMLElement;\n /**\n * Metres along the mouse ray at which the desktop fallback places its\n * synthetic grip pose. Hand-driven behaviours (grab, hinge, dial, slide)\n * track a grip position; a mouse has none, so one is projected onto the ray.\n * Set this near the distance of the things being manipulated - too short and\n * levers barely swing, too long and they over-swing. Default 1 metre.\n */\n desktopGripDistance?: number;\n /**\n * Which mouse button reports `squeeze` on desktop. Default `\"left\"`.\n *\n * The right button is NOT the default, because the shared desktop camera\n * controls (`DesktopControls` in `@realitycollective/xrblocks-uiextensions`)\n * bind right-drag to look and reserve the left button for interaction. That\n * leaves the left button to carry both actions, which is fine as long as an\n * interactable does not mix a select-driven behaviour (press) with a\n * grab-driven one (grab, hinge, dial, slide) - such an interactable would\n * receive both on a single click. Use `\"right\"` only in an app that does not\n * use right-drag to look.\n */\n desktopSqueezeButton?: \"left\" | \"right\" | \"none\";\n}\n\ninterface SelectState {\n selecting: boolean;\n squeezing: boolean;\n}\n\n/** Where the desktop fallback puts its synthetic grip along the mouse ray. */\nconst DEFAULT_DESKTOP_GRIP_DISTANCE = 1;\n\n/** Centre of the viewport, used while the pointer is locked. */\nconst ZERO_NDC = new Vector2(0, 0);\n\nexport class WebXRInputProvider implements InputProvider {\n private readonly context: WebXRProviderContext;\n private capabilities: InputCapabilities;\n private readonly capsListeners = new Set<(c: InputCapabilities) => void>();\n private readonly sourceListeners = new Set<() => void>();\n private readonly selectStates = new Map<XRInputSource, SelectState>();\n private boundSession: XRSession | null = null;\n private readonly sessionHandlers: Array<[string, EventListener]> = [];\n\n // Desktop pointer state.\n private mouseDown = false;\n private mouseRight = false;\n private readonly mouseNdc = new Vector2();\n private readonly raycaster = new Raycaster();\n private readonly detachDom: Unsubscribe;\n private readonly gripDistance: number;\n private readonly squeezeButton: \"left\" | \"right\" | \"none\";\n\n // Temps.\n private readonly v = new Vector3();\n private readonly q = new Quaternion();\n private readonly pointerNdc = new Vector2();\n private readonly gripPoint = new Vector3();\n private readonly gripQuaternion = new Quaternion();\n\n constructor(context: WebXRProviderContext) {\n this.context = context;\n this.gripDistance = context.desktopGripDistance ?? DEFAULT_DESKTOP_GRIP_DISTANCE;\n // Read before attachDom - it decides whether to claim the context menu.\n this.squeezeButton = context.desktopSqueezeButton ?? \"left\";\n this.capabilities = { ...NO_CAPABILITIES, headPose: true, gaze: true };\n this.detachDom = this.attachDom(context.domElement);\n this.refreshCapabilities();\n }\n\n private attachDom(element: HTMLElement | undefined): Unsubscribe {\n if (!element) return () => undefined;\n const onMove = (event: PointerEvent) => {\n const rect = element.getBoundingClientRect();\n this.mouseNdc.set(\n ((event.clientX - rect.left) / rect.width) * 2 - 1,\n -((event.clientY - rect.top) / rect.height) * 2 + 1,\n );\n };\n const onDown = (event: PointerEvent) => {\n if (event.button === 0) this.mouseDown = true;\n if (event.button === 2) this.mouseRight = true;\n onMove(event);\n };\n const onUp = (event: PointerEvent) => {\n if (event.button === 0) this.mouseDown = false;\n if (event.button === 2) this.mouseRight = false;\n };\n element.addEventListener(\"pointermove\", onMove);\n element.addEventListener(\"pointerdown\", onDown);\n // Only when the right button carries squeeze. Otherwise the menu belongs to\n // whoever else is listening - the shared camera controls suppress it there.\n // Without this, a right press opens the menu, the matching pointerup never\n // arrives, and the squeeze latches on.\n const onContextMenu =\n this.squeezeButton === \"right\" ? (event: Event) => event.preventDefault() : undefined;\n if (onContextMenu) element.addEventListener(\"contextmenu\", onContextMenu);\n window.addEventListener(\"pointerup\", onUp);\n return () => {\n element.removeEventListener(\"pointermove\", onMove);\n element.removeEventListener(\"pointerdown\", onDown);\n if (onContextMenu) element.removeEventListener(\"contextmenu\", onContextMenu);\n window.removeEventListener(\"pointerup\", onUp);\n };\n }\n\n /** Bind/unbind session listeners as the session comes and goes. */\n private syncSession(): XRSession | null {\n const session = this.context.xr.getSession();\n if (session === this.boundSession) return session;\n\n if (this.boundSession) {\n for (const [type, handler] of this.sessionHandlers) {\n this.boundSession.removeEventListener(type, handler);\n }\n this.sessionHandlers.length = 0;\n this.selectStates.clear();\n }\n this.boundSession = session;\n if (session) {\n const setSelect = (selecting: boolean) => (event: Event) => {\n const source = (event as XRInputSourceEvent).inputSource;\n const state = this.selectState(source);\n state.selecting = selecting;\n };\n const setSqueeze = (squeezing: boolean) => (event: Event) => {\n const source = (event as XRInputSourceEvent).inputSource;\n const state = this.selectState(source);\n state.squeezing = squeezing;\n };\n const onSourcesChange = () => {\n this.refreshCapabilities();\n for (const listener of [...this.sourceListeners]) listener();\n };\n const onEnd = () => {\n this.boundSession = null;\n this.sessionHandlers.length = 0;\n this.selectStates.clear();\n this.refreshCapabilities();\n };\n const pairs: Array<[string, EventListener]> = [\n [\"selectstart\", setSelect(true)],\n [\"selectend\", setSelect(false)],\n [\"squeezestart\", setSqueeze(true)],\n [\"squeezeend\", setSqueeze(false)],\n [\"inputsourceschange\", onSourcesChange],\n [\"end\", onEnd],\n ];\n for (const [type, handler] of pairs) {\n session.addEventListener(type, handler);\n this.sessionHandlers.push([type, handler]);\n }\n this.refreshCapabilities();\n }\n return session;\n }\n\n private selectState(source: XRInputSource): SelectState {\n let state = this.selectStates.get(source);\n if (!state) {\n state = { selecting: false, squeezing: false };\n this.selectStates.set(source, state);\n }\n return state;\n }\n\n private refreshCapabilities(): void {\n const session = this.boundSession ?? this.context.xr.getSession();\n const desktop = this.context.domElement !== undefined && session === null;\n const next: InputCapabilities = {\n ...NO_CAPABILITIES,\n headPose: true,\n gaze: true,\n pointer2d: desktop,\n // NOTE: `rays` stays false on desktop on purpose. sample() uses it as the\n // \"a session just ended\" sentinel, so setting it here would re-derive\n // capabilities on every frame for the whole life of the page.\n // The desktop fallback synthesises a grip on the mouse ray, so hand-driven\n // behaviours (grab, hinge, dial, slide) negotiate successfully. Without\n // this `grabs` stays \"none\" off-headset and capability negotiation\n // disables every one of them, leaving press as the only usable behaviour.\n grabs: desktop ? \"poseOnly\" : NO_CAPABILITIES.grabs,\n };\n if (session) {\n for (const source of session.inputSources) {\n if (source.targetRaySpace) next.rays = true;\n if (source.gripSpace || source.hand) next.grabs = \"poseOnly\";\n if (source.hand) {\n next.handJoints = true;\n next.pokes = true;\n next.pinch = true;\n }\n if (source.gamepad) {\n next.buttonsAxes = true;\n if ((source.gamepad.hapticActuators?.length ?? 0) > 0) next.haptics = true;\n }\n }\n }\n const changed = JSON.stringify(next) !== JSON.stringify(this.capabilities);\n this.capabilities = next;\n if (changed) {\n for (const listener of [...this.capsListeners]) listener(next);\n }\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(listener: () => void): Unsubscribe {\n this.sourceListeners.add(listener);\n return () => this.sourceListeners.delete(listener);\n }\n\n sample(): readonly InputSourceSnapshot[] {\n const session = this.syncSession();\n // The session-null path also re-derives capabilities when a session\n // just ended between frames.\n if (!session) {\n if (this.capabilities.rays) this.refreshCapabilities();\n return this.sampleDesktop();\n }\n\n const frame = this.context.xr.getFrame();\n const referenceSpace = this.context.xr.getReferenceSpace();\n if (!frame || !referenceSpace) return [];\n\n const snapshots: InputSourceSnapshot[] = [];\n let index = 0;\n for (const source of session.inputSources) {\n const state = this.selectState(source);\n const id = `${source.handedness}-${source.hand ? \"hand\" : \"controller\"}-${index++}`;\n const snapshot: InputSourceSnapshot = {\n id,\n kind: source.hand ? \"hand\" : \"controller\",\n handedness:\n source.handedness === \"left\" || source.handedness === \"right\"\n ? source.handedness\n : \"none\",\n select: this.selectValue(source, state),\n squeeze: this.squeezeValue(source, state),\n };\n\n const rayPose = frame.getPose(source.targetRaySpace, referenceSpace);\n if (rayPose) {\n const p = rayPose.transform.position;\n const o = rayPose.transform.orientation;\n this.q.set(o.x, o.y, o.z, o.w);\n this.v.set(0, 0, -1).applyQuaternion(this.q);\n snapshot.ray = {\n origin: [p.x, p.y, p.z],\n direction: [this.v.x, this.v.y, this.v.z],\n };\n }\n if (source.gripSpace) {\n const gripPose = frame.getPose(source.gripSpace, referenceSpace);\n if (gripPose) snapshot.gripPose = xrPoseToTuple(gripPose);\n }\n if (source.hand) {\n const joint = source.hand.get(\"index-finger-tip\");\n const jointPose = joint ? frame.getJointPose?.(joint, referenceSpace) : undefined;\n if (jointPose) {\n const p = jointPose.transform.position;\n snapshot.indexTip = [p.x, p.y, p.z];\n }\n // Hands without a gripSpace still need a carry pose: use the wrist.\n if (!snapshot.gripPose) {\n const wrist = source.hand.get(\"wrist\");\n const wristPose = wrist ? frame.getJointPose?.(wrist, referenceSpace) : undefined;\n if (wristPose) snapshot.gripPose = xrPoseToTuple(wristPose);\n }\n }\n if ((source.gamepad?.hapticActuators?.length ?? 0) > 0) {\n snapshot.hapticsAvailable = true;\n }\n snapshots.push(snapshot);\n }\n return snapshots;\n }\n\n /** Analog trigger where available, else the select event state. */\n private selectValue(source: XRInputSource, state: SelectState): number {\n const analog = source.gamepad?.buttons[0]?.value;\n if (analog !== undefined && analog > 0) return analog;\n return state.selecting ? 1 : 0;\n }\n\n private squeezeValue(source: XRInputSource, state: SelectState): number {\n const analog = source.gamepad?.buttons[1]?.value;\n if (analog !== undefined && analog > 0) return analog;\n return state.squeezing ? 1 : 0;\n }\n\n /** Is the configured squeeze button currently held? */\n private squeezing(): boolean {\n if (this.squeezeButton === \"left\") return this.mouseDown;\n if (this.squeezeButton === \"right\") return this.mouseRight;\n return false;\n }\n\n private sampleDesktop(): readonly InputSourceSnapshot[] {\n const element = this.context.domElement;\n if (!element) return [];\n\n // Under pointer lock the cursor stops moving and clientX/clientY freeze, so\n // the tracked NDC would stick wherever the pointer was when it locked. A\n // locked pointer aims from the centre of the viewport instead.\n const locked =\n typeof document !== \"undefined\" && document.pointerLockElement === element;\n this.pointerNdc.copy(locked ? ZERO_NDC : this.mouseNdc);\n this.raycaster.setFromCamera(this.pointerNdc, this.context.camera);\n\n const { origin, direction } = this.raycaster.ray;\n // A mouse has no grip. Hand-driven behaviours read `gripPose.position` (or\n // fall back to `ray.origin`, which is the camera and barely moves), so\n // project a grip onto the ray to give them something that tracks the\n // pointer.\n this.gripPoint.copy(direction).multiplyScalar(this.gripDistance).add(origin);\n this.context.camera.getWorldQuaternion(this.gripQuaternion);\n\n return [\n {\n id: \"mouse\",\n kind: \"pointer2d\",\n handedness: \"none\",\n ray: {\n origin: [origin.x, origin.y, origin.z],\n direction: [direction.x, direction.y, direction.z],\n },\n gripPose: {\n position: [this.gripPoint.x, this.gripPoint.y, this.gripPoint.z],\n quaternion: [\n this.gripQuaternion.x,\n this.gripQuaternion.y,\n this.gripQuaternion.z,\n this.gripQuaternion.w,\n ],\n },\n select: this.mouseDown ? 1 : 0,\n squeeze: this.squeezing() ? 1 : 0,\n },\n ];\n }\n\n getHeadPose(): HeadPose {\n this.context.camera.getWorldPosition(this.v);\n this.context.camera.getWorldQuaternion(this.q);\n return {\n position: [this.v.x, this.v.y, this.v.z],\n quaternion: [this.q.x, this.q.y, this.q.z, this.q.w],\n };\n }\n\n pulse(sourceId: string, intensity: number, durationMs: number): boolean {\n const session = this.boundSession;\n if (!session) return false;\n let index = 0;\n for (const source of session.inputSources) {\n const id = `${source.handedness}-${source.hand ? \"hand\" : \"controller\"}-${index++}`;\n if (id !== sourceId) continue;\n const actuator = source.gamepad?.hapticActuators?.[0];\n if (!actuator) return false;\n void (actuator as { pulse?: (i: number, d: number) => Promise<boolean> }).pulse?.(\n Math.min(1, Math.max(0, intensity)),\n durationMs,\n );\n return true;\n }\n return false;\n }\n\n dispose(): void {\n this.detachDom();\n if (this.boundSession) {\n for (const [type, handler] of this.sessionHandlers) {\n this.boundSession.removeEventListener(type, handler);\n }\n }\n }\n}\n\nfunction xrPoseToTuple(pose: XRPose): PoseTuple {\n const p = pose.transform.position;\n const o = pose.transform.orientation;\n return { position: [p.x, p.y, p.z], quaternion: [o.x, o.y, o.z, o.w] };\n}\n"]}
1
+ {"version":3,"file":"webxr-provider.js","sourceRoot":"","sources":["../src/webxr-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,SAAS,EACT,OAAO,EACP,OAAO,EACP,UAAU,GAIX,MAAM,OAAO,CAAC;AACf,OAAO,EACL,eAAe,GAOhB,MAAM,gCAAgC,CAAC;AAgDxC,8EAA8E;AAC9E,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAExC,gEAAgE;AAChE,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEnC,MAAM,OAAO,kBAAkB;IACZ,OAAO,CAAuB;IACvC,YAAY,CAAoB;IACvB,aAAa,GAAG,IAAI,GAAG,EAAkC,CAAC;IAC1D,eAAe,GAAG,IAAI,GAAG,EAAc,CAAC;IACxC,YAAY,GAAG,IAAI,GAAG,EAA8B,CAAC;IACrD,OAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;IACzD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AS,CAAC,QAAQ,CAAC;IAClC,MAAM,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;IACrC,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACzE,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,iBAAiB,CAAC,QAAyC,EAAE,IAAY;IAChF,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;IACnC,IAAI,MAAM;QAAE,QAAQ,CAAC,cAAc,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACrE,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC;IACrC,IAAI,OAAO;QAAE,QAAQ,CAAC,eAAe,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["/**\n * WebXRInputProvider - the standalone, framework-free input provider.\n *\n * Speaks the browser's OpenXR binding directly: `XRSession` input sources\n * (`targetRaySpace`, `gripSpace`, `hand` joints), `selectstart/selectend`\n * and `squeezestart/squeezeend`, gamepad analog values where present, and\n * haptic actuators. Falls back to a desktop mouse pointer (a ray from the\n * camera through the cursor) when no immersive session is live, so every\n * consumer runs in a flat browser too.\n *\n * Capabilities are derived from the LIVE session (never the requested\n * config) and re-published on session start/end and input-source changes.\n */\nimport {\n Raycaster,\n Vector2,\n Vector3,\n Quaternion,\n type Camera,\n type Object3D,\n type WebXRManager,\n} from \"three\";\nimport {\n NO_CAPABILITIES,\n type HeadPose,\n type InputCapabilities,\n type InputProvider,\n type InputSourceSnapshot,\n type PoseTuple,\n type Unsubscribe,\n} from \"@realitycollective/webxr-input\";\n// Collapses into `InputSourceSnapshot` at `@realitycollective/webxr-input` 0.1.1, which adds the two velocity fields.\nimport type { InputSourceSnapshotWithVelocity } from \"@realitycollective/webxr-interactions\";\n\nexport interface WebXRProviderContext {\n /** three.js `renderer.xr` (or anything with the same session surface). */\n xr: Pick<WebXRManager, \"getSession\" | \"getReferenceSpace\" | \"getFrame\">;\n /** The rendering camera - head pose in XR, pointer projection on desktop. */\n camera: Camera;\n /** DOM element for the desktop mouse fallback (canvas). Omit to disable. */\n domElement?: HTMLElement;\n /**\n * Metres along the mouse ray at which the desktop fallback places its\n * synthetic grip pose. Hand-driven behaviours (grab, hinge, dial, slide)\n * track a grip position; a mouse has none, so one is projected onto the ray.\n * Set this near the distance of the things being manipulated - too short and\n * levers barely swing, too long and they over-swing. Default 1 metre.\n */\n desktopGripDistance?: number;\n /**\n * Which mouse button reports `squeeze` on desktop. Default `\"left\"`.\n *\n * The right button is NOT the default, because the shared desktop camera\n * controls (`DesktopControls` in `@realitycollective/xrblocks-uiextensions`)\n * bind right-drag to look and reserve the left button for interaction. That\n * leaves the left button to carry both actions, which is fine as long as an\n * interactable does not mix a select-driven behaviour (press) with a\n * grab-driven one (grab, hinge, dial, slide) - such an interactable would\n * receive both on a single click. Use `\"right\"` only in an app that does not\n * use right-drag to look.\n */\n desktopSqueezeButton?: \"left\" | \"right\" | \"none\";\n}\n\ninterface SelectState {\n selecting: boolean;\n squeezing: boolean;\n}\n\n/** Which side's visual a presence call targets. `\"all\"` is both. */\nexport type PresenceTarget = \"left\" | \"right\" | \"none\" | \"all\";\n\n/**\n * Which family of visuals presence shows. This provider does not build\n * controller or hand models, so it cannot switch between them.\n */\nexport type PresenceModality = \"hands\" | \"controllers\" | \"auto\";\n\n/** Where the desktop fallback puts its synthetic grip along the mouse ray. */\nconst DEFAULT_DESKTOP_GRIP_DISTANCE = 1;\n\n/** Centre of the viewport, used while the pointer is locked. */\nconst ZERO_NDC = new Vector2(0, 0);\n\nexport class WebXRInputProvider implements InputProvider {\n private readonly context: WebXRProviderContext;\n private capabilities: InputCapabilities;\n private readonly capsListeners = new Set<(c: InputCapabilities) => void>();\n private readonly sourceListeners = new Set<() => void>();\n private readonly selectStates = new Map<XRInputSource, SelectState>();\n private readonly visuals = new Map<\"left\" | \"right\", Object3D>();\n private boundSession: XRSession | null = null;\n private readonly sessionHandlers: Array<[string, EventListener]> = [];\n\n // Desktop pointer state.\n private mouseDown = false;\n private mouseRight = false;\n private readonly mouseNdc = new Vector2();\n private readonly raycaster = new Raycaster();\n private readonly detachDom: Unsubscribe;\n private readonly gripDistance: number;\n private readonly squeezeButton: \"left\" | \"right\" | \"none\";\n\n // Temps.\n private readonly v = new Vector3();\n private readonly q = new Quaternion();\n private readonly pointerNdc = new Vector2();\n private readonly gripPoint = new Vector3();\n private readonly gripQuaternion = new Quaternion();\n\n constructor(context: WebXRProviderContext) {\n this.context = context;\n this.gripDistance = context.desktopGripDistance ?? DEFAULT_DESKTOP_GRIP_DISTANCE;\n // Read before attachDom - it decides whether to claim the context menu.\n this.squeezeButton = context.desktopSqueezeButton ?? \"left\";\n this.capabilities = { ...NO_CAPABILITIES, headPose: true, gaze: true };\n this.detachDom = this.attachDom(context.domElement);\n this.refreshCapabilities();\n }\n\n private attachDom(element: HTMLElement | undefined): Unsubscribe {\n if (!element) return () => undefined;\n const onMove = (event: PointerEvent) => {\n const rect = element.getBoundingClientRect();\n this.mouseNdc.set(\n ((event.clientX - rect.left) / rect.width) * 2 - 1,\n -((event.clientY - rect.top) / rect.height) * 2 + 1,\n );\n };\n const onDown = (event: PointerEvent) => {\n if (event.button === 0) this.mouseDown = true;\n if (event.button === 2) this.mouseRight = true;\n onMove(event);\n };\n const onUp = (event: PointerEvent) => {\n if (event.button === 0) this.mouseDown = false;\n if (event.button === 2) this.mouseRight = false;\n };\n element.addEventListener(\"pointermove\", onMove);\n element.addEventListener(\"pointerdown\", onDown);\n // Only when the right button carries squeeze. Otherwise the menu belongs to\n // whoever else is listening - the shared camera controls suppress it there.\n // Without this, a right press opens the menu, the matching pointerup never\n // arrives, and the squeeze latches on.\n const onContextMenu =\n this.squeezeButton === \"right\" ? (event: Event) => event.preventDefault() : undefined;\n if (onContextMenu) element.addEventListener(\"contextmenu\", onContextMenu);\n window.addEventListener(\"pointerup\", onUp);\n return () => {\n element.removeEventListener(\"pointermove\", onMove);\n element.removeEventListener(\"pointerdown\", onDown);\n if (onContextMenu) element.removeEventListener(\"contextmenu\", onContextMenu);\n window.removeEventListener(\"pointerup\", onUp);\n };\n }\n\n /** Bind/unbind session listeners as the session comes and goes. */\n private syncSession(): XRSession | null {\n const session = this.context.xr.getSession();\n if (session === this.boundSession) return session;\n\n if (this.boundSession) {\n for (const [type, handler] of this.sessionHandlers) {\n this.boundSession.removeEventListener(type, handler);\n }\n this.sessionHandlers.length = 0;\n this.selectStates.clear();\n }\n this.boundSession = session;\n if (session) {\n const setSelect = (selecting: boolean) => (event: Event) => {\n const source = (event as XRInputSourceEvent).inputSource;\n const state = this.selectState(source);\n state.selecting = selecting;\n };\n const setSqueeze = (squeezing: boolean) => (event: Event) => {\n const source = (event as XRInputSourceEvent).inputSource;\n const state = this.selectState(source);\n state.squeezing = squeezing;\n };\n const onSourcesChange = () => {\n this.refreshCapabilities();\n for (const listener of [...this.sourceListeners]) listener();\n };\n const onEnd = () => {\n this.boundSession = null;\n this.sessionHandlers.length = 0;\n this.selectStates.clear();\n this.refreshCapabilities();\n };\n const pairs: Array<[string, EventListener]> = [\n [\"selectstart\", setSelect(true)],\n [\"selectend\", setSelect(false)],\n [\"squeezestart\", setSqueeze(true)],\n [\"squeezeend\", setSqueeze(false)],\n [\"inputsourceschange\", onSourcesChange],\n [\"end\", onEnd],\n ];\n for (const [type, handler] of pairs) {\n session.addEventListener(type, handler);\n this.sessionHandlers.push([type, handler]);\n }\n this.refreshCapabilities();\n }\n return session;\n }\n\n private selectState(source: XRInputSource): SelectState {\n let state = this.selectStates.get(source);\n if (!state) {\n state = { selecting: false, squeezing: false };\n this.selectStates.set(source, state);\n }\n return state;\n }\n\n private refreshCapabilities(): void {\n const session = this.boundSession ?? this.context.xr.getSession();\n const desktop = this.context.domElement !== undefined && session === null;\n const next: InputCapabilities = {\n ...NO_CAPABILITIES,\n headPose: true,\n gaze: true,\n pointer2d: desktop,\n // NOTE: `rays` stays false on desktop on purpose. sample() uses it as the\n // \"a session just ended\" sentinel, so setting it here would re-derive\n // capabilities on every frame for the whole life of the page.\n // The desktop fallback synthesises a grip on the mouse ray, so hand-driven\n // behaviours (grab, hinge, dial, slide) negotiate successfully. Without\n // this `grabs` stays \"none\" off-headset and capability negotiation\n // disables every one of them, leaving press as the only usable behaviour.\n grabs: desktop ? \"poseOnly\" : NO_CAPABILITIES.grabs,\n };\n if (session) {\n for (const source of session.inputSources) {\n if (source.targetRaySpace) next.rays = true;\n if (source.gripSpace || source.hand) next.grabs = \"poseOnly\";\n if (source.hand) {\n next.handJoints = true;\n next.pokes = true;\n next.pinch = true;\n }\n if (source.gamepad) {\n next.buttonsAxes = true;\n if ((source.gamepad.hapticActuators?.length ?? 0) > 0) next.haptics = true;\n }\n }\n }\n const changed = JSON.stringify(next) !== JSON.stringify(this.capabilities);\n this.capabilities = next;\n if (changed) {\n for (const listener of [...this.capsListeners]) listener(next);\n }\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(listener: () => void): Unsubscribe {\n this.sourceListeners.add(listener);\n return () => this.sourceListeners.delete(listener);\n }\n\n sample(): readonly InputSourceSnapshot[] {\n const session = this.syncSession();\n // The session-null path also re-derives capabilities when a session\n // just ended between frames.\n if (!session) {\n if (this.capabilities.rays) this.refreshCapabilities();\n return this.sampleDesktop();\n }\n\n const frame = this.context.xr.getFrame();\n const referenceSpace = this.context.xr.getReferenceSpace();\n if (!frame || !referenceSpace) return [];\n\n const snapshots: InputSourceSnapshotWithVelocity[] = [];\n let index = 0;\n for (const source of session.inputSources) {\n const state = this.selectState(source);\n const id = `${source.handedness}-${source.hand ? \"hand\" : \"controller\"}-${index++}`;\n const snapshot: InputSourceSnapshotWithVelocity = {\n id,\n kind: source.hand ? \"hand\" : \"controller\",\n handedness:\n source.handedness === \"left\" || source.handedness === \"right\"\n ? source.handedness\n : \"none\",\n select: this.selectValue(source, state),\n squeeze: this.squeezeValue(source, state),\n };\n\n const rayPose = frame.getPose(source.targetRaySpace, referenceSpace);\n if (rayPose) {\n const p = rayPose.transform.position;\n const o = rayPose.transform.orientation;\n this.q.set(o.x, o.y, o.z, o.w);\n this.v.set(0, 0, -1).applyQuaternion(this.q);\n snapshot.ray = {\n origin: [p.x, p.y, p.z],\n direction: [this.v.x, this.v.y, this.v.z],\n };\n }\n if (source.gripSpace) {\n const gripPose = frame.getPose(source.gripSpace, referenceSpace);\n if (gripPose) {\n snapshot.gripPose = xrPoseToTuple(gripPose);\n applyPoseVelocity(snapshot, gripPose);\n }\n }\n if (source.hand) {\n const joint = source.hand.get(\"index-finger-tip\");\n const jointPose = joint ? frame.getJointPose?.(joint, referenceSpace) : undefined;\n if (jointPose) {\n const p = jointPose.transform.position;\n snapshot.indexTip = [p.x, p.y, p.z];\n }\n // Hands without a gripSpace still need a carry pose: use the wrist.\n if (!snapshot.gripPose) {\n const wrist = source.hand.get(\"wrist\");\n const wristPose = wrist ? frame.getJointPose?.(wrist, referenceSpace) : undefined;\n if (wristPose) {\n snapshot.gripPose = xrPoseToTuple(wristPose);\n applyPoseVelocity(snapshot, wristPose);\n }\n }\n }\n if ((source.gamepad?.hapticActuators?.length ?? 0) > 0) {\n snapshot.hapticsAvailable = true;\n }\n snapshots.push(snapshot);\n }\n return snapshots;\n }\n\n /** Analog trigger where available, else the select event state. */\n private selectValue(source: XRInputSource, state: SelectState): number {\n const analog = source.gamepad?.buttons[0]?.value;\n if (analog !== undefined && analog > 0) return analog;\n return state.selecting ? 1 : 0;\n }\n\n private squeezeValue(source: XRInputSource, state: SelectState): number {\n const analog = source.gamepad?.buttons[1]?.value;\n if (analog !== undefined && analog > 0) return analog;\n return state.squeezing ? 1 : 0;\n }\n\n /** Is the configured squeeze button currently held? */\n private squeezing(): boolean {\n if (this.squeezeButton === \"left\") return this.mouseDown;\n if (this.squeezeButton === \"right\") return this.mouseRight;\n return false;\n }\n\n private sampleDesktop(): readonly InputSourceSnapshot[] {\n const element = this.context.domElement;\n if (!element) return [];\n\n // Under pointer lock the cursor stops moving and clientX/clientY freeze, so\n // the tracked NDC would stick wherever the pointer was when it locked. A\n // locked pointer aims from the centre of the viewport instead.\n const locked =\n typeof document !== \"undefined\" && document.pointerLockElement === element;\n this.pointerNdc.copy(locked ? ZERO_NDC : this.mouseNdc);\n this.raycaster.setFromCamera(this.pointerNdc, this.context.camera);\n\n const { origin, direction } = this.raycaster.ray;\n // A mouse has no grip. Hand-driven behaviours read `gripPose.position` (or\n // fall back to `ray.origin`, which is the camera and barely moves), so\n // project a grip onto the ray to give them something that tracks the\n // pointer.\n this.gripPoint.copy(direction).multiplyScalar(this.gripDistance).add(origin);\n this.context.camera.getWorldQuaternion(this.gripQuaternion);\n\n return [\n {\n id: \"mouse\",\n kind: \"pointer2d\",\n handedness: \"none\",\n ray: {\n origin: [origin.x, origin.y, origin.z],\n direction: [direction.x, direction.y, direction.z],\n },\n gripPose: {\n position: [this.gripPoint.x, this.gripPoint.y, this.gripPoint.z],\n quaternion: [\n this.gripQuaternion.x,\n this.gripQuaternion.y,\n this.gripQuaternion.z,\n this.gripQuaternion.w,\n ],\n },\n select: this.mouseDown ? 1 : 0,\n squeeze: this.squeezing() ? 1 : 0,\n },\n ];\n }\n\n getHeadPose(): HeadPose {\n this.context.camera.getWorldPosition(this.v);\n this.context.camera.getWorldQuaternion(this.q);\n return {\n position: [this.v.x, this.v.y, this.v.z],\n quaternion: [this.q.x, this.q.y, this.q.z, this.q.w],\n };\n }\n\n // -- presence -----------------------------------------------------------------\n\n /**\n * Hand the provider the scene object that represents one side's hand or\n * controller, so presence can hide and show it. Nothing here builds those\n * models: a standalone three.js app owns its own, and this is the hook\n * that lets it be driven from the same place as an IWSDK app's.\n *\n * Registering the same side twice replaces the previous root.\n */\n registerVisual(handedness: \"left\" | \"right\", root: Object3D): void {\n this.visuals.set(handedness, root);\n }\n\n /**\n * True once a visual has been registered. Becomes `capabilities.presence`\n * at `@realitycollective/webxr-input` 0.1.1.\n */\n get supportsPresence(): boolean {\n return this.visuals.size > 0;\n }\n\n /**\n * Show or hide registered visuals. Returns false when the targeted side\n * has no registered visual. `\"none\"` targets no side, so it reports\n * whether presence is usable at all without changing anything.\n */\n setPresenceVisible(target: PresenceTarget, visible: boolean): boolean {\n if (target === \"none\") return this.visuals.size > 0;\n let applied = false;\n for (const side of [\"left\", \"right\"] as const) {\n if (target !== \"all\" && target !== side) continue;\n const root = this.visuals.get(side);\n if (!root) continue;\n root.visible = visible;\n applied = true;\n }\n return applied;\n }\n\n /**\n * Always false. Switching between hand and controller models means owning\n * both, and this provider owns neither - the app registered one root per\n * side and decides for itself what that root contains. IWSDK builds both\n * families, so its adapter implements this.\n */\n setPresenceModality(_mode: PresenceModality): boolean {\n return false;\n }\n\n pulse(sourceId: string, intensity: number, durationMs: number): boolean {\n const session = this.boundSession;\n if (!session) return false;\n let index = 0;\n for (const source of session.inputSources) {\n const id = `${source.handedness}-${source.hand ? \"hand\" : \"controller\"}-${index++}`;\n if (id !== sourceId) continue;\n const actuator = source.gamepad?.hapticActuators?.[0];\n if (!actuator) return false;\n void (actuator as { pulse?: (i: number, d: number) => Promise<boolean> }).pulse?.(\n Math.min(1, Math.max(0, intensity)),\n durationMs,\n );\n return true;\n }\n return false;\n }\n\n dispose(): void {\n this.detachDom();\n if (this.boundSession) {\n for (const [type, handler] of this.sessionHandlers) {\n this.boundSession.removeEventListener(type, handler);\n }\n }\n }\n}\n\nfunction xrPoseToTuple(pose: XRPose): PoseTuple {\n const p = pose.transform.position;\n const o = pose.transform.orientation;\n return { position: [p.x, p.y, p.z], quaternion: [o.x, o.y, o.z, o.w] };\n}\n\n/**\n * Pass the platform's own velocity through when it reports one.\n *\n * `XRPose.linearVelocity` (metres per second) and `angularVelocity` (radians\n * per second about each axis) are optional, and undefined on a user agent that\n * does not compute them. Both are expressed in the reference space the pose was\n * taken in, which is the space the snapshot's grip pose already uses. What is\n * left undefined here is filled in by the core's `VelocityTracker`, which\n * differentiates consecutive grip poses and never overwrites a supplied value.\n */\nfunction applyPoseVelocity(snapshot: InputSourceSnapshotWithVelocity, pose: XRPose): void {\n const linear = pose.linearVelocity;\n if (linear) snapshot.linearVelocity = [linear.x, linear.y, linear.z];\n const angular = pose.angularVelocity;\n if (angular) snapshot.angularVelocity = [angular.x, angular.y, angular.z];\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realitycollective/threejs-interactions",
3
- "version": "0.1.0-preview.1",
3
+ "version": "0.1.0-preview.2",
4
4
  "description": "The default, standalone engine adapter for the Reality Collective Interaction Extensions: raw WebXR (the browser's OpenXR binding - XRSession, XRInputSource, select/squeeze, hand joints) plus three.js hit-testing and transform ports, with a desktop mouse fallback. No framework required. Re-exports the @realitycollective/webxr-interactions core.",
5
5
  "keywords": [
6
6
  "realitycollective",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@realitycollective/webxr-input": "^0.1.0",
37
- "@realitycollective/webxr-interactions": "^0.1.0-preview.1"
37
+ "@realitycollective/webxr-interactions": "^0.1.0-preview.2"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "three": ">=0.170.0"