@pmndrs/viverse 0.1.3 → 0.1.5

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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <h1 align="center">@pmndrs/viverse</h1>
2
- <h3 align="center">Build 3D web games with threejs and viverse.</h3>
2
+ <h3 align="center">Toolkit for building Three.js Apps for Viverse and beyond.</h3>
3
3
  <br/>
4
4
 
5
5
  <p align="center">
@@ -26,7 +26,7 @@ npm install three @react-three/fiber @react-three/viverse
26
26
  | A prototype map with the `SimpleCharacter` class and its default model. | ![render of the code below](../../docs/getting-started/basic-example.gif) |
27
27
  | --------------------------------------------------------------------------- | --------------------------------------------------------------------- |
28
28
 
29
- ```jsx
29
+ ```tsx
30
30
  const world = new BvhPhysicsWorld()
31
31
  world.addFixedBody(ground.scene)
32
32
  const character = new SimpleCharacter(camera, world, canvas, { model: { url: profile.activeAvatar?.vrmUrl } })
package/dist/camera.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Object3D, Vector3, Vector3Tuple, Ray } from 'three';
2
- import { type InputSystem } from './input/index.js';
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: Object3D;
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: Object3D, inputSystem: InputSystem, raycast?: ((ray: Ray, far: number) => number | undefined) | undefined);
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, inputSystem, raycast) {
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
- this.deltaYaw -= (0.4 * event.movementX) / window.innerHeight;
16
- this.deltaPitch -= (0.4 * event.movementY) / window.innerHeight;
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
  });
@@ -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, this.inputSystem, world.raycast.bind(world));
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmndrs/viverse",
3
- "description": "Toolkit for building and publishing Threejs Apps to Viverse.",
3
+ "description": "Toolkit for building Three.js Apps for Viverse and beyond.",
4
4
  "author": "Bela Bohlender",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://github.com/pmndrs/viverse",
@@ -21,7 +21,7 @@
21
21
  "peerDependencies": {
22
22
  "three": "*"
23
23
  },
24
- "version": "0.1.3",
24
+ "version": "0.1.5",
25
25
  "type": "module",
26
26
  "dependencies": {
27
27
  "@pixiv/three-vrm": "^3.4.2",