@onerjs/core 8.30.1 → 8.30.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AudioV2/abstractAudio/abstractSound.d.ts +4 -0
- package/AudioV2/abstractAudio/abstractSound.js +6 -0
- package/AudioV2/abstractAudio/abstractSound.js.map +1 -1
- package/AudioV2/abstractAudio/abstractSoundInstance.js +3 -0
- package/AudioV2/abstractAudio/abstractSoundInstance.js.map +1 -1
- package/AudioV2/webAudio/webAudioStreamingSound.js +1 -1
- package/AudioV2/webAudio/webAudioStreamingSound.js.map +1 -1
- package/AudioV2/webAudio/webAudioUnmuteUI.js +1 -1
- package/AudioV2/webAudio/webAudioUnmuteUI.js.map +1 -1
- package/Cameras/arcRotateCamera.js +1 -1
- package/Cameras/arcRotateCamera.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js +1 -1
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js.map +1 -1
- package/Materials/Textures/mirrorTexture.d.ts +4 -0
- package/Materials/Textures/mirrorTexture.js +9 -0
- package/Materials/Textures/mirrorTexture.js.map +1 -1
- package/Shaders/ShadersInclude/gaussianSplatting.js +2 -10
- package/Shaders/ShadersInclude/gaussianSplatting.js.map +1 -1
- package/Shaders/gaussianSplattingDepth.fragment.js +7 -1
- package/Shaders/gaussianSplattingDepth.fragment.js.map +1 -1
- package/Shaders/gaussianSplattingDepth.vertex.js +2 -2
- package/Shaders/gaussianSplattingDepth.vertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/gaussianSplatting.js +1 -7
- package/ShadersWGSL/ShadersInclude/gaussianSplatting.js.map +1 -1
- package/ShadersWGSL/gaussianSplattingDepth.fragment.d.ts +1 -0
- package/ShadersWGSL/gaussianSplattingDepth.fragment.js +15 -3
- package/ShadersWGSL/gaussianSplattingDepth.fragment.js.map +1 -1
- package/ShadersWGSL/gaussianSplattingDepth.vertex.js +2 -2
- package/ShadersWGSL/gaussianSplattingDepth.vertex.js.map +1 -1
- package/XR/features/WebXRAnchorSystem.js +14 -21
- package/XR/features/WebXRAnchorSystem.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,6 @@ import { WebXRFeatureName, WebXRFeaturesManager } from "../webXRFeaturesManager.
|
|
|
2
2
|
import { Observable } from "../../Misc/observable.js";
|
|
3
3
|
import { Matrix, Vector3, Quaternion } from "../../Maths/math.vector.js";
|
|
4
4
|
import { WebXRAbstractFeature } from "./WebXRAbstractFeature.js";
|
|
5
|
-
import { Tools } from "../../Misc/tools.js";
|
|
6
5
|
let AnchorIdProvider = 0;
|
|
7
6
|
/**
|
|
8
7
|
* An implementation of the anchor system for WebXR.
|
|
@@ -179,17 +178,14 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
|
|
|
179
178
|
}
|
|
180
179
|
const trackedAnchors = frame.trackedAnchors;
|
|
181
180
|
if (trackedAnchors) {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
for (const index of toRemove) {
|
|
189
|
-
const anchor = this._trackedAnchors.splice(index - idxTracker, 1)[0];
|
|
181
|
+
for (const anchor of this._trackedAnchors) {
|
|
182
|
+
if (!anchor._removed) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const index = this._trackedAnchors.indexOf(anchor);
|
|
186
|
+
this._trackedAnchors.splice(index, 1);
|
|
190
187
|
anchor.xrAnchor.delete();
|
|
191
188
|
this.onAnchorRemovedObservable.notifyObservers(anchor);
|
|
192
|
-
idxTracker++;
|
|
193
189
|
}
|
|
194
190
|
// now check for new ones
|
|
195
191
|
trackedAnchors.forEach((xrAnchor) => {
|
|
@@ -214,19 +210,16 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
|
|
|
214
210
|
}
|
|
215
211
|
else {
|
|
216
212
|
const index = this._findIndexInAnchorArray(xrAnchor);
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
// anchors update every frame
|
|
220
|
-
this._updateAnchorWithXRFrame(xrAnchor, anchor, frame);
|
|
221
|
-
if (anchor.attachedNode) {
|
|
222
|
-
anchor.attachedNode.rotationQuaternion = anchor.attachedNode.rotationQuaternion || new Quaternion();
|
|
223
|
-
anchor.transformationMatrix.decompose(anchor.attachedNode.scaling, anchor.attachedNode.rotationQuaternion, anchor.attachedNode.position);
|
|
224
|
-
}
|
|
225
|
-
this.onAnchorUpdatedObservable.notifyObservers(anchor);
|
|
213
|
+
if (index < 0) {
|
|
214
|
+
return;
|
|
226
215
|
}
|
|
227
|
-
|
|
228
|
-
|
|
216
|
+
const anchor = this._trackedAnchors[index];
|
|
217
|
+
this._updateAnchorWithXRFrame(xrAnchor, anchor, frame);
|
|
218
|
+
if (anchor.attachedNode) {
|
|
219
|
+
anchor.attachedNode.rotationQuaternion = anchor.attachedNode.rotationQuaternion || new Quaternion();
|
|
220
|
+
anchor.transformationMatrix.decompose(anchor.attachedNode.scaling, anchor.attachedNode.rotationQuaternion, anchor.attachedNode.position);
|
|
229
221
|
}
|
|
222
|
+
this.onAnchorUpdatedObservable.notifyObservers(anchor);
|
|
230
223
|
}
|
|
231
224
|
});
|
|
232
225
|
this._lastFrameDetected = trackedAnchors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebXRAnchorSystem.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRAnchorSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,KAAK,EAAE,MA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D;;GAEG;AACoB,sBAAI,GAAG,gBAAgB,CAAC,aAAa,AAAjC,CAAkC;AAC7D;;;;GAIG;AACoB,yBAAO,GAAG,CAAC,AAAJ,CAAK;AA2TvC,sBAAsB;AACtB,oBAAoB,CAAC,eAAe,CAChC,iBAAiB,CAAC,IAAI,EACtB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,iBAAiB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC,EACD,iBAAiB,CAAC,OAAO,CAC5B,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Matrix, Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { IWebXRHitResult } from \"./WebXRHitTest\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Configuration options of the anchor system\r\n */\r\nexport interface IWebXRAnchorSystemOptions {\r\n /**\r\n * a node that will be used to convert local to world coordinates\r\n */\r\n worldParentNode?: TransformNode;\r\n\r\n /**\r\n * If set to true a reference of the created anchors will be kept until the next session starts\r\n * If not defined, anchors will be removed from the array when the feature is detached or the session ended.\r\n */\r\n doNotRemoveAnchorsOnSessionEnded?: boolean;\r\n\r\n /**\r\n * If set to true, all anchor arrays will be cleared when the session initializes\r\n */\r\n clearAnchorsOnSessionInit?: boolean;\r\n}\r\n\r\n/**\r\n * A babylon container for an XR Anchor\r\n */\r\nexport interface IWebXRAnchor {\r\n /**\r\n * A babylon-assigned ID for this anchor\r\n */\r\n id: number;\r\n /**\r\n * Transformation matrix to apply to an object attached to this anchor\r\n */\r\n transformationMatrix: Matrix;\r\n /**\r\n * The native anchor object\r\n */\r\n xrAnchor: XRAnchor;\r\n\r\n /**\r\n * if defined, this object will be constantly updated by the anchor's position and rotation\r\n */\r\n attachedNode?: TransformNode;\r\n\r\n /**\r\n * Remove this anchor from the scene\r\n */\r\n remove(): void;\r\n\r\n /**\r\n * @internal - set to true when the anchor was removed\r\n */\r\n _removed: boolean;\r\n}\r\n\r\n/**\r\n * An internal interface for a future (promise based) anchor\r\n */\r\ninterface IWebXRFutureAnchor {\r\n /**\r\n * The native anchor\r\n */\r\n nativeAnchor?: XRAnchor;\r\n /**\r\n * Was this request submitted to the xr frame?\r\n */\r\n submitted: boolean;\r\n /**\r\n * Was this promise resolved already?\r\n */\r\n resolved: boolean;\r\n /**\r\n * A resolve function\r\n */\r\n resolve: (xrAnchor: IWebXRAnchor) => void;\r\n /**\r\n * A reject function\r\n */\r\n reject: (msg?: string) => void;\r\n /**\r\n * The XR Transformation of the future anchor\r\n */\r\n xrTransformation: XRRigidTransform;\r\n}\r\n\r\nlet AnchorIdProvider = 0;\r\n\r\n/**\r\n * An implementation of the anchor system for WebXR.\r\n * For further information see https://github.com/immersive-web/anchors/\r\n */\r\nexport class WebXRAnchorSystem extends WebXRAbstractFeature {\r\n private _lastFrameDetected: XRAnchorSet = new Set();\r\n\r\n private _trackedAnchors: Array<IWebXRAnchor> = [];\r\n\r\n private _referenceSpaceForFrameAnchors: XRReferenceSpace;\r\n\r\n private _futureAnchors: IWebXRFutureAnchor[] = [];\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.ANCHOR_SYSTEM;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Observers registered here will be executed when a new anchor was added to the session\r\n */\r\n public onAnchorAddedObservable: Observable<IWebXRAnchor> = new Observable();\r\n /**\r\n * Observers registered here will be executed when an anchor was removed from the session\r\n */\r\n public onAnchorRemovedObservable: Observable<IWebXRAnchor> = new Observable();\r\n /**\r\n * Observers registered here will be executed when an existing anchor updates\r\n * This can execute N times every frame\r\n */\r\n public onAnchorUpdatedObservable: Observable<IWebXRAnchor> = new Observable();\r\n\r\n /**\r\n * Set the reference space to use for anchor creation, when not using a hit test.\r\n * Will default to the session's reference space if not defined\r\n */\r\n public set referenceSpaceForFrameAnchors(referenceSpace: XRReferenceSpace) {\r\n this._referenceSpaceForFrameAnchors = referenceSpace;\r\n }\r\n\r\n /**\r\n * constructs a new anchor system\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param _options configuration object for this feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n private _options: IWebXRAnchorSystemOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"anchors\";\r\n\r\n if (this._options.clearAnchorsOnSessionInit) {\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n this._trackedAnchors.length = 0;\r\n this._futureAnchors.length = 0;\r\n this._lastFrameDetected.clear();\r\n });\r\n }\r\n }\r\n\r\n private _tmpVector = new Vector3();\r\n private _tmpQuaternion = new Quaternion();\r\n\r\n private _populateTmpTransformation(position: Vector3, rotationQuaternion: Quaternion) {\r\n this._tmpVector.copyFrom(position);\r\n this._tmpQuaternion.copyFrom(rotationQuaternion);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n this._tmpVector.z *= -1;\r\n this._tmpQuaternion.z *= -1;\r\n this._tmpQuaternion.w *= -1;\r\n }\r\n return {\r\n position: this._tmpVector,\r\n rotationQuaternion: this._tmpQuaternion,\r\n };\r\n }\r\n\r\n /**\r\n * Create a new anchor point using a hit test result at a specific point in the scene\r\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\r\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\r\n *\r\n * @param hitTestResult The hit test result to use for this anchor creation\r\n * @param position an optional position offset for this anchor\r\n * @param rotationQuaternion an optional rotation offset for this anchor\r\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\r\n */\r\n public async addAnchorPointUsingHitTestResultAsync(\r\n hitTestResult: IWebXRHitResult,\r\n position: Vector3 = new Vector3(),\r\n rotationQuaternion: Quaternion = new Quaternion()\r\n ): Promise<IWebXRAnchor> {\r\n // convert to XR space (right handed) if needed\r\n this._populateTmpTransformation(position, rotationQuaternion);\r\n // the matrix that we'll use\r\n const m = new XRRigidTransform(\r\n { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },\r\n { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }\r\n );\r\n if (!hitTestResult.xrHitResult.createAnchor) {\r\n this.detach();\r\n throw new Error(\"Anchors not enabled in this environment/browser\");\r\n } else {\r\n try {\r\n const nativeAnchor = await hitTestResult.xrHitResult.createAnchor(m);\r\n return await new Promise<IWebXRAnchor>((resolve, reject) => {\r\n this._futureAnchors.push({\r\n nativeAnchor,\r\n resolved: false,\r\n submitted: true,\r\n xrTransformation: m,\r\n resolve,\r\n reject,\r\n });\r\n });\r\n } catch (error) {\r\n throw new Error(error);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Add a new anchor at a specific position and rotation\r\n * This function will add a new anchor per default in the next available frame. Unless forced, the createAnchor function\r\n * will be called in the next xrFrame loop to make sure that the anchor can be created correctly.\r\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\r\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\r\n *\r\n * @param position the position in which to add an anchor\r\n * @param rotationQuaternion an optional rotation for the anchor transformation\r\n * @param forceCreateInCurrentFrame force the creation of this anchor in the current frame. Must be called inside xrFrame loop!\r\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\r\n */\r\n public async addAnchorAtPositionAndRotationAsync(\r\n position: Vector3,\r\n rotationQuaternion: Quaternion = new Quaternion(),\r\n forceCreateInCurrentFrame = false\r\n ): Promise<IWebXRAnchor> {\r\n // convert to XR space (right handed) if needed\r\n this._populateTmpTransformation(position, rotationQuaternion);\r\n // the matrix that we'll use\r\n const xrTransformation = new XRRigidTransform(\r\n { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },\r\n { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }\r\n );\r\n const xrAnchor =\r\n forceCreateInCurrentFrame && this.attached && this._xrSessionManager.currentFrame\r\n ? await this._createAnchorAtTransformationAsync(xrTransformation, this._xrSessionManager.currentFrame)\r\n : undefined;\r\n // add the transformation to the future anchors list\r\n return await new Promise<IWebXRAnchor>((resolve, reject) => {\r\n this._futureAnchors.push({\r\n nativeAnchor: xrAnchor,\r\n resolved: false,\r\n submitted: false,\r\n xrTransformation,\r\n resolve,\r\n reject,\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Get the list of anchors currently being tracked by the system\r\n */\r\n public get anchors(): IWebXRAnchor[] {\r\n return this._trackedAnchors;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n if (!this._options.doNotRemoveAnchorsOnSessionEnded) {\r\n while (this._trackedAnchors.length) {\r\n const toRemove = this._trackedAnchors.pop();\r\n if (toRemove && !toRemove._removed) {\r\n // as the xr frame loop is removed, we need to notify manually\r\n this.onAnchorRemovedObservable.notifyObservers(toRemove);\r\n toRemove._removed = true;\r\n // no need to call the remove fn as the anchor is already removed from the session\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public override dispose(): void {\r\n this._futureAnchors.length = 0;\r\n super.dispose();\r\n this.onAnchorAddedObservable.clear();\r\n this.onAnchorRemovedObservable.clear();\r\n this.onAnchorUpdatedObservable.clear();\r\n }\r\n\r\n protected _onXRFrame(frame: XRFrame) {\r\n if (!this.attached || !frame) {\r\n return;\r\n }\r\n\r\n const trackedAnchors = frame.trackedAnchors;\r\n if (trackedAnchors) {\r\n const toRemove = this._trackedAnchors\r\n .filter((anchor) => anchor._removed)\r\n .map((anchor) => {\r\n return this._trackedAnchors.indexOf(anchor);\r\n });\r\n let idxTracker = 0;\r\n for (const index of toRemove) {\r\n const anchor = this._trackedAnchors.splice(index - idxTracker, 1)[0];\r\n anchor.xrAnchor.delete();\r\n this.onAnchorRemovedObservable.notifyObservers(anchor);\r\n idxTracker++;\r\n }\r\n // now check for new ones\r\n trackedAnchors.forEach((xrAnchor) => {\r\n if (!this._lastFrameDetected.has(xrAnchor)) {\r\n const newAnchor: Partial<IWebXRAnchor> = {\r\n id: AnchorIdProvider++,\r\n xrAnchor: xrAnchor,\r\n remove: () => {\r\n newAnchor._removed = true;\r\n },\r\n };\r\n const anchor = this._updateAnchorWithXRFrame(xrAnchor, newAnchor, frame);\r\n this._trackedAnchors.push(anchor);\r\n this.onAnchorAddedObservable.notifyObservers(anchor);\r\n // search for the future anchor promise that matches this\r\n const results = this._futureAnchors.filter((futureAnchor) => futureAnchor.nativeAnchor === xrAnchor);\r\n const result = results[0];\r\n if (result) {\r\n result.resolve(anchor);\r\n result.resolved = true;\r\n }\r\n } else {\r\n const index = this._findIndexInAnchorArray(xrAnchor);\r\n const anchor = this._trackedAnchors[index];\r\n try {\r\n // anchors update every frame\r\n this._updateAnchorWithXRFrame(xrAnchor, anchor, frame);\r\n if (anchor.attachedNode) {\r\n anchor.attachedNode.rotationQuaternion = anchor.attachedNode.rotationQuaternion || new Quaternion();\r\n anchor.transformationMatrix.decompose(anchor.attachedNode.scaling, anchor.attachedNode.rotationQuaternion, anchor.attachedNode.position);\r\n }\r\n this.onAnchorUpdatedObservable.notifyObservers(anchor);\r\n } catch (e) {\r\n Tools.Warn(`Anchor could not be updated`);\r\n }\r\n }\r\n });\r\n this._lastFrameDetected = trackedAnchors;\r\n }\r\n\r\n // process future anchors\r\n for (const futureAnchor of this._futureAnchors) {\r\n if (!futureAnchor.resolved && !futureAnchor.submitted) {\r\n // eslint-disable-next-line github/no-then\r\n this._createAnchorAtTransformationAsync(futureAnchor.xrTransformation, frame).then(\r\n (nativeAnchor) => {\r\n futureAnchor.nativeAnchor = nativeAnchor;\r\n },\r\n (error) => {\r\n futureAnchor.resolved = true;\r\n futureAnchor.reject(error);\r\n }\r\n );\r\n futureAnchor.submitted = true;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * avoiding using Array.find for global support.\r\n * @param xrAnchor the plane to find in the array\r\n * @returns the index of the anchor in the array or -1 if not found\r\n */\r\n private _findIndexInAnchorArray(xrAnchor: XRAnchor) {\r\n for (let i = 0; i < this._trackedAnchors.length; ++i) {\r\n if (this._trackedAnchors[i].xrAnchor === xrAnchor) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n }\r\n\r\n private _updateAnchorWithXRFrame(xrAnchor: XRAnchor, anchor: Partial<IWebXRAnchor>, xrFrame: XRFrame): IWebXRAnchor {\r\n // matrix\r\n const pose = xrFrame.getPose(xrAnchor.anchorSpace, this._xrSessionManager.referenceSpace);\r\n if (pose) {\r\n const mat = anchor.transformationMatrix || new Matrix();\r\n Matrix.FromArrayToRef(pose.transform.matrix, 0, mat);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n mat.toggleModelMatrixHandInPlace();\r\n }\r\n anchor.transformationMatrix = mat;\r\n if (!this._options.worldParentNode) {\r\n // Logger.Warn(\"Please provide a world parent node to apply world transformation\");\r\n } else {\r\n mat.multiplyToRef(this._options.worldParentNode.getWorldMatrix(), mat);\r\n }\r\n }\r\n\r\n return <IWebXRAnchor>anchor;\r\n }\r\n\r\n private async _createAnchorAtTransformationAsync(xrTransformation: XRRigidTransform, xrFrame: XRFrame) {\r\n if (xrFrame.createAnchor) {\r\n try {\r\n return await xrFrame.createAnchor(xrTransformation, this._referenceSpaceForFrameAnchors ?? this._xrSessionManager.referenceSpace);\r\n } catch (error) {\r\n throw new Error(error);\r\n }\r\n } else {\r\n this.detach();\r\n throw new Error(\"Anchors are not enabled in your browser\");\r\n }\r\n }\r\n}\r\n\r\n// register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRAnchorSystem.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRAnchorSystem(xrSessionManager, options);\r\n },\r\n WebXRAnchorSystem.Version\r\n);\r\n"]}
|
|
1
|
+
{"version":3,"file":"WebXRAnchorSystem.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRAnchorSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAuF9D,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,oBAAoB;IAkCvD;;;OAGG;IACH,IAAW,6BAA6B,CAAC,cAAgC;QACrE,IAAI,CAAC,8BAA8B,GAAG,cAAc,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACH,YACI,iBAAsC,EAC9B,WAAsC,EAAE;QAEhD,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAFjB,aAAQ,GAAR,QAAQ,CAAgC;QAhD5C,uBAAkB,GAAgB,IAAI,GAAG,EAAE,CAAC;QAE5C,oBAAe,GAAwB,EAAE,CAAC;QAI1C,mBAAc,GAAyB,EAAE,CAAC;QAalD;;WAEG;QACI,4BAAuB,GAA6B,IAAI,UAAU,EAAE,CAAC;QAC5E;;WAEG;QACI,8BAAyB,GAA6B,IAAI,UAAU,EAAE,CAAC;QAC9E;;;WAGG;Q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AAO,MAAM,OAAO,CAAC,YAAY,CAAC,gBAAgB,EAAE,IAAI,CAAC,8BAA8B,IAAI,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;YACtI,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC/D,CAAC;IACL,CAAC;;AA5TD;;GAEG;AACoB,sBAAI,GAAG,gBAAgB,CAAC,aAAa,AAAjC,CAAkC;AAC7D;;;;GAIG;AACoB,yBAAO,GAAG,CAAC,AAAJ,CAAK;AAsTvC,sBAAsB;AACtB,oBAAoB,CAAC,eAAe,CAChC,iBAAiB,CAAC,IAAI,EACtB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,iBAAiB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC,EACD,iBAAiB,CAAC,OAAO,CAC5B,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Matrix, Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { IWebXRHitResult } from \"./WebXRHitTest\";\r\n\r\n/**\r\n * Configuration options of the anchor system\r\n */\r\nexport interface IWebXRAnchorSystemOptions {\r\n /**\r\n * a node that will be used to convert local to world coordinates\r\n */\r\n worldParentNode?: TransformNode;\r\n\r\n /**\r\n * If set to true a reference of the created anchors will be kept until the next session starts\r\n * If not defined, anchors will be removed from the array when the feature is detached or the session ended.\r\n */\r\n doNotRemoveAnchorsOnSessionEnded?: boolean;\r\n\r\n /**\r\n * If set to true, all anchor arrays will be cleared when the session initializes\r\n */\r\n clearAnchorsOnSessionInit?: boolean;\r\n}\r\n\r\n/**\r\n * A babylon container for an XR Anchor\r\n */\r\nexport interface IWebXRAnchor {\r\n /**\r\n * A babylon-assigned ID for this anchor\r\n */\r\n id: number;\r\n /**\r\n * Transformation matrix to apply to an object attached to this anchor\r\n */\r\n transformationMatrix: Matrix;\r\n /**\r\n * The native anchor object\r\n */\r\n xrAnchor: XRAnchor;\r\n\r\n /**\r\n * if defined, this object will be constantly updated by the anchor's position and rotation\r\n */\r\n attachedNode?: TransformNode;\r\n\r\n /**\r\n * Remove this anchor from the scene\r\n */\r\n remove(): void;\r\n\r\n /**\r\n * @internal - set to true when the anchor was removed\r\n */\r\n _removed: boolean;\r\n}\r\n\r\n/**\r\n * An internal interface for a future (promise based) anchor\r\n */\r\ninterface IWebXRFutureAnchor {\r\n /**\r\n * The native anchor\r\n */\r\n nativeAnchor?: XRAnchor;\r\n /**\r\n * Was this request submitted to the xr frame?\r\n */\r\n submitted: boolean;\r\n /**\r\n * Was this promise resolved already?\r\n */\r\n resolved: boolean;\r\n /**\r\n * A resolve function\r\n */\r\n resolve: (xrAnchor: IWebXRAnchor) => void;\r\n /**\r\n * A reject function\r\n */\r\n reject: (msg?: string) => void;\r\n /**\r\n * The XR Transformation of the future anchor\r\n */\r\n xrTransformation: XRRigidTransform;\r\n}\r\n\r\nlet AnchorIdProvider = 0;\r\n\r\n/**\r\n * An implementation of the anchor system for WebXR.\r\n * For further information see https://github.com/immersive-web/anchors/\r\n */\r\nexport class WebXRAnchorSystem extends WebXRAbstractFeature {\r\n private _lastFrameDetected: XRAnchorSet = new Set();\r\n\r\n private _trackedAnchors: Array<IWebXRAnchor> = [];\r\n\r\n private _referenceSpaceForFrameAnchors: XRReferenceSpace;\r\n\r\n private _futureAnchors: IWebXRFutureAnchor[] = [];\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.ANCHOR_SYSTEM;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Observers registered here will be executed when a new anchor was added to the session\r\n */\r\n public onAnchorAddedObservable: Observable<IWebXRAnchor> = new Observable();\r\n /**\r\n * Observers registered here will be executed when an anchor was removed from the session\r\n */\r\n public onAnchorRemovedObservable: Observable<IWebXRAnchor> = new Observable();\r\n /**\r\n * Observers registered here will be executed when an existing anchor updates\r\n * This can execute N times every frame\r\n */\r\n public onAnchorUpdatedObservable: Observable<IWebXRAnchor> = new Observable();\r\n\r\n /**\r\n * Set the reference space to use for anchor creation, when not using a hit test.\r\n * Will default to the session's reference space if not defined\r\n */\r\n public set referenceSpaceForFrameAnchors(referenceSpace: XRReferenceSpace) {\r\n this._referenceSpaceForFrameAnchors = referenceSpace;\r\n }\r\n\r\n /**\r\n * constructs a new anchor system\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param _options configuration object for this feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n private _options: IWebXRAnchorSystemOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"anchors\";\r\n\r\n if (this._options.clearAnchorsOnSessionInit) {\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n this._trackedAnchors.length = 0;\r\n this._futureAnchors.length = 0;\r\n this._lastFrameDetected.clear();\r\n });\r\n }\r\n }\r\n\r\n private _tmpVector = new Vector3();\r\n private _tmpQuaternion = new Quaternion();\r\n\r\n private _populateTmpTransformation(position: Vector3, rotationQuaternion: Quaternion) {\r\n this._tmpVector.copyFrom(position);\r\n this._tmpQuaternion.copyFrom(rotationQuaternion);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n this._tmpVector.z *= -1;\r\n this._tmpQuaternion.z *= -1;\r\n this._tmpQuaternion.w *= -1;\r\n }\r\n return {\r\n position: this._tmpVector,\r\n rotationQuaternion: this._tmpQuaternion,\r\n };\r\n }\r\n\r\n /**\r\n * Create a new anchor point using a hit test result at a specific point in the scene\r\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\r\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\r\n *\r\n * @param hitTestResult The hit test result to use for this anchor creation\r\n * @param position an optional position offset for this anchor\r\n * @param rotationQuaternion an optional rotation offset for this anchor\r\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\r\n */\r\n public async addAnchorPointUsingHitTestResultAsync(\r\n hitTestResult: IWebXRHitResult,\r\n position: Vector3 = new Vector3(),\r\n rotationQuaternion: Quaternion = new Quaternion()\r\n ): Promise<IWebXRAnchor> {\r\n // convert to XR space (right handed) if needed\r\n this._populateTmpTransformation(position, rotationQuaternion);\r\n // the matrix that we'll use\r\n const m = new XRRigidTransform(\r\n { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },\r\n { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }\r\n );\r\n if (!hitTestResult.xrHitResult.createAnchor) {\r\n this.detach();\r\n throw new Error(\"Anchors not enabled in this environment/browser\");\r\n } else {\r\n try {\r\n const nativeAnchor = await hitTestResult.xrHitResult.createAnchor(m);\r\n return await new Promise<IWebXRAnchor>((resolve, reject) => {\r\n this._futureAnchors.push({\r\n nativeAnchor,\r\n resolved: false,\r\n submitted: true,\r\n xrTransformation: m,\r\n resolve,\r\n reject,\r\n });\r\n });\r\n } catch (error) {\r\n throw new Error(error);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Add a new anchor at a specific position and rotation\r\n * This function will add a new anchor per default in the next available frame. Unless forced, the createAnchor function\r\n * will be called in the next xrFrame loop to make sure that the anchor can be created correctly.\r\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\r\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\r\n *\r\n * @param position the position in which to add an anchor\r\n * @param rotationQuaternion an optional rotation for the anchor transformation\r\n * @param forceCreateInCurrentFrame force the creation of this anchor in the current frame. Must be called inside xrFrame loop!\r\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\r\n */\r\n public async addAnchorAtPositionAndRotationAsync(\r\n position: Vector3,\r\n rotationQuaternion: Quaternion = new Quaternion(),\r\n forceCreateInCurrentFrame = false\r\n ): Promise<IWebXRAnchor> {\r\n // convert to XR space (right handed) if needed\r\n this._populateTmpTransformation(position, rotationQuaternion);\r\n // the matrix that we'll use\r\n const xrTransformation = new XRRigidTransform(\r\n { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },\r\n { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }\r\n );\r\n const xrAnchor =\r\n forceCreateInCurrentFrame && this.attached && this._xrSessionManager.currentFrame\r\n ? await this._createAnchorAtTransformationAsync(xrTransformation, this._xrSessionManager.currentFrame)\r\n : undefined;\r\n // add the transformation to the future anchors list\r\n return await new Promise<IWebXRAnchor>((resolve, reject) => {\r\n this._futureAnchors.push({\r\n nativeAnchor: xrAnchor,\r\n resolved: false,\r\n submitted: false,\r\n xrTransformation,\r\n resolve,\r\n reject,\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Get the list of anchors currently being tracked by the system\r\n */\r\n public get anchors(): IWebXRAnchor[] {\r\n return this._trackedAnchors;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n if (!this._options.doNotRemoveAnchorsOnSessionEnded) {\r\n while (this._trackedAnchors.length) {\r\n const toRemove = this._trackedAnchors.pop();\r\n if (toRemove && !toRemove._removed) {\r\n // as the xr frame loop is removed, we need to notify manually\r\n this.onAnchorRemovedObservable.notifyObservers(toRemove);\r\n toRemove._removed = true;\r\n // no need to call the remove fn as the anchor is already removed from the session\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public override dispose(): void {\r\n this._futureAnchors.length = 0;\r\n super.dispose();\r\n this.onAnchorAddedObservable.clear();\r\n this.onAnchorRemovedObservable.clear();\r\n this.onAnchorUpdatedObservable.clear();\r\n }\r\n\r\n protected _onXRFrame(frame: XRFrame) {\r\n if (!this.attached || !frame) {\r\n return;\r\n }\r\n\r\n const trackedAnchors = frame.trackedAnchors;\r\n if (trackedAnchors) {\r\n for (const anchor of this._trackedAnchors) {\r\n if (!anchor._removed) {\r\n continue;\r\n }\r\n const index = this._trackedAnchors.indexOf(anchor);\r\n this._trackedAnchors.splice(index, 1);\r\n anchor.xrAnchor.delete();\r\n this.onAnchorRemovedObservable.notifyObservers(anchor);\r\n }\r\n // now check for new ones\r\n trackedAnchors.forEach((xrAnchor) => {\r\n if (!this._lastFrameDetected.has(xrAnchor)) {\r\n const newAnchor: Partial<IWebXRAnchor> = {\r\n id: AnchorIdProvider++,\r\n xrAnchor: xrAnchor,\r\n remove: () => {\r\n newAnchor._removed = true;\r\n },\r\n };\r\n const anchor = this._updateAnchorWithXRFrame(xrAnchor, newAnchor, frame);\r\n this._trackedAnchors.push(anchor);\r\n this.onAnchorAddedObservable.notifyObservers(anchor);\r\n // search for the future anchor promise that matches this\r\n const results = this._futureAnchors.filter((futureAnchor) => futureAnchor.nativeAnchor === xrAnchor);\r\n const result = results[0];\r\n if (result) {\r\n result.resolve(anchor);\r\n result.resolved = true;\r\n }\r\n } else {\r\n const index = this._findIndexInAnchorArray(xrAnchor);\r\n if (index < 0) {\r\n return;\r\n }\r\n const anchor = this._trackedAnchors[index];\r\n this._updateAnchorWithXRFrame(xrAnchor, anchor, frame);\r\n if (anchor.attachedNode) {\r\n anchor.attachedNode.rotationQuaternion = anchor.attachedNode.rotationQuaternion || new Quaternion();\r\n anchor.transformationMatrix.decompose(anchor.attachedNode.scaling, anchor.attachedNode.rotationQuaternion, anchor.attachedNode.position);\r\n }\r\n this.onAnchorUpdatedObservable.notifyObservers(anchor);\r\n }\r\n });\r\n this._lastFrameDetected = trackedAnchors;\r\n }\r\n\r\n // process future anchors\r\n for (const futureAnchor of this._futureAnchors) {\r\n if (!futureAnchor.resolved && !futureAnchor.submitted) {\r\n // eslint-disable-next-line github/no-then\r\n this._createAnchorAtTransformationAsync(futureAnchor.xrTransformation, frame).then(\r\n (nativeAnchor) => {\r\n futureAnchor.nativeAnchor = nativeAnchor;\r\n },\r\n (error) => {\r\n futureAnchor.resolved = true;\r\n futureAnchor.reject(error);\r\n }\r\n );\r\n futureAnchor.submitted = true;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * avoiding using Array.find for global support.\r\n * @param xrAnchor the plane to find in the array\r\n * @returns the index of the anchor in the array or -1 if not found\r\n */\r\n private _findIndexInAnchorArray(xrAnchor: XRAnchor) {\r\n for (let i = 0; i < this._trackedAnchors.length; ++i) {\r\n if (this._trackedAnchors[i].xrAnchor === xrAnchor) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n }\r\n\r\n private _updateAnchorWithXRFrame(xrAnchor: XRAnchor, anchor: Partial<IWebXRAnchor>, xrFrame: XRFrame): IWebXRAnchor {\r\n // matrix\r\n const pose = xrFrame.getPose(xrAnchor.anchorSpace, this._xrSessionManager.referenceSpace);\r\n if (pose) {\r\n const mat = anchor.transformationMatrix || new Matrix();\r\n Matrix.FromArrayToRef(pose.transform.matrix, 0, mat);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n mat.toggleModelMatrixHandInPlace();\r\n }\r\n anchor.transformationMatrix = mat;\r\n if (!this._options.worldParentNode) {\r\n // Logger.Warn(\"Please provide a world parent node to apply world transformation\");\r\n } else {\r\n mat.multiplyToRef(this._options.worldParentNode.getWorldMatrix(), mat);\r\n }\r\n }\r\n\r\n return <IWebXRAnchor>anchor;\r\n }\r\n\r\n private async _createAnchorAtTransformationAsync(xrTransformation: XRRigidTransform, xrFrame: XRFrame) {\r\n if (xrFrame.createAnchor) {\r\n try {\r\n return await xrFrame.createAnchor(xrTransformation, this._referenceSpaceForFrameAnchors ?? this._xrSessionManager.referenceSpace);\r\n } catch (error) {\r\n throw new Error(error);\r\n }\r\n } else {\r\n this.detach();\r\n throw new Error(\"Anchors are not enabled in your browser\");\r\n }\r\n }\r\n}\r\n\r\n// register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRAnchorSystem.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRAnchorSystem(xrSessionManager, options);\r\n },\r\n WebXRAnchorSystem.Version\r\n);\r\n"]}
|