@pmndrs/viverse 0.2.0 → 0.2.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.
Files changed (64) hide show
  1. package/dist/action/action.d.ts +40 -0
  2. package/dist/action/action.js +114 -0
  3. package/dist/action/index.d.ts +18 -0
  4. package/dist/action/index.js +25 -0
  5. package/dist/action/keyboard.d.ts +26 -0
  6. package/dist/action/keyboard.js +89 -0
  7. package/dist/action/pointer-capture.d.ts +8 -0
  8. package/dist/{input → action}/pointer-capture.js +17 -42
  9. package/dist/action/pointer-lock.d.ts +6 -0
  10. package/dist/action/pointer-lock.js +49 -0
  11. package/dist/action/pointer.d.ts +18 -0
  12. package/dist/action/pointer.js +90 -0
  13. package/dist/action/screen-joystick.d.ts +16 -0
  14. package/dist/action/screen-joystick.js +120 -0
  15. package/dist/action/screen-jump-button.d.ts +6 -0
  16. package/dist/action/screen-jump-button.js +32 -0
  17. package/dist/animation/bone-map.d.ts +4 -0
  18. package/dist/animation/bone-map.js +11 -0
  19. package/dist/animation/default.d.ts +9 -1
  20. package/dist/animation/default.js +16 -9
  21. package/dist/animation/index.d.ts +8 -13
  22. package/dist/animation/index.js +61 -39
  23. package/dist/animation/mask.d.ts +4 -1
  24. package/dist/animation/mask.js +50 -0
  25. package/dist/camera.d.ts +8 -4
  26. package/dist/camera.js +24 -9
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +1 -1
  29. package/dist/model/index.d.ts +1 -2
  30. package/dist/simple-character/apply-input-options.d.ts +2 -0
  31. package/dist/simple-character/apply-input-options.js +34 -0
  32. package/dist/simple-character/index.d.ts +33 -10
  33. package/dist/simple-character/index.js +18 -19
  34. package/dist/simple-character/state/jump-down.js +2 -1
  35. package/dist/simple-character/state/jump-forward.js +4 -2
  36. package/dist/simple-character/state/jump-loop.js +2 -1
  37. package/dist/simple-character/state/jump-start.js +2 -2
  38. package/dist/simple-character/state/jump-up.js +4 -2
  39. package/dist/simple-character/state/movement.js +12 -8
  40. package/dist/simple-character/update-input-velocity.d.ts +1 -2
  41. package/dist/simple-character/update-input-velocity.js +4 -4
  42. package/dist/simple-character/update-rotation.js +1 -1
  43. package/dist/utils.d.ts +5 -5
  44. package/dist/utils.js +15 -6
  45. package/package.json +2 -2
  46. package/dist/animation/bvh.d.ts +0 -4
  47. package/dist/animation/bvh.js +0 -8
  48. package/dist/animation/fbx.d.ts +0 -4
  49. package/dist/animation/fbx.js +0 -8
  50. package/dist/animation/gltf.d.ts +0 -3
  51. package/dist/animation/gltf.js +0 -8
  52. package/dist/animation/vrma.d.ts +0 -3
  53. package/dist/animation/vrma.js +0 -8
  54. package/dist/input/index.d.ts +0 -31
  55. package/dist/input/index.js +0 -77
  56. package/dist/input/keyboard.d.ts +0 -16
  57. package/dist/input/keyboard.js +0 -82
  58. package/dist/input/pointer-capture.d.ts +0 -20
  59. package/dist/input/pointer-lock.d.ts +0 -17
  60. package/dist/input/pointer-lock.js +0 -55
  61. package/dist/input/screen-joystick.d.ts +0 -18
  62. package/dist/input/screen-joystick.js +0 -120
  63. package/dist/input/screen-jump-button.d.ts +0 -8
  64. package/dist/input/screen-jump-button.js +0 -49
@@ -1,20 +0,0 @@
1
- import { Input, InputField } from './index.js';
2
- export type PointerCaptureInputOptions = {
3
- pointerCaptureRotationSpeed?: number;
4
- pointerCaptureZoomSpeed?: number;
5
- };
6
- /**
7
- * @requires to manually execute `domElement.setPointerCapture(pointerId)` on pointerdown
8
- */
9
- export declare class PointerCaptureInput implements Input<PointerCaptureInputOptions> {
10
- private readonly domElement;
11
- private readonly abortController;
12
- private deltaZoom;
13
- private deltaYaw;
14
- private deltaPitch;
15
- private activePointers;
16
- private lastPinchDist;
17
- constructor(domElement: HTMLElement);
18
- get<T>(field: InputField<T>, options: PointerCaptureInputOptions): T | undefined;
19
- dispose(): void;
20
- }
@@ -1,17 +0,0 @@
1
- import { Input, InputField } from './index.js';
2
- export type PointerLockInputOptions = {
3
- pointerLockRotationSpeed?: number;
4
- pointerLockZoomSpeed?: number;
5
- };
6
- /**
7
- * @requires to manually execute `domElement.requestPointerLock()`
8
- */
9
- export declare class PointerLockInput implements Input<PointerLockInputOptions> {
10
- private readonly abortController;
11
- private deltaZoom;
12
- private deltaYaw;
13
- private deltaPitch;
14
- constructor(domElement: HTMLElement);
15
- get<T>(field: InputField<T>, options: PointerLockInputOptions): T | undefined;
16
- dispose(): void;
17
- }
@@ -1,55 +0,0 @@
1
- import { DeltaPitchField, DeltaYawField, DeltaZoomField } from './index.js';
2
- /**
3
- * @requires to manually execute `domElement.requestPointerLock()`
4
- */
5
- export class PointerLockInput {
6
- abortController = new AbortController();
7
- deltaZoom = 0;
8
- deltaYaw = 0;
9
- deltaPitch = 0;
10
- constructor(domElement) {
11
- domElement.addEventListener('pointermove', (event) => {
12
- if (document.pointerLockElement != domElement) {
13
- return;
14
- }
15
- // Compute based on domElement bounds instead of window.innerHeight
16
- const rect = domElement.getBoundingClientRect();
17
- this.deltaYaw -= event.movementX / rect.height;
18
- this.deltaPitch -= event.movementY / rect.height;
19
- }, {
20
- signal: this.abortController.signal,
21
- });
22
- domElement.addEventListener('wheel', (event) => {
23
- if (document.pointerLockElement != domElement) {
24
- return;
25
- }
26
- this.deltaZoom += event.deltaY;
27
- event.preventDefault();
28
- }, {
29
- signal: this.abortController.signal,
30
- });
31
- }
32
- get(field, options) {
33
- const rotationSpeed = options.pointerLockRotationSpeed ?? 0.4;
34
- const zoomSpeed = options.pointerLockZoomSpeed ?? 0.0001;
35
- let result;
36
- switch (field) {
37
- case DeltaPitchField:
38
- result = (this.deltaPitch * rotationSpeed);
39
- this.deltaPitch = 0;
40
- break;
41
- case DeltaYawField:
42
- result = (this.deltaYaw * rotationSpeed);
43
- this.deltaYaw = 0;
44
- break;
45
- case DeltaZoomField:
46
- result = (this.deltaZoom * zoomSpeed);
47
- this.deltaZoom = 0;
48
- break;
49
- }
50
- return result;
51
- }
52
- dispose() {
53
- this.abortController.abort();
54
- }
55
- }
@@ -1,18 +0,0 @@
1
- import { Input, InputField } from './index.js';
2
- export type ScreenJoystickInputOptions = {
3
- screenJoystickRunDistancePx?: number;
4
- screenJoystickDeadZonePx?: number;
5
- };
6
- export declare class ScreenJoystickInput implements Input<ScreenJoystickInputOptions> {
7
- readonly root: HTMLDivElement;
8
- private readonly handle;
9
- private pointerId;
10
- private distanceToCenter;
11
- private clampedX;
12
- private clampedY;
13
- constructor(domElement: HTMLElement);
14
- get<T>(field: InputField<T>, options: ScreenJoystickInputOptions): T | undefined;
15
- dispose(): void;
16
- private updateHandle;
17
- private resetHandle;
18
- }
@@ -1,120 +0,0 @@
1
- import { MoveForwardField, MoveBackwardField, MoveLeftField, MoveRightField, RunField, } from './index.js';
2
- const DefaultDeadZonePx = 24;
3
- const DefaultRunDistancePx = 46;
4
- const JoystickRadius = 56;
5
- export class ScreenJoystickInput {
6
- root;
7
- handle;
8
- pointerId;
9
- distanceToCenter = 0;
10
- clampedX = 0;
11
- clampedY = 0;
12
- constructor(domElement) {
13
- const parent = domElement.parentElement ?? domElement;
14
- const joy = document.createElement('div');
15
- joy.className = 'viverse-joystick mobile-only';
16
- parent.appendChild(joy);
17
- this.root = joy;
18
- this.root.style.position = 'absolute';
19
- this.root.style.bottom = '24px';
20
- this.root.style.left = '24px';
21
- this.root.style.width = '112px';
22
- this.root.style.height = '112px';
23
- this.root.style.borderRadius = '9999px';
24
- this.root.style.background = 'rgba(255,255,255,0.2)';
25
- this.root.style.pointerEvents = 'auto';
26
- this.root.style.touchAction = 'none';
27
- this.root.style.userSelect = 'none';
28
- this.root.style.setProperty('-webkit-user-select', 'none');
29
- this.root.style.setProperty('-webkit-touch-callout', 'none');
30
- const handle = document.createElement('div');
31
- handle.className = 'viverse-joystick-handle';
32
- joy.appendChild(handle);
33
- this.handle = handle;
34
- this.handle.style.position = 'absolute';
35
- this.handle.style.left = '50%';
36
- this.handle.style.top = '50%';
37
- this.handle.style.width = '56px';
38
- this.handle.style.height = '56px';
39
- this.handle.style.borderRadius = '9999px';
40
- this.handle.style.background = 'rgba(0,0,0,0.3)';
41
- this.handle.style.transform = 'translate(-50%,-50%)';
42
- this.handle.style.willChange = 'transform';
43
- this.handle.style.pointerEvents = 'none';
44
- this.handle.style.touchAction = 'none';
45
- this.handle.style.userSelect = 'none';
46
- this.handle.style.setProperty('-webkit-user-select', 'none');
47
- this.handle.style.setProperty('-webkit-touch-callout', 'none');
48
- const onPointerDown = (e) => {
49
- if (this.pointerId != null) {
50
- return;
51
- }
52
- e.preventDefault();
53
- e.stopPropagation();
54
- joy.setPointerCapture(e.pointerId);
55
- this.pointerId = e.pointerId;
56
- const rect = joy.getBoundingClientRect();
57
- const joyCenterX = rect.left + rect.width / 2;
58
- const joyCenterY = rect.top + rect.height / 2;
59
- this.updateHandle(e.clientX - joyCenterX, e.clientY - joyCenterY);
60
- };
61
- const onPointerMove = (e) => {
62
- if (this.pointerId == null) {
63
- return;
64
- }
65
- e.preventDefault();
66
- e.stopPropagation();
67
- const rect = joy.getBoundingClientRect();
68
- const joyCenterX = rect.left + rect.width / 2;
69
- const joyCenterY = rect.top + rect.height / 2;
70
- this.updateHandle(e.clientX - joyCenterX, e.clientY - joyCenterY);
71
- };
72
- const onPointerEnd = (e) => {
73
- if (this.pointerId != e.pointerId) {
74
- return;
75
- }
76
- this.pointerId = undefined;
77
- joy.releasePointerCapture(e.pointerId);
78
- e.preventDefault();
79
- this.resetHandle();
80
- };
81
- joy.addEventListener('pointerdown', onPointerDown);
82
- joy.addEventListener('pointermove', onPointerMove);
83
- joy.addEventListener('pointerup', onPointerEnd);
84
- joy.addEventListener('pointercancel', onPointerEnd);
85
- }
86
- get(field, options) {
87
- switch (field) {
88
- case MoveForwardField:
89
- case MoveBackwardField:
90
- const moveY = this.distanceToCenter <= (options.screenJoystickDeadZonePx ?? DefaultDeadZonePx)
91
- ? 0
92
- : -this.clampedY / JoystickRadius;
93
- return field === MoveForwardField ? Math.max(0, moveY) : Math.max(0, -moveY);
94
- case MoveLeftField:
95
- case MoveRightField:
96
- const moveX = this.distanceToCenter <= (options.screenJoystickDeadZonePx ?? DefaultDeadZonePx)
97
- ? 0
98
- : this.clampedX / JoystickRadius;
99
- return field === MoveLeftField ? Math.max(0, moveX) : Math.max(0, moveX);
100
- case RunField:
101
- return (this.distanceToCenter > (options.screenJoystickRunDistancePx ?? DefaultRunDistancePx));
102
- }
103
- return undefined;
104
- }
105
- dispose() {
106
- this.root.remove();
107
- }
108
- updateHandle(dx, dy) {
109
- this.distanceToCenter = Math.hypot(dx, dy) || 1;
110
- this.clampedX = (dx / this.distanceToCenter) * Math.min(this.distanceToCenter, JoystickRadius);
111
- this.clampedY = (dy / this.distanceToCenter) * Math.min(this.distanceToCenter, JoystickRadius);
112
- this.handle.style.transform = `translate(-50%,-50%) translate(${this.clampedX}px, ${this.clampedY}px)`;
113
- }
114
- resetHandle() {
115
- this.handle.style.transform = 'translate(-50%,-50%)';
116
- this.distanceToCenter = 0;
117
- this.clampedX = 0;
118
- this.clampedY = 0;
119
- }
120
- }
@@ -1,8 +0,0 @@
1
- import { Input, InputField } from './index.js';
2
- export declare class ScreenJumpButtonInput implements Input<{}> {
3
- readonly root: HTMLDivElement;
4
- private lastJumpTime;
5
- constructor(domElement: HTMLElement);
6
- get<T>(field: InputField<T>): T | undefined;
7
- dispose(): void;
8
- }
@@ -1,49 +0,0 @@
1
- import { LastTimeJumpPressedField } from './index.js';
2
- export class ScreenJumpButtonInput {
3
- root;
4
- lastJumpTime = null;
5
- constructor(domElement) {
6
- const parent = domElement.parentElement ?? domElement;
7
- const btn = document.createElement('div');
8
- btn.className = 'viverse-button viverse-jump mobile-only';
9
- parent.appendChild(btn);
10
- this.root = btn;
11
- this.root.style.position = 'absolute';
12
- this.root.style.bottom = '32px';
13
- this.root.style.right = '126px';
14
- this.root.style.minWidth = '64px';
15
- this.root.style.height = '64px';
16
- this.root.style.borderRadius = '9999px';
17
- this.root.style.pointerEvents = 'auto';
18
- this.root.style.touchAction = 'none';
19
- this.root.style.userSelect = 'none';
20
- this.root.style.setProperty('-webkit-user-select', 'none');
21
- this.root.style.background = 'rgba(255,255,255,0.3)';
22
- this.root.style.backgroundImage =
23
- 'url("data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%2024%2024%22%20fill=%22none%22%20stroke=%22%23444%22%20stroke-width=%222%22%20stroke-linecap=%22round%22%20stroke-linejoin=%22round%22%3E%3Cpolyline%20points=%2218%2015%2012%209%206%2015%22/%3E%3C/svg%3E")';
24
- this.root.style.backgroundRepeat = 'no-repeat';
25
- this.root.style.backgroundPosition = 'center';
26
- this.root.style.backgroundSize = '50%';
27
- const onPress = (e) => {
28
- e.preventDefault();
29
- e.stopPropagation();
30
- this.lastJumpTime = performance.now() / 1000;
31
- };
32
- const stopPropagation = (e) => {
33
- e.stopPropagation();
34
- e.preventDefault();
35
- };
36
- this.root.addEventListener('pointerdown', onPress);
37
- this.root.addEventListener('pointermove', stopPropagation);
38
- this.root.addEventListener('pointerup', stopPropagation);
39
- }
40
- get(field) {
41
- if (field === LastTimeJumpPressedField) {
42
- return this.lastJumpTime;
43
- }
44
- return undefined;
45
- }
46
- dispose() {
47
- this.root.remove();
48
- }
49
- }