65ec683a10584ffd678b93058985b2d7160d2b747972e90314777b56b7d7ebd1.json 19 KB

1
  1. {"ast":null,"code":"import { Logger } from \"../Misc/logger.js\";\nimport { SerializationHelper } from \"../Misc/decorators.serialization.js\";\nimport { Camera } from \"./camera.js\";\n/**\n * @ignore\n * This is a list of all the different input types that are available in the application.\n * Fo instance: ArcRotateCameraGamepadInput...\n */\n// eslint-disable-next-line no-var, @typescript-eslint/naming-convention\nexport var CameraInputTypes = {};\n/**\n * This represents the input manager used within a camera.\n * It helps dealing with all the different kind of input attached to a camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\nexport class CameraInputsManager {\n /**\n * Instantiate a new Camera Input Manager.\n * @param camera Defines the camera the input manager belongs to\n */\n constructor(camera) {\n /**\n * Defines the dom element the camera is collecting inputs from.\n * This is null if the controls have not been attached.\n */\n this.attachedToElement = false;\n this.attached = {};\n this.camera = camera;\n this.checkInputs = () => {};\n }\n /**\n * Add an input method to a camera\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n * @param input Camera input method\n */\n add(input) {\n const type = input.getSimpleName();\n if (this.attached[type]) {\n Logger.Warn(\"camera input of type \" + type + \" already exists on camera\");\n return;\n }\n this.attached[type] = input;\n input.camera = this.camera;\n // for checkInputs, we are dynamically creating a function\n // the goal is to avoid the performance penalty of looping for inputs in the render loop\n if (input.checkInputs) {\n this.checkInputs = this._addCheckInputs(input.checkInputs.bind(input));\n }\n if (this.attachedToElement) {\n input.attachControl(this.noPreventDefault);\n }\n }\n /**\n * Remove a specific input method from a camera\n * example: camera.inputs.remove(camera.inputs.attached.mouse);\n * @param inputToRemove camera input method\n */\n remove(inputToRemove) {\n for (const cam in this.attached) {\n const input = this.attached[cam];\n if (input === inputToRemove) {\n input.detachControl();\n input.camera = null;\n delete this.attached[cam];\n this.rebuildInputCheck();\n return;\n }\n }\n }\n /**\n * Remove a specific input type from a camera\n * example: camera.inputs.remove(\"ArcRotateCameraGamepadInput\");\n * @param inputType the type of the input to remove\n */\n removeByType(inputType) {\n for (const cam in this.attached) {\n const input = this.attached[cam];\n if (input.getClassName() === inputType) {\n input.detachControl();\n input.camera = null;\n delete this.attached[cam];\n this.rebuildInputCheck();\n }\n }\n }\n _addCheckInputs(fn) {\n const current = this.checkInputs;\n return () => {\n current();\n fn();\n };\n }\n /**\n * Attach the input controls to the currently attached dom element to listen the events from.\n * @param input Defines the input to attach\n */\n attachInput(input) {\n if (this.attachedToElement) {\n input.attachControl(this.noPreventDefault);\n }\n }\n /**\n * Attach the current manager inputs controls to a specific dom element to listen the events 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 attachElement(noPreventDefault = false) {\n if (this.attachedToElement) {\n return;\n }\n noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;\n this.attachedToElement = true;\n this.noPreventDefault = noPreventDefault;\n for (const cam in this.attached) {\n this.attached[cam].attachControl(noPreventDefault);\n }\n }\n /**\n * Detach the current manager inputs controls from a specific dom element.\n * @param disconnect Defines whether the input should be removed from the current list of attached inputs\n */\n detachElement(disconnect = false) {\n for (const cam in this.attached) {\n this.attached[cam].detachControl();\n if (disconnect) {\n this.attached[cam].camera = null;\n }\n }\n this.attachedToElement = false;\n }\n /**\n * Rebuild the dynamic inputCheck function from the current list of\n * defined inputs in the manager.\n */\n rebuildInputCheck() {\n this.checkInputs = () => {};\n for (const cam in this.attached) {\n const input = this.attached[cam];\n if (input.checkInputs) {\n this.checkInputs = this._addCheckInputs(input.checkInputs.bind(input));\n }\n }\n }\n /**\n * Remove all attached input methods from a camera\n */\n clear() {\n if (this.attachedToElement) {\n this.detachElement(true);\n }\n this.attached = {};\n this.attachedToElement = false;\n this.checkInputs = () => {};\n }\n /**\n * Serialize the current input manager attached to a camera.\n * This ensures than once parsed,\n * the input associated to the camera will be identical to the current ones\n * @param serializedCamera Defines the camera serialization JSON the input serialization should write to\n */\n serialize(serializedCamera) {\n const inputs = {};\n for (const cam in this.attached) {\n const input = this.attached[cam];\n const res = SerializationHelper.Serialize(input);\n inputs[input.getClassName()] = res;\n }\n serializedCamera.inputsmgr = inputs;\n }\n /**\n * Parses an input manager serialized JSON to restore the previous list of inputs\n * and states associated to a camera.\n * @param parsedCamera Defines the JSON to parse\n */\n parse(parsedCamera) {\n const parsedInputs = parsedCamera.inputsmgr;\n if (parsedInputs) {\n this.clear();\n for (const n in parsedInputs) {\n const construct = CameraInputTypes[n];\n if (construct) {\n const parsedinput = parsedInputs[n];\n const input = SerializationHelper.Parse(() => {\n return new construct();\n }, parsedinput, null);\n this.add(input);\n }\n }\n } else {\n //2016-03-08 this part is for managing backward compatibility\n for (const n in this.attached) {\n const construct = CameraInputTypes[this.attached[n].getClassName()];\n if (construct) {\n const input = SerializationHelper.Parse(() => {\n return new construct();\n }, parsedCamera, null);\n this.remove(this.attached[n]);\n this.add(input);\n }\n }\n }\n }\n}","map":{"version":3,"names":["Logger","SerializationHelper","Camera","CameraInputTypes","CameraInputsManager","constructor","camera","attachedToElement","attached","checkInputs","add","input","type","getSimpleName","Warn","_addCheckInputs","bind","attachControl","noPreventDefault","remove","inputToRemove","cam","detachControl","rebuildInputCheck","removeByType","inputType","getClassName","fn","current","attachInput","attachElement","ForceAttachControlToAlwaysPreventDefault","detachElement","disconnect","clear","serialize","serializedCamera","inputs","res","Serialize","inputsmgr","parse","parsedCamera","parsedInputs","n","construct","parsedinput","Parse"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Cameras/cameraInputsManager.js"],"sourcesContent":["import { Logger } from \"../Misc/logger.js\";\nimport { SerializationHelper } from \"../Misc/decorators.serialization.js\";\nimport { Camera } from \"./camera.js\";\n/**\n * @ignore\n * This is a list of all the different input types that are available in the application.\n * Fo instance: ArcRotateCameraGamepadInput...\n */\n// eslint-disable-next-line no-var, @typescript-eslint/naming-convention\nexport var CameraInputTypes = {};\n/**\n * This represents the input manager used within a camera.\n * It helps dealing with all the different kind of input attached to a camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\nexport class CameraInputsManager {\n /**\n * Instantiate a new Camera Input Manager.\n * @param camera Defines the camera the input manager belongs to\n */\n constructor(camera) {\n /**\n * Defines the dom element the camera is collecting inputs from.\n * This is null if the controls have not been attached.\n */\n this.attachedToElement = false;\n this.attached = {};\n this.camera = camera;\n this.checkInputs = () => { };\n }\n /**\n * Add an input method to a camera\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n * @param input Camera input method\n */\n add(input) {\n const type = input.getSimpleName();\n if (this.attached[type]) {\n Logger.Warn(\"camera input of type \" + type + \" already exists on camera\");\n return;\n }\n this.attached[type] = input;\n input.camera = this.camera;\n // for checkInputs, we are dynamically creating a function\n // the goal is to avoid the performance penalty of looping for inputs in the render loop\n if (input.checkInputs) {\n this.checkInputs = this._addCheckInputs(input.checkInputs.bind(input));\n }\n if (this.attachedToElement) {\n input.attachControl(this.noPreventDefault);\n }\n }\n /**\n * Remove a specific input method from a camera\n * example: camera.inputs.remove(camera.inputs.attached.mouse);\n * @param inputToRemove camera input method\n */\n remove(inputToRemove) {\n for (const cam in this.attached) {\n const input = this.attached[cam];\n if (input === inputToRemove) {\n input.detachControl();\n input.camera = null;\n delete this.attached[cam];\n this.rebuildInputCheck();\n return;\n }\n }\n }\n /**\n * Remove a specific input type from a camera\n * example: camera.inputs.remove(\"ArcRotateCameraGamepadInput\");\n * @param inputType the type of the input to remove\n */\n removeByType(inputType) {\n for (const cam in this.attached) {\n const input = this.attached[cam];\n if (input.getClassName() === inputType) {\n input.detachControl();\n input.camera = null;\n delete this.attached[cam];\n this.rebuildInputCheck();\n }\n }\n }\n _addCheckInputs(fn) {\n const current = this.checkInputs;\n return () => {\n current();\n fn();\n };\n }\n /**\n * Attach the input controls to the currently attached dom element to listen the events from.\n * @param input Defines the input to attach\n */\n attachInput(input) {\n if (this.attachedToElement) {\n input.attachControl(this.noPreventDefault);\n }\n }\n /**\n * Attach the current manager inputs controls to a specific dom element to listen the events 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 attachElement(noPreventDefault = false) {\n if (this.attachedToElement) {\n return;\n }\n noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;\n this.attachedToElement = true;\n this.noPreventDefault = noPreventDefault;\n for (const cam in this.attached) {\n this.attached[cam].attachControl(noPreventDefault);\n }\n }\n /**\n * Detach the current manager inputs controls from a specific dom element.\n * @param disconnect Defines whether the input should be removed from the current list of attached inputs\n */\n detachElement(disconnect = false) {\n for (const cam in this.attached) {\n this.attached[cam].detachControl();\n if (disconnect) {\n this.attached[cam].camera = null;\n }\n }\n this.attachedToElement = false;\n }\n /**\n * Rebuild the dynamic inputCheck function from the current list of\n * defined inputs in the manager.\n */\n rebuildInputCheck() {\n this.checkInputs = () => { };\n for (const cam in this.attached) {\n const input = this.attached[cam];\n if (input.checkInputs) {\n this.checkInputs = this._addCheckInputs(input.checkInputs.bind(input));\n }\n }\n }\n /**\n * Remove all attached input methods from a camera\n */\n clear() {\n if (this.attachedToElement) {\n this.detachElement(true);\n }\n this.attached = {};\n this.attachedToElement = false;\n this.checkInputs = () => { };\n }\n /**\n * Serialize the current input manager attached to a camera.\n * This ensures than once parsed,\n * the input associated to the camera will be identical to the current ones\n * @param serializedCamera Defines the camera serialization JSON the input serialization should write to\n */\n serialize(serializedCamera) {\n const inputs = {};\n for (const cam in this.attached) {\n const input = this.attached[cam];\n const res = SerializationHelper.Serialize(input);\n inputs[input.getClassName()] = res;\n }\n serializedCamera.inputsmgr = inputs;\n }\n /**\n * Parses an input manager serialized JSON to restore the previous list of inputs\n * and states associated to a camera.\n * @param parsedCamera Defines the JSON to parse\n */\n parse(parsedCamera) {\n const parsedInputs = parsedCamera.inputsmgr;\n if (parsedInputs) {\n this.clear();\n for (const n in parsedInputs) {\n const construct = CameraInputTypes[n];\n if (construct) {\n const parsedinput = parsedInputs[n];\n const input = SerializationHelper.Parse(() => {\n return new construct();\n }, parsedinput, null);\n this.add(input);\n }\n }\n }\n else {\n //2016-03-08 this part is for managing backward compatibility\n for (const n in this.attached) {\n const construct = CameraInputTypes[this.attached[n].getClassName()];\n if (construct) {\n const input = SerializationHelper.Parse(() => {\n return new construct();\n }, parsedCamera, null);\n this.remove(this.attached[n]);\n this.add(input);\n }\n }\n }\n }\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,mBAAmB,QAAQ,qCAAqC;AACzE,SAASC,MAAM,QAAQ,aAAa;AACpC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAIC,gBAAgB,GAAG,CAAC,CAAC;AAChC;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,CAAC;EAC7B;AACJ;AACA;AACA;EACIC,WAAWA,CAACC,MAAM,EAAE;IAChB;AACR;AACA;AACA;IACQ,IAAI,CAACC,iBAAiB,GAAG,KAAK;IAC9B,IAAI,CAACC,QAAQ,GAAG,CAAC,CAAC;IAClB,IAAI,CAACF,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACG,WAAW,GAAG,MAAM,CAAE,CAAC;EAChC;EACA;AACJ;AACA;AACA;AACA;EACIC,GAAGA,CAACC,KAAK,EAAE;IACP,MAAMC,IAAI,GAAGD,KAAK,CAACE,aAAa,CAAC,CAAC;IAClC,IAAI,IAAI,CAACL,QAAQ,CAACI,IAAI,CAAC,EAAE;MACrBZ,MAAM,CAACc,IAAI,CAAC,uBAAuB,GAAGF,IAAI,GAAG,2BAA2B,CAAC;MACzE;IACJ;IACA,IAAI,CAACJ,QAAQ,CAACI,IAAI,CAAC,GAAGD,KAAK;IAC3BA,KAAK,CAACL,MAAM,GAAG,IAAI,CAACA,MAAM;IAC1B;IACA;IACA,IAAIK,KAAK,CAACF,WAAW,EAAE;MACnB,IAAI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