@pmndrs/viverse 0.2.20 → 0.2.22
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.js +10 -6
- package/dist/model/index.js +1 -1
- package/package.json +1 -1
package/dist/camera.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Vector3, Euler, Ray
|
|
1
|
+
import { Vector3, Euler, Ray } from 'three';
|
|
2
2
|
import { clamp } from 'three/src/math/MathUtils.js';
|
|
3
3
|
import { RotatePitchAction, RotateYawAction, ZoomAction } from './action/index.js';
|
|
4
4
|
export const FirstPersonCharacterCameraBehavior = {
|
|
@@ -11,7 +11,7 @@ const sphericalOffset = new Vector3();
|
|
|
11
11
|
const characterWorldPosition = new Vector3();
|
|
12
12
|
const euler = new Euler();
|
|
13
13
|
const rayHelper = new Ray();
|
|
14
|
-
const
|
|
14
|
+
const upAxisHelper = new Vector3(0, 1, 0);
|
|
15
15
|
export class CharacterCameraBehavior {
|
|
16
16
|
rotationPitch = (-20 * Math.PI) / 180;
|
|
17
17
|
rotationYaw = 0;
|
|
@@ -71,8 +71,10 @@ export class CharacterCameraBehavior {
|
|
|
71
71
|
}
|
|
72
72
|
//compute character->camera delta through offset
|
|
73
73
|
this.computeCharacterBaseOffset(chracterBaseOffsetHelper, options.characterBaseOffset);
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
// Rotate the offset by the camera yaw (camera-relative), not the character's body
|
|
75
|
+
// facing: an over-the-shoulder offset then tracks the view instead of swimming with
|
|
76
|
+
// the character, and a purely vertical offset (default / first-person) is unchanged.
|
|
77
|
+
chracterBaseOffsetHelper.applyAxisAngle(upAxisHelper, this.rotationYaw);
|
|
76
78
|
target.getWorldPosition(characterWorldPosition);
|
|
77
79
|
characterWorldPosition.add(chracterBaseOffsetHelper);
|
|
78
80
|
camera.getWorldPosition(deltaHelper);
|
|
@@ -131,8 +133,10 @@ export class CharacterCameraBehavior {
|
|
|
131
133
|
sphericalOffset.applyEuler(camera.rotation);
|
|
132
134
|
// Get target position with offset (reuse helper vector)
|
|
133
135
|
this.computeCharacterBaseOffset(chracterBaseOffsetHelper, options.characterBaseOffset);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
// Rotate the offset by the camera yaw (camera-relative), not the character's body
|
|
137
|
+
// facing: an over-the-shoulder offset then tracks the view instead of swimming with
|
|
138
|
+
// the character, and a purely vertical offset (default / first-person) is unchanged.
|
|
139
|
+
chracterBaseOffsetHelper.applyAxisAngle(upAxisHelper, this.rotationYaw);
|
|
136
140
|
target.getWorldPosition(characterWorldPosition);
|
|
137
141
|
characterWorldPosition.add(chracterBaseOffsetHelper);
|
|
138
142
|
// Set camera position relative to target
|
package/dist/model/index.js
CHANGED
|
@@ -24,7 +24,7 @@ export async function loadCharacterModel(url, type, boneRotationOffset, castShad
|
|
|
24
24
|
//prepare loading the default model
|
|
25
25
|
type = 'gltf';
|
|
26
26
|
url = (await import('../assets/mannequin.js')).url;
|
|
27
|
-
boneRotationOffset = new Quaternion().setFromEuler(new Euler(Math.PI, 0, Math.PI / 2, 'ZYX'));
|
|
27
|
+
boneRotationOffset = new Quaternion().setFromEuler(new Euler(Math.PI / 2, 0, Math.PI / 2, 'ZYX'));
|
|
28
28
|
}
|
|
29
29
|
if (type == null) {
|
|
30
30
|
if (url.endsWith('.gltf') || url.endsWith('.glb')) {
|