diff --git a/packages/dev/core/src/Cameras/arcRotateCamera.ts b/packages/dev/core/src/Cameras/arcRotateCamera.ts index 6aea83e6469..4c35280bf95 100644 --- a/packages/dev/core/src/Cameras/arcRotateCamera.ts +++ b/packages/dev/core/src/Cameras/arcRotateCamera.ts @@ -1040,9 +1040,11 @@ export class ArcRotateCamera extends TargetCamera { } this.inputs.checkInputs(); - let hasUserInteractions = false; + const inertialPanningLimit = this.speed * this._panningEpsilon; + const inertialRotationLimit = this.speed * this._rotationEpsilon; + // Inertia if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) { hasUserInteractions = true; @@ -1062,13 +1064,13 @@ export class ArcRotateCamera extends TargetCamera { this.inertialAlphaOffset *= this.inertia; this.inertialBetaOffset *= this.inertia; this.inertialRadiusOffset *= this.inertia; - if (Math.abs(this.inertialAlphaOffset) < Epsilon) { + if (Math.abs(this.inertialAlphaOffset) < inertialRotationLimit) { this.inertialAlphaOffset = 0; } - if (Math.abs(this.inertialBetaOffset) < Epsilon) { + if (Math.abs(this.inertialBetaOffset) < inertialRotationLimit) { this.inertialBetaOffset = 0; } - if (Math.abs(this.inertialRadiusOffset) < this.speed * Epsilon) { + if (Math.abs(this.inertialRadiusOffset) < inertialRotationLimit) { this.inertialRadiusOffset = 0; } } @@ -1114,10 +1116,10 @@ export class ArcRotateCamera extends TargetCamera { this.inertialPanningX *= this.panningInertia; this.inertialPanningY *= this.panningInertia; - if (Math.abs(this.inertialPanningX) < this.speed * Epsilon) { + if (Math.abs(this.inertialPanningX) < inertialPanningLimit) { this.inertialPanningX = 0; } - if (Math.abs(this.inertialPanningY) < this.speed * Epsilon) { + if (Math.abs(this.inertialPanningY) < inertialPanningLimit) { this.inertialPanningY = 0; } } diff --git a/packages/dev/core/src/Cameras/targetCamera.ts b/packages/dev/core/src/Cameras/targetCamera.ts index 1563b7258d1..a71cd7fdfbe 100644 --- a/packages/dev/core/src/Cameras/targetCamera.ts +++ b/packages/dev/core/src/Cameras/targetCamera.ts @@ -75,6 +75,19 @@ export class TargetCamera extends Camera { */ public inverseRotationSpeed = 0.2; + /** + * @internal + * @experimental + * Can be used to change clamping behavior for inertia. Hook into onBeforeRenderObservable to change the value per-frame + */ + public _panningEpsilon = Epsilon; + /** + * @internal + * @experimental + * Can be used to change clamping behavior for inertia. Hook into onBeforeRenderObservable to change the value per-frame + */ + public _rotationEpsilon = Epsilon; + /** * Define the current target of the camera as an object or a position. * Please note that locking a target will disable panning. @@ -391,28 +404,30 @@ export class TargetCamera extends Camera { } } + const inertialPanningLimit = this.speed * this._panningEpsilon; + const inertialRotationLimit = this.speed * this._rotationEpsilon; // Inertia if (needToMove) { - if (Math.abs(this.cameraDirection.x) < this.speed * Epsilon) { + if (Math.abs(this.cameraDirection.x) < inertialPanningLimit) { this.cameraDirection.x = 0; } - if (Math.abs(this.cameraDirection.y) < this.speed * Epsilon) { + if (Math.abs(this.cameraDirection.y) < inertialPanningLimit) { this.cameraDirection.y = 0; } - if (Math.abs(this.cameraDirection.z) < this.speed * Epsilon) { + if (Math.abs(this.cameraDirection.z) < inertialPanningLimit) { this.cameraDirection.z = 0; } this.cameraDirection.scaleInPlace(this.inertia); } if (needToRotate) { - if (Math.abs(this.cameraRotation.x) < this.speed * Epsilon) { + if (Math.abs(this.cameraRotation.x) < inertialRotationLimit) { this.cameraRotation.x = 0; } - if (Math.abs(this.cameraRotation.y) < this.speed * Epsilon) { + if (Math.abs(this.cameraRotation.y) < inertialRotationLimit) { this.cameraRotation.y = 0; } this.cameraRotation.scaleInPlace(this.inertia);