@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
182 lines • 7.48 kB
JavaScript
import { __decorate } from "../../tslib.es6.js";
import { serialize } from "../../Misc/decorators.js";
import { CameraInputTypes } from "../../Cameras/cameraInputsManager.js";
import { OrbitCameraPointersInput } from "../../Cameras/Inputs/orbitCameraPointersInput.js";
/**
* Manage the pointers inputs to control an arc rotate camera.
* @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs
*/
export class ArcRotateCameraPointersInput extends OrbitCameraPointersInput {
constructor() {
super(...arguments);
/**
* Defines the buttons associated with the input to handle camera move.
*/
this.buttons = [0, 1, 2];
/**
* Defines the pointer angular sensibility along the X axis or how fast is
* the camera rotating.
*/
this.angularSensibilityX = 1000.0;
/**
* Defines the pointer angular sensibility along the Y axis or how fast is
* the camera rotating.
*/
this.angularSensibilityY = 1000.0;
/**
* Defines the pointer pinch precision or how fast is the camera zooming.
*/
this.pinchPrecision = 12.0;
/**
* pinchDeltaPercentage will be used instead of pinchPrecision if different
* from 0.
* It defines the percentage of current camera.radius to use as delta when
* pinch zoom is used.
*/
this.pinchDeltaPercentage = 0;
/**
* When useNaturalPinchZoom is true, multi touch zoom will zoom in such
* that any object in the plane at the camera's target point will scale
* perfectly with finger motion.
* Overrides pinchDeltaPercentage and pinchPrecision.
*/
this.useNaturalPinchZoom = false;
/**
* Defines the pointer panning sensibility or how fast is the camera moving.
*/
this.panningSensibility = 1000.0;
/**
* Revers pinch action direction.
*/
this.pinchInwards = true;
this._isPanClick = false;
}
/**
* Gets the class name of the current input.
* @returns the class name
*/
getClassName() {
return "ArcRotateCameraPointersInput";
}
/**
* Move camera from multi touch panning positions.
* @param previousMultiTouchPanPosition
* @param multiTouchPanPosition
*/
_computeMultiTouchPanning(previousMultiTouchPanPosition, multiTouchPanPosition) {
if (this.panningSensibility !== 0 && previousMultiTouchPanPosition && multiTouchPanPosition) {
const moveDeltaX = multiTouchPanPosition.x - previousMultiTouchPanPosition.x;
const moveDeltaY = multiTouchPanPosition.y - previousMultiTouchPanPosition.y;
this.camera.inertialPanningX += -moveDeltaX / this.panningSensibility;
this.camera.inertialPanningY += moveDeltaY / this.panningSensibility;
}
}
/**
* Move camera from multitouch (pinch) zoom distances.
* @param previousPinchSquaredDistance
* @param pinchSquaredDistance
*/
_computePinchZoom(previousPinchSquaredDistance, pinchSquaredDistance) {
const radius = this.camera.radius || ArcRotateCameraPointersInput.MinimumRadiusForPinch;
if (this.useNaturalPinchZoom) {
this.camera.radius = (radius * Math.sqrt(previousPinchSquaredDistance)) / Math.sqrt(pinchSquaredDistance);
}
else if (this.pinchDeltaPercentage) {
this.camera.inertialRadiusOffset += (pinchSquaredDistance - previousPinchSquaredDistance) * 0.001 * radius * this.pinchDeltaPercentage;
}
else {
this.camera.inertialRadiusOffset +=
(pinchSquaredDistance - previousPinchSquaredDistance) /
((this.pinchPrecision * (this.pinchInwards ? 1 : -1) * (this.angularSensibilityX + this.angularSensibilityY)) / 2);
}
}
/**
* Called on pointer POINTERMOVE event if only a single touch is active.
* @param point current touch point
* @param offsetX offset on X
* @param offsetY offset on Y
*/
onTouch(point, offsetX, offsetY) {
if (this.panningSensibility !== 0 && ((this._ctrlKey && this.camera._useCtrlForPanning) || this._isPanClick)) {
this.camera.inertialPanningX += -offsetX / this.panningSensibility;
this.camera.inertialPanningY += offsetY / this.panningSensibility;
}
else {
this.camera.inertialAlphaOffset -= offsetX / this.angularSensibilityX;
this.camera.inertialBetaOffset -= offsetY / this.angularSensibilityY;
}
}
/**
* Called on pointer POINTERDOUBLETAP event.
*/
onDoubleTap() {
if (this.camera.useInputToRestoreState) {
this.camera.restoreState();
}
}
/**
* Called on pointer POINTERMOVE event if multiple touches are active.
* @param pointA point A
* @param pointB point B
* @param previousPinchSquaredDistance distance between points in previous pinch
* @param pinchSquaredDistance distance between points in current pinch
* @param previousMultiTouchPanPosition multi-touch position in previous step
* @param multiTouchPanPosition multi-touch position in current step
*/
onMultiTouch(pointA, pointB, previousPinchSquaredDistance, pinchSquaredDistance, previousMultiTouchPanPosition, multiTouchPanPosition) {
this._shouldStartPinchZoom =
this._twoFingerActivityCount < 20 && Math.abs(Math.sqrt(pinchSquaredDistance) - Math.sqrt(previousPinchSquaredDistance)) > this.camera.pinchToPanMaxDistance;
super.onMultiTouch(pointA, pointB, previousPinchSquaredDistance, pinchSquaredDistance, previousMultiTouchPanPosition, multiTouchPanPosition);
}
/**
* Called each time a new POINTERDOWN event occurs. Ie, for each button
* press.
* @param evt Defines the event to track
*/
onButtonDown(evt) {
this._isPanClick = evt.button === this.camera._panningMouseButton;
super.onButtonDown(evt);
}
/**
* Called each time a new POINTERUP event occurs. Ie, for each button
* release.
* @param _evt Defines the event to track
*/
onButtonUp(_evt) {
super.onButtonUp(_evt);
}
/**
* Called when window becomes inactive.
*/
onLostFocus() {
this._isPanClick = false;
super.onLostFocus();
}
}
/**
* The minimum radius used for pinch, to avoid radius lock at 0
*/
ArcRotateCameraPointersInput.MinimumRadiusForPinch = 0.001;
__decorate([
serialize()
], ArcRotateCameraPointersInput.prototype, "buttons", void 0);
__decorate([
serialize()
], ArcRotateCameraPointersInput.prototype, "angularSensibilityX", void 0);
__decorate([
serialize()
], ArcRotateCameraPointersInput.prototype, "angularSensibilityY", void 0);
__decorate([
serialize()
], ArcRotateCameraPointersInput.prototype, "pinchPrecision", void 0);
__decorate([
serialize()
], ArcRotateCameraPointersInput.prototype, "pinchDeltaPercentage", void 0);
__decorate([
serialize()
], ArcRotateCameraPointersInput.prototype, "useNaturalPinchZoom", void 0);
__decorate([
serialize()
], ArcRotateCameraPointersInput.prototype, "panningSensibility", void 0);
CameraInputTypes["ArcRotateCameraPointersInput"] = ArcRotateCameraPointersInput;
//# sourceMappingURL=arcRotateCameraPointersInput.js.map