623a9fa0473768fb5b52921cfdb21ced9de2372212beb1825a12301a47b76adf.json 14 KB

1
  1. {"ast":null,"code":"import { Observable } from \"../../Misc/observable.js\";\nimport { Logger } from \"../../Misc/logger.js\";\n/**\n * This is the base class for all WebXR features.\n * Since most features require almost the same resources and callbacks, this class can be used to simplify the development\n * Note that since the features manager is using the `IWebXRFeature` you are in no way obligated to use this class\n */\nexport class WebXRAbstractFeature {\n /**\n * The name of the native xr feature name (like anchor, hit-test, or hand-tracking)\n */\n get xrNativeFeatureName() {\n return this._xrNativeFeatureName;\n }\n set xrNativeFeatureName(name) {\n var _this$_xrSessionManag;\n // check if feature was initialized while in session but needs to be initialized before the session starts\n if (!this._xrSessionManager.isNative && name && this._xrSessionManager.inXRSession && ((_this$_xrSessionManag = this._xrSessionManager.enabledFeatures) === null || _this$_xrSessionManag === void 0 ? void 0 : _this$_xrSessionManag.indexOf(name)) === -1) {\n Logger.Warn(`The feature ${name} needs to be enabled before starting the XR session. Note - It is still possible it is not supported.`);\n }\n this._xrNativeFeatureName = name;\n }\n /**\n * Construct a new (abstract) WebXR feature\n * @param _xrSessionManager the xr session manager for this feature\n */\n constructor(_xrSessionManager) {\n this._xrSessionManager = _xrSessionManager;\n this._attached = false;\n this._removeOnDetach = [];\n /**\n * Is this feature disposed?\n */\n this.isDisposed = false;\n /**\n * Should auto-attach be disabled?\n */\n this.disableAutoAttach = false;\n this._xrNativeFeatureName = \"\";\n /**\n * Observers registered here will be executed when the feature is attached\n */\n this.onFeatureAttachObservable = new Observable();\n /**\n * Observers registered here will be executed when the feature is detached\n */\n this.onFeatureDetachObservable = new Observable();\n }\n /**\n * Is this feature attached\n */\n get attached() {\n return this._attached;\n }\n /**\n * attach this feature\n *\n * @param force should attachment be forced (even when already attached)\n * @returns true if successful, false is failed or already attached\n */\n attach(force) {\n // do not attach a disposed feature\n if (this.isDisposed) {\n return false;\n }\n if (!force) {\n if (this.attached) {\n return false;\n }\n } else {\n if (this.attached) {\n // detach first, to be sure\n this.detach();\n }\n }\n // if this is a native WebXR feature, check if it is enabled on the session\n // For now only check if not using babylon native\n // vision OS doesn't support the enabledFeatures array, so just warn instead of failing\n if (!this._xrSessionManager.enabledFeatures) {\n Logger.Warn(\"session.enabledFeatures is not available on this device. It is possible that this feature is not supported.\");\n } else if (!this._xrSessionManager.isNative && this.xrNativeFeatureName && this._xrSessionManager.enabledFeatures.indexOf(this.xrNativeFeatureName) === -1) {\n return false;\n }\n this._attached = true;\n this._addNewAttachObserver(this._xrSessionManager.onXRFrameObservable, frame => this._onXRFrame(frame));\n this.onFeatureAttachObservable.notifyObservers(this);\n return true;\n }\n /**\n * detach this feature.\n *\n * @returns true if successful, false if failed or already detached\n */\n detach() {\n if (!this._attached) {\n this.disableAutoAttach = true;\n return false;\n }\n this._attached = false;\n this._removeOnDetach.forEach(toRemove => {\n toRemove.observable.remove(toRemove.observer);\n });\n this.onFeatureDetachObservable.notifyObservers(this);\n return true;\n }\n /**\n * Dispose this feature and all of the resources attached\n */\n dispose() {\n this.detach();\n this.isDisposed = true;\n this.onFeatureAttachObservable.clear();\n this.onFeatureDetachObservable.clear();\n }\n /**\n * This function will be executed during before enabling the feature and can be used to not-allow enabling it.\n * Note that at this point the session has NOT started, so this is purely checking if the browser supports it\n *\n * @returns whether or not the feature is compatible in this environment\n */\n isCompatible() {\n return true;\n }\n /**\n * This is used to register callbacks that will automatically be removed when detach is called.\n * @param observable the observable to which the observer will be attached\n * @param callback the callback to register\n * @param insertFirst should the callback be executed as soon as it is registered\n */\n _addNewAttachObserver(observable, callback, insertFirst) {\n this._removeOnDetach.push({\n observable,\n observer: observable.add(callback, undefined, insertFirst)\n });\n }\n}","map":{"version":3,"names":["Observable","Logger","WebXRAbstractFeature","xrNativeFeatureName","_xrNativeFeatureName","name","_this$_xrSessionManag","_xrSessionManager","isNative","inXRSession","enabledFeatures","indexOf","Warn","constructor","_attached","_removeOnDetach","isDisposed","disableAutoAttach","onFeatureAttachObservable","onFeatureDetachObservable","attached","attach","force","detach","_addNewAttachObserver","onXRFrameObservable","frame","_onXRFrame","notifyObservers","forEach","toRemove","observable","remove","observer","dispose","clear","isCompatible","callback","insertFirst","push","add","undefined"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/XR/features/WebXRAbstractFeature.js"],"sourcesContent":["import { Observable } from \"../../Misc/observable.js\";\nimport { Logger } from \"../../Misc/logger.js\";\n/**\n * This is the base class for all WebXR features.\n * Since most features require almost the same resources and callbacks, this class can be used to simplify the development\n * Note that since the features manager is using the `IWebXRFeature` you are in no way obligated to use this class\n */\nexport class WebXRAbstractFeature {\n /**\n * The name of the native xr feature name (like anchor, hit-test, or hand-tracking)\n */\n get xrNativeFeatureName() {\n return this._xrNativeFeatureName;\n }\n set xrNativeFeatureName(name) {\n // check if feature was initialized while in session but needs to be initialized before the session starts\n if (!this._xrSessionManager.isNative && name && this._xrSessionManager.inXRSession && this._xrSessionManager.enabledFeatures?.indexOf(name) === -1) {\n Logger.Warn(`The feature ${name} needs to be enabled before starting the XR session. Note - It is still possible it is not supported.`);\n }\n this._xrNativeFeatureName = name;\n }\n /**\n * Construct a new (abstract) WebXR feature\n * @param _xrSessionManager the xr session manager for this feature\n */\n constructor(_xrSessionManager) {\n this._xrSessionManager = _xrSessionManager;\n this._attached = false;\n this._removeOnDetach = [];\n /**\n * Is this feature disposed?\n */\n this.isDisposed = false;\n /**\n * Should auto-attach be disabled?\n */\n this.disableAutoAttach = false;\n this._xrNativeFeatureName = \"\";\n /**\n * Observers registered here will be executed when the feature is attached\n */\n this.onFeatureAttachObservable = new Observable();\n /**\n * Observers registered here will be executed when the feature is detached\n */\n this.onFeatureDetachObservable = new Observable();\n }\n /**\n * Is this feature attached\n */\n get attached() {\n return this._attached;\n }\n /**\n * attach this feature\n *\n * @param force should attachment be forced (even when already attached)\n * @returns true if successful, false is failed or already attached\n */\n attach(force) {\n // do not attach a disposed feature\n if (this.isDisposed) {\n return false;\n }\n if (!force) {\n if (this.attached) {\n return false;\n }\n }\n else {\n if (this.attached) {\n // detach first, to be sure\n this.detach();\n }\n }\n // if this is a native WebXR feature, check if it is enabled on the session\n // For now only check if not using babylon native\n // vision OS doesn't support the enabledFeatures array, so just warn instead of failing\n if (!this._xrSessionManager.enabledFeatures) {\n Logger.Warn(\"session.enabledFeatures is not available on this device. It is possible that this feature is not supported.\");\n }\n else if (!this._xrSessionManager.isNative && this.xrNativeFeatureName && this._xrSessionManager.enabledFeatures.indexOf(this.xrNativeFeatureName) === -1) {\n return false;\n }\n this._attached = true;\n this._addNewAttachObserver(this._xrSessionManager.onXRFrameObservable, (frame) => this._onXRFrame(frame));\n this.onFeatureAttachObservable.notifyObservers(this);\n return true;\n }\n /**\n * detach this feature.\n *\n * @returns true if successful, false if failed or already detached\n */\n detach() {\n if (!this._attached) {\n this.disableAutoAttach = true;\n return false;\n }\n this._attached = false;\n this._removeOnDetach.forEach((toRemove) => {\n toRemove.observable.remove(toRemove.observer);\n });\n this.onFeatureDetachObservable.notifyObservers(this);\n return true;\n }\n /**\n * Dispose this feature and all of the resources attached\n */\n dispose() {\n this.detach();\n this.isDisposed = true;\n this.onFeatureAttachObservable.clear();\n this.onFeatureDetachObservable.clear();\n }\n /**\n * This function will be executed during before enabling the feature and can be used to not-allow enabling it.\n * Note that at this point the session has NOT started, so this is purely checking if the browser supports it\n *\n * @returns whether or not the feature is compatible in this environment\n */\n isCompatible() {\n return true;\n }\n /**\n * This is used to register callbacks that will automatically be removed when detach is called.\n * @param observable the observable to which the observer will be attached\n * @param callback the callback to register\n * @param insertFirst should the callback be executed as soon as it is registered\n */\n _addNewAttachObserver(observable, callback, insertFirst) {\n this._removeOnDetach.push({\n observable,\n observer: observable.add(callback, undefined, insertFirst),\n });\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,0BAA0B;AACrD,SAASC,MAAM,QAAQ,sBAAsB;AAC7C;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,CAAC;EAC9B;AACJ;AACA;EACI,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AG,IAAI;IACtB,IAAI,CAACE,yBAAyB,CAACiB,KAAK,CAAC,CAAC;IACtC,IAAI,CAAChB,yBAAyB,CAACgB,KAAK,CAAC,CAAC;EAC1C;EACA;AACJ;AACA;AACA;AACA;AACA;EACIC,YAAYA,CAAA,EAAG;IACX,OAAO,IAAI;EACf;EACA;AACJ;AACA;AACA;AACA;AACA;EACIZ,qBAAqBA,CAACO,UAAU,EAAEM,QAAQ,EAAEC,WAAW,EAAE;IACrD,IAAI,CAACvB,eAAe,CAACwB,IAAI,CAAC;MACtBR,UAAU;MACVE,QAAQ,EAAEF,UAAU,CAACS,GAAG,CAACH,QAAQ,EAAEI,SAAS,EAAEH,WAAW;IAC7D,CAAC,CAAC;EACN;AACJ","ignoreList":[]},"metadata":{},"sourceType":"module","externalDependencies":[]}