|
| 1 | +import { XRController, XRControllerEvent } from '@react-three/xr' |
| 2 | +import { Group, XRTargetRaySpace, XRGripSpace, XRHandSpace, Vector3, XRHandInputState, XRHandJoints } from 'three' |
| 3 | + |
| 4 | +export class XRTargetRaySpaceMock extends Group implements XRTargetRaySpace { |
| 5 | + readonly angularVelocity: Vector3 = new Vector3() |
| 6 | + hasAngularVelocity = false |
| 7 | + hasLinearVelocity = false |
| 8 | + readonly linearVelocity: Vector3 = new Vector3() |
| 9 | +} |
| 10 | + |
| 11 | +export class XRGripSpaceMock extends Group implements XRGripSpace { |
| 12 | + readonly angularVelocity: Vector3 = new Vector3() |
| 13 | + hasAngularVelocity = false |
| 14 | + hasLinearVelocity = false |
| 15 | + readonly linearVelocity: Vector3 = new Vector3() |
| 16 | +} |
| 17 | + |
| 18 | +export class XRHandSpaceMock extends Group implements XRHandSpace { |
| 19 | + readonly inputState: XRHandInputState = { pinching: false } |
| 20 | + readonly joints: Partial<XRHandJoints> = {} |
| 21 | +} |
| 22 | + |
| 23 | +export class XRControllerMock extends Group implements XRController { |
| 24 | + readonly controller: XRTargetRaySpace |
| 25 | + readonly grip: XRGripSpace |
| 26 | + readonly hand: XRHandSpace |
| 27 | + readonly index: number |
| 28 | + |
| 29 | + // TODO Implement mocks for inputSource |
| 30 | + // @ts-ignore |
| 31 | + inputSource: XRInputSource |
| 32 | + |
| 33 | + constructor(index: number) { |
| 34 | + super() |
| 35 | + this.index = index |
| 36 | + this.controller = new XRTargetRaySpaceMock() |
| 37 | + this.grip = new XRGripSpaceMock() |
| 38 | + this.hand = new XRHandSpaceMock() |
| 39 | + } |
| 40 | + |
| 41 | + _onConnected(_event: XRControllerEvent): void { |
| 42 | + throw new Error('Method not implemented.') |
| 43 | + } |
| 44 | + |
| 45 | + _onDisconnected(_event: XRControllerEvent): void { |
| 46 | + throw new Error('Method not implemented.') |
| 47 | + } |
| 48 | + |
| 49 | + dispose(): void {} |
| 50 | +} |
0 commit comments