@pmndrs/viverse 0.2.4 → 0.2.6

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.
@@ -0,0 +1,11 @@
1
+ import { EventAction, StateAction } from './action.js';
2
+ export declare function BooleanOr(...values: Array<boolean>): boolean;
3
+ export declare const MoveForwardAction: StateAction<number>;
4
+ export declare const MoveBackwardAction: StateAction<number>;
5
+ export declare const MoveLeftAction: StateAction<number>;
6
+ export declare const MoveRightAction: StateAction<number>;
7
+ export declare const RunAction: StateAction<boolean>;
8
+ export declare const JumpAction: EventAction<unknown>;
9
+ export declare const ZoomAction: EventAction<number>;
10
+ export declare const RotateYawAction: EventAction<number>;
11
+ export declare const RotatePitchAction: EventAction<number>;
@@ -0,0 +1,18 @@
1
+ import { EventAction, StateAction } from './action.js';
2
+ export function BooleanOr(...values) {
3
+ let value = false;
4
+ for (let i = 0; i < values.length; i++) {
5
+ value ||= values[i];
6
+ }
7
+ return value;
8
+ }
9
+ const sum = (...values) => values.reduce((a, b) => a + b, 0);
10
+ export const MoveForwardAction = new StateAction(Math.max, 0);
11
+ export const MoveBackwardAction = new StateAction(Math.max, 0);
12
+ export const MoveLeftAction = new StateAction(Math.max, 0);
13
+ export const MoveRightAction = new StateAction(Math.max, 0);
14
+ export const RunAction = new StateAction(BooleanOr, false);
15
+ export const JumpAction = new EventAction();
16
+ export const ZoomAction = new EventAction(sum, 0);
17
+ export const RotateYawAction = new EventAction(sum, 0);
18
+ export const RotatePitchAction = new EventAction(sum, 0);
@@ -1,14 +1,3 @@
1
- import { EventAction, StateAction } from './action.js';
2
- export declare function BooleanOr(...values: Array<boolean>): boolean;
3
- export declare const MoveForwardAction: StateAction<number>;
4
- export declare const MoveBackwardAction: StateAction<number>;
5
- export declare const MoveLeftAction: StateAction<number>;
6
- export declare const MoveRightAction: StateAction<number>;
7
- export declare const RunAction: StateAction<boolean>;
8
- export declare const JumpAction: EventAction<unknown>;
9
- export declare const ZoomAction: EventAction<number>;
10
- export declare const RotateYawAction: EventAction<number>;
11
- export declare const RotatePitchAction: EventAction<number>;
12
1
  export * from './pointer-lock.js';
13
2
  export * from './pointer-capture.js';
14
3
  export * from './pointer.js';
@@ -16,3 +5,4 @@ export * from './keyboard.js';
16
5
  export * from './screen-joystick.js';
17
6
  export * from './screen-jump-button.js';
18
7
  export * from './action.js';
8
+ export * from './definitions.js';
@@ -1,21 +1,3 @@
1
- import { EventAction, StateAction } from './action.js';
2
- export function BooleanOr(...values) {
3
- let value = false;
4
- for (let i = 0; i < values.length; i++) {
5
- value ||= values[i];
6
- }
7
- return value;
8
- }
9
- const sum = (...values) => values.reduce((a, b) => a + b, 0);
10
- export const MoveForwardAction = new StateAction(Math.max, 0);
11
- export const MoveBackwardAction = new StateAction(Math.max, 0);
12
- export const MoveLeftAction = new StateAction(Math.max, 0);
13
- export const MoveRightAction = new StateAction(Math.max, 0);
14
- export const RunAction = new StateAction(BooleanOr, false);
15
- export const JumpAction = new EventAction();
16
- export const ZoomAction = new EventAction(sum, 0);
17
- export const RotateYawAction = new EventAction(sum, 0);
18
- export const RotatePitchAction = new EventAction(sum, 0);
19
1
  export * from './pointer-lock.js';
20
2
  export * from './pointer-capture.js';
21
3
  export * from './pointer.js';
@@ -23,3 +5,4 @@ export * from './keyboard.js';
23
5
  export * from './screen-joystick.js';
24
6
  export * from './screen-jump-button.js';
25
7
  export * from './action.js';
8
+ export * from './definitions.js';
@@ -1,4 +1,4 @@
1
- import { StateAction, WriteonlyEventAction } from './index.js';
1
+ import { StateAction, WriteonlyEventAction } from './action.js';
2
2
  export declare class KeyboardActionBinding {
3
3
  private pressedKeys;
4
4
  private writer?;
@@ -1,4 +1,5 @@
1
- import { JumpAction, MoveBackwardAction, MoveForwardAction, MoveLeftAction, MoveRightAction, StateAction, RunAction, } from './index.js';
1
+ import { StateAction } from './action.js';
2
+ import { JumpAction, MoveBackwardAction, MoveForwardAction, MoveLeftAction, MoveRightAction, RunAction, } from './definitions.js';
2
3
  export class KeyboardActionBinding {
3
4
  pressedKeys = new Set();
4
5
  writer;
@@ -27,13 +28,11 @@ export class KeyboardActionBinding {
27
28
  this.updateState();
28
29
  }, { signal: abortSignal });
29
30
  domElement.addEventListener('keyup', (e) => {
30
- console.log('up');
31
31
  this.pressedKeys.delete(e.code);
32
32
  this.updateState();
33
33
  }, { signal: abortSignal });
34
34
  // Handle focus loss to clear pressed keys
35
35
  const onBlur = () => {
36
- console.log('blur');
37
36
  this.pressedKeys.clear();
38
37
  this.updateState();
39
38
  };
@@ -1,4 +1,4 @@
1
- import { RotatePitchAction, RotateYawAction, ZoomAction } from './index.js';
1
+ import { RotatePitchAction, RotateYawAction, ZoomAction } from './definitions.js';
2
2
  export class PointerCaptureRotateZoomActionBindings {
3
3
  domElement;
4
4
  activePointers = new Map();
@@ -1,4 +1,4 @@
1
- import { RotatePitchAction, RotateYawAction, ZoomAction } from './index.js';
1
+ import { RotatePitchAction, RotateYawAction, ZoomAction } from './definitions.js';
2
2
  export class PointerLockRotateZoomActionBindings {
3
3
  rotationSpeed; // default 0.4
4
4
  zoomSpeed; // default 0.0001
@@ -1,4 +1,4 @@
1
- import { StateAction, WriteonlyEventAction } from './index.js';
1
+ import { StateAction, WriteonlyEventAction } from './action.js';
2
2
  export declare class PointerButtonActionBinding {
3
3
  private readonly domElement;
4
4
  private writer?;
@@ -1,4 +1,4 @@
1
- import { StateAction } from './index.js';
1
+ import { StateAction } from './action.js';
2
2
  export class PointerButtonActionBinding {
3
3
  domElement;
4
4
  writer;
@@ -1,4 +1,4 @@
1
- import { MoveForwardAction, MoveBackwardAction, MoveLeftAction, MoveRightAction, RunAction, } from './index.js';
1
+ import { MoveForwardAction, MoveBackwardAction, MoveLeftAction, MoveRightAction, RunAction } from './definitions.js';
2
2
  const DefaultDeadZonePx = 24;
3
3
  const DefaultRunDistancePx = 46;
4
4
  const JoystickRadius = 56;
@@ -1,4 +1,4 @@
1
- import { JumpAction } from './index.js';
1
+ import { JumpAction } from './definitions.js';
2
2
  import { PointerButtonActionBinding } from './pointer.js';
3
3
  export const defaultScreenButtonStyles = {
4
4
  position: 'absolute',
@@ -1,2 +1,2 @@
1
- import { SimpleCharacterActionBindingOptions } from './index.js';
1
+ import { SimpleCharacterActionBindingOptions } from './types.js';
2
2
  export declare function applySimpleCharacterActionBindingOptions(actionBindingsList: Array<unknown>, options?: SimpleCharacterActionBindingOptions): void;
@@ -1,102 +1,8 @@
1
1
  import { Group, Object3D, Object3DEventMap, AnimationAction } from 'three';
2
- import { CharacterAnimationOptions } from '../animation/index.js';
3
- import { CharacterCameraBehavior, CharacterCameraBehaviorOptions } from '../camera.js';
4
- import { CharacterModelOptions, CharacterModel } from '../model/index.js';
5
- import { BvhCharacterPhysicsOptions, BvhCharacterPhysics, BvhPhysicsWorld } from '../physics/index.js';
6
- export type SimpleCharacterState = {
7
- camera: Object3D;
8
- model?: CharacterModel;
9
- physics: BvhCharacterPhysics;
10
- lastJump: number;
11
- };
12
- export type SimpleCharacterMovementOptions = {
13
- /**
14
- * @default true
15
- */
16
- jump?: {
17
- /**
18
- * @default 0.2
19
- */
20
- delay?: number;
21
- /**
22
- * @default 0.1
23
- */
24
- bufferTime?: number;
25
- /**
26
- * @default 8
27
- */
28
- speed?: number;
29
- } | boolean;
30
- /**
31
- * @default true
32
- */
33
- walk?: {
34
- speed?: number;
35
- } | boolean;
36
- /**
37
- * @default true
38
- */
39
- run?: {
40
- speed?: number;
41
- } | boolean;
42
- };
43
- export type SimpleCharacterAnimationOptions = {
44
- readonly walk?: CharacterAnimationOptions;
45
- readonly run?: CharacterAnimationOptions;
46
- readonly idle?: CharacterAnimationOptions;
47
- readonly jumpUp?: CharacterAnimationOptions;
48
- readonly jumpLoop?: CharacterAnimationOptions;
49
- readonly jumpDown?: CharacterAnimationOptions;
50
- readonly jumpForward?: CharacterAnimationOptions;
51
- /**
52
- * @default "movement"
53
- */
54
- yawRotationBasedOn?: 'camera' | 'movement';
55
- /**
56
- * @default 10
57
- */
58
- maxYawRotationSpeed?: number;
59
- /**
60
- * @default 0.1
61
- */
62
- crossFadeDuration?: number;
63
- };
64
- export type SimpleCharacterActionBindingOptions = {
65
- screenJoystickRunDistancePx?: number;
66
- screenJoystickDeadZonePx?: number;
67
- pointerCaptureRotationSpeed?: number;
68
- pointerCaptureZoomSpeed?: number;
69
- pointerLockRotationSpeed?: number;
70
- pointerLockZoomSpeed?: number;
71
- keyboardRequiresPointerLock?: boolean;
72
- keyboardMoveForwardKeys?: Array<string>;
73
- keyboardMoveBackwardKeys?: Array<string>;
74
- keyboardMoveLeftKeys?: Array<string>;
75
- keyboardMoveRightKeys?: Array<string>;
76
- keyboardRunKeys?: Array<string>;
77
- keyboardJumpKeys?: Array<string>;
78
- };
79
- export type SimpleCharacterOptions = {
80
- /**
81
- * @deprecated use actionBindings instead
82
- */
83
- readonly input?: ReadonlyArray<{
84
- new (domElement: HTMLElement, abortSignal: AbortSignal): any;
85
- }>;
86
- readonly actionBindings?: ReadonlyArray<{
87
- new (domElement: HTMLElement, abortSignal: AbortSignal): any;
88
- }>;
89
- /**
90
- * @deprecated use actionBindingOptions instead
91
- */
92
- inputOptions?: SimpleCharacterActionBindingOptions;
93
- actionBindingOptions?: SimpleCharacterActionBindingOptions;
94
- movement?: SimpleCharacterMovementOptions;
95
- readonly model?: CharacterModelOptions | boolean;
96
- physics?: BvhCharacterPhysicsOptions;
97
- cameraBehavior?: CharacterCameraBehaviorOptions;
98
- readonly animation?: SimpleCharacterAnimationOptions;
99
- };
2
+ import { CharacterCameraBehavior } from '../camera.js';
3
+ import { CharacterModel } from '../model/index.js';
4
+ import { BvhCharacterPhysics, BvhPhysicsWorld } from '../physics/index.js';
5
+ import { SimpleCharacterOptions, SimpleCharacterState } from './types.js';
100
6
  export declare class SimpleCharacter extends Group<Object3DEventMap & {
101
7
  loaded: {};
102
8
  }> implements SimpleCharacterState {
@@ -122,3 +28,4 @@ export declare class SimpleCharacter extends Group<Object3DEventMap & {
122
28
  export * from './update-input-velocity.js';
123
29
  export * from './update-rotation.js';
124
30
  export * from './apply-input-options.js';
31
+ export * from './types.js';
@@ -4,7 +4,7 @@ import { Group, Vector3 } from 'three';
4
4
  import { applySimpleCharacterActionBindingOptions } from './apply-input-options.js';
5
5
  import { KeyboardLocomotionActionBindings, PointerCaptureRotateZoomActionBindings, ScreenJoystickLocomotionActionBindings, ScreenButtonJumpActionBindings, } from '../action/index.js';
6
6
  import { CharacterCameraBehavior } from '../camera.js';
7
- import { loadCharacterModel, flattenCharacterModelOptions, } from '../model/index.js';
7
+ import { loadCharacterModel, flattenCharacterModelOptions } from '../model/index.js';
8
8
  import { BvhCharacterPhysics } from '../physics/index.js';
9
9
  import { shouldJump } from '../utils.js';
10
10
  import { loadSimpleCharacterJumpDownState } from './state/jump-down.js';
@@ -106,3 +106,4 @@ export class SimpleCharacter extends Group {
106
106
  export * from './update-input-velocity.js';
107
107
  export * from './update-rotation.js';
108
108
  export * from './apply-input-options.js';
109
+ export * from './types.js';
@@ -1,3 +1,3 @@
1
1
  import { type GraphTimelineState } from '@pmndrs/timeline';
2
- import type { SimpleCharacterState, SimpleCharacterOptions } from '../index.js';
2
+ import type { SimpleCharacterState, SimpleCharacterOptions } from '../types.js';
3
3
  export declare function loadSimpleCharacterJumpDownState<T>(state: SimpleCharacterState, options: SimpleCharacterOptions): Promise<GraphTimelineState<T>>;
@@ -1,5 +1,5 @@
1
1
  import { type GraphTimelineState } from '@pmndrs/timeline';
2
2
  import { AnimationAction } from 'three';
3
- import { SimpleCharacterState, SimpleCharacterOptions } from '../index.js';
3
+ import { SimpleCharacterState, SimpleCharacterOptions } from '../types.js';
4
4
  export declare function loadSimpleCharacterJumpForwardAction(state: SimpleCharacterState, options: SimpleCharacterOptions): Promise<AnimationAction>;
5
5
  export declare function loadSimpleCharacterJumpForwardState<T>(jumpForward: AnimationAction, state: SimpleCharacterState, options: SimpleCharacterOptions): Promise<GraphTimelineState<T>>;
@@ -1,3 +1,3 @@
1
1
  import { type GraphTimelineState } from '@pmndrs/timeline';
2
- import type { SimpleCharacterOptions, SimpleCharacterState } from '../index.js';
2
+ import type { SimpleCharacterOptions, SimpleCharacterState } from '../types.js';
3
3
  export declare function loadSimpleCharacterJumpLoopState<T>(state: SimpleCharacterState, options: SimpleCharacterOptions): Promise<GraphTimelineState<T>>;
@@ -1,4 +1,4 @@
1
1
  import { GraphTimelineState } from '@pmndrs/timeline';
2
2
  import { AnimationAction } from 'three';
3
- import type { SimpleCharacterOptions, SimpleCharacterState } from '../index.js';
3
+ import type { SimpleCharacterOptions, SimpleCharacterState } from '../types.js';
4
4
  export declare function loadSimpleCharacterJumpStartState<T>(jumpUp: AnimationAction, jumpForward: AnimationAction, state: SimpleCharacterState, options: SimpleCharacterOptions): Promise<GraphTimelineState<T>>;
@@ -1,5 +1,5 @@
1
1
  import { GraphTimelineState } from '@pmndrs/timeline';
2
2
  import { AnimationAction } from 'three';
3
- import { SimpleCharacterState, SimpleCharacterOptions } from '../index.js';
3
+ import { SimpleCharacterState, SimpleCharacterOptions } from '../types.js';
4
4
  export declare function loadSimpleCharacterJumpUpAction(state: SimpleCharacterState, options: SimpleCharacterOptions): Promise<AnimationAction>;
5
5
  export declare function loadSimpleCharacterJumpUpState<T>(jumpUp: AnimationAction, state: SimpleCharacterState, options: SimpleCharacterOptions): Promise<GraphTimelineState<T>>;
@@ -1,3 +1,3 @@
1
1
  import { type GraphTimelineState } from '@pmndrs/timeline';
2
- import type { SimpleCharacterOptions, SimpleCharacterState } from '../index.js';
2
+ import type { SimpleCharacterOptions, SimpleCharacterState } from '../types.js';
3
3
  export declare function loadSimpleCharacterMovingState<T>(state: SimpleCharacterState, options: SimpleCharacterOptions): Promise<GraphTimelineState<T>>;
@@ -0,0 +1,99 @@
1
+ import { Object3D } from 'three';
2
+ import { CharacterAnimationOptions } from '../animation/index.js';
3
+ import { CharacterCameraBehaviorOptions } from '../camera.js';
4
+ import { CharacterModel, CharacterModelOptions } from '../model/index.js';
5
+ import { BvhCharacterPhysics, BvhCharacterPhysicsOptions } from '../physics/index.js';
6
+ export type SimpleCharacterState = {
7
+ camera: Object3D;
8
+ model?: CharacterModel;
9
+ physics: BvhCharacterPhysics;
10
+ lastJump: number;
11
+ };
12
+ export type SimpleCharacterMovementOptions = {
13
+ /**
14
+ * @default true
15
+ */
16
+ jump?: {
17
+ /**
18
+ * @default 0.2
19
+ */
20
+ delay?: number;
21
+ /**
22
+ * @default 0.1
23
+ */
24
+ bufferTime?: number;
25
+ /**
26
+ * @default 8
27
+ */
28
+ speed?: number;
29
+ } | boolean;
30
+ /**
31
+ * @default true
32
+ */
33
+ walk?: {
34
+ speed?: number;
35
+ } | boolean;
36
+ /**
37
+ * @default true
38
+ */
39
+ run?: {
40
+ speed?: number;
41
+ } | boolean;
42
+ };
43
+ export type SimpleCharacterAnimationOptions = {
44
+ readonly walk?: CharacterAnimationOptions;
45
+ readonly run?: CharacterAnimationOptions;
46
+ readonly idle?: CharacterAnimationOptions;
47
+ readonly jumpUp?: CharacterAnimationOptions;
48
+ readonly jumpLoop?: CharacterAnimationOptions;
49
+ readonly jumpDown?: CharacterAnimationOptions;
50
+ readonly jumpForward?: CharacterAnimationOptions;
51
+ /**
52
+ * @default "movement"
53
+ */
54
+ yawRotationBasedOn?: 'camera' | 'movement';
55
+ /**
56
+ * @default 10
57
+ */
58
+ maxYawRotationSpeed?: number;
59
+ /**
60
+ * @default 0.1
61
+ */
62
+ crossFadeDuration?: number;
63
+ };
64
+ export type SimpleCharacterActionBindingOptions = {
65
+ screenJoystickRunDistancePx?: number;
66
+ screenJoystickDeadZonePx?: number;
67
+ pointerCaptureRotationSpeed?: number;
68
+ pointerCaptureZoomSpeed?: number;
69
+ pointerLockRotationSpeed?: number;
70
+ pointerLockZoomSpeed?: number;
71
+ keyboardRequiresPointerLock?: boolean;
72
+ keyboardMoveForwardKeys?: Array<string>;
73
+ keyboardMoveBackwardKeys?: Array<string>;
74
+ keyboardMoveLeftKeys?: Array<string>;
75
+ keyboardMoveRightKeys?: Array<string>;
76
+ keyboardRunKeys?: Array<string>;
77
+ keyboardJumpKeys?: Array<string>;
78
+ };
79
+ export type SimpleCharacterOptions = {
80
+ /**
81
+ * @deprecated use actionBindings instead
82
+ */
83
+ readonly input?: ReadonlyArray<{
84
+ new (domElement: HTMLElement, abortSignal: AbortSignal): any;
85
+ }>;
86
+ readonly actionBindings?: ReadonlyArray<{
87
+ new (domElement: HTMLElement, abortSignal: AbortSignal): any;
88
+ }>;
89
+ /**
90
+ * @deprecated use actionBindingOptions instead
91
+ */
92
+ inputOptions?: SimpleCharacterActionBindingOptions;
93
+ actionBindingOptions?: SimpleCharacterActionBindingOptions;
94
+ movement?: SimpleCharacterMovementOptions;
95
+ readonly model?: CharacterModelOptions | boolean;
96
+ physics?: BvhCharacterPhysicsOptions;
97
+ cameraBehavior?: CharacterCameraBehaviorOptions;
98
+ readonly animation?: SimpleCharacterAnimationOptions;
99
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
1
  import { Object3D } from 'three';
2
- import type { SimpleCharacterMovementOptions } from './index.js';
2
+ import type { SimpleCharacterMovementOptions } from './types.js';
3
3
  import type { BvhCharacterPhysics } from '../physics/index.js';
4
4
  export declare function updateSimpleCharacterVelocity(camera: Object3D, physics: BvhCharacterPhysics, options?: SimpleCharacterMovementOptions): void;
@@ -1,6 +1,6 @@
1
1
  import { Object3D } from 'three';
2
2
  import { BvhCharacterPhysics } from '../physics/index.js';
3
- import type { SimpleCharacterAnimationOptions } from './index.js';
3
+ import type { SimpleCharacterAnimationOptions } from './types.js';
4
4
  export declare function updateSimpleCharacterRotation(delta: number, physics: BvhCharacterPhysics, camera: Object3D, model: {
5
5
  scene: Object3D;
6
6
  }, options?: SimpleCharacterAnimationOptions): true | undefined;
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "peerDependencies": {
22
22
  "three": "*"
23
23
  },
24
- "version": "0.2.4",
24
+ "version": "0.2.6",
25
25
  "type": "module",
26
26
  "dependencies": {
27
27
  "@pixiv/three-vrm": "^3.4.2",