1 |
- {"ast":null,"code":"import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager.js\";\nimport { Observable } from \"../../Misc/observable.js\";\nimport { Vector3 } from \"../../Maths/math.vector.js\";\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature.js\";\n/**\n * The feature point system is used to detect feature points from real world geometry.\n * This feature is currently experimental and only supported on BabylonNative, and should not be used in the browser.\n * The newly introduced API can be seen in webxr.nativeextensions.d.ts and described in FeaturePoints.md.\n */\nexport class WebXRFeaturePointSystem extends WebXRAbstractFeature {\n /**\n * The current feature point cloud maintained across frames.\n */\n get featurePointCloud() {\n return this._featurePointCloud;\n }\n /**\n * construct the feature point system\n * @param _xrSessionManager an instance of xr Session manager\n */\n constructor(_xrSessionManager) {\n super(_xrSessionManager);\n this._enabled = false;\n this._featurePointCloud = [];\n /**\n * Observers registered here will be executed whenever new feature points are added (on XRFrame while the session is tracking).\n * Will notify the observers about which feature points have been added.\n */\n this.onFeaturePointsAddedObservable = new Observable();\n /**\n * Observers registered here will be executed whenever a feature point has been updated (on XRFrame while the session is tracking).\n * Will notify the observers about which feature points have been updated.\n */\n this.onFeaturePointsUpdatedObservable = new Observable();\n this.xrNativeFeatureName = \"bjsfeature-points\";\n if (this._xrSessionManager.session) {\n this._init();\n } else {\n this._xrSessionManager.onXRSessionInit.addOnce(() => {\n this._init();\n });\n }\n }\n /**\n * Detach this feature.\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n detach() {\n if (!super.detach()) {\n return false;\n }\n this.featurePointCloud.length = 0;\n return true;\n }\n /**\n * Dispose this feature and all of the resources attached\n */\n dispose() {\n super.dispose();\n this._featurePointCloud.length = 0;\n this.onFeaturePointsUpdatedObservable.clear();\n this.onFeaturePointsAddedObservable.clear();\n }\n /**\n * On receiving a new XR frame if this feature is attached notify observers new feature point data is available.\n * @param frame\n */\n _onXRFrame(frame) {\n if (!this.attached || !this._enabled || !frame) {\n return;\n }\n const featurePointRawData = frame.featurePointCloud;\n if (!featurePointRawData || featurePointRawData.length === 0) {\n return;\n } else {\n if (featurePointRawData.length % 5 !== 0) {\n throw new Error(\"Received malformed feature point cloud of length: \" + featurePointRawData.length);\n }\n const numberOfFeaturePoints = featurePointRawData.length / 5;\n const updatedFeaturePoints = [];\n const addedFeaturePoints = [];\n for (let i = 0; i < numberOfFeaturePoints; i++) {\n const rawIndex = i * 5;\n const id = featurePointRawData[rawIndex + 4];\n // IDs should be durable across frames and strictly increasing from 0 up, so use them as indexing into the feature point array.\n if (!this._featurePointCloud[id]) {\n this._featurePointCloud[id] = {\n position: new Vector3(),\n confidenceValue: 0\n };\n addedFeaturePoints.push(id);\n } else {\n updatedFeaturePoints.push(id);\n }\n // Set the feature point values.\n this._featurePointCloud[id].position.x = featurePointRawData[rawIndex];\n this._featurePointCloud[id].position.y = featurePointRawData[rawIndex + 1];\n this._featurePointCloud[id].position.z = featurePointRawData[rawIndex + 2];\n this._featurePointCloud[id].confidenceValue = featurePointRawData[rawIndex + 3];\n }\n // Signal observers that feature points have been added if necessary.\n if (addedFeaturePoints.length > 0) {\n this.onFeaturePointsAddedObservable.notifyObservers(addedFeaturePoints);\n }\n // Signal observers that feature points have been updated if necessary.\n if (updatedFeaturePoints.length > 0) {\n this.onFeaturePointsUpdatedObservable.notifyObservers(updatedFeaturePoints);\n }\n }\n }\n /**\n * Initializes the feature. If the feature point feature is not available for this environment do not mark the feature as enabled.\n */\n _init() {\n if (!this._xrSessionManager.session.trySetFeaturePointCloudEnabled || !this._xrSessionManager.session.trySetFeaturePointCloudEnabled(true)) {\n // fail silently\n return;\n }\n this._enabled = true;\n }\n}\n/**\n * The module's name\n */\nWebXRFeaturePointSystem.Name = WebXRFeatureName.FEATURE_POINTS;\n/**\n * The (Babylon) version of this module.\n * This is an integer representing the implementation version.\n * This number does not correspond to the WebXR specs version\n */\nWebXRFeaturePointSystem.Version = 1;\n// register the plugin\nWebXRFeaturesManager.AddWebXRFeature(WebXRFeaturePointSystem.Name, xrSessionManager => {\n return () => new WebXRFeaturePointSystem(xrSessionManager);\n}, WebXRFeaturePointSystem.Version);","map":{"version":3,"names":["WebXRFeaturesManager","WebXRFeatureName","Observable","Vector3","WebXRAbstractFeature","WebXRFeaturePointSystem","featurePointCloud","_featurePointCloud","constructor","_xrSessionManager","_enabled","onFeaturePointsAddedObservable","onFeaturePointsUpdatedObservable","xrNativeFeatureName","session","_init","onXRSessionInit","addOnce","detach","length","dispose","clear","_onXRFrame","frame","attached","featurePointRawData","Error","numberOfFeaturePoints","updatedFeaturePoints","addedFeaturePoints","i","rawIndex","id","position","confidenceValue","push","x","y","z","notifyObservers","trySetFeaturePointCloudEnabled","Name","FEATURE_POINTS","Version","AddWebXRFeature","xrSessionManager"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/XR/features/WebXRFeaturePointSystem.js"],"sourcesContent":["import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager.js\";\nimport { Observable } from \"../../Misc/observable.js\";\nimport { Vector3 } from \"../../Maths/math.vector.js\";\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature.js\";\n/**\n * The feature point system is used to detect feature points from real world geometry.\n * This feature is currently experimental and only supported on BabylonNative, and should not be used in the browser.\n * The newly introduced API can be seen in webxr.nativeextensions.d.ts and described in FeaturePoints.md.\n */\nexport class WebXRFeaturePointSystem extends WebXRAbstractFeature {\n /**\n * The current feature point cloud maintained across frames.\n */\n get featurePointCloud() {\n return this._featurePointCloud;\n }\n /**\n * construct the feature point system\n * @param _xrSessionManager an instance of xr Session manager\n */\n constructor(_xrSessionManager) {\n super(_xrSessionManager);\n this._enabled = false;\n this._featurePointCloud = [];\n /**\n * Observers registered here will be executed whenever new feature points are added (on XRFrame while the session is tracking).\n * Will notify the observers about which feature points have been added.\n */\n this.onFeaturePointsAddedObservable = new Observable();\n /**\n * Observers registered here will be executed whenever a feature point has been updated (on XRFrame while the session is tracking).\n * Will notify the observers about which feature points have been updated.\n */\n this.onFeaturePointsUpdatedObservable = new Observable();\n this.xrNativeFeatureName = \"bjsfeature-points\";\n if (this._xrSessionManager.session) {\n this._init();\n }\n else {\n this._xrSessionManager.onXRSessionInit.addOnce(() => {\n this._init();\n });\n }\n }\n /**\n * Detach this feature.\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n detach() {\n if (!super.detach()) {\n return false;\n }\n this.featurePointCloud.length = 0;\n return true;\n }\n /**\n * Dispose this feature and all of the resources attached\n */\n dispose() {\n super.dispose();\n this._featurePointCloud.length = 0;\n this.onFeaturePointsUpdatedObservable.clear();\n this.onFeaturePointsAddedObservable.clear();\n }\n /**\n * On receiving a new XR frame if this feature is attached notify observers new feature point data is available.\n * @param frame\n */\n _onXRFrame(frame) {\n if (!this.attached || !this._enabled || !frame) {\n return;\n }\n const featurePointRawData = frame.featurePointCloud;\n if (!featurePointRawData || featurePointRawData.length === 0) {\n return;\n }\n else {\n if (featurePointRawData.length % 5 !== 0) {\n throw new Error(\"Received malformed feature point cloud of length: \" + featurePointRawData.length);\n }\n const numberOfFeaturePoints = featurePointRawData.length / 5;\n const updatedFeaturePoints = [];\n const addedFeaturePoints = [];\n for (let i = 0; i < numberOfFeaturePoints; i++) {\n const rawIndex = i * 5;\n const id = featurePointRawData[rawIndex + 4];\n // IDs should be durable across frames and strictly increasing from 0 up, so use them as indexing into the feature point array.\n if (!this._featurePointCloud[id]) {\n this._featurePointCloud[id] = { position: new Vector3(), confidenceValue: 0 };\n addedFeaturePoints.push(id);\n }\n else {\n updatedFeaturePoints.push(id);\n }\n // Set the feature point values.\n this._featurePointCloud[id].position.x = featurePointRawData[rawIndex];\n this._featurePointCloud[id].position.y = featurePointRawData[rawIndex + 1];\n this._featurePointCloud[id].position.z = featurePointRawData[rawIndex + 2];\n this._featurePointCloud[id].confidenceValue = featurePointRawData[rawIndex + 3];\n }\n // Signal observers that feature points have been added if necessary.\n if (addedFeaturePoints.length > 0) {\n this.onFeaturePointsAddedObservable.notifyObservers(addedFeaturePoints);\n }\n // Signal observers that feature points have been updated if necessary.\n if (updatedFeaturePoints.length > 0) {\n this.onFeaturePointsUpdatedObservable.notifyObservers(updatedFeaturePoints);\n }\n }\n }\n /**\n * Initializes the feature. If the feature point feature is not available for this environment do not mark the feature as enabled.\n */\n _init() {\n if (!this._xrSessionManager.session.trySetFeaturePointCloudEnabled || !this._xrSessionManager.session.trySetFeaturePointCloudEnabled(true)) {\n // fail silently\n return;\n }\n this._enabled = true;\n }\n}\n/**\n * The module's name\n */\nWebXRFeaturePointSystem.Name = WebXRFeatureName.FEATURE_POINTS;\n/**\n * The (Babylon) version of this module.\n * This is an integer representing the implementation version.\n * This number does not correspond to the WebXR specs version\n */\nWebXRFeaturePointSystem.Version = 1;\n// register the plugin\nWebXRFeaturesManager.AddWebXRFeature(WebXRFeaturePointSystem.Name, (xrSessionManager) => {\n return () => new WebXRFeaturePointSystem(xrSessionManager);\n}, WebXRFeaturePointSystem.Version);\n"],"mappings":"AAAA,SAASA,oBAAoB,EAAEC,gBAAgB,QAAQ,4BAA4B;AACnF,SAASC,UAAU,QAAQ,0BAA0B;AACrD,SAASC,OAAO,QAAQ,4BAA4B;AACpD,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,uBAAuB,SAASD,oBAAoB,CAAC;EAC9D;AACJ;AACA;EACI,IAAIE,iBAAiBA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACC,kBAAkB;EAClC;EACA;AACJ;AACA;AACA;EACIC,WAAWA,CAACC,iBAAiB,EAAE;IAC3B,KAAK,CAACA,iBAAiB,CAAC;IACxB,IAAI,CAACC,QAAQ,GAAG,KAAK;IACrB,IAAI,CAACH,kBAAkB,GAAG,EAAE;IAC5B;AACR;AACA;AACA;IACQ,IAAI,CAACI,8BAA8B,GAAG,IAAIT,UAAU,CAAC,CAAC;IACtD;AACR;AACA;AACA;IACQ,IAAI,CAACU,gCAAgC,GAAG,IAAIV,UAAU,CAAC,CAAC;IACxD,I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