1 |
- {"ast":null,"code":"import { CameraInputTypes } from \"../../Cameras/cameraInputsManager.js\";\nimport { ArcRotateCameraInputsManager } from \"../../Cameras/arcRotateCameraInputsManager.js\";\nimport { Tools } from \"../../Misc/tools.js\";\n/**\n * Add orientation input support to the input manager.\n * @returns the current input manager\n */\nArcRotateCameraInputsManager.prototype.addVRDeviceOrientation = function () {\n this.add(new ArcRotateCameraVRDeviceOrientationInput());\n return this;\n};\n/**\n * Manage the device orientation inputs (gyroscope) to control an arc rotate camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\nexport class ArcRotateCameraVRDeviceOrientationInput {\n /**\n * Instantiate a new ArcRotateCameraVRDeviceOrientationInput.\n */\n constructor() {\n /**\n * Defines a correction factor applied on the alpha value retrieved from the orientation events.\n */\n this.alphaCorrection = 1;\n /**\n * Defines a correction factor applied on the gamma value retrieved from the orientation events.\n */\n this.gammaCorrection = 1;\n this._alpha = 0;\n this._gamma = 0;\n this._dirty = false;\n this._deviceOrientationHandler = evt => this._onOrientationEvent(evt);\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachControl(noPreventDefault) {\n // eslint-disable-next-line prefer-rest-params\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\n this.camera.attachControl(noPreventDefault);\n const hostWindow = this.camera.getScene().getEngine().getHostWindow();\n if (hostWindow) {\n // check iOS 13+ support\n if (typeof DeviceOrientationEvent !== \"undefined\" && typeof DeviceOrientationEvent.requestPermission === \"function\") {\n DeviceOrientationEvent.requestPermission().then(response => {\n if (response === \"granted\") {\n hostWindow.addEventListener(\"deviceorientation\", this._deviceOrientationHandler);\n } else {\n Tools.Warn(\"Permission not granted.\");\n }\n }).catch(error => {\n Tools.Error(error);\n });\n } else {\n hostWindow.addEventListener(\"deviceorientation\", this._deviceOrientationHandler);\n }\n }\n }\n /**\n * @internal\n */\n _onOrientationEvent(evt) {\n if (evt.alpha !== null) {\n this._alpha = (+evt.alpha | 0) * this.alphaCorrection;\n }\n if (evt.gamma !== null) {\n this._gamma = (+evt.gamma | 0) * this.gammaCorrection;\n }\n this._dirty = true;\n }\n /**\n * Update the current camera state depending on the inputs that have been used this frame.\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\n */\n checkInputs() {\n if (this._dirty) {\n this._dirty = false;\n if (this._gamma < 0) {\n this._gamma = 180 + this._gamma;\n }\n this.camera.alpha = -this._alpha / 180.0 * Math.PI % Math.PI * 2;\n this.camera.beta = this._gamma / 180.0 * Math.PI;\n }\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n window.removeEventListener(\"deviceorientation\", this._deviceOrientationHandler);\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"ArcRotateCameraVRDeviceOrientationInput\";\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"VRDeviceOrientation\";\n }\n}\nCameraInputTypes[\"ArcRotateCameraVRDeviceOrientationInput\"] = ArcRotateCameraVRDeviceOrientationInput;","map":{"version":3,"names":["CameraInputTypes","ArcRotateCameraInputsManager","Tools","prototype","addVRDeviceOrientation","add","ArcRotateCameraVRDeviceOrientationInput","constructor","alphaCorrection","gammaCorrection","_alpha","_gamma","_dirty","_deviceOrientationHandler","evt","_onOrientationEvent","attachControl","noPreventDefault","BackCompatCameraNoPreventDefault","arguments","camera","hostWindow","getScene","getEngine","getHostWindow","DeviceOrientationEvent","requestPermission","then","response","addEventListener","Warn","catch","error","Error","alpha","gamma","checkInputs","Math","PI","beta","detachControl","window","removeEventListener","getClassName","getSimpleName"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Cameras/Inputs/arcRotateCameraVRDeviceOrientationInput.js"],"sourcesContent":["import { CameraInputTypes } from \"../../Cameras/cameraInputsManager.js\";\nimport { ArcRotateCameraInputsManager } from \"../../Cameras/arcRotateCameraInputsManager.js\";\nimport { Tools } from \"../../Misc/tools.js\";\n/**\n * Add orientation input support to the input manager.\n * @returns the current input manager\n */\nArcRotateCameraInputsManager.prototype.addVRDeviceOrientation = function () {\n this.add(new ArcRotateCameraVRDeviceOrientationInput());\n return this;\n};\n/**\n * Manage the device orientation inputs (gyroscope) to control an arc rotate camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\nexport class ArcRotateCameraVRDeviceOrientationInput {\n /**\n * Instantiate a new ArcRotateCameraVRDeviceOrientationInput.\n */\n constructor() {\n /**\n * Defines a correction factor applied on the alpha value retrieved from the orientation events.\n */\n this.alphaCorrection = 1;\n /**\n * Defines a correction factor applied on the gamma value retrieved from the orientation events.\n */\n this.gammaCorrection = 1;\n this._alpha = 0;\n this._gamma = 0;\n this._dirty = false;\n this._deviceOrientationHandler = (evt) => this._onOrientationEvent(evt);\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachControl(noPreventDefault) {\n // eslint-disable-next-line prefer-rest-params\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\n this.camera.attachControl(noPreventDefault);\n const hostWindow = this.camera.getScene().getEngine().getHostWindow();\n if (hostWindow) {\n // check iOS 13+ support\n if (typeof DeviceOrientationEvent !== \"undefined\" && typeof DeviceOrientationEvent.requestPermission === \"function\") {\n DeviceOrientationEvent\n .requestPermission()\n .then((response) => {\n if (response === \"granted\") {\n hostWindow.addEventListener(\"deviceorientation\", this._deviceOrientationHandler);\n }\n else {\n Tools.Warn(\"Permission not granted.\");\n }\n })\n .catch((error) => {\n Tools.Error(error);\n });\n }\n else {\n hostWindow.addEventListener(\"deviceorientation\", this._deviceOrientationHandler);\n }\n }\n }\n /**\n * @internal\n */\n _onOrientationEvent(evt) {\n if (evt.alpha !== null) {\n this._alpha = (+evt.alpha | 0) * this.alphaCorrection;\n }\n if (evt.gamma !== null) {\n this._gamma = (+evt.gamma | 0) * this.gammaCorrection;\n }\n this._dirty = true;\n }\n /**\n * Update the current camera state depending on the inputs that have been used this frame.\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\n */\n checkInputs() {\n if (this._dirty) {\n this._dirty = false;\n if (this._gamma < 0) {\n this._gamma = 180 + this._gamma;\n }\n this.camera.alpha = (((-this._alpha / 180.0) * Math.PI) % Math.PI) * 2;\n this.camera.beta = (this._gamma / 180.0) * Math.PI;\n }\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n window.removeEventListener(\"deviceorientation\", this._deviceOrientationHandler);\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"ArcRotateCameraVRDeviceOrientationInput\";\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"VRDeviceOrientation\";\n }\n}\nCameraInputTypes[\"ArcRotateCameraVRDeviceOrientationInput\"] = ArcRotateCameraVRDeviceOrientationInput;\n"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,sCAAsC;AACvE,SAASC,4BAA4B,QAAQ,+CAA+C;AAC5F,SAASC,KAAK,QAAQ,qBAAqB;AAC3C;AACA;AACA;AACA;AACAD,4BAA4B,CAACE,SAAS,CAACC,sBAAsB,GAAG,YAAY;EACxE,IAAI,CAACC,GAAG,CAAC,IAAIC,uCAAuC,CAAC,CAAC,CAAC;EACvD,OAAO,IAAI;AACf,CAAC;AACD;AACA;AACA;AACA;AACA,OAAO,MAAMA,uCAAuC,CAAC;EACjD;AACJ;AACA;EACIC,WAAWA,CAAA,EAAG;IACV;AACR;AACA;IACQ,IAAI,CAACC,eAAe,GAAG,CAAC;IACxB;AACR;AACA;IACQ,IAAI,CAACC,eAAe,GAAG,CAAC;IACxB,IAAI,CAACC,MAAM,GAAG,CAAC;IACf,IAA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AC,IAAI,IAAI,CAAC1B,eAAe;IACzD;IACA,IAAIM,GAAG,CAACqB,KAAK,KAAK,IAAI,EAAE;MACpB,IAAI,CAACxB,MAAM,GAAG,CAAC,CAACG,GAAG,CAACqB,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC1B,eAAe;IACzD;IACA,IAAI,CAACG,MAAM,GAAG,IAAI;EACtB;EACA;AACJ;AACA;AACA;EACIwB,WAAWA,CAAA,EAAG;IACV,IAAI,IAAI,CAACxB,MAAM,EAAE;MACb,IAAI,CAACA,MAAM,GAAG,KAAK;MACnB,IAAI,IAAI,CAACD,MAAM,GAAG,CAAC,EAAE;QACjB,IAAI,CAACA,MAAM,GAAG,GAAG,GAAG,IAAI,CAACA,MAAM;MACnC;MACA,IAAI,CAACS,MAAM,CAACc,KAAK,GAAM,CAAC,IAAI,CAACxB,MAAM,GAAG,KAAK,GAAI2B,IAAI,CAACC,EAAE,GAAID,IAAI,CAACC,EAAE,GAAI,CAAC;MACtE,IAAI,CAAClB,MAAM,CAACmB,IAAI,GAAI,IAAI,CAAC5B,MAAM,GAAG,KAAK,GAAI0B,IAAI,CAACC,EAAE;IACtD;EACJ;EACA;AACJ;AACA;EACIE,aAAaA,CAAA,EAAG;IACZC,MAAM,CAACC,mBAAmB,CAAC,mBAAmB,EAAE,IAAI,CAAC7B,yBAAyB,CAAC;EACnF;EACA;AACJ;AACA;AACA;EACI8B,YAAYA,CAAA,EAAG;IACX,OAAO,yCAAyC;EACpD;EACA;AACJ;AACA;AACA;EACIC,aAAaA,CAAA,EAAG;IACZ,OAAO,qBAAqB;EAChC;AACJ;AACA5C,gBAAgB,CAAC,yCAAyC,CAAC,GAAGM,uCAAuC","ignoreList":[]},"metadata":{},"sourceType":"module","externalDependencies":[]}
|