@splnlss/3d-story-viewer 0.6.0 → 0.7.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/build/viewer.js CHANGED
@@ -27380,6 +27380,16 @@ class GaussianSplatLayer extends ContentLayer {
27380
27380
  this.callbacks = {};
27381
27381
  }
27382
27382
  }
27383
+ function applyKeyboardMovement(position, forward, right, up, state, deltaTime, movementSpeed, boostMultiplier) {
27384
+ const boost = state.BOOST ? boostMultiplier : 1;
27385
+ const distance = movementSpeed * deltaTime * boost;
27386
+ if (state.FRONT) position.addScaledVector(forward, distance);
27387
+ if (state.BACK) position.addScaledVector(forward, -distance);
27388
+ if (state.LEFT) position.addScaledVector(right, -distance);
27389
+ if (state.RIGHT) position.addScaledVector(right, distance);
27390
+ if (state.UP) position.addScaledVector(up, distance);
27391
+ if (state.DOWN) position.addScaledVector(up, -distance);
27392
+ }
27383
27393
  const shadowCanvas = document.createElement("canvas");
27384
27394
  shadowCanvas.width = 128;
27385
27395
  shadowCanvas.height = 128;
@@ -27477,7 +27487,9 @@ class Viewer extends EventDispatcher {
27477
27487
  this.pointerCoords = {};
27478
27488
  this.pointerXYZ = new Vector3();
27479
27489
  this.keysDown = {};
27480
- this.keysEnabled = true;
27490
+ this._keysEnabled = true;
27491
+ this.movementSpeed = 100;
27492
+ this.boostMultiplier = 5;
27481
27493
  this.movementKeys = {
27482
27494
  BOOST: ["ShiftLeft", "ShiftRight"],
27483
27495
  FRONT: ["KeyW"],
@@ -27497,6 +27509,7 @@ class Viewer extends EventDispatcher {
27497
27509
  DOWN: false
27498
27510
  };
27499
27511
  this._onKeyDown = (event) => {
27512
+ if (event.repeat && !this.keysDown[event.code]) return;
27500
27513
  this.keysDown[event.code] = true;
27501
27514
  this.updateMovementState();
27502
27515
  };
@@ -27545,6 +27558,15 @@ class Viewer extends EventDispatcher {
27545
27558
  window.addEventListener("pointermove", this._onPointerMove);
27546
27559
  this.setAnimate();
27547
27560
  }
27561
+ get keysEnabled() {
27562
+ return this._keysEnabled;
27563
+ }
27564
+ set keysEnabled(enabled) {
27565
+ if (enabled === this._keysEnabled) return;
27566
+ this._keysEnabled = enabled;
27567
+ this.keysDown = {};
27568
+ for (const key in this.movementState) this.movementState[key] = false;
27569
+ }
27548
27570
  updateMovementState() {
27549
27571
  if (!this.keysEnabled) return;
27550
27572
  for (const key in this.movementKeys) {
@@ -27815,24 +27837,8 @@ class Viewer extends EventDispatcher {
27815
27837
  this.updateCameraDirections();
27816
27838
  this.cameraCoords = ecefToGeodeticRotation(this.camera.position.x, this.camera.position.y, this.camera.position.z, this.camera.quaternion);
27817
27839
  this.sky.setSurfaceUp(geodeticToEcefUpVector(this.cameraCoords.lon, this.cameraCoords.lat));
27818
- const boost = this.movementState.BOOST ? 5 : 1;
27819
- if (this.movementState.FRONT) {
27820
- this.camera.position.addScaledVector(this.cameraForward, 100 * deltaTime * boost);
27821
- }
27822
- if (this.movementState.BACK) {
27823
- this.camera.position.addScaledVector(this.cameraForward, -100 * deltaTime * boost);
27824
- }
27825
- if (this.movementState.LEFT) {
27826
- this.camera.position.addScaledVector(this.cameraRight, -100 * deltaTime * boost);
27827
- }
27828
- if (this.movementState.RIGHT) {
27829
- this.camera.position.addScaledVector(this.cameraRight, 100 * deltaTime * boost);
27830
- }
27831
- if (this.movementState.UP) {
27832
- this.camera.position.addScaledVector(this.cameraUp, 100 * deltaTime * boost);
27833
- }
27834
- if (this.movementState.DOWN) {
27835
- this.camera.position.addScaledVector(this.cameraUp, -100 * deltaTime * boost);
27840
+ if (this.keysEnabled) {
27841
+ applyKeyboardMovement(this.camera.position, this.cameraForward, this.cameraRight, this.cameraUp, this.movementState, deltaTime, this.movementSpeed, this.boostMultiplier);
27836
27842
  }
27837
27843
  this.globeManager.update();
27838
27844
  for (let i2 = 0; i2 < this.content.children.length; i2++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splnlss/3d-story-viewer",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"