1 |
- {"ast":null,"code":"import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager.js\";\nimport { Observable } from \"../../Misc/observable.js\";\nimport { Vector3, Matrix } from \"../../Maths/math.vector.js\";\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature.js\";\nimport { Tools } from \"../../Misc/tools.js\";\n/**\n * The currently-working hit-test module.\n * Hit test (or Ray-casting) is used to interact with the real world.\n * For further information read here - https://github.com/immersive-web/hit-test\n */\nexport class WebXRHitTestLegacy extends WebXRAbstractFeature {\n /**\n * Creates a new instance of the (legacy version) hit test feature\n * @param _xrSessionManager an instance of WebXRSessionManager\n * @param options options to use when constructing this feature\n */\n constructor(_xrSessionManager,\n /**\n * [Empty Object] options to use when constructing this feature\n */\n options = {}) {\n super(_xrSessionManager);\n this.options = options;\n // in XR space z-forward is negative\n this._direction = new Vector3(0, 0, -1);\n this._mat = new Matrix();\n this._onSelectEnabled = false;\n this._origin = new Vector3(0, 0, 0);\n /**\n * Populated with the last native XR Hit Results\n */\n this.lastNativeXRHitResults = [];\n /**\n * Triggered when new babylon (transformed) hit test results are available\n */\n this.onHitTestResultObservable = new Observable();\n this._onHitTestResults = xrResults => {\n const mats = xrResults.map(result => {\n const mat = Matrix.FromArray(result.hitMatrix);\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\n mat.toggleModelMatrixHandInPlace();\n }\n // if (this.options.coordinatesSpace === Space.WORLD) {\n if (this.options.worldParentNode) {\n mat.multiplyToRef(this.options.worldParentNode.getWorldMatrix(), mat);\n }\n return {\n xrHitResult: result,\n transformationMatrix: mat\n };\n });\n this.lastNativeXRHitResults = xrResults;\n this.onHitTestResultObservable.notifyObservers(mats);\n };\n // can be done using pointerdown event, and xrSessionManager.currentFrame\n this._onSelect = event => {\n if (!this._onSelectEnabled) {\n return;\n }\n WebXRHitTestLegacy.XRHitTestWithSelectEvent(event, this._xrSessionManager.referenceSpace);\n };\n this.xrNativeFeatureName = \"hit-test\";\n Tools.Warn(\"A newer version of this plugin is available\");\n }\n /**\n * execute a hit test with an XR Ray\n *\n * @param xrSession a native xrSession that will execute this hit test\n * @param xrRay the ray (position and direction) to use for ray-casting\n * @param referenceSpace native XR reference space to use for the hit-test\n * @param filter filter function that will filter the results\n * @returns a promise that resolves with an array of native XR hit result in xr coordinates system\n */\n static XRHitTestWithRay(xrSession, xrRay, referenceSpace, filter) {\n return xrSession.requestHitTest(xrRay, referenceSpace).then(results => {\n const filterFunction = filter || (result => !!result.hitMatrix);\n return results.filter(filterFunction);\n });\n }\n /**\n * Execute a hit test on the current running session using a select event returned from a transient input (such as touch)\n * @param event the (select) event to use to select with\n * @param referenceSpace the reference space to use for this hit test\n * @returns a promise that resolves with an array of native XR hit result in xr coordinates system\n */\n static XRHitTestWithSelectEvent(event, referenceSpace) {\n const targetRayPose = event.frame.getPose(event.inputSource.targetRaySpace, referenceSpace);\n if (!targetRayPose) {\n return Promise.resolve([]);\n }\n const targetRay = new XRRay(targetRayPose.transform);\n return this.XRHitTestWithRay(event.frame.session, targetRay, referenceSpace);\n }\n /**\n * attach this feature\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n attach() {\n if (!super.attach()) {\n return false;\n }\n if (this.options.testOnPointerDownOnly) {\n this._xrSessionManager.session.addEventListener(\"select\", this._onSelect, false);\n }\n return true;\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 // disable select\n this._onSelectEnabled = false;\n this._xrSessionManager.session.removeEventListener(\"select\", this._onSelect);\n return true;\n }\n /**\n * Dispose this feature and all of the resources attached\n */\n dispose() {\n super.dispose();\n this.onHitTestResultObservable.clear();\n }\n _onXRFrame(frame) {\n // make sure we do nothing if (async) not attached\n if (!this.attached || this.options.testOnPointerDownOnly) {\n return;\n }\n const pose = frame.getViewerPose(this._xrSessionManager.referenceSpace);\n if (!pose) {\n return;\n }\n Matrix.FromArrayToRef(pose.transform.matrix, 0, this._mat);\n Vector3.TransformCoordinatesFromFloatsToRef(0, 0, 0, this._mat, this._origin);\n Vector3.TransformCoordinatesFromFloatsToRef(0, 0, -1, this._mat, this._direction);\n this._direction.subtractInPlace(this._origin);\n this._direction.normalize();\n const ray = new XRRay({\n x: this._origin.x,\n y: this._origin.y,\n z: this._origin.z,\n w: 0\n }, {\n x: this._direction.x,\n y: this._direction.y,\n z: this._direction.z,\n w: 0\n });\n WebXRHitTestLegacy.XRHitTestWithRay(this._xrSessionManager.session, ray, this._xrSessionManager.referenceSpace).then(this._onHitTestResults);\n }\n}\n/**\n * The module's name\n */\nWebXRHitTestLegacy.Name = WebXRFeatureName.HIT_TEST;\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 */\nWebXRHitTestLegacy.Version = 1;\n//register the plugin versions\nWebXRFeaturesManager.AddWebXRFeature(WebXRHitTestLegacy.Name, (xrSessionManager, options) => {\n return () => new WebXRHitTestLegacy(xrSessionManager, options);\n}, WebXRHitTestLegacy.Version, false);","map":{"version":3,"names":["WebXRFeaturesManager","WebXRFeatureName","Observable","Vector3","Matrix","WebXRAbstractFeature","Tools","WebXRHitTestLegacy","constructor","_xrSessionManager","options","_direction","_mat","_onSelectEnabled","_origin","lastNativeXRHitResults","onHitTestResultObservable","_onHitTestResults","xrResults","mats","map","result","mat","FromArray","hitMatrix","scene","useRightHandedSystem","toggleModelMatrixHandInPlace","worldParentNode","multiplyToRef","getWorldMatrix","xrHitResult","transformationMatrix","notifyObservers","_onSelect","event","XRHitTestWithSelectEvent","referenceSpace","xrNativeFeatureName","Warn","XRHitTestWithRay","xrSession","xrRay","filter","requestHitTest","then","results","filterFunction","targetRayPose","frame","getPose","inputSource","targetRaySpace","Promise","resolve","targetRay","XRRay","transform","session","attach","testOnPointerDownOnly","addEventListener","detach","removeEventListener","dispose","clear","_onXRFrame","attached","pose","getViewerPose","FromArrayToRef","matrix","TransformCoordinatesFromFloatsToRef","subtractInPlace","normalize","ray","x","y","z","w","Name","HIT_TEST","Version","AddWebXRFeature","xrSessionManager"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/XR/features/WebXRHitTestLegacy.js"],"sourcesContent":["import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager.js\";\nimport { Observable } from \"../../Misc/observable.js\";\nimport { Vector3, Matrix } from \"../../Maths/math.vector.js\";\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature.js\";\nimport { Tools } from \"../../Misc/tools.js\";\n/**\n * The currently-working hit-test module.\n * Hit test (or Ray-casting) is used to interact with the real world.\n * For further information read here - https://github.com/immersive-web/hit-test\n */\nexport class WebXRHitTestLegacy extends WebXRAbstractFeature {\n /**\n * Creates a new instance of the (legacy version) hit test feature\n * @param _xrSessionManager an instance of WebXRSessionManager\n * @param options options to use when constructing this feature\n */\n constructor(_xrSessionManager, \n /**\n * [Empty Object] options to use when constructing this feature\n */\n options = {}) {\n super(_xrSessionManager);\n this.options = options;\n // in XR space z-forward is negative\n this._direction = new Vector3(0, 0, -1);\n this._mat = new Matrix();\n this._onSelectEnabled = false;\n this._origin = new Vector3(0, 0, 0);\n /**\n * Populated with the last native XR Hit Results\n */\n this.lastNativeXRHitResults = [];\n /**\n * Triggered when new babylon (transformed) hit test results are available\n */\n this.onHitTestResultObservable = new Observable();\n this._onHitTestResults = (xrResults) => {\n const mats = xrResults.map((result) => {\n const mat = Matrix.FromArray(result.hitMatrix);\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\n mat.toggleModelMatrixHandInPlace();\n }\n // if (this.options.coordinatesSpace === Space.WORLD) {\n if (this.options.worldParentNode) {\n mat.multiplyToRef(this.options.worldParentNode.getWorldMatrix(), mat);\n }\n return {\n xrHitResult: result,\n transformationMatrix: mat,\n };\n });\n this.lastNativeXRHitResults = xrResults;\n this.onHitTestResultObservable.notifyObservers(mats);\n };\n // can be done using pointerdown event, and xrSessionManager.currentFrame\n this._onSelect = (event) => {\n if (!this._onSelectEnabled) {\n return;\n }\n WebXRHitTestLegacy.XRHitTestWithSelectEvent(event, this._xrSessionManager.referenceSpace);\n };\n this.xrNativeFeatureName = \"hit-test\";\n Tools.Warn(\"A newer version of this plugin is available\");\n }\n /**\n * execute a hit test with an XR Ray\n *\n * @param xrSession a native xrSession that will execute this hit test\n * @param xrRay the ray (position and direction) to use for ray-casting\n * @param referenceSpace native XR reference space to use for the hit-test\n * @param filter filter function that will filter the results\n * @returns a promise that resolves with an array of native XR hit result in xr coordinates system\n */\n static XRHitTestWithRay(xrSession, xrRay, referenceSpace, filter) {\n return xrSession.requestHitTest(xrRay, referenceSpace).then((results) => {\n const filterFunction = filter || ((result) => !!result.hitMatrix);\n return results.filter(filterFunction);\n });\n }\n /**\n * Execute a hit test on the current running session using a select event returned from a transient input (such as touch)\n * @param event the (select) event to use to select with\n * @param referenceSpace the reference space to use for this hit test\n * @returns a promise that resolves with an array of native XR hit result in xr coordinates system\n */\n static XRHitTestWithSelectEvent(event, referenceSpace) {\n const targetRayPose = event.frame.getPose(event.inputSource.targetRaySpace, referenceSpace);\n if (!targetRayPose) {\n return Promise.resolve([]);\n }\n const targetRay = new XRRay(targetRayPose.transform);\n return this.XRHitTestWithRay(event.frame.session, targetRay, referenceSpace);\n }\n /**\n * attach this feature\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n attach() {\n if (!super.attach()) {\n return false;\n }\n if (this.options.testOnPointerDownOnly) {\n this._xrSessionManager.session.addEventListener(\"select\", this._onSelect, false);\n }\n return true;\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 // disable select\n this._onSelectEnabled = false;\n this._xrSessionManager.session.removeEventListener(\"select\", this._onSelect);\n return true;\n }\n /**\n * Dispose this feature and all of the resources attached\n */\n dispose() {\n super.dispose();\n this.onHitTestResultObservable.clear();\n }\n _onXRFrame(frame) {\n // make sure we do nothing if (async) not attached\n if (!this.attached || this.options.testOnPointerDownOnly) {\n return;\n }\n const pose = frame.getViewerPose(this._xrSessionManager.referenceSpace);\n if (!pose) {\n return;\n }\n Matrix.FromArrayToRef(pose.transform.matrix, 0, this._mat);\n Vector3.TransformCoordinatesFromFloatsToRef(0, 0, 0, this._mat, this._origin);\n Vector3.TransformCoordinatesFromFloatsToRef(0, 0, -1, this._mat, this._direction);\n this._direction.subtractInPlace(this._origin);\n this._direction.normalize();\n const ray = new XRRay({ x: this._origin.x, y: this._origin.y, z: this._origin.z, w: 0 }, { x: this._direction.x, y: this._direction.y, z: this._direction.z, w: 0 });\n WebXRHitTestLegacy.XRHitTestWithRay(this._xrSessionManager.session, ray, this._xrSessionManager.referenceSpace).then(this._onHitTestResults);\n }\n}\n/**\n * The module's name\n */\nWebXRHitTestLegacy.Name = WebXRFeatureName.HIT_TEST;\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 */\nWebXRHitTestLegacy.Version = 1;\n//register the plugin versions\nWebXRFeaturesManager.AddWebXRFeature(WebXRHitTestLegacy.Name, (xrSessionManager, options) => {\n return () => new WebXRHitTestLegacy(xrSessionManager, options);\n}, WebXRHitTestLegacy.Version, false);\n"],"mappings":"AAAA,SAASA,oBAAoB,EAAEC,gBAAgB,QAAQ,4BAA4B;AACnF,SAASC,UAAU,QAAQ,0BAA0B;AACrD,SAASC,OAAO,EAAEC,MAAM,QAAQ,4BAA4B;AAC5D,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,KAAK,QAAQ,qBAAqB;AAC3C;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,SAASF,oBAAoB,CAAC;EACzD;AACJ;AACA;AACA;AACA;EACIG,WAAWA,CAACC,iBAAiB;EAC7B;AACJ;AACA;EACIC,OAAO,GAAG,CAAC,CAAC,EAAE;IACV,KAAK,CAACD,iBAAiB,CAAC;IACxB,IAAI,CAACC,OAAO,GAAGA,OAAO;IACtB;IACA,IAAI,CAACC,U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