UNPKG

2.24 kBTypeScriptView Raw
1import { Object3DEventMap } from "../../core/Object3D.js";
2import { Vector3 } from "../../math/Vector3.js";
3import { Group } from "../../objects/Group.js";
4
5export type XRControllerEventType = XRSessionEventType | XRInputSourceEventType | "disconnected" | "connected";
6
7export class XRJointSpace extends Group {
8 readonly jointRadius: number | undefined;
9}
10
11export type XRHandJoints = Record<XRHandJoint, XRJointSpace>;
12
13export interface XRHandInputState {
14 pinching: boolean;
15}
16
17export interface WebXRSpaceEventMap extends Object3DEventMap {
18 select: { data: XRInputSource };
19 selectstart: { data: XRInputSource };
20 selectend: { data: XRInputSource };
21 squeeze: { data: XRInputSource };
22 squeezestart: { data: XRInputSource };
23 squeezeend: { data: XRInputSource };
24
25 connected: { data: XRInputSource };
26 disconnected: { data: XRInputSource };
27
28 pinchend: { handedness: XRHandedness; target: WebXRController }; // This Event break the THREE.EventDispatcher contract, replacing the target to the wrong instance.
29 pinchstart: { handedness: XRHandedness; target: WebXRController }; // This Event break the THREE.EventDispatcher contract, replacing the target to the wrong instance.
30
31 move: {};
32}
33
34export class XRHandSpace extends Group<WebXRSpaceEventMap> {
35 readonly joints: Partial<XRHandJoints>;
36 readonly inputState: XRHandInputState;
37}
38
39export class XRTargetRaySpace extends Group<WebXRSpaceEventMap> {
40 hasLinearVelocity: boolean;
41 readonly linearVelocity: Vector3;
42 hasAngularVelocity: boolean;
43 readonly angularVelocity: Vector3;
44}
45
46export class XRGripSpace extends Group<WebXRSpaceEventMap> {
47 hasLinearVelocity: boolean;
48 readonly linearVelocity: Vector3;
49 hasAngularVelocity: boolean;
50 readonly angularVelocity: Vector3;
51}
52
53export class WebXRController {
54 constructor();
55
56 getHandSpace(): XRHandSpace;
57 getTargetRaySpace(): XRTargetRaySpace;
58 getGripSpace(): XRGripSpace;
59 dispatchEvent(event: { type: XRControllerEventType; data?: XRInputSource }): this;
60 connect(inputSource: XRInputSource): this;
61 disconnect(inputSource: XRInputSource): this;
62 update(inputSource: XRInputSource, frame: XRFrame, referenceSpace: XRReferenceSpace): this;
63}