Skip to content

Commit

Permalink
fix(viewer-lib): Fixes two issues regarding very small scale streams (#…
Browse files Browse the repository at this point in the history
…3930)

- The orbit controller would not properly report changes in camera movement on a per frame basis becuase of a hardcoded epsilon which was not small enough for very small scenes. Now the epsilon is dynamically computed
- WASD-ing would jitter in very small scenes because of a too large normalization value sent to the position dampers. Now that value is also dynamically computed for small scenes
  • Loading branch information
AlexandruPopovici authored Feb 4, 2025
1 parent 2d5ff8e commit 065c242
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/viewer-sandbox/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,10 @@ const getStream = () => {
// 'https://latest.speckle.systems/projects/db06488e1c/models/21f3930771'

// FAR OFF
// // 'https://app.speckle.systems/projects/bdd828221e/models/eb99326dc3'
// 'https://latest.speckle.systems/projects/5e9c38fae7/models/d44c54b6b7'
// 'https://app.speckle.systems/projects/bdd828221e/models/eb99326dc3'

// SUPER TINY
// 'https://latest.speckle.systems/projects/6631c0378c/models/4fed65a49c'

// v2 colored lines
// 'https://app.speckle.systems/projects/052b576a45/models/c756235fcc'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ class FlyControls extends SpeckleControls {

protected updatePositionRotation(delta: number) {
const diagonal = this.world.worldBox.min.distanceTo(this.world.worldBox.max)
const minMaxRange = diagonal < 1 ? diagonal : 1
/** For very small values, the dampners need even smaller normalization */
const minMaxRange = diagonal < 1 ? this.world.getRelativeOffset(diagonal) : 1
this.position.x = this.positionXDamper.update(
this.position.x,
this.goalPosition.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,16 @@ export class SmoothOrbitControls extends SpeckleControls {
const mat = this.orbitSphere.material as SpeckleBasicMaterial
mat.userData.billboardPos.value.copy(spherePos)

/** We'd rather have a palpable epsilon for regular sized streams, but also
* compute a custom one for microscopic ones
*/
const epsilon = Math.min(
MOVEMENT_EPSILON,
this.world.getRelativeOffset(MOVEMENT_EPSILON)
)
return (
lastCameraPos.sub(this._targetCamera.position).length() > MOVEMENT_EPSILON ||
lastCameraQuat.angleTo(this._targetCamera.quaternion) > MOVEMENT_EPSILON
lastCameraPos.sub(this._targetCamera.position).length() > epsilon ||
lastCameraQuat.angleTo(this._targetCamera.quaternion) > epsilon
)
}

Expand Down

0 comments on commit 065c242

Please sign in to comment.