5b65429a0aa738edb4811a47e7143cae0b99ceab80c46e9f138345d3663b56bf.json 17 KB

1
  1. {"ast":null,"code":"import { Observable } from \"../../Misc/observable.js\";\n/**\n * This class represents a single component (for example button or thumbstick) of a motion controller\n */\nexport class WebXRControllerComponent {\n /**\n * Creates a new component for a motion controller.\n * It is created by the motion controller itself\n *\n * @param id the id of this component\n * @param type the type of the component\n * @param _buttonIndex index in the buttons array of the gamepad\n * @param _axesIndices indices of the values in the axes array of the gamepad\n */\n constructor(\n /**\n * the id of this component\n */\n id,\n /**\n * the type of the component\n */\n type, _buttonIndex = -1, _axesIndices = []) {\n this.id = id;\n this.type = type;\n this._buttonIndex = _buttonIndex;\n this._axesIndices = _axesIndices;\n this._axes = {\n x: 0,\n y: 0\n };\n this._changes = {};\n this._currentValue = 0;\n this._hasChanges = false;\n this._pressed = false;\n this._touched = false;\n /**\n * If axes are available for this component (like a touchpad or thumbstick) the observers will be notified when\n * the axes data changes\n */\n this.onAxisValueChangedObservable = new Observable();\n /**\n * Observers registered here will be triggered when the state of a button changes\n * State change is either pressed / touched / value\n */\n this.onButtonStateChangedObservable = new Observable();\n }\n /**\n * The current axes data. If this component has no axes it will still return an object { x: 0, y: 0 }\n */\n get axes() {\n return this._axes;\n }\n /**\n * Get the changes. Elements will be populated only if they changed with their previous and current value\n */\n get changes() {\n return this._changes;\n }\n /**\n * Return whether or not the component changed the last frame\n */\n get hasChanges() {\n return this._hasChanges;\n }\n /**\n * is the button currently pressed\n */\n get pressed() {\n return this._pressed;\n }\n /**\n * is the button currently touched\n */\n get touched() {\n return this._touched;\n }\n /**\n * Get the current value of this component\n */\n get value() {\n return this._currentValue;\n }\n /**\n * Dispose this component\n */\n dispose() {\n this.onAxisValueChangedObservable.clear();\n this.onButtonStateChangedObservable.clear();\n }\n /**\n * Are there axes correlating to this component\n * @returns true is axes data is available\n */\n isAxes() {\n return this._axesIndices.length !== 0;\n }\n /**\n * Is this component a button (hence - pressable)\n * @returns true if can be pressed\n */\n isButton() {\n return this._buttonIndex !== -1;\n }\n /**\n * update this component using the gamepad object it is in. Called on every frame\n * @param nativeController the native gamepad controller object\n */\n update(nativeController) {\n let buttonUpdated = false;\n let axesUpdate = false;\n this._hasChanges = false;\n this._changes = {};\n if (this.isButton()) {\n const button = nativeController.buttons[this._buttonIndex];\n // defensive, in case a profile was forced\n if (!button) {\n return;\n }\n if (this._currentValue !== button.value) {\n this.changes.value = {\n current: button.value,\n previous: this._currentValue\n };\n buttonUpdated = true;\n this._currentValue = button.value;\n }\n if (this._touched !== button.touched) {\n this.changes.touched = {\n current: button.touched,\n previous: this._touched\n };\n buttonUpdated = true;\n this._touched = button.touched;\n }\n if (this._pressed !== button.pressed) {\n this.changes.pressed = {\n current: button.pressed,\n previous: this._pressed\n };\n buttonUpdated = true;\n this._pressed = button.pressed;\n }\n }\n if (this.isAxes()) {\n if (this._axes.x !== nativeController.axes[this._axesIndices[0]]) {\n this.changes.axes = {\n current: {\n x: nativeController.axes[this._axesIndices[0]],\n y: this._axes.y\n },\n previous: {\n x: this._axes.x,\n y: this._axes.y\n }\n };\n this._axes.x = nativeController.axes[this._axesIndices[0]];\n axesUpdate = true;\n }\n if (this._axes.y !== nativeController.axes[this._axesIndices[1]]) {\n if (this.changes.axes) {\n this.changes.axes.current.y = nativeController.axes[this._axesIndices[1]];\n } else {\n this.changes.axes = {\n current: {\n x: this._axes.x,\n y: nativeController.axes[this._axesIndices[1]]\n },\n previous: {\n x: this._axes.x,\n y: this._axes.y\n }\n };\n }\n this._axes.y = nativeController.axes[this._axesIndices[1]];\n axesUpdate = true;\n }\n }\n if (buttonUpdated) {\n this._hasChanges = true;\n this.onButtonStateChangedObservable.notifyObservers(this);\n }\n if (axesUpdate) {\n this._hasChanges = true;\n this.onAxisValueChangedObservable.notifyObservers(this._axes);\n }\n }\n}\n/**\n * button component type\n */\nWebXRControllerComponent.BUTTON_TYPE = \"button\";\n/**\n * squeeze component type\n */\nWebXRControllerComponent.SQUEEZE_TYPE = \"squeeze\";\n/**\n * Thumbstick component type\n */\nWebXRControllerComponent.THUMBSTICK_TYPE = \"thumbstick\";\n/**\n * Touchpad component type\n */\nWebXRControllerComponent.TOUCHPAD_TYPE = \"touchpad\";\n/**\n * trigger component type\n */\nWebXRControllerComponent.TRIGGER_TYPE = \"trigger\";","map":{"version":3,"names":["Observable","WebXRControllerComponent","constructor","id","type","_buttonIndex","_axesIndices","_axes","x","y","_changes","_currentValue","_hasChanges","_pressed","_touched","onAxisValueChangedObservable","onButtonStateChangedObservable","axes","changes","hasChanges","pressed","touched","value","dispose","clear","isAxes","length","isButton","update","nativeController","buttonUpdated","axesUpdate","button","buttons","current","previous","notifyObservers","BUTTON_TYPE","SQUEEZE_TYPE","THUMBSTICK_TYPE","TOUCHPAD_TYPE","TRIGGER_TYPE"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/XR/motionController/webXRControllerComponent.js"],"sourcesContent":["import { Observable } from \"../../Misc/observable.js\";\n/**\n * This class represents a single component (for example button or thumbstick) of a motion controller\n */\nexport class WebXRControllerComponent {\n /**\n * Creates a new component for a motion controller.\n * It is created by the motion controller itself\n *\n * @param id the id of this component\n * @param type the type of the component\n * @param _buttonIndex index in the buttons array of the gamepad\n * @param _axesIndices indices of the values in the axes array of the gamepad\n */\n constructor(\n /**\n * the id of this component\n */\n id, \n /**\n * the type of the component\n */\n type, _buttonIndex = -1, _axesIndices = []) {\n this.id = id;\n this.type = type;\n this._buttonIndex = _buttonIndex;\n this._axesIndices = _axesIndices;\n this._axes = {\n x: 0,\n y: 0,\n };\n this._changes = {};\n this._currentValue = 0;\n this._hasChanges = false;\n this._pressed = false;\n this._touched = false;\n /**\n * If axes are available for this component (like a touchpad or thumbstick) the observers will be notified when\n * the axes data changes\n */\n this.onAxisValueChangedObservable = new Observable();\n /**\n * Observers registered here will be triggered when the state of a button changes\n * State change is either pressed / touched / value\n */\n this.onButtonStateChangedObservable = new Observable();\n }\n /**\n * The current axes data. If this component has no axes it will still return an object { x: 0, y: 0 }\n */\n get axes() {\n return this._axes;\n }\n /**\n * Get the changes. Elements will be populated only if they changed with their previous and current value\n */\n get changes() {\n return this._changes;\n }\n /**\n * Return whether or not the component changed the last frame\n */\n get hasChanges() {\n return this._hasChanges;\n }\n /**\n * is the button currently pressed\n */\n get pressed() {\n return this._pressed;\n }\n /**\n * is the button currently touched\n */\n get touched() {\n return this._touched;\n }\n /**\n * Get the current value of this component\n */\n get value() {\n return this._currentValue;\n }\n /**\n * Dispose this component\n */\n dispose() {\n this.onAxisValueChangedObservable.clear();\n this.onButtonStateChangedObservable.clear();\n }\n /**\n * Are there axes correlating to this component\n * @returns true is axes data is available\n */\n isAxes() {\n return this._axesIndices.length !== 0;\n }\n /**\n * Is this component a button (hence - pressable)\n * @returns true if can be pressed\n */\n isButton() {\n return this._buttonIndex !== -1;\n }\n /**\n * update this component using the gamepad object it is in. Called on every frame\n * @param nativeController the native gamepad controller object\n */\n update(nativeController) {\n let buttonUpdated = false;\n let axesUpdate = false;\n this._hasChanges = false;\n this._changes = {};\n if (this.isButton()) {\n const button = nativeController.buttons[this._buttonIndex];\n // defensive, in case a profile was forced\n if (!button) {\n return;\n }\n if (this._currentValue !== button.value) {\n this.changes.value = {\n current: button.value,\n previous: this._currentValue,\n };\n buttonUpdated = true;\n this._currentValue = button.value;\n }\n if (this._touched !== button.touched) {\n this.changes.touched = {\n current: button.touched,\n previous: this._touched,\n };\n buttonUpdated = true;\n this._touched = button.touched;\n }\n if (this._pressed !== button.pressed) {\n this.changes.pressed = {\n current: button.pressed,\n previous: this._pressed,\n };\n buttonUpdated = true;\n this._pressed = button.pressed;\n }\n }\n if (this.isAxes()) {\n if (this._axes.x !== nativeController.axes[this._axesIndices[0]]) {\n this.changes.axes = {\n current: {\n x: nativeController.axes[this._axesIndices[0]],\n y: this._axes.y,\n },\n previous: {\n x: this._axes.x,\n y: this._axes.y,\n },\n };\n this._axes.x = nativeController.axes[this._axesIndices[0]];\n axesUpdate = true;\n }\n if (this._axes.y !== nativeController.axes[this._axesIndices[1]]) {\n if (this.changes.axes) {\n this.changes.axes.current.y = nativeController.axes[this._axesIndices[1]];\n }\n else {\n this.changes.axes = {\n current: {\n x: this._axes.x,\n y: nativeController.axes[this._axesIndices[1]],\n },\n previous: {\n x: this._axes.x,\n y: this._axes.y,\n },\n };\n }\n this._axes.y = nativeController.axes[this._axesIndices[1]];\n axesUpdate = true;\n }\n }\n if (buttonUpdated) {\n this._hasChanges = true;\n this.onButtonStateChangedObservable.notifyObservers(this);\n }\n if (axesUpdate) {\n this._hasChanges = true;\n this.onAxisValueChangedObservable.notifyObservers(this._axes);\n }\n }\n}\n/**\n * button component type\n */\nWebXRControllerComponent.BUTTON_TYPE = \"button\";\n/**\n * squeeze component type\n */\nWebXRControllerComponent.SQUEEZE_TYPE = \"squeeze\";\n/**\n * Thumbstick component type\n */\nWebXRControllerComponent.THUMBSTICK_TYPE = \"thumbstick\";\n/**\n * Touchpad component type\n */\nWebXRControllerComponent.TOUCHPAD_TYPE = \"touchpad\";\n/**\n * trigger component type\n */\nWebXRControllerComponent.TRIGGER_TYPE = \"trigger\";\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,0BAA0B;AACrD;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,CAAC;EAClC;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIC,WAAWA;EACX;AACJ;AACA;EACIC,EAAE;EACF;AACJ;AACA;EACIC,IAAI,EAAEC,YAAY,GAAG,CAAC,CAAC,EAAEC,YAAY,GAAG,EAAE,EAAE;IACxC,IAAI,CAACH,EAAE,GAAGA,EAAE;IACZ,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,YAAY,GAAGA,YAAY;IAChC,IAAI,CAACC,YAAY,GAAGA,YAAY;IAChC,IAAI,CAACC,KAAK,GAAG;MACTC,CAAC,EAAE,CAAC;MACJC,CAAC,EAAE;IACP,CAAC;IACD,IAAI,CAACC,QAAQ,GAAG,CAAC,C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;YAClB;UACJ,CAAC;QACL;QACA,IAAI,CAACF,KAAK,CAACE,CAAC,GAAGoB,gBAAgB,CAACZ,IAAI,CAAC,IAAI,CAACX,YAAY,CAAC,CAAC,CAAC,CAAC;QAC1DyB,UAAU,GAAG,IAAI;MACrB;IACJ;IACA,IAAID,aAAa,EAAE;MACf,IAAI,CAAClB,WAAW,GAAG,IAAI;MACvB,IAAI,CAACI,8BAA8B,CAACoB,eAAe,CAAC,IAAI,CAAC;IAC7D;IACA,IAAIL,UAAU,EAAE;MACZ,IAAI,CAACnB,WAAW,GAAG,IAAI;MACvB,IAAI,CAACG,4BAA4B,CAACqB,eAAe,CAAC,IAAI,CAAC7B,KAAK,CAAC;IACjE;EACJ;AACJ;AACA;AACA;AACA;AACAN,wBAAwB,CAACoC,WAAW,GAAG,QAAQ;AAC/C;AACA;AACA;AACApC,wBAAwB,CAACqC,YAAY,GAAG,SAAS;AACjD;AACA;AACA;AACArC,wBAAwB,CAACsC,eAAe,GAAG,YAAY;AACvD;AACA;AACA;AACAtC,wBAAwB,CAACuC,aAAa,GAAG,UAAU;AACnD;AACA;AACA;AACAvC,wBAAwB,CAACwC,YAAY,GAAG,SAAS","ignoreList":[]},"metadata":{},"sourceType":"module","externalDependencies":[]}