@pmndrs/viverse 0.1.2 → 0.1.4
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/dist/camera.d.ts +3 -4
- package/dist/camera.js +4 -6
- package/dist/input/pointer-lock.js +4 -2
- package/dist/simple-character.js +1 -1
- package/package.json +1 -1
package/dist/camera.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Object3D, Vector3, Vector3Tuple, Ray } from 'three';
|
|
2
|
-
import {
|
|
2
|
+
import { SimpleCharacter } from './simple-character.js';
|
|
3
3
|
export declare const FirstPersonCharacterCameraBehavior: SimpleCharacterCameraBehaviorOptions;
|
|
4
4
|
export type SimpleCharacterCameraBehaviorOptions = {
|
|
5
5
|
/**
|
|
@@ -57,15 +57,14 @@ export type SimpleCharacterCameraBehaviorOptions = {
|
|
|
57
57
|
} | boolean;
|
|
58
58
|
export declare class SimpleCharacterCameraBehavior {
|
|
59
59
|
camera: Object3D;
|
|
60
|
-
character:
|
|
61
|
-
inputSystem: InputSystem;
|
|
60
|
+
character: SimpleCharacter;
|
|
62
61
|
private readonly raycast?;
|
|
63
62
|
rotationPitch: number;
|
|
64
63
|
rotationYaw: number;
|
|
65
64
|
zoomDistance: number;
|
|
66
65
|
private collisionFreeZoomDistance;
|
|
67
66
|
private firstUpdate;
|
|
68
|
-
constructor(camera: Object3D, character:
|
|
67
|
+
constructor(camera: Object3D, character: SimpleCharacter, raycast?: ((ray: Ray, far: number) => number | undefined) | undefined);
|
|
69
68
|
private setRotationFromDelta;
|
|
70
69
|
private setDistanceFromDelta;
|
|
71
70
|
private computeCharacterBaseOffset;
|
package/dist/camera.js
CHANGED
|
@@ -14,7 +14,6 @@ const rayHelper = new Ray();
|
|
|
14
14
|
export class SimpleCharacterCameraBehavior {
|
|
15
15
|
camera;
|
|
16
16
|
character;
|
|
17
|
-
inputSystem;
|
|
18
17
|
raycast;
|
|
19
18
|
rotationPitch = (-20 * Math.PI) / 180;
|
|
20
19
|
rotationYaw = 0;
|
|
@@ -22,10 +21,9 @@ export class SimpleCharacterCameraBehavior {
|
|
|
22
21
|
//internal state
|
|
23
22
|
collisionFreeZoomDistance = this.zoomDistance;
|
|
24
23
|
firstUpdate = true;
|
|
25
|
-
constructor(camera, character,
|
|
24
|
+
constructor(camera, character, raycast) {
|
|
26
25
|
this.camera = camera;
|
|
27
26
|
this.character = character;
|
|
28
|
-
this.inputSystem = inputSystem;
|
|
29
27
|
this.raycast = raycast;
|
|
30
28
|
}
|
|
31
29
|
setRotationFromDelta(delta, rotationOptions) {
|
|
@@ -85,8 +83,8 @@ export class SimpleCharacterCameraBehavior {
|
|
|
85
83
|
if (!this.firstUpdate && rotationOptions !== false) {
|
|
86
84
|
rotationOptions = rotationOptions === true ? {} : rotationOptions;
|
|
87
85
|
const rotationSpeed = rotationOptions.speed ?? 1000.0;
|
|
88
|
-
const deltaYaw = this.inputSystem.get(DeltaYawField);
|
|
89
|
-
const deltaPitch = this.inputSystem.get(DeltaPitchField);
|
|
86
|
+
const deltaYaw = this.character.inputSystem.get(DeltaYawField);
|
|
87
|
+
const deltaPitch = this.character.inputSystem.get(DeltaPitchField);
|
|
90
88
|
this.rotationYaw = this.clampYaw(this.rotationYaw + deltaYaw * rotationSpeed * deltaTime, rotationOptions);
|
|
91
89
|
this.rotationPitch = this.clampPitch(this.rotationPitch + deltaPitch * rotationSpeed * deltaTime, rotationOptions);
|
|
92
90
|
}
|
|
@@ -102,7 +100,7 @@ export class SimpleCharacterCameraBehavior {
|
|
|
102
100
|
if (!this.firstUpdate && zoomOptions !== false) {
|
|
103
101
|
zoomOptions = zoomOptions === true ? {} : zoomOptions;
|
|
104
102
|
const zoomSpeed = zoomOptions.speed ?? 1000.0;
|
|
105
|
-
const deltaZoom = this.inputSystem.get(DeltaZoomField);
|
|
103
|
+
const deltaZoom = this.character.inputSystem.get(DeltaZoomField);
|
|
106
104
|
const zoomFactor = 1 + deltaZoom * zoomSpeed * deltaTime;
|
|
107
105
|
if (deltaZoom >= 0) {
|
|
108
106
|
this.zoomDistance *= zoomFactor;
|
|
@@ -12,8 +12,10 @@ export class PointerLockInput {
|
|
|
12
12
|
if (document.pointerLockElement != domElement) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
// Compute based on domElement bounds instead of window.innerHeight
|
|
16
|
+
const rect = domElement.getBoundingClientRect();
|
|
17
|
+
this.deltaYaw -= (0.4 * event.movementX) / rect.height;
|
|
18
|
+
this.deltaPitch -= (0.4 * event.movementY) / rect.height;
|
|
17
19
|
}, {
|
|
18
20
|
signal: this.abortController.signal,
|
|
19
21
|
});
|
package/dist/simple-character.js
CHANGED
|
@@ -288,7 +288,7 @@ export class SimpleCharacter extends Group {
|
|
|
288
288
|
: new InputSystem(domElement, options.input ?? [LocomotionKeyboardInput, PointerCaptureInput]);
|
|
289
289
|
options.physics ??= {};
|
|
290
290
|
// camera behavior
|
|
291
|
-
this.cameraBehavior = new SimpleCharacterCameraBehavior(camera, this,
|
|
291
|
+
this.cameraBehavior = new SimpleCharacterCameraBehavior(camera, this, world.raycast.bind(world));
|
|
292
292
|
// physics
|
|
293
293
|
this.physics = new BvhCharacterPhysics(this, world);
|
|
294
294
|
this.init(camera, options).catch(console.error);
|