@mml-io/3d-web-client-core 0.1.0 → 0.3.0

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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2023 Improbable MV Limited
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -1,23 +1,37 @@
1
- import { PerspectiveCamera } from "three";
1
+ import { PerspectiveCamera, Vector3 } from "three";
2
+ import { CollisionsManager } from "../collisions/CollisionsManager";
2
3
  export declare class CameraManager {
4
+ private collisionsManager;
3
5
  readonly camera: PerspectiveCamera;
4
- private dragging;
5
- private target;
6
- private targetDistance;
7
- private maxTargetDistance;
6
+ initialDistance: number;
7
+ private minDistance;
8
+ private maxDistance;
9
+ private initialFOV;
10
+ private fov;
11
+ private minFOV;
12
+ private maxFOV;
13
+ private targetFOV;
14
+ private minPolarAngle;
15
+ private maxPolarAngle;
16
+ private dampingFactor;
17
+ targetDistance: number;
8
18
  private distance;
9
19
  private targetPhi;
10
20
  private phi;
11
21
  private targetTheta;
12
22
  private theta;
23
+ private dragging;
24
+ private target;
13
25
  private hadTarget;
14
- constructor();
26
+ private rayCaster;
27
+ constructor(collisionsManager: CollisionsManager);
15
28
  private onResize;
16
29
  private onMouseDown;
17
30
  private onMouseUp;
18
31
  private onMouseMove;
19
32
  private onMouseWheel;
20
- setTarget(target: THREE.Vector3): void;
33
+ setTarget(target: Vector3): void;
21
34
  private reverseUpdateFromPositions;
35
+ adjustCameraPosition(): void;
22
36
  update(): void;
23
37
  }
@@ -10,6 +10,7 @@ export type CharacterDescription = {
10
10
  idleAnimationFileUrl: string;
11
11
  jogAnimationFileUrl: string;
12
12
  sprintAnimationFileUrl: string;
13
+ airAnimationFileUrl: string;
13
14
  modelScale: number;
14
15
  };
15
16
  export declare class Character {
@@ -1,5 +1,5 @@
1
1
  import { PositionAndRotation } from "mml-web";
2
- import { Group } from "three";
2
+ import { Group, Vector3 } from "three";
3
3
  import { CameraManager } from "../camera/CameraManager";
4
4
  import { CollisionsManager } from "../collisions/CollisionsManager";
5
5
  import { KeyInputManager } from "../input/KeyInputManager";
@@ -20,9 +20,11 @@ export declare class CharacterManager {
20
20
  remoteCharacterControllers: Map<number, RemoteController>;
21
21
  private characterDescription;
22
22
  character: Character | null;
23
+ private cameraOffsetTarget;
24
+ private cameraOffset;
23
25
  readonly group: Group;
24
26
  constructor(collisionsManager: CollisionsManager, cameraManager: CameraManager, timeManager: TimeManager, inputManager: KeyInputManager, clientStates: Map<number, CharacterState>, sendUpdate: (update: CharacterState) => void);
25
- spawnCharacter(characterDescription: CharacterDescription, id: number, isLocal?: boolean): Promise<Character>;
27
+ spawnCharacter(characterDescription: CharacterDescription, id: number, isLocal?: boolean, spawnPosition?: Vector3): Promise<Character>;
26
28
  getLocalCharacterPositionAndRotation(): PositionAndRotation;
27
29
  clear(): void;
28
30
  update(): void;
@@ -7,5 +7,6 @@ export declare class CharacterMaterial extends MeshPhysicalMaterial {
7
7
  colorsCube216: Color[];
8
8
  constructor();
9
9
  private generateColorCube;
10
+ update(): void;
10
11
  }
11
12
  export {};
@@ -17,10 +17,20 @@ export declare class LocalController {
17
17
  radius: number;
18
18
  segment: Line3;
19
19
  };
20
+ private maxWalkSpeed;
21
+ private maxRunSpeed;
22
+ private gravity;
23
+ private jumpForce;
24
+ private coyoteTimeThreshold;
25
+ private coyoteTime;
26
+ private canJump;
20
27
  private characterOnGround;
28
+ private characterWasOnGround;
29
+ private characterAirborneSince;
30
+ private currentHeight;
21
31
  private characterVelocity;
22
- private gravity;
23
- private upVector;
32
+ private vectorUp;
33
+ private vectorDown;
24
34
  private rotationOffset;
25
35
  private azimuthalAngle;
26
36
  private tempBox;
@@ -28,11 +38,15 @@ export declare class LocalController {
28
38
  private tempSegment;
29
39
  private tempVector;
30
40
  private tempVector2;
31
- private jumpInput;
32
- private jumpForce;
33
- private canJump;
34
- private inputDirections;
35
- private runInput;
41
+ private rayCaster;
42
+ private forward;
43
+ private backward;
44
+ private left;
45
+ private right;
46
+ private run;
47
+ private jump;
48
+ private anyDirection;
49
+ private conflictingDirections;
36
50
  private thirdPersonCamera;
37
51
  private speed;
38
52
  private targetSpeed;
@@ -1,9 +1,14 @@
1
1
  import { AnimationClip, Object3D } from "three";
2
2
  export declare class ModelLoader {
3
- private debug;
3
+ private static instance;
4
4
  private readonly loadingManager;
5
- private readonly fbxLoader;
6
5
  private readonly gltfLoader;
7
- constructor();
6
+ private modelCache;
7
+ private ongoingLoads;
8
+ constructor(maxCacheSize?: number);
9
+ static getInstance(): ModelLoader;
8
10
  load(fileUrl: string, fileType: "model" | "animation"): Promise<Object3D | AnimationClip | undefined>;
11
+ private loadFromUrl;
9
12
  }
13
+ declare const MODEL_LOADER: ModelLoader;
14
+ export default MODEL_LOADER;
@@ -4,17 +4,15 @@ import { AnimationState, CharacterState } from "./CharacterState";
4
4
  export declare class RemoteController {
5
5
  readonly character: Character;
6
6
  readonly id: number;
7
+ private modelLoader;
7
8
  characterModel: Object3D | null;
8
- private loadManager;
9
9
  private animationMixer;
10
10
  private animations;
11
11
  currentAnimation: AnimationState;
12
- private fbxLoader;
13
- private gltfLoader;
14
12
  networkState: CharacterState;
15
13
  constructor(character: Character, id: number);
16
14
  update(clientUpdate: CharacterState, time: number, deltaTime: number): void;
17
- setAnimationFromFile(animationType: AnimationState, fileName: string): void;
15
+ setAnimationFromFile(animationType: AnimationState, fileName: string): Promise<void>;
18
16
  private transitionToAnimation;
19
17
  private updateFromNetwork;
20
18
  }
@@ -1,13 +1,20 @@
1
1
  import { MElement } from "mml-web";
2
- import { Box3, Group, Line3, Scene } from "three";
2
+ import { Box3, Group, Line3, Ray, Scene } from "three";
3
+ import { MeshBVH, MeshBVHVisualizer } from "three-mesh-bvh";
4
+ type CollisionMeshState = {
5
+ source: Group;
6
+ meshBVH: MeshBVH;
7
+ visualizer: MeshBVHVisualizer | null;
8
+ };
3
9
  export declare class CollisionsManager {
4
10
  private debug;
5
11
  private scene;
6
12
  private tempVector;
7
13
  private tempVector2;
8
- private collisionMeshState;
14
+ collisionMeshState: Map<Group, CollisionMeshState>;
9
15
  private collisionTrigger;
10
16
  constructor(scene: Scene);
17
+ raycastFirstDistance(ray: Ray): number | null;
11
18
  private createCollisionMeshState;
12
19
  addMeshesGroup(group: Group, mElement?: MElement): void;
13
20
  updateMeshesGroup(group: Group): void;
@@ -15,3 +22,4 @@ export declare class CollisionsManager {
15
22
  private applyCollider;
16
23
  applyColliders(tempSegment: Line3, radius: number, boundingBox: Box3): void;
17
24
  }
25
+ export {};
@@ -2,3 +2,5 @@ import { Vector3 } from "three";
2
2
  export declare const getSpawnPositionInsideCircle: (radius: number, positions: number, id: number, yPos?: number) => Vector3;
3
3
  export declare const round: (n: number, digits: number) => number;
4
4
  export declare const ease: (target: number, n: number, factor: number) => number;
5
+ export declare function clamp(value: number, min: number, max: number): number;
6
+ export declare const remap: (value: number, minValue: number, maxValue: number, minScaledValue: number, maxScaledValue: number) => number;