@realitycollective/babylon-interactions 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 +35 -0
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/babylon-types.d.ts +220 -0
- package/dist/babylon-types.js +92 -0
- package/dist/babylon-types.js.map +1 -0
- package/dist/hit-tester.d.ts +57 -0
- package/dist/hit-tester.js +90 -0
- package/dist/hit-tester.js.map +1 -0
- package/dist/host.d.ts +49 -0
- package/dist/host.js +86 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +113 -0
- package/dist/provider.js +371 -0
- package/dist/provider.js.map +1 -0
- package/dist/transform-port.d.ts +72 -0
- package/dist/transform-port.js +90 -0
- package/dist/transform-port.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACL,eAAe,GAOhB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,aAAa,EACb,MAAM,EACN,MAAM,GASP,MAAM,oBAAoB,CAAC;AAgC5B,sDAAsD;AACtD,MAAM,iBAAiB,GAAG,SAAS,CAAC;AACpC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAEpC,yEAAyE;AACzE,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAcnD,MAAM,OAAO,oBAAoB;IACd,OAAO,CAAyB;IACzC,YAAY,CAAoB;IACvB,aAAa,GAAG,IAAI,GAAG,EAAkC,CAAC;IAC1D,eAAe,GAAG,IAAI,GAAG,EAAc,CAAC;IACzD,6EAA6E;IAC5D,OAAO,GA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;QACrB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;CACF;AAED,2EAA2E;AAC3E,SAAS,cAAc,CACrB,SAAmE;IAEnE,IAAI,CAAC,SAAS;QAAE,OAAO,CAAC,CAAC;IACzB,IAAI,OAAO,SAAS,CAAC,KAAK,KAAK,QAAQ,IAAI,SAAS,CAAC,KAAK,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC,KAAK,CAAC;IACvF,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,aAAa,CACpB,IAA8B,EAC9B,KAAa;IAEb,MAAM,IAAI,GAAG,IAAI,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1D,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAyB;IACpD,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;AAChE,CAAC","sourcesContent":["/**\n * BabylonInputProvider - the Babylon.js input provider.\n *\n * Reads a `WebXRDefaultExperience`: its `input.controllers` for poses and\n * motion-controller components, its session manager for what is live, and\n * the hand-tracking feature for fingertip joints. Falls back to the scene's\n * own pointer (`scene.onPointerObservable`) when no immersive session is\n * running, so the same scene is usable in a flat browser.\n *\n * Nothing here imports `@babylonjs/core` - see `babylon-types.ts`.\n *\n * Capabilities are derived from the LIVE session, never from the requested\n * configuration, and are re-published on session start, session end and\n * controller add/remove.\n */\nimport {\n NO_CAPABILITIES,\n type HeadPose,\n type InputCapabilities,\n type InputProvider,\n type InputSourceSnapshot,\n type Unsubscribe,\n type Vec3Tuple,\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\";\nimport {\n HAND_TRACKING_FEATURE,\n INDEX_TIP_JOINT,\n POINTER_EVENT_TYPES,\n nodeForward,\n defaultForward,\n nodeWorldPose,\n toQuat,\n toVec3,\n type BabylonCameraLike,\n type BabylonHandTrackingLike,\n type BabylonPointerInfoLike,\n type BabylonSceneLike,\n type BabylonTransformNodeLike,\n type BabylonXRControllerLike,\n type BabylonXRExperienceLike,\n type BabylonXRHandLike,\n} from \"./babylon-types.js\";\n\nexport interface BabylonProviderOptions {\n /**\n * The `WebXRDefaultExperience` (or anything with the same surface).\n * Omit it, or pass null, for a desktop-only app: the provider then only\n * ever reports the scene pointer.\n */\n xr?: BabylonXRExperienceLike | null;\n /** The scene. Supplies the pointer fallback, the camera and the engine. */\n scene: BabylonSceneLike;\n /** Head pose camera. Defaults to `scene.activeCamera`. */\n camera?: BabylonCameraLike | null;\n /**\n * Metres along the pointer ray at which the desktop fallback places its\n * synthetic grip pose. Default 1 metre, matching the three.js adapter, so\n * grab, hinge, dial and slide follow the cursor on desktop. Set it near\n * the distance of the things being manipulated; at 0 the grip sits on the\n * camera and a mouse drag reports camera motion only.\n */\n desktopGripDistance?: number;\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. Babylon chooses this per input\n * source, so this provider reports every mode as unavailable.\n */\nexport type PresenceModality = \"hands\" | \"controllers\" | \"auto\";\n\n/** Trigger, then the main component, then nothing. */\nconst TRIGGER_COMPONENT = \"trigger\";\nconst SQUEEZE_COMPONENT = \"squeeze\";\n\n/** The desktop pointer source's id - stable for the life of the page. */\nexport const DESKTOP_SOURCE_ID = \"babylon-pointer\";\n\ninterface PointerState {\n down: boolean;\n x: number;\n y: number;\n ray: { origin: Vec3Tuple; direction: Vec3Tuple } | null;\n}\n\ninterface SampledSource {\n handedness: \"left\" | \"right\" | \"none\";\n controller: BabylonXRControllerLike;\n}\n\nexport class BabylonInputProvider implements InputProvider {\n private readonly options: BabylonProviderOptions;\n private capabilities: InputCapabilities;\n private readonly capsListeners = new Set<(c: InputCapabilities) => void>();\n private readonly sourceListeners = new Set<() => void>();\n /** id -> handedness + controller, recorded while sampling, read by pulse. */\n private readonly sampled = new Map<string, SampledSource>();\n private readonly detach: Unsubscribe[] = [];\n private readonly gripDistance: number;\n /** Read once from `scene.useRightHandedSystem`; flips forward to -Z. */\n private readonly rightHanded: boolean;\n\n private readonly pointer: PointerState = { down: false, x: 0, y: 0, ray: null };\n\n constructor(options: BabylonProviderOptions) {\n this.options = options;\n this.gripDistance = options.desktopGripDistance ?? 1;\n this.rightHanded = options.scene.useRightHandedSystem === true;\n this.capabilities = { ...NO_CAPABILITIES, headPose: true, gaze: true };\n this.attachPointer();\n this.attachSession();\n this.refreshCapabilities();\n }\n\n // -- wiring -------------------------------------------------------------------\n\n private attachPointer(): void {\n const observable = this.options.scene.onPointerObservable;\n if (!observable) return;\n const observer = observable.add((info: BabylonPointerInfoLike) => this.onPointer(info));\n this.detach.push(() => {\n observable.remove(observer);\n });\n }\n\n private onPointer(info: BabylonPointerInfoLike): void {\n const event = info.event;\n if (event?.clientX !== undefined) this.pointer.x = event.clientX;\n if (event?.clientY !== undefined) this.pointer.y = event.clientY;\n // Babylon hands the pick it already did for this event; reuse it rather\n // than picking the scene a second time on the next sample.\n const ray = info.pickInfo?.ray;\n if (ray) {\n this.pointer.ray = {\n origin: toVec3(ray.origin) ?? [0, 0, 0],\n direction: toVec3(ray.direction) ?? defaultForward(this.rightHanded),\n };\n }\n // Only the primary button selects. Babylon reports it as button 0, the\n // same numbering as a DOM PointerEvent.\n if (info.type === POINTER_EVENT_TYPES.down && (event?.button ?? 0) === 0) {\n this.pointer.down = true;\n }\n if (info.type === POINTER_EVENT_TYPES.up && (event?.button ?? 0) === 0) {\n this.pointer.down = false;\n }\n }\n\n private attachSession(): void {\n const manager = this.options.xr?.baseExperience?.sessionManager;\n const input = this.options.xr?.input;\n const republish = () => {\n this.refreshCapabilities();\n for (const listener of [...this.sourceListeners]) listener();\n };\n const subscribe = <T>(\n observable: { add(cb: (value: T) => void): unknown; remove(o: unknown): boolean } | undefined,\n handler: () => void,\n ): void => {\n if (!observable) return;\n const observer = observable.add(() => handler());\n this.detach.push(() => {\n observable.remove(observer);\n });\n };\n subscribe(manager?.onXRSessionInit, republish);\n subscribe(manager?.onXRSessionEnded, () => {\n this.sampled.clear();\n republish();\n });\n subscribe(input?.onControllerAddedObservable, republish);\n subscribe(input?.onControllerRemovedObservable, republish);\n }\n\n // -- capabilities -------------------------------------------------------------\n\n /** The live XR session, or null when none is running. */\n private session(): unknown {\n return this.options.xr?.baseExperience?.sessionManager?.session ?? null;\n }\n\n private controllers(): readonly BabylonXRControllerLike[] {\n return this.options.xr?.input?.controllers ?? [];\n }\n\n /** The hand-tracking feature, when the app enabled it. */\n private handTracking(): BabylonHandTrackingLike | null {\n const manager = this.options.xr?.baseExperience?.featuresManager;\n if (!manager) return null;\n const feature = manager.getEnabledFeature(HAND_TRACKING_FEATURE);\n if (!feature || typeof feature !== \"object\") return null;\n const candidate = feature as Partial<BabylonHandTrackingLike>;\n return typeof candidate.getHandByControllerId === \"function\"\n ? (feature as BabylonHandTrackingLike)\n : null;\n }\n\n private handFor(controller: BabylonXRControllerLike): BabylonXRHandLike | null {\n return this.handTracking()?.getHandByControllerId(controller.uniqueId) ?? null;\n }\n\n private refreshCapabilities(): void {\n const inSession = this.session() !== null;\n const desktop = !inSession && this.options.scene.onPointerObservable !== undefined;\n // Babylon reports no native grab observation, so grabs are always\n // poseOnly: the core drives the transform through the port.\n const next: InputCapabilities = {\n ...NO_CAPABILITIES,\n headPose: true,\n gaze: true,\n pointer2d: desktop,\n // The pointer fallback synthesises a grip on the ray, so hand-driven\n // behaviours negotiate on desktop too. Without this every one of them\n // switches itself off off-headset and only press remains usable.\n grabs: desktop ? \"poseOnly\" : NO_CAPABILITIES.grabs,\n };\n if (inSession) {\n for (const controller of this.controllers()) {\n if (controller.pointer) next.rays = true;\n if (controller.grip ?? controller.pointer) next.grabs = \"poseOnly\";\n if (controller.inputSource.hand) {\n next.handJoints = true;\n next.pokes = true;\n }\n // Pinch strength needs the tracked hand itself, not just the flag on\n // the input source, so it is gated on the feature reporting a hand.\n if (this.handFor(controller)) next.pinch = true;\n if (controller.motionController) next.buttonsAxes = true;\n if ((controller.inputSource.gamepad?.hapticActuators?.length ?? 0) > 0) {\n 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 // -- sampling -----------------------------------------------------------------\n\n sample(): readonly InputSourceSnapshot[] {\n this.sampled.clear();\n if (this.session() === null) {\n // A session that ended between frames leaves stale capabilities behind.\n if (this.capabilities.rays) this.refreshCapabilities();\n return this.samplePointer();\n }\n\n const snapshots: InputSourceSnapshotWithVelocity[] = [];\n for (const controller of this.controllers()) {\n const handedness = normalizeHandedness(controller.inputSource.handedness);\n const hand = this.handFor(controller);\n const pointerNode = controller.pointer;\n const snapshot: InputSourceSnapshotWithVelocity = {\n id: controller.uniqueId,\n kind: controller.inputSource.hand ? \"hand\" : \"controller\",\n handedness,\n select: componentValue(\n controller.motionController?.getComponentOfType?.(TRIGGER_COMPONENT) ??\n controller.motionController?.getMainComponent?.() ??\n null,\n ),\n squeeze: componentValue(\n controller.motionController?.getComponentOfType?.(SQUEEZE_COMPONENT) ?? null,\n ),\n };\n if (pointerNode) {\n snapshot.ray = {\n origin: toVec3(pointerNode.getAbsolutePosition()) ?? [0, 0, 0],\n direction: nodeForward(pointerNode, this.rightHanded),\n };\n }\n // Babylon exposes the grip node only for a controller with one; a hand,\n // and a controller without a grip space, carry on the pointer node.\n const gripNode = controller.grip ?? pointerNode;\n if (gripNode) snapshot.gripPose = nodeWorldPose(gripNode);\n const tip = jointPosition(hand, INDEX_TIP_JOINT);\n if (tip) snapshot.indexTip = tip;\n if ((controller.inputSource.gamepad?.hapticActuators?.length ?? 0) > 0) {\n snapshot.hapticsAvailable = true;\n }\n // Babylon reports no per-pose velocity, so nothing is set here and the\n // core's VelocityTracker derives it from consecutive grip poses.\n snapshots.push(snapshot);\n this.sampled.set(snapshot.id, { handedness, controller });\n }\n return snapshots;\n }\n\n /**\n * The desktop pointer, shaped like the three.js adapter's mouse fallback:\n * one source, `handedness: \"none\"`, `kind: \"pointer2d\"`.\n */\n private samplePointer(): readonly InputSourceSnapshot[] {\n if (this.options.scene.onPointerObservable === undefined) return [];\n const ray = this.pointer.ray ?? this.pickRay();\n if (!ray) return [];\n const grip: Vec3Tuple = [\n ray.origin[0] + ray.direction[0] * this.gripDistance,\n ray.origin[1] + ray.direction[1] * this.gripDistance,\n ray.origin[2] + ray.direction[2] * this.gripDistance,\n ];\n return [\n {\n id: DESKTOP_SOURCE_ID,\n kind: \"pointer2d\",\n handedness: \"none\",\n ray: { origin: ray.origin, direction: ray.direction },\n gripPose: { position: grip, quaternion: toQuat(this.camera()?.absoluteRotation) },\n select: this.pointer.down ? 1 : 0,\n // A mouse has one button that means select. Squeeze stays 0 rather\n // than doubling the left button up as both, which would fire a press\n // and a grab together on an interactable that carries both.\n squeeze: 0,\n },\n ];\n }\n\n /** Pick the scene at the last known cursor position for a ray. */\n private pickRay(): { origin: Vec3Tuple; direction: Vec3Tuple } | null {\n const picked = this.options.scene.pick?.(this.pointer.x, this.pointer.y);\n const ray = picked?.ray;\n if (!ray) return null;\n return {\n origin: toVec3(ray.origin) ?? [0, 0, 0],\n direction: toVec3(ray.direction) ?? defaultForward(this.rightHanded),\n };\n }\n\n private camera(): BabylonCameraLike | null {\n return this.options.camera ?? this.options.scene.activeCamera ?? null;\n }\n\n getHeadPose(): HeadPose {\n const camera = this.camera();\n return {\n position: toVec3(camera?.globalPosition ?? camera?.position) ?? [0, 0, 0],\n quaternion: toQuat(camera?.absoluteRotation),\n };\n }\n\n // -- haptics ------------------------------------------------------------------\n\n /**\n * Babylon routes haptics through the motion controller rather than the\n * gamepad actuator, so a source with no motion controller cannot pulse\n * even when the gamepad reports an actuator.\n */\n pulse(sourceId: string, intensity: number, durationMs: number): boolean {\n const controller =\n this.sampled.get(sourceId)?.controller ??\n this.controllers().find((c) => c.uniqueId === sourceId);\n const motionController = controller?.motionController;\n if (!motionController?.pulse) return false;\n void motionController.pulse(Math.min(1, Math.max(0, intensity)), durationMs);\n return true;\n }\n\n // -- presence -----------------------------------------------------------------\n\n /**\n * True when Babylon has built at least one visual this provider can hide:\n * a motion controller root mesh, or a hand mesh from the hand-tracking\n * feature. Becomes `capabilities.presence` at\n * `@realitycollective/webxr-input` 0.1.1.\n */\n get supportsPresence(): boolean {\n for (const controller of this.controllers()) {\n if (this.visualsFor(controller).length > 0) return true;\n }\n return false;\n }\n\n /**\n * Show or hide the visuals Babylon built for the targeted sides. Returns\n * false when the target has nothing to show or hide. `\"none\"` targets no\n * side, so it reports whether presence is usable at all without changing\n * anything.\n */\n setPresenceVisible(target: PresenceTarget, visible: boolean): boolean {\n if (target === \"none\") return this.supportsPresence;\n let applied = false;\n for (const controller of this.controllers()) {\n const side = normalizeHandedness(controller.inputSource.handedness);\n if (target !== \"all\" && target !== side) continue;\n for (const node of this.visualsFor(controller)) {\n node.setEnabled?.(visible);\n applied = true;\n }\n }\n return applied;\n }\n\n /**\n * Always false. Babylon picks the visual per input source - a controller\n * gets its motion-controller model, a tracked hand gets the hand mesh -\n * and exposes no switch between the two. IWSDK builds both families, so\n * its adapter implements this.\n */\n setPresenceModality(_mode: PresenceModality): boolean {\n return false;\n }\n\n /** Every node that represents this controller on screen. */\n private visualsFor(controller: BabylonXRControllerLike): BabylonTransformNodeLike[] {\n const nodes: BabylonTransformNodeLike[] = [];\n const root = controller.motionController?.rootMesh;\n if (root) nodes.push(root);\n const handMesh = this.handFor(controller)?.handMesh;\n if (handMesh) nodes.push(handMesh);\n return nodes;\n }\n\n dispose(): void {\n for (const off of this.detach.splice(0)) off();\n this.sampled.clear();\n this.capsListeners.clear();\n this.sourceListeners.clear();\n }\n}\n\n/** Analog value where the component reports one, else the pressed flag. */\nfunction componentValue(\n component: { value?: number; pressed?: boolean } | null | undefined,\n): number {\n if (!component) return 0;\n if (typeof component.value === \"number\" && component.value > 0) return component.value;\n return component.pressed ? 1 : 0;\n}\n\nfunction jointPosition(\n hand: BabylonXRHandLike | null,\n joint: string,\n): Vec3Tuple | null {\n const mesh = hand?.getJointMesh?.(joint);\n return mesh ? toVec3(mesh.getAbsolutePosition()) : null;\n}\n\nfunction normalizeHandedness(value: string | undefined): \"left\" | \"right\" | \"none\" {\n return value === \"left\" || value === \"right\" ? value : \"none\";\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BabylonTransformPort - the read/write surface of one interactable's
|
|
3
|
+
* Babylon node, honouring the core's FROM-REST semantics: the rest pose is
|
|
4
|
+
* captured at construction and offsets and rotations apply relative to it,
|
|
5
|
+
* so a behaviour composes with anything else animating the same node.
|
|
6
|
+
*
|
|
7
|
+
* Every write mutates the node's existing `Vector3`/`Quaternion` in place.
|
|
8
|
+
* Babylon compares the live values against its cache to decide whether the
|
|
9
|
+
* world matrix needs recomputing, so in-place writes are seen; assigning a
|
|
10
|
+
* plain object in their place would break Babylon, which calls methods on
|
|
11
|
+
* them.
|
|
12
|
+
*/
|
|
13
|
+
import type { PoseTuple, QuatTuple, Vec3Tuple } from "@realitycollective/webxr-input";
|
|
14
|
+
import { type TransformPort } from "@realitycollective/webxr-interactions";
|
|
15
|
+
import { type BabylonQuaternionLike, type BabylonTransformNodeLike } from "./babylon-types.js";
|
|
16
|
+
export interface BabylonTransformPortOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Builds the `Quaternion` written to a node whose `rotationQuaternion` is
|
|
19
|
+
* null - a node still driven by Euler `rotation`, which is Babylon's
|
|
20
|
+
* default. Pass `() => Quaternion.Identity()` from `@babylonjs/core`.
|
|
21
|
+
*
|
|
22
|
+
* The fallback is a plain `{ x, y, z, w }` object, which carries the
|
|
23
|
+
* numbers correctly but is NOT a Babylon `Quaternion` and will fail as
|
|
24
|
+
* soon as Babylon calls a method on it. So: either give a node a real
|
|
25
|
+
* `rotationQuaternion` before registering it, or supply this factory.
|
|
26
|
+
* A node that already has one needs neither - it is mutated in place.
|
|
27
|
+
*/
|
|
28
|
+
createQuaternion?: () => BabylonQuaternionLike;
|
|
29
|
+
}
|
|
30
|
+
export declare class BabylonTransformPort implements TransformPort {
|
|
31
|
+
private readonly node;
|
|
32
|
+
private readonly createQuaternion;
|
|
33
|
+
private restPosition;
|
|
34
|
+
private restQuaternion;
|
|
35
|
+
private restScale;
|
|
36
|
+
constructor(node: BabylonTransformNodeLike, options?: BabylonTransformPortOptions);
|
|
37
|
+
/** Re-read the node's current local transform as the new rest. */
|
|
38
|
+
recaptureRest(): void;
|
|
39
|
+
/**
|
|
40
|
+
* The node's LIVE world pose, from its absolute position and rotation.
|
|
41
|
+
*
|
|
42
|
+
* This differs from the three.js port, which reports the rest pose in
|
|
43
|
+
* world space. Babylon computes absolutes for its own render anyway, so
|
|
44
|
+
* reading them costs nothing and a grab starts from where the object
|
|
45
|
+
* actually is rather than from where it was registered.
|
|
46
|
+
*/
|
|
47
|
+
getWorldPose(): PoseTuple;
|
|
48
|
+
getLocalOffset(): Vec3Tuple;
|
|
49
|
+
setLocalOffset(offset: Vec3Tuple): void;
|
|
50
|
+
setLocalRotation(quaternion: QuatTuple): void;
|
|
51
|
+
/**
|
|
52
|
+
* Follow a world pose while grabbed. With a parent, the pose is resolved
|
|
53
|
+
* into the parent's frame through its absolute position and rotation.
|
|
54
|
+
*
|
|
55
|
+
* Simplification: parent SCALE is ignored. A grabbed object under a scaled
|
|
56
|
+
* parent tracks the hand at the wrong distance. Grabbables are expected to
|
|
57
|
+
* sit under an unscaled parent, which is how the demos build them.
|
|
58
|
+
*/
|
|
59
|
+
setWorldPose(pose: PoseTuple): void;
|
|
60
|
+
/**
|
|
61
|
+
* Uniform scale about the rest scale. The emissive part of the intent is
|
|
62
|
+
* not applied: reaching a material's emissive colour means knowing which
|
|
63
|
+
* Babylon material the node carries, and this package holds no Babylon
|
|
64
|
+
* types. Apps that want the glow subscribe to the core's feedback intents.
|
|
65
|
+
*/
|
|
66
|
+
setEffect(effect: {
|
|
67
|
+
scale?: number;
|
|
68
|
+
emissive?: number;
|
|
69
|
+
}): void;
|
|
70
|
+
/** Write a quaternion, creating the node's `rotationQuaternion` if needed. */
|
|
71
|
+
private writeRotation;
|
|
72
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { quatConjugate, quatMultiply, vAdd, vApplyQuat, vSub, } from "@realitycollective/webxr-interactions";
|
|
2
|
+
import { nodeWorldPose, parentOf, toQuat, toVec3, writeQuat, writeVec3, } from "./babylon-types.js";
|
|
3
|
+
export class BabylonTransformPort {
|
|
4
|
+
node;
|
|
5
|
+
createQuaternion;
|
|
6
|
+
restPosition = [0, 0, 0];
|
|
7
|
+
restQuaternion = [0, 0, 0, 1];
|
|
8
|
+
restScale = [1, 1, 1];
|
|
9
|
+
constructor(node, options = {}) {
|
|
10
|
+
this.node = node;
|
|
11
|
+
this.createQuaternion = options.createQuaternion ?? (() => ({ x: 0, y: 0, z: 0, w: 1 }));
|
|
12
|
+
this.recaptureRest();
|
|
13
|
+
}
|
|
14
|
+
/** Re-read the node's current local transform as the new rest. */
|
|
15
|
+
recaptureRest() {
|
|
16
|
+
this.restPosition = toVec3(this.node.position) ?? [0, 0, 0];
|
|
17
|
+
this.restQuaternion = toQuat(this.node.rotationQuaternion);
|
|
18
|
+
this.restScale = toVec3(this.node.scaling) ?? [1, 1, 1];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The node's LIVE world pose, from its absolute position and rotation.
|
|
22
|
+
*
|
|
23
|
+
* This differs from the three.js port, which reports the rest pose in
|
|
24
|
+
* world space. Babylon computes absolutes for its own render anyway, so
|
|
25
|
+
* reading them costs nothing and a grab starts from where the object
|
|
26
|
+
* actually is rather than from where it was registered.
|
|
27
|
+
*/
|
|
28
|
+
getWorldPose() {
|
|
29
|
+
this.node.computeWorldMatrix?.(true);
|
|
30
|
+
return nodeWorldPose(this.node);
|
|
31
|
+
}
|
|
32
|
+
getLocalOffset() {
|
|
33
|
+
const delta = vSub(toVec3(this.node.position) ?? [0, 0, 0], this.restPosition);
|
|
34
|
+
return vApplyQuat(delta, quatConjugate(this.restQuaternion));
|
|
35
|
+
}
|
|
36
|
+
setLocalOffset(offset) {
|
|
37
|
+
writeVec3(this.node.position, vAdd(this.restPosition, vApplyQuat(offset, this.restQuaternion)));
|
|
38
|
+
}
|
|
39
|
+
setLocalRotation(quaternion) {
|
|
40
|
+
this.writeRotation(quatMultiply(this.restQuaternion, quaternion));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Follow a world pose while grabbed. With a parent, the pose is resolved
|
|
44
|
+
* into the parent's frame through its absolute position and rotation.
|
|
45
|
+
*
|
|
46
|
+
* Simplification: parent SCALE is ignored. A grabbed object under a scaled
|
|
47
|
+
* parent tracks the hand at the wrong distance. Grabbables are expected to
|
|
48
|
+
* sit under an unscaled parent, which is how the demos build them.
|
|
49
|
+
*/
|
|
50
|
+
setWorldPose(pose) {
|
|
51
|
+
const parent = parentOf(this.node);
|
|
52
|
+
if (!parent) {
|
|
53
|
+
writeVec3(this.node.position, pose.position);
|
|
54
|
+
this.writeRotation(pose.quaternion);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const parentPose = nodeWorldPose(parent);
|
|
58
|
+
const inverse = quatConjugate(parentPose.quaternion);
|
|
59
|
+
writeVec3(this.node.position, vApplyQuat(vSub(pose.position, parentPose.position), inverse));
|
|
60
|
+
this.writeRotation(quatMultiply(inverse, pose.quaternion));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Uniform scale about the rest scale. The emissive part of the intent is
|
|
64
|
+
* not applied: reaching a material's emissive colour means knowing which
|
|
65
|
+
* Babylon material the node carries, and this package holds no Babylon
|
|
66
|
+
* types. Apps that want the glow subscribe to the core's feedback intents.
|
|
67
|
+
*/
|
|
68
|
+
setEffect(effect) {
|
|
69
|
+
if (effect.scale === undefined)
|
|
70
|
+
return;
|
|
71
|
+
const scaling = this.node.scaling;
|
|
72
|
+
if (!scaling)
|
|
73
|
+
return;
|
|
74
|
+
writeVec3(scaling, [
|
|
75
|
+
this.restScale[0] * effect.scale,
|
|
76
|
+
this.restScale[1] * effect.scale,
|
|
77
|
+
this.restScale[2] * effect.scale,
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
/** Write a quaternion, creating the node's `rotationQuaternion` if needed. */
|
|
81
|
+
writeRotation(value) {
|
|
82
|
+
let target = this.node.rotationQuaternion;
|
|
83
|
+
if (!target) {
|
|
84
|
+
target = this.createQuaternion();
|
|
85
|
+
this.node.rotationQuaternion = target;
|
|
86
|
+
}
|
|
87
|
+
writeQuat(target, value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=transform-port.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-port.js","sourceRoot":"","sources":["../src/transform-port.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,aAAa,EACb,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,IAAI,GAEL,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,aAAa,EACb,QAAQ,EACR,MAAM,EACN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,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,MAA6C;QACrD,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS;YAAE,OAAO;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;QAClC,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,SAAS,CAAC,OAAO,EAAE;YACjB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK;YAChC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK;YAChC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK;SACjC,CAAC,CAAC;IACL,CAAC;IAED,8EAA8E;IACtE,aAAa,CAAC,KAAgB;QACpC,IAAI,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC;QAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACjC,IAAI,CAAC,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC;QACxC,CAAC;QACD,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;CACF","sourcesContent":["/**\n * BabylonTransformPort - the read/write surface of one interactable's\n * Babylon node, honouring the core's FROM-REST semantics: the rest pose is\n * captured at construction and offsets and rotations apply relative to it,\n * so a behaviour composes with anything else animating the same node.\n *\n * Every write mutates the node's existing `Vector3`/`Quaternion` in place.\n * Babylon compares the live values against its cache to decide whether the\n * world matrix needs recomputing, so in-place writes are seen; assigning a\n * plain object in their place would break Babylon, which calls methods on\n * them.\n */\nimport type { PoseTuple, QuatTuple, Vec3Tuple } from \"@realitycollective/webxr-input\";\nimport {\n quatConjugate,\n quatMultiply,\n vAdd,\n vApplyQuat,\n vSub,\n type TransformPort,\n} from \"@realitycollective/webxr-interactions\";\nimport {\n nodeWorldPose,\n parentOf,\n toQuat,\n toVec3,\n writeQuat,\n writeVec3,\n type BabylonQuaternionLike,\n type BabylonTransformNodeLike,\n} from \"./babylon-types.js\";\n\nexport interface BabylonTransformPortOptions {\n /**\n * Builds the `Quaternion` written to a node whose `rotationQuaternion` is\n * null - a node still driven by Euler `rotation`, which is Babylon's\n * default. Pass `() => Quaternion.Identity()` from `@babylonjs/core`.\n *\n * The fallback is a plain `{ x, y, z, w }` object, which carries the\n * numbers correctly but is NOT a Babylon `Quaternion` and will fail as\n * soon as Babylon calls a method on it. So: either give a node a real\n * `rotationQuaternion` before registering it, or supply this factory.\n * A node that already has one needs neither - it is mutated in place.\n */\n createQuaternion?: () => BabylonQuaternionLike;\n}\n\nexport class BabylonTransformPort implements TransformPort {\n private readonly node: BabylonTransformNodeLike;\n private readonly createQuaternion: () => BabylonQuaternionLike;\n private restPosition: Vec3Tuple = [0, 0, 0];\n private restQuaternion: QuatTuple = [0, 0, 0, 1];\n private restScale: Vec3Tuple = [1, 1, 1];\n\n constructor(node: BabylonTransformNodeLike, options: BabylonTransformPortOptions = {}) {\n this.node = node;\n this.createQuaternion = options.createQuaternion ?? (() => ({ x: 0, y: 0, z: 0, w: 1 }));\n this.recaptureRest();\n }\n\n /** Re-read the node's current local transform as the new rest. */\n recaptureRest(): void {\n this.restPosition = toVec3(this.node.position) ?? [0, 0, 0];\n this.restQuaternion = toQuat(this.node.rotationQuaternion);\n this.restScale = toVec3(this.node.scaling) ?? [1, 1, 1];\n }\n\n /**\n * The node's LIVE world pose, from its absolute position and rotation.\n *\n * This differs from the three.js port, which reports the rest pose in\n * world space. Babylon computes absolutes for its own render anyway, so\n * reading them costs nothing and a grab starts from where the object\n * actually is rather than from where it was registered.\n */\n getWorldPose(): PoseTuple {\n this.node.computeWorldMatrix?.(true);\n return nodeWorldPose(this.node);\n }\n\n getLocalOffset(): Vec3Tuple {\n const delta = vSub(toVec3(this.node.position) ?? [0, 0, 0], this.restPosition);\n return vApplyQuat(delta, quatConjugate(this.restQuaternion));\n }\n\n setLocalOffset(offset: Vec3Tuple): void {\n writeVec3(this.node.position, vAdd(this.restPosition, vApplyQuat(offset, this.restQuaternion)));\n }\n\n setLocalRotation(quaternion: QuatTuple): void {\n this.writeRotation(quatMultiply(this.restQuaternion, quaternion));\n }\n\n /**\n * Follow a world pose while grabbed. With a parent, the pose is resolved\n * into the parent's frame through its absolute position and rotation.\n *\n * Simplification: parent SCALE is ignored. A grabbed object under a scaled\n * parent tracks the hand at the wrong distance. Grabbables are expected to\n * sit under an unscaled parent, which is how the demos build them.\n */\n setWorldPose(pose: PoseTuple): void {\n const parent = parentOf(this.node);\n if (!parent) {\n writeVec3(this.node.position, pose.position);\n this.writeRotation(pose.quaternion);\n return;\n }\n const parentPose = nodeWorldPose(parent);\n const inverse = quatConjugate(parentPose.quaternion);\n writeVec3(this.node.position, vApplyQuat(vSub(pose.position, parentPose.position), inverse));\n this.writeRotation(quatMultiply(inverse, pose.quaternion));\n }\n\n /**\n * Uniform scale about the rest scale. The emissive part of the intent is\n * not applied: reaching a material's emissive colour means knowing which\n * Babylon material the node carries, and this package holds no Babylon\n * types. Apps that want the glow subscribe to the core's feedback intents.\n */\n setEffect(effect: { scale?: number; emissive?: number }): void {\n if (effect.scale === undefined) return;\n const scaling = this.node.scaling;\n if (!scaling) return;\n writeVec3(scaling, [\n this.restScale[0] * effect.scale,\n this.restScale[1] * effect.scale,\n this.restScale[2] * effect.scale,\n ]);\n }\n\n /** Write a quaternion, creating the node's `rotationQuaternion` if needed. */\n private writeRotation(value: QuatTuple): void {\n let target = this.node.rotationQuaternion;\n if (!target) {\n target = this.createQuaternion();\n this.node.rotationQuaternion = target;\n }\n writeQuat(target, value);\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@realitycollective/babylon-interactions",
|
|
3
|
+
"version": "0.1.0-preview.2",
|
|
4
|
+
"description": "Babylon.js adapter for the Reality Collective Interaction Extensions - maps a Babylon WebXR experience (WebXRDefaultExperience controllers, motion controller components, hand-tracking joints) into the engine-free @realitycollective/webxr-interactions core, with a scene pointer fallback on desktop. Structurally typed: no @babylonjs/core import. Re-exports the core.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"realitycollective",
|
|
7
|
+
"babylonjs",
|
|
8
|
+
"babylon",
|
|
9
|
+
"webxr",
|
|
10
|
+
"xr",
|
|
11
|
+
"interaction",
|
|
12
|
+
"input",
|
|
13
|
+
"typescript"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Reality Collective",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"CHANGELOG.md"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.build.json",
|
|
33
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@realitycollective/webxr-input": "^0.1.0",
|
|
37
|
+
"@realitycollective/webxr-interactions": "^0.1.0-preview.2"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/realitycollective/WebXR-Interactions.git",
|
|
42
|
+
"directory": "packages/babylon-interactions"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/realitycollective/WebXR-Interactions#readme",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/realitycollective/WebXR-Interactions/issues"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=20.19.0 <21.0.0-0 || >=22.12.0 <23.0.0-0 || >=24.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|