c947dc5838691137c0d2cbf41e7e1ea2e09ff4d72267d97fa20184913afe2b91.json 13 KB

1
  1. {"ast":null,"code":"import { FreeCamera } from \"./freeCamera.js\";\nimport { Quaternion, Vector3 } from \"../Maths/math.vector.js\";\nimport { Node } from \"../node.js\";\nimport \"./Inputs/freeCameraDeviceOrientationInput.js\";\nimport { Axis } from \"../Maths/math.axis.js\";\nNode.AddNodeConstructor(\"DeviceOrientationCamera\", (name, scene) => {\n return () => new DeviceOrientationCamera(name, Vector3.Zero(), scene);\n});\n// We're mainly based on the logic defined into the FreeCamera code\n/**\n * This is a camera specifically designed to react to device orientation events such as a modern mobile device\n * being tilted forward or back and left or right.\n */\nexport class DeviceOrientationCamera extends FreeCamera {\n /**\n * Creates a new device orientation camera\n * @param name The name of the camera\n * @param position The start position camera\n * @param scene The scene the camera belongs to\n */\n constructor(name, position, scene) {\n super(name, position, scene);\n this._tmpDragQuaternion = new Quaternion();\n this._disablePointerInputWhenUsingDeviceOrientation = true;\n this._dragFactor = 0;\n this._quaternionCache = new Quaternion();\n this.inputs.addDeviceOrientation();\n // When the orientation sensor fires it's first event, disable mouse input\n if (this.inputs._deviceOrientationInput) {\n this.inputs._deviceOrientationInput._onDeviceOrientationChangedObservable.addOnce(() => {\n if (this._disablePointerInputWhenUsingDeviceOrientation) {\n if (this.inputs._mouseInput) {\n this.inputs._mouseInput._allowCameraRotation = false;\n this.inputs._mouseInput.onPointerMovedObservable.add(e => {\n if (this._dragFactor != 0) {\n if (!this._initialQuaternion) {\n this._initialQuaternion = new Quaternion();\n }\n // Rotate the initial space around the y axis to allow users to \"turn around\" via touch/mouse\n Quaternion.FromEulerAnglesToRef(0, e.offsetX * this._dragFactor, 0, this._tmpDragQuaternion);\n this._initialQuaternion.multiplyToRef(this._tmpDragQuaternion, this._initialQuaternion);\n }\n });\n }\n }\n });\n }\n }\n /**\n * Gets or sets a boolean indicating that pointer input must be disabled on first orientation sensor update (Default: true)\n */\n get disablePointerInputWhenUsingDeviceOrientation() {\n return this._disablePointerInputWhenUsingDeviceOrientation;\n }\n set disablePointerInputWhenUsingDeviceOrientation(value) {\n this._disablePointerInputWhenUsingDeviceOrientation = value;\n }\n /**\n * Enabled turning on the y axis when the orientation sensor is active\n * @param dragFactor the factor that controls the turn speed (default: 1/300)\n */\n enableHorizontalDragging(dragFactor = 1 / 300) {\n this._dragFactor = dragFactor;\n }\n /**\n * Gets the current instance class name (\"DeviceOrientationCamera\").\n * This helps avoiding instanceof at run time.\n * @returns the class name\n */\n getClassName() {\n return \"DeviceOrientationCamera\";\n }\n /**\n * @internal\n * Checks and applies the current values of the inputs to the camera. (Internal use only)\n */\n _checkInputs() {\n super._checkInputs();\n this._quaternionCache.copyFrom(this.rotationQuaternion);\n if (this._initialQuaternion) {\n this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\n }\n }\n /**\n * Reset the camera to its default orientation on the specified axis only.\n * @param axis The axis to reset\n */\n resetToCurrentRotation(axis = Axis.Y) {\n //can only work if this camera has a rotation quaternion already.\n if (!this.rotationQuaternion) {\n return;\n }\n if (!this._initialQuaternion) {\n this._initialQuaternion = new Quaternion();\n }\n this._initialQuaternion.copyFrom(this._quaternionCache || this.rotationQuaternion);\n [\"x\", \"y\", \"z\"].forEach(axisName => {\n if (!axis[axisName]) {\n this._initialQuaternion[axisName] = 0;\n } else {\n this._initialQuaternion[axisName] *= -1;\n }\n });\n this._initialQuaternion.normalize();\n //force rotation update\n this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\n }\n}","map":{"version":3,"names":["FreeCamera","Quaternion","Vector3","Node","Axis","AddNodeConstructor","name","scene","DeviceOrientationCamera","Zero","constructor","position","_tmpDragQuaternion","_disablePointerInputWhenUsingDeviceOrientation","_dragFactor","_quaternionCache","inputs","addDeviceOrientation","_deviceOrientationInput","_onDeviceOrientationChangedObservable","addOnce","_mouseInput","_allowCameraRotation","onPointerMovedObservable","add","e","_initialQuaternion","FromEulerAnglesToRef","offsetX","multiplyToRef","disablePointerInputWhenUsingDeviceOrientation","value","enableHorizontalDragging","dragFactor","getClassName","_checkInputs","copyFrom","rotationQuaternion","resetToCurrentRotation","axis","Y","forEach","axisName","normalize"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Cameras/deviceOrientationCamera.js"],"sourcesContent":["import { FreeCamera } from \"./freeCamera.js\";\nimport { Quaternion, Vector3 } from \"../Maths/math.vector.js\";\nimport { Node } from \"../node.js\";\nimport \"./Inputs/freeCameraDeviceOrientationInput.js\";\nimport { Axis } from \"../Maths/math.axis.js\";\nNode.AddNodeConstructor(\"DeviceOrientationCamera\", (name, scene) => {\n return () => new DeviceOrientationCamera(name, Vector3.Zero(), scene);\n});\n// We're mainly based on the logic defined into the FreeCamera code\n/**\n * This is a camera specifically designed to react to device orientation events such as a modern mobile device\n * being tilted forward or back and left or right.\n */\nexport class DeviceOrientationCamera extends FreeCamera {\n /**\n * Creates a new device orientation camera\n * @param name The name of the camera\n * @param position The start position camera\n * @param scene The scene the camera belongs to\n */\n constructor(name, position, scene) {\n super(name, position, scene);\n this._tmpDragQuaternion = new Quaternion();\n this._disablePointerInputWhenUsingDeviceOrientation = true;\n this._dragFactor = 0;\n this._quaternionCache = new Quaternion();\n this.inputs.addDeviceOrientation();\n // When the orientation sensor fires it's first event, disable mouse input\n if (this.inputs._deviceOrientationInput) {\n this.inputs._deviceOrientationInput._onDeviceOrientationChangedObservable.addOnce(() => {\n if (this._disablePointerInputWhenUsingDeviceOrientation) {\n if (this.inputs._mouseInput) {\n this.inputs._mouseInput._allowCameraRotation = false;\n this.inputs._mouseInput.onPointerMovedObservable.add((e) => {\n if (this._dragFactor != 0) {\n if (!this._initialQuaternion) {\n this._initialQuaternion = new Quaternion();\n }\n // Rotate the initial space around the y axis to allow users to \"turn around\" via touch/mouse\n Quaternion.FromEulerAnglesToRef(0, e.offsetX * this._dragFactor, 0, this._tmpDragQuaternion);\n this._initialQuaternion.multiplyToRef(this._tmpDragQuaternion, this._initialQuaternion);\n }\n });\n }\n }\n });\n }\n }\n /**\n * Gets or sets a boolean indicating that pointer input must be disabled on first orientation sensor update (Default: true)\n */\n get disablePointerInputWhenUsingDeviceOrientation() {\n return this._disablePointerInputWhenUsingDeviceOrientation;\n }\n set disablePointerInputWhenUsingDeviceOrientation(value) {\n this._disablePointerInputWhenUsingDeviceOrientation = value;\n }\n /**\n * Enabled turning on the y axis when the orientation sensor is active\n * @param dragFactor the factor that controls the turn speed (default: 1/300)\n */\n enableHorizontalDragging(dragFactor = 1 / 300) {\n this._dragFactor = dragFactor;\n }\n /**\n * Gets the current instance class name (\"DeviceOrientationCamera\").\n * This helps avoiding instanceof at run time.\n * @returns the class name\n */\n getClassName() {\n return \"DeviceOrientationCamera\";\n }\n /**\n * @internal\n * Checks and applies the current values of the inputs to the camera. (Internal use only)\n */\n _checkInputs() {\n super._checkInputs();\n this._quaternionCache.copyFrom(this.rotationQuaternion);\n if (this._initialQuaternion) {\n this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\n }\n }\n /**\n * Reset the camera to its default orientation on the specified axis only.\n * @param axis The axis to reset\n */\n resetToCurrentRotation(axis = Axis.Y) {\n //can only work if this camera has a rotation quaternion already.\n if (!this.rotationQuaternion) {\n return;\n }\n if (!this._initialQuaternion) {\n this._initialQuaternion = new Quaternion();\n }\n this._initialQuaternion.copyFrom(this._quaternionCache || this.rotationQuaternion);\n [\"x\", \"y\", \"z\"].forEach((axisName) => {\n if (!axis[axisName]) {\n this._initialQuaternion[axisName] = 0;\n }\n else {\n this._initialQuaternion[axisName] *= -1;\n }\n });\n this._initialQuaternion.normalize();\n //force rotation update\n this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,UAAU,EAAEC,OAAO,QAAQ,yBAAyB;AAC7D,SAASC,IAAI,QAAQ,YAAY;AACjC,OAAO,8CAA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