@aura3d/input 1.4.0 → 1.4.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/package.json +36 -4
- package/src/ActionMap.ts +0 -94
- package/src/GamepadDevice.ts +0 -48
- package/src/GamepadInput.ts +0 -2
- package/src/GestureControls.ts +0 -2
- package/src/GestureHapticsFixtures.ts +0 -179
- package/src/GestureRecognizer.ts +0 -43
- package/src/InputActionBindingFixtures.ts +0 -121
- package/src/InputReplay.ts +0 -275
- package/src/InputSnapshot.ts +0 -92
- package/src/InputSystem.ts +0 -92
- package/src/InteractionSystem.ts +0 -119
- package/src/KeyboardDevice.ts +0 -32
- package/src/PickingRay.ts +0 -49
- package/src/PointerDevice.ts +0 -102
- package/src/VirtualTouchControls.ts +0 -169
- package/src/WebXRSessionController.ts +0 -248
- package/src/XRFixtures.ts +0 -203
- package/src/controls/CameraRig.ts +0 -38
- package/src/controls/ControlTypes.ts +0 -21
- package/src/controls/EditorFlyControls.ts +0 -55
- package/src/controls/FirstPersonControls.ts +0 -60
- package/src/controls/OrbitControls.ts +0 -168
- package/src/controls/PointerLockControls.ts +0 -24
- package/src/controls/SceneCameraAdapter.ts +0 -100
- package/src/controls/ThirdPersonFollowControls.ts +0 -42
- package/src/index.ts +0 -72
- package/tests/input.test.ts +0 -69
- package/tsconfig.json +0 -7
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { type CameraTransformLike, type Vec3Like } from "./ControlTypes";
|
|
2
|
-
|
|
3
|
-
export interface ThirdPersonFollowControlsOptions {
|
|
4
|
-
readonly offset?: Vec3Like;
|
|
5
|
-
readonly damping?: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class ThirdPersonFollowControls {
|
|
9
|
-
enabled = true;
|
|
10
|
-
target?: { readonly position: Vec3Like };
|
|
11
|
-
readonly offset: Vec3Like;
|
|
12
|
-
damping: number;
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
private readonly camera: CameraTransformLike,
|
|
16
|
-
target?: { readonly position: Vec3Like },
|
|
17
|
-
options: ThirdPersonFollowControlsOptions = {}
|
|
18
|
-
) {
|
|
19
|
-
this.target = target;
|
|
20
|
-
this.offset = { ...(options.offset ?? { x: 0, y: 2, z: 6 }) };
|
|
21
|
-
this.damping = options.damping ?? 12;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
update(deltaSeconds: number): void {
|
|
25
|
-
if (!this.enabled || !this.target) return;
|
|
26
|
-
const desired = {
|
|
27
|
-
x: this.target.position.x + this.offset.x,
|
|
28
|
-
y: this.target.position.y + this.offset.y,
|
|
29
|
-
z: this.target.position.z + this.offset.z
|
|
30
|
-
};
|
|
31
|
-
const alpha = 1 - Math.exp(-this.damping * Math.max(0, deltaSeconds));
|
|
32
|
-
this.camera.position.x += (desired.x - this.camera.position.x) * alpha;
|
|
33
|
-
this.camera.position.y += (desired.y - this.camera.position.y) * alpha;
|
|
34
|
-
this.camera.position.z += (desired.z - this.camera.position.z) * alpha;
|
|
35
|
-
this.camera.lookAt?.(this.target.position);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
dispose(): void {
|
|
39
|
-
this.enabled = false;
|
|
40
|
-
this.target = undefined;
|
|
41
|
-
}
|
|
42
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
export { ActionMap } from "./ActionMap";
|
|
2
|
-
export type { ActionBinding, AxisBinding } from "./ActionMap";
|
|
3
|
-
export { GamepadDevice } from "./GamepadDevice";
|
|
4
|
-
export type { GamepadButtonLike, GamepadLike } from "./GamepadDevice";
|
|
5
|
-
export { sampleGestureHapticsFixture } from "./GestureHapticsFixtures";
|
|
6
|
-
export type { GestureHapticsFixture, GestureHapticsFixtureOptions, GestureHapticsGestureType, GestureHapticsPatternName } from "./GestureHapticsFixtures";
|
|
7
|
-
export { GestureRecognizer } from "./GestureRecognizer";
|
|
8
|
-
export type { Gesture } from "./GestureRecognizer";
|
|
9
|
-
export { processInputValue, sampleInputActionBindingFixture } from "./InputActionBindingFixtures";
|
|
10
|
-
export type { InputActionBindingFixture, InputValueProcessor } from "./InputActionBindingFixtures";
|
|
11
|
-
export { InputSnapshot } from "./InputSnapshot";
|
|
12
|
-
export type { ButtonState, GamepadSnapshot, InputSnapshotOptions, PointerSnapshot, PointerTouch } from "./InputSnapshot";
|
|
13
|
-
export { InputPlayback, InputRecorder, parseInputRecording } from "./InputReplay";
|
|
14
|
-
export type { InputPlaybackOptions, InputPlaybackSnapshot, InputRecording, InputRecordingMetadata, InputReplayEvent, InputReplayEventType } from "./InputReplay";
|
|
15
|
-
export { InputSystem } from "./InputSystem";
|
|
16
|
-
export type { InputEventTargetLike } from "./InputSystem";
|
|
17
|
-
export { InteractionSystem } from "./InteractionSystem";
|
|
18
|
-
export type {
|
|
19
|
-
InteractionBounds,
|
|
20
|
-
InteractionEvent,
|
|
21
|
-
InteractionEventType,
|
|
22
|
-
InteractionHit,
|
|
23
|
-
InteractionListener,
|
|
24
|
-
InteractionRayProvider,
|
|
25
|
-
InteractionTarget,
|
|
26
|
-
InteractionTargetProvider
|
|
27
|
-
} from "./InteractionSystem";
|
|
28
|
-
export { KeyboardDevice } from "./KeyboardDevice";
|
|
29
|
-
export type { KeyboardEventLike } from "./KeyboardDevice";
|
|
30
|
-
export { pickingRayFromCamera } from "./PickingRay";
|
|
31
|
-
export type { PickingRayViewport } from "./PickingRay";
|
|
32
|
-
export { PointerDevice } from "./PointerDevice";
|
|
33
|
-
export type { PointerEventLike, WheelEventLike } from "./PointerDevice";
|
|
34
|
-
export { VirtualTouchJoystick, sampleVirtualTouchJoystickFixture } from "./VirtualTouchControls";
|
|
35
|
-
export type { VirtualJoystickConfig, VirtualTouchJoystickSnapshot, VirtualTouchPoint } from "./VirtualTouchControls";
|
|
36
|
-
export { sampleXRRuntimeFixture } from "./XRFixtures";
|
|
37
|
-
export type { XRFixtureLodLevel, XRFixtureOptions, XRFixtureSessionMode, XRRuntimeFixture } from "./XRFixtures";
|
|
38
|
-
export { WebXRSessionController } from "./WebXRSessionController";
|
|
39
|
-
export type {
|
|
40
|
-
A3DXRFrameLike,
|
|
41
|
-
A3DXRHandedness,
|
|
42
|
-
A3DXRHitTestResultLike,
|
|
43
|
-
A3DXRInputSourceLike,
|
|
44
|
-
A3DXRPoseLike,
|
|
45
|
-
A3DXRReferenceSpaceLike,
|
|
46
|
-
A3DXRReferenceSpaceType,
|
|
47
|
-
A3DXRSessionInit,
|
|
48
|
-
A3DXRSessionLike,
|
|
49
|
-
A3DXRSessionMode,
|
|
50
|
-
A3DXRSystemLike,
|
|
51
|
-
WebXRControllerSample,
|
|
52
|
-
WebXRFrameSample,
|
|
53
|
-
WebXRHitTestSample,
|
|
54
|
-
WebXRSessionControllerOptions,
|
|
55
|
-
WebXRSessionStartResult
|
|
56
|
-
} from "./WebXRSessionController";
|
|
57
|
-
export * from "./GamepadInput.js";
|
|
58
|
-
export * from "./GestureControls.js";
|
|
59
|
-
export * from "./controls/PointerLockControls.js";
|
|
60
|
-
export { CameraRig } from "./controls/CameraRig";
|
|
61
|
-
export type { CameraRigState } from "./controls/CameraRig";
|
|
62
|
-
export type { CameraTransformLike, EulerLike, Vec3Like } from "./controls/ControlTypes";
|
|
63
|
-
export { createSceneCameraControlAdapter } from "./controls/SceneCameraAdapter";
|
|
64
|
-
export type { SceneCameraControlAdapter } from "./controls/SceneCameraAdapter";
|
|
65
|
-
export { EditorFlyControls } from "./controls/EditorFlyControls";
|
|
66
|
-
export type { EditorFlyControlsOptions } from "./controls/EditorFlyControls";
|
|
67
|
-
export { FirstPersonControls } from "./controls/FirstPersonControls";
|
|
68
|
-
export type { FirstPersonControlsOptions } from "./controls/FirstPersonControls";
|
|
69
|
-
export { DEFAULT_ORBIT_MAX_POLAR, OrbitControls } from "./controls/OrbitControls";
|
|
70
|
-
export type { OrbitControlsOptions } from "./controls/OrbitControls";
|
|
71
|
-
export { ThirdPersonFollowControls } from "./controls/ThirdPersonFollowControls";
|
|
72
|
-
export type { ThirdPersonFollowControlsOptions } from "./controls/ThirdPersonFollowControls";
|
package/tests/input.test.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import test from "node:test";
|
|
3
|
-
import { Ray, Vector3 } from "@aura3d/math";
|
|
4
|
-
import { Scene } from "@aura3d/scene";
|
|
5
|
-
import { ActionMap, InputSnapshot, InputSystem, InteractionSystem, pickingRayFromCamera } from "../src/index";
|
|
6
|
-
|
|
7
|
-
test("InputSystem produces stable key transitions across frames", () => {
|
|
8
|
-
const input = new InputSystem();
|
|
9
|
-
input.keyboard.keyDown({ code: "Space" });
|
|
10
|
-
let snapshot = input.update();
|
|
11
|
-
assert.equal(snapshot.key("Space").pressed, true);
|
|
12
|
-
assert.equal(snapshot.key("Space").down, true);
|
|
13
|
-
|
|
14
|
-
input.endFrame();
|
|
15
|
-
snapshot = input.update();
|
|
16
|
-
assert.equal(snapshot.key("Space").pressed, false);
|
|
17
|
-
assert.equal(snapshot.key("Space").down, true);
|
|
18
|
-
|
|
19
|
-
input.keyboard.keyUp({ code: "Space" });
|
|
20
|
-
snapshot = input.update();
|
|
21
|
-
assert.equal(snapshot.key("Space").released, true);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("ActionMap supports alternatives and axes", () => {
|
|
25
|
-
const input = new InputSystem();
|
|
26
|
-
const actions = new ActionMap();
|
|
27
|
-
actions.bind("jump", [
|
|
28
|
-
{ type: "keyboard", code: "Space" },
|
|
29
|
-
{ type: "pointer", button: 0 }
|
|
30
|
-
]);
|
|
31
|
-
actions.bindAxis("moveX", [{ type: "keyboard-axis", negative: "KeyA", positive: "KeyD", scale: 2 }]);
|
|
32
|
-
|
|
33
|
-
input.keyboard.keyDown({ code: "KeyD" });
|
|
34
|
-
input.pointer.down({ clientX: 5, clientY: 7, button: 0 });
|
|
35
|
-
const snapshot = input.update();
|
|
36
|
-
|
|
37
|
-
assert.equal(actions.pressed("jump", snapshot), true);
|
|
38
|
-
assert.equal(actions.axis("moveX", snapshot), 2);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test("pickingRayFromCamera creates a center ray through the camera forward axis", () => {
|
|
42
|
-
const scene = new Scene();
|
|
43
|
-
const camera = scene.createPerspectiveCamera({ aspect: 1 });
|
|
44
|
-
scene.root.addChild(camera);
|
|
45
|
-
camera.setViewport({ x: 0, y: 0, width: 100, height: 100 });
|
|
46
|
-
|
|
47
|
-
const ray = pickingRayFromCamera(camera, 50, 50);
|
|
48
|
-
assert.ok(ray.direction.equals(new Vector3(0, 0, -1), 1e-6));
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("InteractionSystem picks nearest target and emits click lifecycle", () => {
|
|
52
|
-
const events: string[] = [];
|
|
53
|
-
const interaction = new InteractionSystem(
|
|
54
|
-
() => new Ray(new Vector3(0, 0, 5), new Vector3(0, 0, -1)),
|
|
55
|
-
() => [
|
|
56
|
-
{ id: "far", bounds: { min: [-1, -1, -5], max: [1, 1, -4] } },
|
|
57
|
-
{ id: "near", bounds: { min: [-1, -1, 0], max: [1, 1, 1] } }
|
|
58
|
-
]
|
|
59
|
-
);
|
|
60
|
-
interaction.subscribe((event) => events.push(event.type));
|
|
61
|
-
|
|
62
|
-
const down = new InputSnapshot({ pointer: { buttons: new Map([[0, { down: true, pressed: false, released: false }]]) } });
|
|
63
|
-
const hit = interaction.update(down);
|
|
64
|
-
const up = new InputSnapshot({ pointer: { buttons: new Map() }, previousPointerButtons: new Set([0]) });
|
|
65
|
-
interaction.update(up);
|
|
66
|
-
|
|
67
|
-
assert.equal(hit?.target.id, "near");
|
|
68
|
-
assert.deepEqual(events, ["hover-enter", "pointer-down", "click"]);
|
|
69
|
-
});
|