@babylonjs/core 8.0.0 → 8.0.1

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.
@@ -80,11 +80,8 @@ export class ArcRotateCameraMouseWheelInput {
80
80
  // this will stop multiple scroll events zooming in from adding too much inertia
81
81
  if (delta > 0) {
82
82
  let estimatedTargetRadius = this.camera.radius;
83
- let targetInertia = this.camera.inertialRadiusOffset + delta;
84
- for (let i = 0; i < 20 && Math.abs(targetInertia) > 0.001; i++) {
85
- estimatedTargetRadius -= targetInertia;
86
- targetInertia *= this.camera.inertia;
87
- }
83
+ const targetInertia = this.camera.inertialRadiusOffset + delta;
84
+ estimatedTargetRadius -= targetInertia;
88
85
  estimatedTargetRadius = Clamp(estimatedTargetRadius, 0, Number.MAX_VALUE);
89
86
  delta = this._computeDeltaFromMouseWheelLegacyEvent(wheelDelta, estimatedTargetRadius);
90
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"arcRotateCameraMouseWheelInput.js","sourceRoot":"","sources":["../../../../../dev/core/src/Cameras/Inputs/arcRotateCameraMouseWheelInput.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAIlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,YAAY,G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,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC;YAC5B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC;YAC5B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC;YAC5B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;IACL,CAAC;CACJ;AA9OU;IADN,SAAS,EAAE;sEACgB;AAOrB;IADN,SAAS,EAAE;2EACuB;AAO5B;IADN,SAAS,EAAE;4EACoB;AAkO9B,gBAAiB,CAAC,gCAAgC,CAAC,GAAG,8BAA8B,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { EventState, Observer } from \"../../Misc/observable\";\r\nimport type { ArcRotateCamera } from \"../../Cameras/arcRotateCamera\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport type { PointerInfo } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport { Plane } from \"../../Maths/math.plane\";\r\nimport { Vector3, Matrix, TmpVectors } from \"../../Maths/math.vector\";\r\nimport { Epsilon } from \"../../Maths/math.constants\";\r\nimport type { IWheelEvent } from \"../../Events/deviceInputEvents\";\r\nimport { EventConstants } from \"../../Events/deviceInputEvents\";\r\nimport { Clamp } from \"../../Maths/math.scalar.functions\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Firefox uses a different scheme to report scroll distances to other\r\n * browsers. Rather than use complicated methods to calculate the exact\r\n * multiple we need to apply, let's just cheat and use a constant.\r\n * https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode\r\n * https://stackoverflow.com/questions/20110224/what-is-the-height-of-a-line-in-a-wheel-event-deltamode-dom-delta-line\r\n */\r\nconst ffMultiplier = 40;\r\n\r\n/**\r\n * Manage the mouse wheel inputs to control an arc rotate camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCamera> {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: ArcRotateCamera;\r\n\r\n /**\r\n * Gets or Set the mouse wheel precision or how fast is the camera zooming.\r\n */\r\n @serialize()\r\n public wheelPrecision = 3.0;\r\n\r\n /**\r\n * Gets or Set the boolean value that controls whether or not the mouse wheel\r\n * zooms to the location of the mouse pointer or not. The default is false.\r\n */\r\n @serialize()\r\n public zoomToMouseLocation = false;\r\n\r\n /**\r\n * wheelDeltaPercentage will be used instead of wheelPrecision if different from 0.\r\n * It defines the percentage of current camera.radius to use as delta when wheel is used.\r\n */\r\n @serialize()\r\n public wheelDeltaPercentage = 0;\r\n\r\n /**\r\n * If set, this function will be used to set the radius delta that will be added to the current camera radius\r\n */\r\n public customComputeDeltaFromMouseWheel: Nullable<(wheelDelta: number, input: ArcRotateCameraMouseWheelInput, event: IWheelEvent) => number> = null;\r\n\r\n private _wheel: Nullable<(p: PointerInfo, s: EventState) => void>;\r\n private _observer: Nullable<Observer<PointerInfo>>;\r\n private _hitPlane: Nullable<Plane>;\r\n private _viewOffset: Vector3 = new Vector3(0, 0, 0);\r\n private _globalOffset: Vector3 = new Vector3(0, 0, 0);\r\n\r\n protected _computeDeltaFromMouseWheelLegacyEvent(mouseWheelDelta: number, radius: number) {\r\n let delta = 0;\r\n const wheelDelta = mouseWheelDelta * 0.01 * this.wheelDeltaPercentage * radius;\r\n if (mouseWheelDelta > 0) {\r\n delta = wheelDelta / (1.0 + this.wheelDeltaPercentage);\r\n } else {\r\n delta = wheelDelta * (1.0 + this.wheelDeltaPercentage);\r\n }\r\n return delta;\r\n }\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n this._wheel = (p) => {\r\n //sanity check - this should be a PointerWheel event.\r\n if (p.type !== PointerEventTypes.POINTERWHEEL) {\r\n return;\r\n }\r\n const event = <IWheelEvent>p.event;\r\n let delta = 0;\r\n const platformScale = event.deltaMode === EventConstants.DOM_DELTA_LINE ? ffMultiplier : 1; // If this happens to be set to DOM_DELTA_LINE, adjust accordingly\r\n\r\n const wheelDelta = -(event.deltaY * platformScale);\r\n\r\n if (this.customComputeDeltaFromMouseWheel) {\r\n delta = this.customComputeDeltaFromMouseWheel(wheelDelta, this, event);\r\n } else {\r\n if (this.wheelDeltaPercentage) {\r\n delta = this._computeDeltaFromMouseWheelLegacyEvent(wheelDelta, this.camera.radius);\r\n\r\n // If zooming in, estimate the target radius and use that to compute the delta for inertia\r\n // this will stop multiple scroll events zooming in from adding too much inertia\r\n if (delta > 0) {\r\n let estimatedTargetRadius = this.camera.radius;\r\n let targetInertia = this.camera.inertialRadiusOffset + delta;\r\n for (let i = 0; i < 20 && Math.abs(targetInertia) > 0.001; i++) {\r\n estimatedTargetRadius -= targetInertia;\r\n targetInertia *= this.camera.inertia;\r\n }\r\n estimatedTargetRadius = Clamp(estimatedTargetRadius, 0, Number.MAX_VALUE);\r\n delta = this._computeDeltaFromMouseWheelLegacyEvent(wheelDelta, estimatedTargetRadius);\r\n }\r\n } else {\r\n delta = wheelDelta / (this.wheelPrecision * 40);\r\n }\r\n }\r\n\r\n if (delta) {\r\n if (this.zoomToMouseLocation) {\r\n // If we are zooming to the mouse location, then we need to get the hit plane at the start of the zoom gesture if it doesn't exist\r\n // The hit plane is normally calculated after the first motion and each time there's motion so if we don't do this first,\r\n // the first zoom will be to the center of the screen\r\n if (!this._hitPlane) {\r\n this._updateHitPlane();\r\n }\r\n\r\n this._zoomToMouse(delta);\r\n } else {\r\n this.camera.inertialRadiusOffset += delta;\r\n }\r\n }\r\n\r\n if (event.preventDefault) {\r\n if (!noPreventDefault) {\r\n event.preventDefault();\r\n }\r\n }\r\n };\r\n\r\n this._observer = this.camera.getScene()._inputManager._addCameraPointerObserver(this._wheel, PointerEventTypes.POINTERWHEEL);\r\n\r\n if (this.zoomToMouseLocation) {\r\n this._inertialPanning.setAll(0);\r\n }\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n if (this._observer) {\r\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\r\n this._observer = null;\r\n this._wheel = null;\r\n }\r\n }\r\n\r\n /**\r\n * Update the current camera state depending on the inputs that have been used this frame.\r\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\r\n */\r\n public checkInputs(): void {\r\n if (!this.zoomToMouseLocation) {\r\n return;\r\n }\r\n\r\n const camera = this.camera;\r\n const motion = 0.0 + camera.inertialAlphaOffset + camera.inertialBetaOffset + camera.inertialRadiusOffset;\r\n if (motion) {\r\n // if zooming is still happening as a result of inertia, then we also need to update\r\n // the hit plane.\r\n this._updateHitPlane();\r\n\r\n // Note we cannot use arcRotateCamera.inertialPlanning here because arcRotateCamera panning\r\n // uses a different panningInertia which could cause this panning to get out of sync with\r\n // the zooming, and for this to work they must be exactly in sync.\r\n camera.target.addInPlace(this._inertialPanning);\r\n this._inertialPanning.scaleInPlace(camera.inertia);\r\n this._zeroIfClose(this._inertialPanning);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ArcRotateCameraMouseWheelInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"mousewheel\";\r\n }\r\n\r\n private _updateHitPlane() {\r\n const camera = this.camera;\r\n const direction = camera.target.subtract(camera.position);\r\n this._hitPlane = Plane.FromPositionAndNormal(camera.target, direction);\r\n }\r\n\r\n // Get position on the hit plane\r\n private _getPosition(): Vector3 {\r\n const camera = this.camera;\r\n const scene = camera.getScene();\r\n\r\n // since the _hitPlane is always updated to be orthogonal to the camera position vector\r\n // we don't have to worry about this ray shooting off to infinity. This ray creates\r\n // a vector defining where we want to zoom to.\r\n const ray = scene.createPickingRay(scene.pointerX, scene.pointerY, Matrix.Identity(), camera, false);\r\n // Since the camera is the origin of the picking ray, we need to offset it by the camera's offset manually\r\n // Because the offset is in view space, we need to convert it to world space first\r\n if (camera.targetScreenOffset.x !== 0 || camera.targetScreenOffset.y !== 0) {\r\n this._viewOffset.set(camera.targetScreenOffset.x, camera.targetScreenOffset.y, 0);\r\n camera.getViewMatrix().invertToRef(camera._cameraTransformMatrix);\r\n this._globalOffset = Vector3.TransformNormal(this._viewOffset, camera._cameraTransformMatrix);\r\n ray.origin.addInPlace(this._globalOffset);\r\n }\r\n\r\n let distance = 0;\r\n if (this._hitPlane) {\r\n distance = ray.intersectsPlane(this._hitPlane) ?? 0;\r\n }\r\n\r\n // not using this ray again, so modifying its vectors here is fine\r\n return ray.origin.addInPlace(ray.direction.scaleInPlace(distance));\r\n }\r\n\r\n private _inertialPanning: Vector3 = Vector3.Zero();\r\n\r\n private _zoomToMouse(delta: number) {\r\n const camera = this.camera;\r\n const inertiaComp = 1 - camera.inertia;\r\n if (camera.lowerRadiusLimit) {\r\n const lowerLimit = camera.lowerRadiusLimit ?? 0;\r\n if (camera.radius - (camera.inertialRadiusOffset + delta) / inertiaComp < lowerLimit) {\r\n delta = (camera.radius - lowerLimit) * inertiaComp - camera.inertialRadiusOffset;\r\n }\r\n }\r\n if (camera.upperRadiusLimit) {\r\n const upperLimit = camera.upperRadiusLimit ?? 0;\r\n if (camera.radius - (camera.inertialRadiusOffset + delta) / inertiaComp > upperLimit) {\r\n delta = (camera.radius - upperLimit) * inertiaComp - camera.inertialRadiusOffset;\r\n }\r\n }\r\n\r\n const zoomDistance = delta / inertiaComp;\r\n const ratio = zoomDistance / camera.radius;\r\n const vec = this._getPosition();\r\n\r\n // Now this vector tells us how much we also need to pan the camera\r\n // so the targeted mouse location becomes the center of zooming.\r\n\r\n const directionToZoomLocation = TmpVectors.Vector3[6];\r\n vec.subtractToRef(camera.target, directionToZoomLocation);\r\n directionToZoomLocation.scaleInPlace(ratio);\r\n directionToZoomLocation.scaleInPlace(inertiaComp);\r\n this._inertialPanning.addInPlace(directionToZoomLocation);\r\n\r\n camera.inertialRadiusOffset += delta;\r\n }\r\n\r\n // Sets x y or z of passed in vector to zero if less than Epsilon.\r\n private _zeroIfClose(vec: Vector3) {\r\n if (Math.abs(vec.x) < Epsilon) {\r\n vec.x = 0;\r\n }\r\n if (Math.abs(vec.y) < Epsilon) {\r\n vec.y = 0;\r\n }\r\n if (Math.abs(vec.z) < Epsilon) {\r\n vec.z = 0;\r\n }\r\n }\r\n}\r\n\r\n(<any>CameraInputTypes)[\"ArcRotateCameraMouseWheelInput\"] = ArcRotateCameraMouseWheelInput;\r\n"]}
1
+ {"version":3,"file":"arcRotateCameraMouseWheelInput.js","sourceRoot":"","sources":["../../../../../dev/core/src/Cameras/Inputs/arcRotateCameraMouseWheelInput.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAIlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,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,OAAO,EAAE,CAAC;YAC5B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC;YAC5B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC;YAC5B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;IACL,CAAC;CACJ;AA3OU;IADN,SAAS,EAAE;sEACgB;AAOrB;IADN,SAAS,EAAE;2EACuB;AAO5B;IADN,SAAS,EAAE;4EACoB;AA+N9B,gBAAiB,CAAC,gCAAgC,CAAC,GAAG,8BAA8B,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { EventState, Observer } from \"../../Misc/observable\";\r\nimport type { ArcRotateCamera } from \"../../Cameras/arcRotateCamera\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport type { PointerInfo } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport { Plane } from \"../../Maths/math.plane\";\r\nimport { Vector3, Matrix, TmpVectors } from \"../../Maths/math.vector\";\r\nimport { Epsilon } from \"../../Maths/math.constants\";\r\nimport type { IWheelEvent } from \"../../Events/deviceInputEvents\";\r\nimport { EventConstants } from \"../../Events/deviceInputEvents\";\r\nimport { Clamp } from \"../../Maths/math.scalar.functions\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Firefox uses a different scheme to report scroll distances to other\r\n * browsers. Rather than use complicated methods to calculate the exact\r\n * multiple we need to apply, let's just cheat and use a constant.\r\n * https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode\r\n * https://stackoverflow.com/questions/20110224/what-is-the-height-of-a-line-in-a-wheel-event-deltamode-dom-delta-line\r\n */\r\nconst ffMultiplier = 40;\r\n\r\n/**\r\n * Manage the mouse wheel inputs to control an arc rotate camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCamera> {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: ArcRotateCamera;\r\n\r\n /**\r\n * Gets or Set the mouse wheel precision or how fast is the camera zooming.\r\n */\r\n @serialize()\r\n public wheelPrecision = 3.0;\r\n\r\n /**\r\n * Gets or Set the boolean value that controls whether or not the mouse wheel\r\n * zooms to the location of the mouse pointer or not. The default is false.\r\n */\r\n @serialize()\r\n public zoomToMouseLocation = false;\r\n\r\n /**\r\n * wheelDeltaPercentage will be used instead of wheelPrecision if different from 0.\r\n * It defines the percentage of current camera.radius to use as delta when wheel is used.\r\n */\r\n @serialize()\r\n public wheelDeltaPercentage = 0;\r\n\r\n /**\r\n * If set, this function will be used to set the radius delta that will be added to the current camera radius\r\n */\r\n public customComputeDeltaFromMouseWheel: Nullable<(wheelDelta: number, input: ArcRotateCameraMouseWheelInput, event: IWheelEvent) => number> = null;\r\n\r\n private _wheel: Nullable<(p: PointerInfo, s: EventState) => void>;\r\n private _observer: Nullable<Observer<PointerInfo>>;\r\n private _hitPlane: Nullable<Plane>;\r\n private _viewOffset: Vector3 = new Vector3(0, 0, 0);\r\n private _globalOffset: Vector3 = new Vector3(0, 0, 0);\r\n\r\n protected _computeDeltaFromMouseWheelLegacyEvent(mouseWheelDelta: number, radius: number) {\r\n let delta = 0;\r\n const wheelDelta = mouseWheelDelta * 0.01 * this.wheelDeltaPercentage * radius;\r\n if (mouseWheelDelta > 0) {\r\n delta = wheelDelta / (1.0 + this.wheelDeltaPercentage);\r\n } else {\r\n delta = wheelDelta * (1.0 + this.wheelDeltaPercentage);\r\n }\r\n return delta;\r\n }\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n this._wheel = (p) => {\r\n //sanity check - this should be a PointerWheel event.\r\n if (p.type !== PointerEventTypes.POINTERWHEEL) {\r\n return;\r\n }\r\n const event = <IWheelEvent>p.event;\r\n let delta = 0;\r\n const platformScale = event.deltaMode === EventConstants.DOM_DELTA_LINE ? ffMultiplier : 1; // If this happens to be set to DOM_DELTA_LINE, adjust accordingly\r\n\r\n const wheelDelta = -(event.deltaY * platformScale);\r\n\r\n if (this.customComputeDeltaFromMouseWheel) {\r\n delta = this.customComputeDeltaFromMouseWheel(wheelDelta, this, event);\r\n } else {\r\n if (this.wheelDeltaPercentage) {\r\n delta = this._computeDeltaFromMouseWheelLegacyEvent(wheelDelta, this.camera.radius);\r\n\r\n // If zooming in, estimate the target radius and use that to compute the delta for inertia\r\n // this will stop multiple scroll events zooming in from adding too much inertia\r\n if (delta > 0) {\r\n let estimatedTargetRadius = this.camera.radius;\r\n const targetInertia = this.camera.inertialRadiusOffset + delta;\r\n estimatedTargetRadius -= targetInertia;\r\n estimatedTargetRadius = Clamp(estimatedTargetRadius, 0, Number.MAX_VALUE);\r\n delta = this._computeDeltaFromMouseWheelLegacyEvent(wheelDelta, estimatedTargetRadius);\r\n }\r\n } else {\r\n delta = wheelDelta / (this.wheelPrecision * 40);\r\n }\r\n }\r\n\r\n if (delta) {\r\n if (this.zoomToMouseLocation) {\r\n // If we are zooming to the mouse location, then we need to get the hit plane at the start of the zoom gesture if it doesn't exist\r\n // The hit plane is normally calculated after the first motion and each time there's motion so if we don't do this first,\r\n // the first zoom will be to the center of the screen\r\n if (!this._hitPlane) {\r\n this._updateHitPlane();\r\n }\r\n\r\n this._zoomToMouse(delta);\r\n } else {\r\n this.camera.inertialRadiusOffset += delta;\r\n }\r\n }\r\n\r\n if (event.preventDefault) {\r\n if (!noPreventDefault) {\r\n event.preventDefault();\r\n }\r\n }\r\n };\r\n\r\n this._observer = this.camera.getScene()._inputManager._addCameraPointerObserver(this._wheel, PointerEventTypes.POINTERWHEEL);\r\n\r\n if (this.zoomToMouseLocation) {\r\n this._inertialPanning.setAll(0);\r\n }\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n if (this._observer) {\r\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\r\n this._observer = null;\r\n this._wheel = null;\r\n }\r\n }\r\n\r\n /**\r\n * Update the current camera state depending on the inputs that have been used this frame.\r\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\r\n */\r\n public checkInputs(): void {\r\n if (!this.zoomToMouseLocation) {\r\n return;\r\n }\r\n\r\n const camera = this.camera;\r\n const motion = 0.0 + camera.inertialAlphaOffset + camera.inertialBetaOffset + camera.inertialRadiusOffset;\r\n if (motion) {\r\n // if zooming is still happening as a result of inertia, then we also need to update\r\n // the hit plane.\r\n this._updateHitPlane();\r\n\r\n // Note we cannot use arcRotateCamera.inertialPlanning here because arcRotateCamera panning\r\n // uses a different panningInertia which could cause this panning to get out of sync with\r\n // the zooming, and for this to work they must be exactly in sync.\r\n camera.target.addInPlace(this._inertialPanning);\r\n this._inertialPanning.scaleInPlace(camera.inertia);\r\n this._zeroIfClose(this._inertialPanning);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ArcRotateCameraMouseWheelInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"mousewheel\";\r\n }\r\n\r\n private _updateHitPlane() {\r\n const camera = this.camera;\r\n const direction = camera.target.subtract(camera.position);\r\n this._hitPlane = Plane.FromPositionAndNormal(camera.target, direction);\r\n }\r\n\r\n // Get position on the hit plane\r\n private _getPosition(): Vector3 {\r\n const camera = this.camera;\r\n const scene = camera.getScene();\r\n\r\n // since the _hitPlane is always updated to be orthogonal to the camera position vector\r\n // we don't have to worry about this ray shooting off to infinity. This ray creates\r\n // a vector defining where we want to zoom to.\r\n const ray = scene.createPickingRay(scene.pointerX, scene.pointerY, Matrix.Identity(), camera, false);\r\n // Since the camera is the origin of the picking ray, we need to offset it by the camera's offset manually\r\n // Because the offset is in view space, we need to convert it to world space first\r\n if (camera.targetScreenOffset.x !== 0 || camera.targetScreenOffset.y !== 0) {\r\n this._viewOffset.set(camera.targetScreenOffset.x, camera.targetScreenOffset.y, 0);\r\n camera.getViewMatrix().invertToRef(camera._cameraTransformMatrix);\r\n this._globalOffset = Vector3.TransformNormal(this._viewOffset, camera._cameraTransformMatrix);\r\n ray.origin.addInPlace(this._globalOffset);\r\n }\r\n\r\n let distance = 0;\r\n if (this._hitPlane) {\r\n distance = ray.intersectsPlane(this._hitPlane) ?? 0;\r\n }\r\n\r\n // not using this ray again, so modifying its vectors here is fine\r\n return ray.origin.addInPlace(ray.direction.scaleInPlace(distance));\r\n }\r\n\r\n private _inertialPanning: Vector3 = Vector3.Zero();\r\n\r\n private _zoomToMouse(delta: number) {\r\n const camera = this.camera;\r\n const inertiaComp = 1 - camera.inertia;\r\n if (camera.lowerRadiusLimit) {\r\n const lowerLimit = camera.lowerRadiusLimit ?? 0;\r\n if (camera.radius - (camera.inertialRadiusOffset + delta) / inertiaComp < lowerLimit) {\r\n delta = (camera.radius - lowerLimit) * inertiaComp - camera.inertialRadiusOffset;\r\n }\r\n }\r\n if (camera.upperRadiusLimit) {\r\n const upperLimit = camera.upperRadiusLimit ?? 0;\r\n if (camera.radius - (camera.inertialRadiusOffset + delta) / inertiaComp > upperLimit) {\r\n delta = (camera.radius - upperLimit) * inertiaComp - camera.inertialRadiusOffset;\r\n }\r\n }\r\n\r\n const zoomDistance = delta / inertiaComp;\r\n const ratio = zoomDistance / camera.radius;\r\n const vec = this._getPosition();\r\n\r\n // Now this vector tells us how much we also need to pan the camera\r\n // so the targeted mouse location becomes the center of zooming.\r\n\r\n const directionToZoomLocation = TmpVectors.Vector3[6];\r\n vec.subtractToRef(camera.target, directionToZoomLocation);\r\n directionToZoomLocation.scaleInPlace(ratio);\r\n directionToZoomLocation.scaleInPlace(inertiaComp);\r\n this._inertialPanning.addInPlace(directionToZoomLocation);\r\n\r\n camera.inertialRadiusOffset += delta;\r\n }\r\n\r\n // Sets x y or z of passed in vector to zero if less than Epsilon.\r\n private _zeroIfClose(vec: Vector3) {\r\n if (Math.abs(vec.x) < Epsilon) {\r\n vec.x = 0;\r\n }\r\n if (Math.abs(vec.y) < Epsilon) {\r\n vec.y = 0;\r\n }\r\n if (Math.abs(vec.z) < Epsilon) {\r\n vec.z = 0;\r\n }\r\n }\r\n}\r\n\r\n(<any>CameraInputTypes)[\"ArcRotateCameraMouseWheelInput\"] = ArcRotateCameraMouseWheelInput;\r\n"]}
@@ -777,13 +777,13 @@ export class AbstractEngine {
777
777
  */
778
778
  // Not mixed with Version for tooling purpose.
779
779
  static get NpmPackage() {
780
- return "babylonjs@8.0.0";
780
+ return "babylonjs@8.0.1";
781
781
  }
782
782
  /**
783
783
  * Returns the current version of the framework
784
784
  */
785
785
  static get Version() {
786
- return "8.0.0";
786
+ return "8.0.1";
787
787
  }
788
788
  /**
789
789
  * Gets the HTML canvas attached with the current webGL context