@realitycollective/iwsdk-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
@@ -23,7 +23,20 @@ export interface IWSDKProviderOptions {
23
23
  nativeGrab?: boolean;
24
24
  }
25
25
  type Side = "left" | "right";
26
+ /** Which side's visuals a presence call targets. `"all"` is both. */
27
+ export type PresenceTarget = "left" | "right" | "none" | "all";
28
+ /**
29
+ * Which family of visuals presence shows. `"auto"` follows the engine:
30
+ * hand visuals while hand tracking is live, controller visuals otherwise.
31
+ */
32
+ export type PresenceModality = "hands" | "controllers" | "auto";
26
33
  export declare class IWSDKInputProvider implements InputProvider {
34
+ /**
35
+ * This provider can show and hide the controller/hand visuals.
36
+ * Becomes `capabilities.presence` at
37
+ * `@realitycollective/webxr-input` 0.1.1.
38
+ */
39
+ readonly supportsPresence = true;
27
40
  private readonly world;
28
41
  private readonly nativeGrab;
29
42
  private capabilities;
@@ -31,6 +44,12 @@ export declare class IWSDKInputProvider implements InputProvider {
31
44
  private readonly sourceListeners;
32
45
  private hints;
33
46
  private readonly nativeGrabbing;
47
+ /** Snapshot id -> side, filled by `sample()` so `pulse` need not parse ids. */
48
+ private readonly sideBySourceId;
49
+ private readonly presenceVisible;
50
+ private presenceModality;
51
+ /** Presence is only re-applied once a client has actually asked for it. */
52
+ private presenceRequested;
34
53
  private readonly disposers;
35
54
  private boundSession;
36
55
  private readonly onSourcesChange;
@@ -47,6 +66,24 @@ export declare class IWSDKInputProvider implements InputProvider {
47
66
  /** Bridge-system input: a side is currently native-grabbing. */
48
67
  setNativeGrabbing(side: Side, grabbing: boolean): void;
49
68
  sample(): readonly InputSourceSnapshot[];
69
+ /**
70
+ * Show or hide this session's controller/hand visuals. Returns false when
71
+ * IWSDK has published no visual adapters, which is the case outside a
72
+ * session. The request is remembered and re-applied on every sample, so
73
+ * a call made before the adapters exist still lands.
74
+ *
75
+ * `"none"` targets no side - the handedness value that has no visual
76
+ * here - so the call reports availability without changing anything.
77
+ */
78
+ setPresenceVisible(target: PresenceTarget, visible: boolean): boolean;
79
+ /**
80
+ * Choose which family of visuals is shown. `"hands"` and `"controllers"`
81
+ * force one family and hide the other; `"auto"` follows the engine's own
82
+ * modality (hand visuals while hand tracking is live).
83
+ */
84
+ setPresenceModality(mode: PresenceModality): boolean;
85
+ private visualAdapters;
86
+ private applyPresence;
50
87
  getHeadPose(): HeadPose;
51
88
  pulse(sourceId: string, intensity: number, durationMs: number): boolean;
52
89
  dispose(): void;
package/dist/provider.js CHANGED
@@ -16,7 +16,37 @@
16
16
  import { InputComponent, VisibilityState } from "@iwsdk/core";
17
17
  import { NO_CAPABILITIES, } from "@realitycollective/webxr-input";
18
18
  const SIDES = ["left", "right"];
19
+ /**
20
+ * Show or hide a visual by walking its DESCENDANTS rather than setting
21
+ * `visible` on the root.
22
+ *
23
+ * Verified against `@iwsdk/xr-input` 0.5.3 (`dist/xr-input-manager.js`, the
24
+ * per-frame update): IWSDK writes `visualAdapter.visual.model.visible =
25
+ * inputSourceData.isPrimary` every frame, so a root-level write is undone
26
+ * before it is drawn. The engine never touches the descendants, so hiding
27
+ * them is the write that sticks, independent of system ordering.
28
+ */
29
+ function setDescendantsVisible(adapter, visible) {
30
+ const model = adapter?.visual?.model;
31
+ if (!model)
32
+ return;
33
+ const stack = [...(model.children ?? [])];
34
+ while (stack.length > 0) {
35
+ const node = stack.pop();
36
+ if (!node)
37
+ continue;
38
+ node.visible = visible;
39
+ for (const child of node.children ?? [])
40
+ stack.push(child);
41
+ }
42
+ }
19
43
  export class IWSDKInputProvider {
44
+ /**
45
+ * This provider can show and hide the controller/hand visuals.
46
+ * Becomes `capabilities.presence` at
47
+ * `@realitycollective/webxr-input` 0.1.1.
48
+ */
49
+ supportsPresence = true;
20
50
  world;
21
51
  nativeGrab;
22
52
  capabilities;
@@ -24,6 +54,12 @@ export class IWSDKInputProvider {
24
54
  sourceListeners = new Set();
25
55
  hints = [];
26
56
  nativeGrabbing = { left: false, right: false };
57
+ /** Snapshot id -> side, filled by `sample()` so `pulse` need not parse ids. */
58
+ sideBySourceId = new Map();
59
+ presenceVisible = { left: true, right: true };
60
+ presenceModality = "auto";
61
+ /** Presence is only re-applied once a client has actually asked for it. */
62
+ presenceRequested = false;
27
63
  disposers = [];
28
64
  boundSession = null;
29
65
  onSourcesChange = () => {
@@ -117,6 +153,11 @@ export class IWSDKInputProvider {
117
153
  this.nativeGrabbing[side] = grabbing;
118
154
  }
119
155
  sample() {
156
+ this.sideBySourceId.clear();
157
+ // Adapters are created as input sources connect, which can be after the
158
+ // client set its presence, so the desired state is re-applied here.
159
+ if (this.presenceRequested)
160
+ this.applyPresence();
120
161
  if (!this.world.session)
121
162
  return [];
122
163
  if (this.world.visibilityState.peek() !== VisibilityState.Visible)
@@ -167,10 +208,58 @@ export class IWSDKInputProvider {
167
208
  if ((gamepad?.gamepad?.hapticActuators?.length ?? 0) > 0) {
168
209
  snapshot.hapticsAvailable = true;
169
210
  }
211
+ this.sideBySourceId.set(snapshot.id, side);
170
212
  snapshots.push(snapshot);
171
213
  }
172
214
  return snapshots;
173
215
  }
216
+ // -- presence ---------------------------------------------------------------
217
+ /**
218
+ * Show or hide this session's controller/hand visuals. Returns false when
219
+ * IWSDK has published no visual adapters, which is the case outside a
220
+ * session. The request is remembered and re-applied on every sample, so
221
+ * a call made before the adapters exist still lands.
222
+ *
223
+ * `"none"` targets no side - the handedness value that has no visual
224
+ * here - so the call reports availability without changing anything.
225
+ */
226
+ setPresenceVisible(target, visible) {
227
+ this.presenceRequested = true;
228
+ for (const side of SIDES) {
229
+ if (target === "all" || target === side)
230
+ this.presenceVisible[side] = visible;
231
+ }
232
+ return this.applyPresence();
233
+ }
234
+ /**
235
+ * Choose which family of visuals is shown. `"hands"` and `"controllers"`
236
+ * force one family and hide the other; `"auto"` follows the engine's own
237
+ * modality (hand visuals while hand tracking is live).
238
+ */
239
+ setPresenceModality(mode) {
240
+ this.presenceRequested = true;
241
+ this.presenceModality = mode;
242
+ return this.applyPresence();
243
+ }
244
+ visualAdapters() {
245
+ const xr = this.world.input?.xr;
246
+ return xr?.visualAdapters ?? null;
247
+ }
248
+ applyPresence() {
249
+ const adapters = this.visualAdapters();
250
+ if (!adapters)
251
+ return false;
252
+ const hands = this.presenceModality === "hands" ||
253
+ (this.presenceModality === "auto" && this.capabilities.handJoints);
254
+ const controllers = this.presenceModality === "controllers" ||
255
+ (this.presenceModality === "auto" && !this.capabilities.handJoints);
256
+ for (const side of SIDES) {
257
+ const wanted = this.presenceVisible[side];
258
+ setDescendantsVisible(adapters.hand?.[side], wanted && hands);
259
+ setDescendantsVisible(adapters.controller?.[side], wanted && controllers);
260
+ }
261
+ return true;
262
+ }
174
263
  getHeadPose() {
175
264
  const head = this.world.playerSpaceEntities.head.object3D;
176
265
  if (!head)
@@ -183,7 +272,11 @@ export class IWSDKInputProvider {
183
272
  };
184
273
  }
185
274
  pulse(sourceId, intensity, durationMs) {
186
- const side = sourceId.startsWith("left") ? "left" : sourceId.startsWith("right") ? "right" : null;
275
+ // The side comes from the handedness recorded when the snapshot was
276
+ // built. Parsing the id is the fallback for an id this provider did not
277
+ // produce (a caller's own naming, or a pulse before the first sample).
278
+ const side = this.sideBySourceId.get(sourceId) ??
279
+ (sourceId.startsWith("left") ? "left" : sourceId.startsWith("right") ? "right" : null);
187
280
  if (!side)
188
281
  return false;
189
282
  const actuator = this.world.input.xr.gamepads[side]?.gamepad?.hapticActuators?.[0];
@@ -196,6 +289,8 @@ export class IWSDKInputProvider {
196
289
  this.boundSession?.removeEventListener("inputsourceschange", this.onSourcesChange);
197
290
  for (const dispose of this.disposers)
198
291
  dispose();
292
+ this.disposers.length = 0;
293
+ this.sideBySourceId.clear();
199
294
  }
200
295
  }
201
296
  // Shared scratch objects (single-threaded frame sampling).
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAc,MAAM,aAAa,CAAC;AAC1E,OAAO,EACL,eAAe,GAOhB,MAAM,gCAAgC,CAAC;AAWxC,MAAM,KAAK,GAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,MAAM,OAAO,kBAAkB;IACZ,KAAK,CAAQ;IACb,UAAU,CAAU;IAC7B,YAAY,CAAoB;IACvB,aAAa,GAAG,IAAI,GAAG,EAAkC,CAAC;IAC1D,eAAe,GAAG,IAAI,GAAG,EAAc,CAAC;IACjD,KAAK,GAAmB,EAAE,CAAC;IAClB,cAAc,GAA0B,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACtE,SAAS,GAAkB,EAAE,CAAC;IACvC,YAAY,G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I,CAAC;QAClG,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC;QACnF,IAAI,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC5B,KAAM,QAAmE,CAAC,KAAK,EAAE,CAC/E,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EACnC,UAAU,CACX,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,IAAI,CAAC,YAAY,EAAE,mBAAmB,CAAC,oBAAoB,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QACnF,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO,EAAE,CAAC;IAClD,CAAC;CACF;AAED,2DAA2D;AAC3D,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAClD,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,IAAI,OAAO,EAAE,EAAE,EAAE,EAAE,IAAI,OAAO,EAAE,EAAE,EAAE,EAAE,IAAI,UAAU,EAAE,EAAE,CAAC","sourcesContent":["/**\n * IWSDKInputProvider - feeds Meta IWSDK's input machinery into the shared\n * input contracts, in place of the standalone WebXR provider.\n *\n * Poses come from the IWSDK player rig (`world.playerSpaceEntities`:\n * ray/grip/index-tip spaces, head), signals from the stateful XR gamepads\n * (`world.input.xr.gamepads` - analog trigger/squeeze with `getSelecting`\n * fallback, which also covers hand pinch). Capabilities derive from the\n * LIVE session and re-publish on visibility/input-source changes.\n *\n * Provider power: IWSDK resolves its own targeting (BVH raycasts →\n * `Pressed`/`Grabbed` tags). The bridge system turns those tags into\n * pre-resolved hints (`setHints`) and flags native grabbing, which the\n * core consumes IN PLACE of its own hit-testing.\n */\nimport { InputComponent, VisibilityState, type World } from \"@iwsdk/core\";\nimport {\n NO_CAPABILITIES,\n type HeadPose,\n type InputCapabilities,\n type InputHitHint,\n type InputProvider,\n type InputSourceSnapshot,\n type Unsubscribe,\n} from \"@realitycollective/webxr-input\";\n\nexport interface IWSDKProviderOptions {\n /**\n * The app enabled IWSDK's `features.grabbing` (+ physics where needed),\n * so grab behaviours are fulfilled NATIVELY by the engine.\n */\n nativeGrab?: boolean;\n}\n\ntype Side = \"left\" | \"right\";\nconst SIDES: readonly Side[] = [\"left\", \"right\"];\n\nexport class IWSDKInputProvider implements InputProvider {\n private readonly world: World;\n private readonly nativeGrab: boolean;\n private capabilities: InputCapabilities;\n private readonly capsListeners = new Set<(c: InputCapabilities) => void>();\n private readonly sourceListeners = new Set<() => void>();\n private hints: InputHitHint[] = [];\n private readonly nativeGrabbing: Record<Side, boolean> = { left: false, right: false };\n private readonly disposers: Unsubscribe[] = [];\n private boundSession: XRSession | null = null;\n private readonly onSourcesChange = () => {\n this.refreshCapabilities();\n for (const listener of [...this.sourceListeners]) listener();\n };\n\n constructor(world: World, options: IWSDKProviderOptions = {}) {\n this.world = world;\n this.nativeGrab = options.nativeGrab ?? false;\n this.capabilities = { ...NO_CAPABILITIES };\n const unsubscribe = world.visibilityState.subscribe(() => {\n this.bindSession();\n this.refreshCapabilities();\n });\n this.disposers.push(unsubscribe);\n this.bindSession();\n this.refreshCapabilities();\n }\n\n private bindSession(): void {\n const session = this.world.session ?? null;\n if (session === this.boundSession) return;\n this.boundSession?.removeEventListener(\"inputsourceschange\", this.onSourcesChange);\n this.boundSession = session;\n session?.addEventListener(\"inputsourceschange\", this.onSourcesChange);\n }\n\n private hasTrackedHand(): boolean {\n const session = this.world.session;\n if (!session) return false;\n for (const source of session.inputSources) {\n if (source.hand) return true;\n }\n return false;\n }\n\n private refreshCapabilities(): void {\n const session = this.world.session;\n const immersive = !!session;\n const handTracking =\n immersive &&\n ((session?.enabledFeatures?.includes(\"hand-tracking\") ?? false) || this.hasTrackedHand());\n let buttonsAxes = false;\n let haptics = false;\n for (const side of SIDES) {\n const gamepad = this.world.input.xr.gamepads[side];\n if (gamepad?.gamepad) buttonsAxes = true;\n if ((gamepad?.gamepad?.hapticActuators?.length ?? 0) > 0) haptics = true;\n }\n const next: InputCapabilities = {\n ...NO_CAPABILITIES,\n rays: immersive,\n // Index-tip spaces exist for controllers too (fall back to ray pose).\n pokes: immersive,\n grabs: immersive ? (this.nativeGrab ? \"native\" : \"poseOnly\") : \"none\",\n handJoints: handTracking,\n pinch: handTracking,\n buttonsAxes,\n gaze: true,\n headPose: true,\n haptics,\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 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 /** Bridge-system input: this frame's pre-resolved tag hints. */\n setHints(hints: InputHitHint[]): void {\n this.hints = hints;\n }\n\n sampleHints(): readonly InputHitHint[] {\n return this.hints;\n }\n\n /** Bridge-system input: a side is currently native-grabbing. */\n setNativeGrabbing(side: Side, grabbing: boolean): void {\n this.nativeGrabbing[side] = grabbing;\n }\n\n sample(): readonly InputSourceSnapshot[] {\n if (!this.world.session) return [];\n if (this.world.visibilityState.peek() !== VisibilityState.Visible) return [];\n\n const spaces = this.world.playerSpaceEntities;\n const snapshots: InputSourceSnapshot[] = [];\n for (const side of SIDES) {\n const rayObject = spaces.raySpaces[side].object3D;\n if (!rayObject) continue;\n const gamepad = this.world.input.xr.gamepads[side];\n const hand = this.capabilities.handJoints;\n\n rayObject.updateWorldMatrix(true, false);\n const rayPos = rayObject.getWorldPosition(TEMP.v1);\n const rayQuat = rayObject.getWorldQuaternion(TEMP.q1);\n const forward = TEMP.v2.set(0, 0, -1).applyQuaternion(rayQuat);\n\n const select = gamepad\n ? Math.max(gamepad.getButtonValue(InputComponent.Trigger), gamepad.getSelecting() ? 1 : 0)\n : 0;\n const squeeze = gamepad ? gamepad.getButtonValue(InputComponent.Squeeze) : 0;\n\n const snapshot: InputSourceSnapshot = {\n id: `${side}-input`,\n kind: hand ? \"hand\" : \"controller\",\n handedness: side,\n ray: {\n origin: [rayPos.x, rayPos.y, rayPos.z],\n direction: [forward.x, forward.y, forward.z],\n },\n select,\n squeeze,\n };\n\n const gripObject = spaces.gripSpaces[side].object3D;\n if (gripObject) {\n const gripPos = gripObject.getWorldPosition(TEMP.v1);\n const gripQuat = gripObject.getWorldQuaternion(TEMP.q1);\n snapshot.gripPose = {\n position: [gripPos.x, gripPos.y, gripPos.z],\n quaternion: [gripQuat.x, gripQuat.y, gripQuat.z, gripQuat.w],\n };\n }\n const tipObject = spaces.indexTipSpaces[side].object3D;\n if (tipObject) {\n const tipPos = tipObject.getWorldPosition(TEMP.v1);\n snapshot.indexTip = [tipPos.x, tipPos.y, tipPos.z];\n }\n if (this.nativeGrabbing[side]) snapshot.nativeGrabbing = true;\n if ((gamepad?.gamepad?.hapticActuators?.length ?? 0) > 0) {\n snapshot.hapticsAvailable = true;\n }\n snapshots.push(snapshot);\n }\n return snapshots;\n }\n\n getHeadPose(): HeadPose {\n const head = this.world.playerSpaceEntities.head.object3D;\n if (!head) return { position: [0, 0, 0], quaternion: [0, 0, 0, 1] };\n const position = head.getWorldPosition(TEMP.v1);\n const quaternion = head.getWorldQuaternion(TEMP.q1);\n return {\n position: [position.x, position.y, position.z],\n quaternion: [quaternion.x, quaternion.y, quaternion.z, quaternion.w],\n };\n }\n\n pulse(sourceId: string, intensity: number, durationMs: number): boolean {\n const side = sourceId.startsWith(\"left\") ? \"left\" : sourceId.startsWith(\"right\") ? \"right\" : null;\n if (!side) return false;\n const actuator = this.world.input.xr.gamepads[side]?.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\n dispose(): void {\n this.boundSession?.removeEventListener(\"inputsourceschange\", this.onSourcesChange);\n for (const dispose of this.disposers) dispose();\n }\n}\n\n// Shared scratch objects (single-threaded frame sampling).\nimport { Quaternion, Vector3 } from \"@iwsdk/core\";\nconst TEMP = { v1: new Vector3(), v2: new Vector3(), q1: new Quaternion() };\n"]}
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAc,MAAM,aAAa,CAAC;AAC1E,OAAO,EACL,eAAe,GAOhB,MAAM,gCAAgC,CAAC;AAWxC,MAAM,KAAK,GAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA+BjD;;;;;;;;;GASG;AACH,SAAS,qBAAqB,CAAC,OAAwC,EAAE,OAAgB;IACvF,MAAM,KAAK,GAAG,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC;IACrC,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,MAAM,KAAK,GAAyB,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;IAChE,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,IAAI,EAAE;YAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED,MAAM,OAAO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AG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC;QACnF,IAAI,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC5B,KAAM,QAAmE,CAAC,KAAK,EAAE,CAC/E,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EACnC,UAAU,CACX,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,IAAI,CAAC,YAAY,EAAE,mBAAmB,CAAC,oBAAoB,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QACnF,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO,EAAE,CAAC;QAChD,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;CACF;AAED,2DAA2D;AAC3D,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAClD,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,IAAI,OAAO,EAAE,EAAE,EAAE,EAAE,IAAI,OAAO,EAAE,EAAE,EAAE,EAAE,IAAI,UAAU,EAAE,EAAE,CAAC","sourcesContent":["/**\n * IWSDKInputProvider - feeds Meta IWSDK's input machinery into the shared\n * input contracts, in place of the standalone WebXR provider.\n *\n * Poses come from the IWSDK player rig (`world.playerSpaceEntities`:\n * ray/grip/index-tip spaces, head), signals from the stateful XR gamepads\n * (`world.input.xr.gamepads` - analog trigger/squeeze with `getSelecting`\n * fallback, which also covers hand pinch). Capabilities derive from the\n * LIVE session and re-publish on visibility/input-source changes.\n *\n * Provider power: IWSDK resolves its own targeting (BVH raycasts →\n * `Pressed`/`Grabbed` tags). The bridge system turns those tags into\n * pre-resolved hints (`setHints`) and flags native grabbing, which the\n * core consumes IN PLACE of its own hit-testing.\n */\nimport { InputComponent, VisibilityState, type World } from \"@iwsdk/core\";\nimport {\n NO_CAPABILITIES,\n type HeadPose,\n type InputCapabilities,\n type InputHitHint,\n type InputProvider,\n type InputSourceSnapshot,\n type Unsubscribe,\n} from \"@realitycollective/webxr-input\";\n\nexport interface IWSDKProviderOptions {\n /**\n * The app enabled IWSDK's `features.grabbing` (+ physics where needed),\n * so grab behaviours are fulfilled NATIVELY by the engine.\n */\n nativeGrab?: boolean;\n}\n\ntype Side = \"left\" | \"right\";\nconst SIDES: readonly Side[] = [\"left\", \"right\"];\n\n/** Which side's visuals a presence call targets. `\"all\"` is both. */\nexport type PresenceTarget = \"left\" | \"right\" | \"none\" | \"all\";\n\n/**\n * Which family of visuals presence shows. `\"auto\"` follows the engine:\n * hand visuals while hand tracking is live, controller visuals otherwise.\n */\nexport type PresenceModality = \"hands\" | \"controllers\" | \"auto\";\n\n/**\n * Structural slice of `world.input.xr.visualAdapters`. Only two fields are\n * needed and the real typings drag the whole `@iwsdk/xr-input` visual\n * stack in for them, so the shape is declared here. A per-side adapter,\n * and its `visual`, are both absent until that input source connects.\n */\ninterface PresenceObjectLike {\n visible: boolean;\n children?: readonly PresenceObjectLike[];\n}\n\ninterface PresenceAdapterLike {\n visual?: { model?: PresenceObjectLike } | undefined;\n}\n\ninterface PresenceAdaptersLike {\n controller?: Partial<Record<Side, PresenceAdapterLike | undefined>> | undefined;\n hand?: Partial<Record<Side, PresenceAdapterLike | undefined>> | undefined;\n}\n\n/**\n * Show or hide a visual by walking its DESCENDANTS rather than setting\n * `visible` on the root.\n *\n * Verified against `@iwsdk/xr-input` 0.5.3 (`dist/xr-input-manager.js`, the\n * per-frame update): IWSDK writes `visualAdapter.visual.model.visible =\n * inputSourceData.isPrimary` every frame, so a root-level write is undone\n * before it is drawn. The engine never touches the descendants, so hiding\n * them is the write that sticks, independent of system ordering.\n */\nfunction setDescendantsVisible(adapter: PresenceAdapterLike | undefined, visible: boolean): void {\n const model = adapter?.visual?.model;\n if (!model) return;\n const stack: PresenceObjectLike[] = [...(model.children ?? [])];\n while (stack.length > 0) {\n const node = stack.pop();\n if (!node) continue;\n node.visible = visible;\n for (const child of node.children ?? []) stack.push(child);\n }\n}\n\nexport class IWSDKInputProvider implements InputProvider {\n /**\n * This provider can show and hide the controller/hand visuals.\n * Becomes `capabilities.presence` at\n * `@realitycollective/webxr-input` 0.1.1.\n */\n readonly supportsPresence = true;\n\n private readonly world: World;\n private readonly nativeGrab: boolean;\n private capabilities: InputCapabilities;\n private readonly capsListeners = new Set<(c: InputCapabilities) => void>();\n private readonly sourceListeners = new Set<() => void>();\n private hints: InputHitHint[] = [];\n private readonly nativeGrabbing: Record<Side, boolean> = { left: false, right: false };\n /** Snapshot id -> side, filled by `sample()` so `pulse` need not parse ids. */\n private readonly sideBySourceId = new Map<string, Side>();\n private readonly presenceVisible: Record<Side, boolean> = { left: true, right: true };\n private presenceModality: PresenceModality = \"auto\";\n /** Presence is only re-applied once a client has actually asked for it. */\n private presenceRequested = false;\n private readonly disposers: Unsubscribe[] = [];\n private boundSession: XRSession | null = null;\n private readonly onSourcesChange = () => {\n this.refreshCapabilities();\n for (const listener of [...this.sourceListeners]) listener();\n };\n\n constructor(world: World, options: IWSDKProviderOptions = {}) {\n this.world = world;\n this.nativeGrab = options.nativeGrab ?? false;\n this.capabilities = { ...NO_CAPABILITIES };\n const unsubscribe = world.visibilityState.subscribe(() => {\n this.bindSession();\n this.refreshCapabilities();\n });\n this.disposers.push(unsubscribe);\n this.bindSession();\n this.refreshCapabilities();\n }\n\n private bindSession(): void {\n const session = this.world.session ?? null;\n if (session === this.boundSession) return;\n this.boundSession?.removeEventListener(\"inputsourceschange\", this.onSourcesChange);\n this.boundSession = session;\n session?.addEventListener(\"inputsourceschange\", this.onSourcesChange);\n }\n\n private hasTrackedHand(): boolean {\n const session = this.world.session;\n if (!session) return false;\n for (const source of session.inputSources) {\n if (source.hand) return true;\n }\n return false;\n }\n\n private refreshCapabilities(): void {\n const session = this.world.session;\n const immersive = !!session;\n const handTracking =\n immersive &&\n ((session?.enabledFeatures?.includes(\"hand-tracking\") ?? false) || this.hasTrackedHand());\n let buttonsAxes = false;\n let haptics = false;\n for (const side of SIDES) {\n const gamepad = this.world.input.xr.gamepads[side];\n if (gamepad?.gamepad) buttonsAxes = true;\n if ((gamepad?.gamepad?.hapticActuators?.length ?? 0) > 0) haptics = true;\n }\n const next: InputCapabilities = {\n ...NO_CAPABILITIES,\n rays: immersive,\n // Index-tip spaces exist for controllers too (fall back to ray pose).\n pokes: immersive,\n grabs: immersive ? (this.nativeGrab ? \"native\" : \"poseOnly\") : \"none\",\n handJoints: handTracking,\n pinch: handTracking,\n buttonsAxes,\n gaze: true,\n headPose: true,\n haptics,\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 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 /** Bridge-system input: this frame's pre-resolved tag hints. */\n setHints(hints: InputHitHint[]): void {\n this.hints = hints;\n }\n\n sampleHints(): readonly InputHitHint[] {\n return this.hints;\n }\n\n /** Bridge-system input: a side is currently native-grabbing. */\n setNativeGrabbing(side: Side, grabbing: boolean): void {\n this.nativeGrabbing[side] = grabbing;\n }\n\n sample(): readonly InputSourceSnapshot[] {\n this.sideBySourceId.clear();\n // Adapters are created as input sources connect, which can be after the\n // client set its presence, so the desired state is re-applied here.\n if (this.presenceRequested) this.applyPresence();\n if (!this.world.session) return [];\n if (this.world.visibilityState.peek() !== VisibilityState.Visible) return [];\n\n const spaces = this.world.playerSpaceEntities;\n const snapshots: InputSourceSnapshot[] = [];\n for (const side of SIDES) {\n const rayObject = spaces.raySpaces[side].object3D;\n if (!rayObject) continue;\n const gamepad = this.world.input.xr.gamepads[side];\n const hand = this.capabilities.handJoints;\n\n rayObject.updateWorldMatrix(true, false);\n const rayPos = rayObject.getWorldPosition(TEMP.v1);\n const rayQuat = rayObject.getWorldQuaternion(TEMP.q1);\n const forward = TEMP.v2.set(0, 0, -1).applyQuaternion(rayQuat);\n\n const select = gamepad\n ? Math.max(gamepad.getButtonValue(InputComponent.Trigger), gamepad.getSelecting() ? 1 : 0)\n : 0;\n const squeeze = gamepad ? gamepad.getButtonValue(InputComponent.Squeeze) : 0;\n\n const snapshot: InputSourceSnapshot = {\n id: `${side}-input`,\n kind: hand ? \"hand\" : \"controller\",\n handedness: side,\n ray: {\n origin: [rayPos.x, rayPos.y, rayPos.z],\n direction: [forward.x, forward.y, forward.z],\n },\n select,\n squeeze,\n };\n\n const gripObject = spaces.gripSpaces[side].object3D;\n if (gripObject) {\n const gripPos = gripObject.getWorldPosition(TEMP.v1);\n const gripQuat = gripObject.getWorldQuaternion(TEMP.q1);\n snapshot.gripPose = {\n position: [gripPos.x, gripPos.y, gripPos.z],\n quaternion: [gripQuat.x, gripQuat.y, gripQuat.z, gripQuat.w],\n };\n }\n const tipObject = spaces.indexTipSpaces[side].object3D;\n if (tipObject) {\n const tipPos = tipObject.getWorldPosition(TEMP.v1);\n snapshot.indexTip = [tipPos.x, tipPos.y, tipPos.z];\n }\n if (this.nativeGrabbing[side]) snapshot.nativeGrabbing = true;\n if ((gamepad?.gamepad?.hapticActuators?.length ?? 0) > 0) {\n snapshot.hapticsAvailable = true;\n }\n this.sideBySourceId.set(snapshot.id, side);\n snapshots.push(snapshot);\n }\n return snapshots;\n }\n\n // -- presence ---------------------------------------------------------------\n\n /**\n * Show or hide this session's controller/hand visuals. Returns false when\n * IWSDK has published no visual adapters, which is the case outside a\n * session. The request is remembered and re-applied on every sample, so\n * a call made before the adapters exist still lands.\n *\n * `\"none\"` targets no side - the handedness value that has no visual\n * here - so the call reports availability without changing anything.\n */\n setPresenceVisible(target: PresenceTarget, visible: boolean): boolean {\n this.presenceRequested = true;\n for (const side of SIDES) {\n if (target === \"all\" || target === side) this.presenceVisible[side] = visible;\n }\n return this.applyPresence();\n }\n\n /**\n * Choose which family of visuals is shown. `\"hands\"` and `\"controllers\"`\n * force one family and hide the other; `\"auto\"` follows the engine's own\n * modality (hand visuals while hand tracking is live).\n */\n setPresenceModality(mode: PresenceModality): boolean {\n this.presenceRequested = true;\n this.presenceModality = mode;\n return this.applyPresence();\n }\n\n private visualAdapters(): PresenceAdaptersLike | null {\n const xr = this.world.input?.xr as unknown as\n | { visualAdapters?: PresenceAdaptersLike }\n | undefined;\n return xr?.visualAdapters ?? null;\n }\n\n private applyPresence(): boolean {\n const adapters = this.visualAdapters();\n if (!adapters) return false;\n const hands =\n this.presenceModality === \"hands\" ||\n (this.presenceModality === \"auto\" && this.capabilities.handJoints);\n const controllers =\n this.presenceModality === \"controllers\" ||\n (this.presenceModality === \"auto\" && !this.capabilities.handJoints);\n for (const side of SIDES) {\n const wanted = this.presenceVisible[side];\n setDescendantsVisible(adapters.hand?.[side], wanted && hands);\n setDescendantsVisible(adapters.controller?.[side], wanted && controllers);\n }\n return true;\n }\n\n getHeadPose(): HeadPose {\n const head = this.world.playerSpaceEntities.head.object3D;\n if (!head) return { position: [0, 0, 0], quaternion: [0, 0, 0, 1] };\n const position = head.getWorldPosition(TEMP.v1);\n const quaternion = head.getWorldQuaternion(TEMP.q1);\n return {\n position: [position.x, position.y, position.z],\n quaternion: [quaternion.x, quaternion.y, quaternion.z, quaternion.w],\n };\n }\n\n pulse(sourceId: string, intensity: number, durationMs: number): boolean {\n // The side comes from the handedness recorded when the snapshot was\n // built. Parsing the id is the fallback for an id this provider did not\n // produce (a caller's own naming, or a pulse before the first sample).\n const side =\n this.sideBySourceId.get(sourceId) ??\n (sourceId.startsWith(\"left\") ? \"left\" : sourceId.startsWith(\"right\") ? \"right\" : null);\n if (!side) return false;\n const actuator = this.world.input.xr.gamepads[side]?.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\n dispose(): void {\n this.boundSession?.removeEventListener(\"inputsourceschange\", this.onSourcesChange);\n for (const dispose of this.disposers) dispose();\n this.disposers.length = 0;\n this.sideBySourceId.clear();\n }\n}\n\n// Shared scratch objects (single-threaded frame sampling).\nimport { Quaternion, Vector3 } from \"@iwsdk/core\";\nconst TEMP = { v1: new Vector3(), v2: new Vector3(), q1: new Quaternion() };\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realitycollective/iwsdk-interactions",
3
- "version": "0.1.0-preview.1",
3
+ "version": "0.1.0-preview.2",
4
4
  "description": "Meta IWSDK adapter for the Reality Collective Interaction Extensions - feeds IWSDK's input machinery (Pressed/Grabbed tags, poke/ray interactables, grabbables, XR gamepads, hand joints) into the engine-free @realitycollective/webxr-interactions core, with native grab fulfilment. Re-exports the core.",
5
5
  "keywords": [
6
6
  "realitycollective",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@realitycollective/webxr-input": "^0.1.0",
36
- "@realitycollective/webxr-interactions": "^0.1.0-preview.1"
36
+ "@realitycollective/webxr-interactions": "^0.1.0-preview.2"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@iwsdk/core": ">=0.5.0 <0.6.0"