@babylonjs/core 6.7.0 → 6.8.0

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.
Files changed (74) hide show
  1. package/Culling/ray.d.ts +7 -2
  2. package/Culling/ray.js +8 -3
  3. package/Culling/ray.js.map +1 -1
  4. package/Engines/Extensions/engine.multiview.d.ts +6 -1
  5. package/Engines/Extensions/engine.multiview.js +27 -7
  6. package/Engines/Extensions/engine.multiview.js.map +1 -1
  7. package/Engines/Native/nativeInterfaces.d.ts +1 -0
  8. package/Engines/Native/nativeInterfaces.js.map +1 -1
  9. package/Engines/Processors/Expressions/shaderDefineExpression.d.ts +37 -0
  10. package/Engines/Processors/Expressions/shaderDefineExpression.js +57 -0
  11. package/Engines/Processors/Expressions/shaderDefineExpression.js.map +1 -1
  12. package/Engines/Processors/shaderProcessor.js +26 -13
  13. package/Engines/Processors/shaderProcessor.js.map +1 -1
  14. package/Engines/WebGL/webGLRenderTargetWrapper.d.ts +19 -0
  15. package/Engines/WebGL/webGLRenderTargetWrapper.js +20 -1
  16. package/Engines/WebGL/webGLRenderTargetWrapper.js.map +1 -1
  17. package/Engines/engine.d.ts +8 -1
  18. package/Engines/engineCapabilities.d.ts +2 -0
  19. package/Engines/engineCapabilities.js.map +1 -1
  20. package/Engines/nativeEngine.d.ts +2 -0
  21. package/Engines/nativeEngine.js +16 -0
  22. package/Engines/nativeEngine.js.map +1 -1
  23. package/Engines/thinEngine.js +6 -9
  24. package/Engines/thinEngine.js.map +1 -1
  25. package/Loading/sceneLoader.d.ts +8 -8
  26. package/Loading/sceneLoader.js +35 -19
  27. package/Loading/sceneLoader.js.map +1 -1
  28. package/Materials/Node/nodeMaterial.d.ts +6 -1
  29. package/Materials/Node/nodeMaterial.js +7 -5
  30. package/Materials/Node/nodeMaterial.js.map +1 -1
  31. package/Materials/multiMaterial.js +1 -1
  32. package/Materials/multiMaterial.js.map +1 -1
  33. package/Materials/shaderMaterial.d.ts +23 -4
  34. package/Materials/shaderMaterial.js +38 -5
  35. package/Materials/shaderMaterial.js.map +1 -1
  36. package/Meshes/abstractMesh.d.ts +2 -1
  37. package/Meshes/abstractMesh.js +2 -1
  38. package/Meshes/abstractMesh.js.map +1 -1
  39. package/Misc/deepCopier.js +1 -1
  40. package/Misc/deepCopier.js.map +1 -1
  41. package/Misc/observable.d.ts +11 -0
  42. package/Misc/observable.js +26 -1
  43. package/Misc/observable.js.map +1 -1
  44. package/Particles/gpuParticleSystem.d.ts +1 -0
  45. package/Particles/gpuParticleSystem.js +3 -2
  46. package/Particles/gpuParticleSystem.js.map +1 -1
  47. package/Rendering/boundingBoxRenderer.js +2 -4
  48. package/Rendering/boundingBoxRenderer.js.map +1 -1
  49. package/Shaders/ShadersInclude/pbrDebug.js +8 -1
  50. package/Shaders/ShadersInclude/pbrDebug.js.map +1 -1
  51. package/Shaders/velocity.fragment.d.ts +5 -0
  52. package/Shaders/velocity.fragment.js +13 -0
  53. package/Shaders/velocity.fragment.js.map +1 -0
  54. package/Shaders/velocity.vertex.d.ts +7 -0
  55. package/Shaders/velocity.vertex.js +23 -0
  56. package/Shaders/velocity.vertex.js.map +1 -0
  57. package/XR/features/WebXRLayers.js +16 -6
  58. package/XR/features/WebXRLayers.js.map +1 -1
  59. package/XR/features/WebXRSpaceWarp.d.ts +138 -0
  60. package/XR/features/WebXRSpaceWarp.js +290 -0
  61. package/XR/features/WebXRSpaceWarp.js.map +1 -0
  62. package/XR/features/index.d.ts +1 -0
  63. package/XR/features/index.js +1 -0
  64. package/XR/features/index.js.map +1 -1
  65. package/XR/webXRFeaturesManager.d.ts +4 -0
  66. package/XR/webXRFeaturesManager.js +4 -0
  67. package/XR/webXRFeaturesManager.js.map +1 -1
  68. package/XR/webXRSessionManager.d.ts +4 -0
  69. package/XR/webXRSessionManager.js +6 -0
  70. package/XR/webXRSessionManager.js.map +1 -1
  71. package/package.json +1 -1
  72. package/scene.d.ts +5 -2
  73. package/scene.js +5 -2
  74. package/scene.js.map +1 -1
@@ -0,0 +1,290 @@
1
+ import { WebXRFeatureName, WebXRFeaturesManager } from "../webXRFeaturesManager.js";
2
+ import { WebXRAbstractFeature } from "./WebXRAbstractFeature.js";
3
+ import { Matrix } from "../../Maths/math.vector.js";
4
+ import { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture.js";
5
+
6
+ import { ShaderMaterial } from "../../Materials/shaderMaterial.js";
7
+ import "../../Shaders/velocity.fragment.js";
8
+ import "../../Shaders/velocity.vertex.js";
9
+ /**
10
+ * Used for Space Warp render process
11
+ */
12
+ export class XRSpaceWarpRenderTarget extends RenderTargetTexture {
13
+ /**
14
+ * Creates a Space Warp render target
15
+ * @param motionVectorTexture WebGLTexture provided by WebGLSubImage
16
+ * @param depthStencilTexture WebGLTexture provided by WebGLSubImage
17
+ * @param scene scene used with the render target
18
+ * @param size the size of the render target (used for each view)
19
+ */
20
+ constructor(motionVectorTexture, depthStencilTexture, scene, size = 512) {
21
+ super("spacewarp rtt", size, scene, false, true, 2, false, undefined, false, false, true, undefined, true);
22
+ this._originalPairing = [];
23
+ this._previousWorldMatrices = [];
24
+ this._previousTransforms = [Matrix.Identity(), Matrix.Identity()];
25
+ this._renderTarget = this.getScene()
26
+ .getEngine()
27
+ .createMultiviewRenderTargetTexture(this.getRenderWidth(), this.getRenderHeight(), motionVectorTexture, depthStencilTexture);
28
+ this._renderTarget._disposeOnlyFramebuffers = true;
29
+ this._texture = this._renderTarget.texture;
30
+ this._texture.isMultiview = true;
31
+ this._texture.format = 5;
32
+ if (scene) {
33
+ this._velocityMaterial = new ShaderMaterial("velocity shader material", scene, {
34
+ vertex: "velocity",
35
+ fragment: "velocity",
36
+ }, {
37
+ uniforms: ["world", "previousWorld", "viewProjection", "viewProjectionR", "previousViewProjection", "previousViewProjectionR"],
38
+ });
39
+ this._velocityMaterial._materialHelperNeedsPreviousMatrices = true;
40
+ this._velocityMaterial.onBindObservable.add((mesh) => {
41
+ // mesh. getWorldMatrix can be incorrect under rare conditions (e.g. when using a effective mesh in the render function).
42
+ // If the case arise that will require changing it we will need to change the bind process in the material class to also provide the world matrix as a parameter
43
+ this._previousWorldMatrices[mesh.uniqueId] = this._previousWorldMatrices[mesh.uniqueId] || mesh.getWorldMatrix();
44
+ this._velocityMaterial.getEffect().setMatrix("previousWorld", this._previousWorldMatrices[mesh.uniqueId]);
45
+ this._previousWorldMatrices[mesh.uniqueId] = mesh.getWorldMatrix();
46
+ // now set the scene's previous matrix
47
+ this._velocityMaterial.getEffect().setMatrix("previousViewProjection", this._previousTransforms[0]);
48
+ // multiview for sure
49
+ this._velocityMaterial.getEffect().setMatrix("previousViewProjectionR", this._previousTransforms[1]);
50
+ // store the previous (current, to be exact) transforms
51
+ this._previousTransforms[0].copyFrom(scene.getTransformMatrix());
52
+ this._previousTransforms[1].copyFrom(scene._transformMatrixR);
53
+ });
54
+ this._velocityMaterial.freeze();
55
+ }
56
+ }
57
+ /**
58
+ * {@inheritDoc}
59
+ */
60
+ render(useCameraPostProcess = false, dumpForDebug = false) {
61
+ // Swap to use velocity material
62
+ this._originalPairing.length = 0;
63
+ const scene = this.getScene();
64
+ // set the velocity material to render the velocity RTT
65
+ if (scene && this._velocityMaterial) {
66
+ scene.getActiveMeshes().forEach((mesh) => {
67
+ this._originalPairing.push([mesh, mesh.material]);
68
+ mesh.material = this._velocityMaterial;
69
+ });
70
+ }
71
+ super.render(useCameraPostProcess, dumpForDebug);
72
+ // Restore original materials
73
+ this._originalPairing.forEach((tuple) => {
74
+ tuple[0].material = tuple[1];
75
+ });
76
+ }
77
+ /**
78
+ * @internal
79
+ */
80
+ _bindFrameBuffer() {
81
+ if (!this._renderTarget) {
82
+ return;
83
+ }
84
+ this.getScene().getEngine().bindSpaceWarpFramebuffer(this._renderTarget);
85
+ }
86
+ /**
87
+ * Gets the number of views the corresponding to the texture (eg. a SpaceWarpRenderTarget will have > 1)
88
+ * @returns the view count
89
+ */
90
+ getViewCount() {
91
+ return 2;
92
+ }
93
+ /**
94
+ * {@inheritdoc}
95
+ */
96
+ dispose() {
97
+ super.dispose();
98
+ this._velocityMaterial.dispose();
99
+ this._previousTransforms.length = 0;
100
+ this._previousWorldMatrices.length = 0;
101
+ this._originalPairing.length = 0;
102
+ }
103
+ }
104
+ /**
105
+ * WebXR Space Warp Render Target Texture Provider
106
+ */
107
+ export class WebXRSpaceWarpRenderTargetTextureProvider {
108
+ constructor(_scene, _xrSessionManager, _xrWebGLBinding) {
109
+ this._scene = _scene;
110
+ this._xrSessionManager = _xrSessionManager;
111
+ this._xrWebGLBinding = _xrWebGLBinding;
112
+ this._lastSubImages = new Map();
113
+ this._renderTargetTextures = new Map();
114
+ this._engine = _scene.getEngine();
115
+ }
116
+ _getSubImageForView(view) {
117
+ const layerWrapper = this._xrSessionManager._getBaseLayerWrapper();
118
+ if (!layerWrapper) {
119
+ throw new Error("For Space Warp, the base layer should be a WebXR Projection Layer.");
120
+ }
121
+ if (layerWrapper.layerType !== "XRProjectionLayer") {
122
+ throw new Error('For Space Warp, the base layer type should "XRProjectionLayer".');
123
+ }
124
+ const layer = layerWrapper.layer;
125
+ return this._xrWebGLBinding.getViewSubImage(layer, view);
126
+ }
127
+ _setViewportForSubImage(viewport, subImage) {
128
+ viewport.x = 0;
129
+ viewport.y = 0;
130
+ viewport.width = subImage.motionVectorTextureWidth;
131
+ viewport.height = subImage.motionVectorTextureHeight;
132
+ }
133
+ _createRenderTargetTexture(width, height, framebuffer, motionVectorTexture, depthStencilTexture) {
134
+ if (!this._engine) {
135
+ throw new Error("Engine is disposed");
136
+ }
137
+ const textureSize = { width, height };
138
+ // Create render target texture from the internal texture
139
+ const renderTargetTexture = new XRSpaceWarpRenderTarget(motionVectorTexture, depthStencilTexture, this._scene, textureSize);
140
+ const renderTargetWrapper = renderTargetTexture.renderTarget;
141
+ if (framebuffer) {
142
+ renderTargetWrapper._framebuffer = framebuffer;
143
+ }
144
+ // Create internal texture
145
+ renderTargetWrapper._colorTextureArray = motionVectorTexture;
146
+ renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;
147
+ renderTargetTexture.disableRescaling();
148
+ renderTargetTexture.renderListPredicate = () => true;
149
+ return renderTargetTexture;
150
+ }
151
+ _getRenderTargetForSubImage(subImage, view) {
152
+ const lastSubImage = this._lastSubImages.get(view);
153
+ let renderTargetTexture = this._renderTargetTextures.get(view.eye);
154
+ const width = subImage.motionVectorTextureWidth;
155
+ const height = subImage.motionVectorTextureHeight;
156
+ if (!renderTargetTexture || (lastSubImage === null || lastSubImage === void 0 ? void 0 : lastSubImage.textureWidth) !== width || (lastSubImage === null || lastSubImage === void 0 ? void 0 : lastSubImage.textureHeight) != height) {
157
+ renderTargetTexture = this._createRenderTargetTexture(width, height, null, subImage.motionVectorTexture, subImage.depthStencilTexture);
158
+ this._renderTargetTextures.set(view.eye, renderTargetTexture);
159
+ this._framebufferDimensions = {
160
+ framebufferWidth: width,
161
+ framebufferHeight: height,
162
+ };
163
+ }
164
+ this._lastSubImages.set(view, subImage);
165
+ return renderTargetTexture;
166
+ }
167
+ /**
168
+ * {@inheritDoc}
169
+ */
170
+ trySetViewportForView(viewport, view) {
171
+ const subImage = this._lastSubImages.get(view) || this._getSubImageForView(view);
172
+ if (subImage) {
173
+ this._setViewportForSubImage(viewport, subImage);
174
+ return true;
175
+ }
176
+ return false;
177
+ }
178
+ /**
179
+ * Access the motion vector (which will turn on Space Warp)
180
+ * @param view the view to access the motion vector texture for
181
+ */
182
+ accessMotionVector(view) {
183
+ const subImage = this._getSubImageForView(view);
184
+ if (subImage) {
185
+ // Meta Quest Browser uses accessing these textures as a sign for turning on Space Warp
186
+ subImage.motionVectorTexture;
187
+ subImage.depthStencilTexture;
188
+ }
189
+ }
190
+ /**
191
+ * {@inheritDoc}
192
+ */
193
+ getRenderTargetTextureForEye(_eye) {
194
+ return null;
195
+ }
196
+ /**
197
+ * {@inheritDoc}
198
+ */
199
+ getRenderTargetTextureForView(view) {
200
+ const subImage = this._getSubImageForView(view);
201
+ if (subImage) {
202
+ return this._getRenderTargetForSubImage(subImage, view);
203
+ }
204
+ return null;
205
+ }
206
+ /**
207
+ * {@inheritDoc}
208
+ */
209
+ dispose() {
210
+ this._renderTargetTextures.forEach((rtt) => rtt.dispose());
211
+ this._renderTargetTextures.clear();
212
+ }
213
+ }
214
+ /**
215
+ * the WebXR Space Warp feature.
216
+ */
217
+ export class WebXRSpaceWarp extends WebXRAbstractFeature {
218
+ /**
219
+ * constructor for the space warp feature
220
+ * @param _xrSessionManager the xr session manager for this feature
221
+ */
222
+ constructor(_xrSessionManager) {
223
+ super(_xrSessionManager);
224
+ /**
225
+ * {@inheritdoc}
226
+ */
227
+ this.dependsOn = [WebXRFeatureName.LAYERS];
228
+ this.xrNativeFeatureName = "space-warp";
229
+ this._xrSessionManager.scene.needsPreviousWorldMatrices = true;
230
+ }
231
+ /**
232
+ * Attach this feature.
233
+ * Will usually be called by the features manager.
234
+ *
235
+ * @returns true if successful.
236
+ */
237
+ attach() {
238
+ if (!super.attach()) {
239
+ return false;
240
+ }
241
+ const engine = this._xrSessionManager.scene.getEngine();
242
+ this._glContext = engine._gl;
243
+ this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);
244
+ this.spaceWarpRTTProvider = new WebXRSpaceWarpRenderTargetTextureProvider(this._xrSessionManager.scene, this._xrSessionManager, this._xrWebGLBinding);
245
+ this._xrSessionManager.scene.onAfterRenderObservable.add(this._onAfterRender.bind(this));
246
+ return true;
247
+ }
248
+ _onAfterRender() {
249
+ if (this.attached && this._renderTargetTexture) {
250
+ this._renderTargetTexture.render(false, false);
251
+ }
252
+ }
253
+ /**
254
+ * {@inheritdoc}
255
+ */
256
+ isCompatible() {
257
+ return this._xrSessionManager.scene.getEngine().getCaps().colorBufferHalfFloat || false;
258
+ }
259
+ /**
260
+ * {@inheritdoc}
261
+ */
262
+ dispose() {
263
+ super.dispose();
264
+ }
265
+ _onXRFrame(_xrFrame) {
266
+ const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);
267
+ if (!pose) {
268
+ return;
269
+ }
270
+ // get the first view to which we will create a texture (or update it)
271
+ const view = pose.views[0];
272
+ this._renderTargetTexture = this._renderTargetTexture || this.spaceWarpRTTProvider.getRenderTargetTextureForView(view);
273
+ this.spaceWarpRTTProvider.accessMotionVector(view);
274
+ }
275
+ }
276
+ /**
277
+ * The module's name
278
+ */
279
+ WebXRSpaceWarp.Name = WebXRFeatureName.SPACE_WARP;
280
+ /**
281
+ * The (Babylon) version of this module.
282
+ * This is an integer representing the implementation version.
283
+ * This number does not correspond to the WebXR specs version
284
+ */
285
+ WebXRSpaceWarp.Version = 1;
286
+ //register the plugin
287
+ WebXRFeaturesManager.AddWebXRFeature(WebXRSpaceWarp.Name, (xrSessionManager) => {
288
+ return () => new WebXRSpaceWarp(xrSessionManager);
289
+ }, WebXRSpaceWarp.Version, false);
290
+ //# sourceMappingURL=WebXRSpaceWarp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebXRSpaceWarp.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/features/WebXRSpaceWarp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAIhE,OAAO,iCAAiC,CAAC;AACzC,OAAO,+BAA+B,CAAC;AAEvC;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,mBAAmB;IAM5D;;;;;;OAMG;IACH,YAAY,mBAAiC,EAAE,mBAAiC,EAAE,KAAa,EAAE,OAAuE,GAAG;QACvK,KAAK,CAAC,eAAe,EAAE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CAAC,OAAO,EAAE,CAAC,oBAAoB,IAAI,KAAK,CAAC;IAC5F,CAAC;IAED;;OAEG;IACI,OAAO;QACV,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;IAES,UAAU,CAAC,QAAiB;QAClC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;QAC3E,IAAI,CAAC,IAAI,EAAE;YACP,OAAO;SACV;QAED,sEAAsE;QACtE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,oBAAqB,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC;QACxH,IAAI,CAAC,oBAAqB,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC;;AAtFD;;GAEG;AACoB,mBAAI,GAAG,gBAAgB,CAAC,UAAU,CAAC;AAC1D;;;;GAIG;AACoB,sBAAO,GAAG,CAAC,CAAC;AAgFvC,qBAAqB;AACrB,oBAAoB,CAAC,eAAe,CAChC,cAAc,CAAC,IAAI,EACnB,CAAC,gBAAgB,EAAE,EAAE;IACjB,OAAO,GAAG,EAAE,CAAC,IAAI,cAAc,CAAC,gBAAgB,CAAC,CAAC;AACtD,CAAC,EACD,cAAc,CAAC,OAAO,EACtB,KAAK,CACR,CAAC","sourcesContent":["import type { Engine } from \"../../Engines/engine\";\r\nimport type { WebGLRenderTargetWrapper } from \"../../Engines/WebGL/webGLRenderTargetWrapper\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IWebXRRenderTargetTextureProvider } from \"../webXRRenderTargetTextureProvider\";\r\nimport type { Viewport } from \"../../Maths/math.viewport\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { ShaderMaterial } from \"../../Materials/shaderMaterial\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Material } from \"../../Materials/material\";\r\n\r\nimport \"../../Shaders/velocity.fragment\";\r\nimport \"../../Shaders/velocity.vertex\";\r\n\r\n/**\r\n * Used for Space Warp render process\r\n */\r\nexport class XRSpaceWarpRenderTarget extends RenderTargetTexture {\r\n private _velocityMaterial: ShaderMaterial;\r\n private _originalPairing: Array<[AbstractMesh, Nullable<Material>]> = [];\r\n private _previousWorldMatrices: Array<Matrix> = [];\r\n private _previousTransforms: Matrix[] = [Matrix.Identity(), Matrix.Identity()];\r\n\r\n /**\r\n * Creates a Space Warp render target\r\n * @param motionVectorTexture WebGLTexture provided by WebGLSubImage\r\n * @param depthStencilTexture WebGLTexture provided by WebGLSubImage\r\n * @param scene scene used with the render target\r\n * @param size the size of the render target (used for each view)\r\n */\r\n constructor(motionVectorTexture: WebGLTexture, depthStencilTexture: WebGLTexture, scene?: Scene, size: number | { width: number; height: number } | { ratio: number } = 512) {\r\n super(\"spacewarp rtt\", size, scene, false, true, Constants.TEXTURETYPE_HALF_FLOAT, false, undefined, false, false, true, undefined, true);\r\n this._renderTarget = this.getScene()!\r\n .getEngine()\r\n .createMultiviewRenderTargetTexture(this.getRenderWidth(), this.getRenderHeight(), motionVectorTexture, depthStencilTexture);\r\n (this._renderTarget as WebGLRenderTargetWrapper)._disposeOnlyFramebuffers = true;\r\n this._texture = this._renderTarget.texture!;\r\n this._texture.isMultiview = true;\r\n this._texture.format = Constants.TEXTUREFORMAT_RGBA;\r\n\r\n if (scene) {\r\n this._velocityMaterial = new ShaderMaterial(\r\n \"velocity shader material\",\r\n scene,\r\n {\r\n vertex: \"velocity\",\r\n fragment: \"velocity\",\r\n },\r\n {\r\n uniforms: [\"world\", \"previousWorld\", \"viewProjection\", \"viewProjectionR\", \"previousViewProjection\", \"previousViewProjectionR\"],\r\n }\r\n );\r\n this._velocityMaterial._materialHelperNeedsPreviousMatrices = true;\r\n this._velocityMaterial.onBindObservable.add((mesh) => {\r\n // mesh. getWorldMatrix can be incorrect under rare conditions (e.g. when using a effective mesh in the render function).\r\n // If the case arise that will require changing it we will need to change the bind process in the material class to also provide the world matrix as a parameter\r\n this._previousWorldMatrices[mesh.uniqueId] = this._previousWorldMatrices[mesh.uniqueId] || mesh.getWorldMatrix();\r\n this._velocityMaterial.getEffect().setMatrix(\"previousWorld\", this._previousWorldMatrices[mesh.uniqueId]);\r\n this._previousWorldMatrices[mesh.uniqueId] = mesh.getWorldMatrix();\r\n // now set the scene's previous matrix\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjection\", this._previousTransforms[0]);\r\n // multiview for sure\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjectionR\", this._previousTransforms[1]);\r\n\r\n // store the previous (current, to be exact) transforms\r\n this._previousTransforms[0].copyFrom(scene.getTransformMatrix());\r\n this._previousTransforms[1].copyFrom(scene._transformMatrixR);\r\n });\r\n this._velocityMaterial.freeze();\r\n }\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public render(useCameraPostProcess: boolean = false, dumpForDebug: boolean = false): void {\r\n // Swap to use velocity material\r\n this._originalPairing.length = 0;\r\n const scene = this.getScene();\r\n // set the velocity material to render the velocity RTT\r\n if (scene && this._velocityMaterial) {\r\n scene.getActiveMeshes().forEach((mesh) => {\r\n this._originalPairing.push([mesh, mesh.material]);\r\n mesh.material = this._velocityMaterial;\r\n });\r\n }\r\n\r\n super.render(useCameraPostProcess, dumpForDebug);\r\n\r\n // Restore original materials\r\n this._originalPairing.forEach((tuple) => {\r\n tuple[0].material = tuple[1];\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bindFrameBuffer() {\r\n if (!this._renderTarget) {\r\n return;\r\n }\r\n this.getScene()!.getEngine().bindSpaceWarpFramebuffer(this._renderTarget);\r\n }\r\n\r\n /**\r\n * Gets the number of views the corresponding to the texture (eg. a SpaceWarpRenderTarget will have > 1)\r\n * @returns the view count\r\n */\r\n public getViewCount() {\r\n return 2;\r\n }\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n this._velocityMaterial.dispose();\r\n this._previousTransforms.length = 0;\r\n this._previousWorldMatrices.length = 0;\r\n this._originalPairing.length = 0;\r\n }\r\n}\r\n\r\n/**\r\n * WebXR Space Warp Render Target Texture Provider\r\n */\r\nexport class WebXRSpaceWarpRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n protected _lastSubImages = new Map<XRView, XRWebGLSubImage>();\r\n protected _renderTargetTextures = new Map<XREye, RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n protected _engine: Engine;\r\n\r\n constructor(protected readonly _scene: Scene, protected readonly _xrSessionManager: WebXRSessionManager, protected readonly _xrWebGLBinding: XRWebGLBinding) {\r\n this._engine = _scene.getEngine();\r\n }\r\n\r\n private _getSubImageForView(view: XRView): XRWebGLSubImage {\r\n const layerWrapper = this._xrSessionManager._getBaseLayerWrapper();\r\n if (!layerWrapper) {\r\n throw new Error(\"For Space Warp, the base layer should be a WebXR Projection Layer.\");\r\n }\r\n if (layerWrapper.layerType !== \"XRProjectionLayer\") {\r\n throw new Error('For Space Warp, the base layer type should \"XRProjectionLayer\".');\r\n }\r\n const layer = layerWrapper.layer as XRProjectionLayer;\r\n return this._xrWebGLBinding.getViewSubImage(layer, view);\r\n }\r\n\r\n protected _setViewportForSubImage(viewport: Viewport, subImage: XRWebGLSubImage) {\r\n viewport.x = 0;\r\n viewport.y = 0;\r\n viewport.width = subImage.motionVectorTextureWidth!;\r\n viewport.height = subImage.motionVectorTextureHeight!;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable<WebGLFramebuffer>,\r\n motionVectorTexture: WebGLTexture,\r\n depthStencilTexture: WebGLTexture\r\n ): RenderTargetTexture {\r\n if (!this._engine) {\r\n throw new Error(\"Engine is disposed\");\r\n }\r\n\r\n const textureSize = { width, height };\r\n\r\n // Create render target texture from the internal texture\r\n const renderTargetTexture = new XRSpaceWarpRenderTarget(motionVectorTexture, depthStencilTexture, this._scene, textureSize);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n if (framebuffer) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n renderTargetWrapper._colorTextureArray = motionVectorTexture;\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n\r\n renderTargetTexture.disableRescaling();\r\n renderTargetTexture.renderListPredicate = () => true;\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _getRenderTargetForSubImage(subImage: XRWebGLSubImage, view: XRView) {\r\n const lastSubImage = this._lastSubImages.get(view);\r\n let renderTargetTexture = this._renderTargetTextures.get(view.eye);\r\n\r\n const width = subImage.motionVectorTextureWidth!;\r\n const height = subImage.motionVectorTextureHeight!;\r\n\r\n if (!renderTargetTexture || lastSubImage?.textureWidth !== width || lastSubImage?.textureHeight != height) {\r\n renderTargetTexture = this._createRenderTargetTexture(width, height, null, subImage.motionVectorTexture!, subImage.depthStencilTexture!);\r\n this._renderTargetTextures.set(view.eye, renderTargetTexture);\r\n\r\n this._framebufferDimensions = {\r\n framebufferWidth: width,\r\n framebufferHeight: height,\r\n };\r\n }\r\n\r\n this._lastSubImages.set(view, subImage);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n const subImage = this._lastSubImages.get(view) || this._getSubImageForView(view);\r\n if (subImage) {\r\n this._setViewportForSubImage(viewport, subImage);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Access the motion vector (which will turn on Space Warp)\r\n * @param view the view to access the motion vector texture for\r\n */\r\n public accessMotionVector(view: XRView): void {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n // Meta Quest Browser uses accessing these textures as a sign for turning on Space Warp\r\n subImage.motionVectorTexture;\r\n subImage.depthStencilTexture;\r\n }\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public getRenderTargetTextureForEye(_eye: XREye): Nullable<RenderTargetTexture> {\r\n return null;\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n return this._getRenderTargetForSubImage(subImage, view);\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.clear();\r\n }\r\n}\r\n\r\n/**\r\n * the WebXR Space Warp feature.\r\n */\r\nexport class WebXRSpaceWarp extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.SPACE_WARP;\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 * The space warp provider\r\n */\r\n public spaceWarpRTTProvider: Nullable<WebXRSpaceWarpRenderTargetTextureProvider>;\r\n private _glContext: WebGLRenderingContext | WebGL2RenderingContext;\r\n private _xrWebGLBinding: XRWebGLBinding;\r\n private _renderTargetTexture: Nullable<RenderTargetTexture>;\r\n\r\n /**\r\n * constructor for the space warp feature\r\n * @param _xrSessionManager the xr session manager for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"space-warp\";\r\n this._xrSessionManager.scene.needsPreviousWorldMatrices = true;\r\n }\r\n\r\n /**\r\n * Attach 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 attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n const engine = this._xrSessionManager.scene.getEngine();\r\n this._glContext = engine._gl;\r\n this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n\r\n this.spaceWarpRTTProvider = new WebXRSpaceWarpRenderTargetTextureProvider(this._xrSessionManager.scene, this._xrSessionManager, this._xrWebGLBinding);\r\n\r\n this._xrSessionManager.scene.onAfterRenderObservable.add(this._onAfterRender.bind(this));\r\n\r\n return true;\r\n }\r\n\r\n private _onAfterRender(): void {\r\n if (this.attached && this._renderTargetTexture) {\r\n this._renderTargetTexture.render(false, false);\r\n }\r\n }\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public dependsOn: string[] = [WebXRFeatureName.LAYERS];\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public isCompatible(): boolean {\r\n return this._xrSessionManager.scene.getEngine().getCaps().colorBufferHalfFloat || false;\r\n }\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n\r\n // get the first view to which we will create a texture (or update it)\r\n const view = pose.views[0];\r\n this._renderTargetTexture = this._renderTargetTexture || this.spaceWarpRTTProvider!.getRenderTargetTextureForView(view);\r\n this.spaceWarpRTTProvider!.accessMotionVector(view);\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRSpaceWarp.Name,\r\n (xrSessionManager) => {\r\n return () => new WebXRSpaceWarp(xrSessionManager);\r\n },\r\n WebXRSpaceWarp.Version,\r\n false\r\n);\r\n"]}
@@ -19,3 +19,4 @@ export * from "./WebXREyeTracking";
19
19
  export * from "./WebXRWalkingLocomotion";
20
20
  export * from "./WebXRLayers";
21
21
  export * from "./WebXRDepthSensing";
22
+ export * from "./WebXRSpaceWarp";
@@ -19,4 +19,5 @@ export * from "./WebXREyeTracking.js";
19
19
  export * from "./WebXRWalkingLocomotion.js";
20
20
  export * from "./WebXRLayers.js";
21
21
  export * from "./WebXRDepthSensing.js";
22
+ export * from "./WebXRSpaceWarp.js";
22
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/features/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC","sourcesContent":["export * from \"./WebXRAbstractFeature\";\r\nexport * from \"./WebXRHitTestLegacy\";\r\nexport * from \"./WebXRAnchorSystem\";\r\nexport * from \"./WebXRPlaneDetector\";\r\nexport * from \"./WebXRBackgroundRemover\";\r\nexport * from \"./WebXRControllerTeleportation\";\r\nexport * from \"./WebXRControllerPointerSelection\";\r\nexport * from \"./WebXRControllerPhysics\";\r\nexport * from \"./WebXRHitTest\";\r\nexport * from \"./WebXRFeaturePointSystem\";\r\nexport * from \"./WebXRHandTracking\";\r\nexport * from \"./WebXRMeshDetector\";\r\nexport * from \"./WebXRImageTracking\";\r\nexport * from \"./WebXRNearInteraction\";\r\nexport * from \"./WebXRDOMOverlay\";\r\nexport * from \"./WebXRControllerMovement\";\r\nexport * from \"./WebXRLightEstimation\";\r\nexport * from \"./WebXREyeTracking\";\r\nexport * from \"./WebXRWalkingLocomotion\";\r\nexport * from \"./WebXRLayers\";\r\nexport * from \"./WebXRDepthSensing\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/features/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC","sourcesContent":["export * from \"./WebXRAbstractFeature\";\r\nexport * from \"./WebXRHitTestLegacy\";\r\nexport * from \"./WebXRAnchorSystem\";\r\nexport * from \"./WebXRPlaneDetector\";\r\nexport * from \"./WebXRBackgroundRemover\";\r\nexport * from \"./WebXRControllerTeleportation\";\r\nexport * from \"./WebXRControllerPointerSelection\";\r\nexport * from \"./WebXRControllerPhysics\";\r\nexport * from \"./WebXRHitTest\";\r\nexport * from \"./WebXRFeaturePointSystem\";\r\nexport * from \"./WebXRHandTracking\";\r\nexport * from \"./WebXRMeshDetector\";\r\nexport * from \"./WebXRImageTracking\";\r\nexport * from \"./WebXRNearInteraction\";\r\nexport * from \"./WebXRDOMOverlay\";\r\nexport * from \"./WebXRControllerMovement\";\r\nexport * from \"./WebXRLightEstimation\";\r\nexport * from \"./WebXREyeTracking\";\r\nexport * from \"./WebXRWalkingLocomotion\";\r\nexport * from \"./WebXRLayers\";\r\nexport * from \"./WebXRDepthSensing\";\r\nexport * from \"./WebXRSpaceWarp\";\r\n"]}
@@ -131,6 +131,10 @@ export declare class WebXRFeatureName {
131
131
  * The name of the depth sensing feature
132
132
  */
133
133
  static readonly DEPTH_SENSING = "xr-depth-sensing";
134
+ /**
135
+ * The name of the WebXR Space Warp feature
136
+ */
137
+ static readonly SPACE_WARP = "xr-space-warp";
134
138
  }
135
139
  /**
136
140
  * Defining the constructor of a feature. Used to register the modules.
@@ -80,6 +80,10 @@ WebXRFeatureName.LAYERS = "xr-layers";
80
80
  * The name of the depth sensing feature
81
81
  */
82
82
  WebXRFeatureName.DEPTH_SENSING = "xr-depth-sensing";
83
+ /**
84
+ * The name of the WebXR Space Warp feature
85
+ */
86
+ WebXRFeatureName.SPACE_WARP = "xr-space-warp";
83
87
  /**
84
88
  * The WebXR features manager is responsible of enabling or disabling features required for the current XR session.
85
89
  * It is mainly used in AR sessions.
@@ -1 +1 @@
1
- {"version":3,"file":"webXRFeaturesManager.js","sourceRoot":"","sources":["../../../../lts/core/generated/XR/webXRFeaturesManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AA4DtC;;GAEG;AACH,MAAM,OAAO,gBAAgB;;AACzB;;GAEG;AACoB,8BAAa,GAAG,kBAAkB,CAAC;A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AC,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE;wBAC3D,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;qBACnD;iBACJ;aACJ;YACD,IAAI,OAAO,CAAC,qBAAqB,CAAC,yBAAyB,EAAE;gBACzD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,qBAAqB,CAAC,yBAAyB,EAAE,CAAC;gBACjF,aAAa,GAAG;oBACZ,GAAG,aAAa;oBAChB,GAAG,QAAQ;iBACd,CAAC;aACL;SACJ;QACD,OAAO,aAAa,CAAC;IACzB,CAAC;;AAxUuB,uCAAkB,GAMtC,EAAE,CAAC;AAWP;;GAEG;AACqB,yCAAoB,GAA8B;IACtE,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,gBAAgB,CAAC,QAAQ;IAC3D,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,aAAa;CAC9D,CAAC","sourcesContent":["import type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport { Tools } from \"../Misc/tools\";\r\n\r\n/**\r\n * Defining the interface required for a (webxr) feature\r\n */\r\nexport interface IWebXRFeature extends IDisposable {\r\n /**\r\n * Is this feature attached\r\n */\r\n attached: boolean;\r\n /**\r\n * Should auto-attach be disabled?\r\n */\r\n disableAutoAttach: boolean;\r\n\r\n /**\r\n * Attach the feature to the session\r\n * Will usually be called by the features manager\r\n *\r\n * @param force should attachment be forced (even when already attached)\r\n * @returns true if successful.\r\n */\r\n attach(force?: boolean): boolean;\r\n /**\r\n * Detach the feature from the session\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n detach(): boolean;\r\n\r\n /**\r\n * This function will be executed during before enabling the feature and can be used to not-allow enabling it.\r\n * Note that at this point the session has NOT started, so this is purely checking if the browser supports it\r\n *\r\n * @returns whether or not the feature is compatible in this environment\r\n */\r\n isCompatible(): boolean;\r\n\r\n /**\r\n * Was this feature disposed;\r\n */\r\n isDisposed: boolean;\r\n\r\n /**\r\n * The name of the native xr feature name, if applicable (like anchor, hit-test, or hand-tracking)\r\n */\r\n xrNativeFeatureName?: string;\r\n\r\n /**\r\n * A list of (Babylon WebXR) features this feature depends on\r\n */\r\n dependsOn?: string[];\r\n\r\n /**\r\n * If this feature requires to extend the XRSessionInit object, this function will return the partial XR session init object\r\n */\r\n getXRSessionInitExtension?: () => Promise<Partial<XRSessionInit>>;\r\n}\r\n\r\n/**\r\n * A list of the currently available features without referencing them\r\n */\r\nexport class WebXRFeatureName {\r\n /**\r\n * The name of the anchor system feature\r\n */\r\n public static readonly ANCHOR_SYSTEM = \"xr-anchor-system\";\r\n /**\r\n * The name of the background remover feature\r\n */\r\n public static readonly BACKGROUND_REMOVER = \"xr-background-remover\";\r\n /**\r\n * The name of the hit test feature\r\n */\r\n public static readonly HIT_TEST = \"xr-hit-test\";\r\n /**\r\n * The name of the mesh detection feature\r\n */\r\n public static readonly MESH_DETECTION = \"xr-mesh-detection\";\r\n /**\r\n * physics impostors for xr controllers feature\r\n */\r\n public static readonly PHYSICS_CONTROLLERS = \"xr-physics-controller\";\r\n /**\r\n * The name of the plane detection feature\r\n */\r\n public static readonly PLANE_DETECTION = \"xr-plane-detection\";\r\n /**\r\n * The name of the pointer selection feature\r\n */\r\n public static readonly POINTER_SELECTION = \"xr-controller-pointer-selection\";\r\n /**\r\n * The name of the teleportation feature\r\n */\r\n public static readonly TELEPORTATION = \"xr-controller-teleportation\";\r\n /**\r\n * The name of the feature points feature.\r\n */\r\n public static readonly FEATURE_POINTS = \"xr-feature-points\";\r\n /**\r\n * The name of the hand tracking feature.\r\n */\r\n public static readonly HAND_TRACKING = \"xr-hand-tracking\";\r\n /**\r\n * The name of the image tracking feature\r\n */\r\n public static readonly IMAGE_TRACKING = \"xr-image-tracking\";\r\n /**\r\n * The name of the near interaction feature\r\n */\r\n public static readonly NEAR_INTERACTION = \"xr-near-interaction\";\r\n /**\r\n * The name of the DOM overlay feature\r\n */\r\n public static readonly DOM_OVERLAY = \"xr-dom-overlay\";\r\n /**\r\n * The name of the movement feature\r\n */\r\n public static readonly MOVEMENT = \"xr-controller-movement\";\r\n /**\r\n * The name of the light estimation feature\r\n */\r\n public static readonly LIGHT_ESTIMATION = \"xr-light-estimation\";\r\n /**\r\n * The name of the eye tracking feature\r\n */\r\n public static readonly EYE_TRACKING = \"xr-eye-tracking\";\r\n /**\r\n * The name of the walking locomotion feature\r\n */\r\n public static readonly WALKING_LOCOMOTION = \"xr-walking-locomotion\";\r\n /**\r\n * The name of the composition layers feature\r\n */\r\n public static readonly LAYERS = \"xr-layers\";\r\n /**\r\n * The name of the depth sensing feature\r\n */\r\n public static readonly DEPTH_SENSING = \"xr-depth-sensing\";\r\n}\r\n\r\n/**\r\n * Defining the constructor of a feature. Used to register the modules.\r\n */\r\nexport type WebXRFeatureConstructor = (xrSessionManager: WebXRSessionManager, options?: any) => () => IWebXRFeature;\r\n\r\n/**\r\n * The WebXR features manager is responsible of enabling or disabling features required for the current XR session.\r\n * It is mainly used in AR sessions.\r\n *\r\n * A feature can have a version that is defined by Babylon (and does not correspond with the webxr version).\r\n */\r\nexport class WebXRFeaturesManager implements IDisposable {\r\n private static readonly _AvailableFeatures: {\r\n [name: string]: {\r\n stable: number;\r\n latest: number;\r\n [version: number]: WebXRFeatureConstructor;\r\n };\r\n } = {};\r\n\r\n private _features: {\r\n [name: string]: {\r\n featureImplementation: IWebXRFeature;\r\n version: number;\r\n enabled: boolean;\r\n required: boolean;\r\n };\r\n } = {};\r\n\r\n /**\r\n * The key is the feature to check and the value is the feature that conflicts.\r\n */\r\n private static readonly _ConflictingFeatures: { [key: string]: string } = {\r\n [WebXRFeatureName.TELEPORTATION]: WebXRFeatureName.MOVEMENT,\r\n [WebXRFeatureName.MOVEMENT]: WebXRFeatureName.TELEPORTATION,\r\n };\r\n\r\n /**\r\n * constructs a new features manages.\r\n *\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n */\r\n constructor(private _xrSessionManager: WebXRSessionManager) {\r\n // when session starts / initialized - attach\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n this.getEnabledFeatures().forEach((featureName) => {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && !feature.featureImplementation.attached && !feature.featureImplementation.disableAutoAttach) {\r\n this.attachFeature(featureName);\r\n }\r\n });\r\n });\r\n\r\n // when session ends - detach\r\n this._xrSessionManager.onXRSessionEnded.add(() => {\r\n this.getEnabledFeatures().forEach((featureName) => {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && feature.featureImplementation.attached) {\r\n // detach, but don't disable!\r\n this.detachFeature(featureName);\r\n }\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Used to register a module. After calling this function a developer can use this feature in the scene.\r\n * Mainly used internally.\r\n *\r\n * @param featureName the name of the feature to register\r\n * @param constructorFunction the function used to construct the module\r\n * @param version the (babylon) version of the module\r\n * @param stable is that a stable version of this module\r\n */\r\n public static AddWebXRFeature(featureName: string, constructorFunction: WebXRFeatureConstructor, version: number = 1, stable: boolean = false) {\r\n this._AvailableFeatures[featureName] = this._AvailableFeatures[featureName] || { latest: version };\r\n if (version > this._AvailableFeatures[featureName].latest) {\r\n this._AvailableFeatures[featureName].latest = version;\r\n }\r\n if (stable) {\r\n this._AvailableFeatures[featureName].stable = version;\r\n }\r\n this._AvailableFeatures[featureName][version] = constructorFunction;\r\n }\r\n\r\n /**\r\n * Returns a constructor of a specific feature.\r\n *\r\n * @param featureName the name of the feature to construct\r\n * @param version the version of the feature to load\r\n * @param xrSessionManager the xrSessionManager. Used to construct the module\r\n * @param options optional options provided to the module.\r\n * @returns a function that, when called, will return a new instance of this feature\r\n */\r\n public static ConstructFeature(featureName: string, version: number = 1, xrSessionManager: WebXRSessionManager, options?: any): () => IWebXRFeature {\r\n const constructorFunction = this._AvailableFeatures[featureName][version];\r\n if (!constructorFunction) {\r\n // throw an error? return nothing?\r\n throw new Error(\"feature not found\");\r\n }\r\n\r\n return constructorFunction(xrSessionManager, options);\r\n }\r\n\r\n /**\r\n * Can be used to return the list of features currently registered\r\n *\r\n * @returns an Array of available features\r\n */\r\n public static GetAvailableFeatures() {\r\n return Object.keys(this._AvailableFeatures);\r\n }\r\n\r\n /**\r\n * Gets the versions available for a specific feature\r\n * @param featureName the name of the feature\r\n * @returns an array with the available versions\r\n */\r\n public static GetAvailableVersions(featureName: string) {\r\n return Object.keys(this._AvailableFeatures[featureName]);\r\n }\r\n\r\n /**\r\n * Return the latest unstable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetLatestVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].latest) || -1;\r\n }\r\n\r\n /**\r\n * Return the latest stable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetStableVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].stable) || -1;\r\n }\r\n\r\n /**\r\n * Attach a feature to the current session. Mainly used when session started to start the feature effect.\r\n * Can be used during a session to start a feature\r\n * @param featureName the name of feature to attach\r\n */\r\n public attachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.enabled && !feature.featureImplementation.attached) {\r\n feature.featureImplementation.attach();\r\n }\r\n }\r\n\r\n /**\r\n * Can be used inside a session or when the session ends to detach a specific feature\r\n * @param featureName the name of the feature to detach\r\n */\r\n public detachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.featureImplementation.attached) {\r\n feature.featureImplementation.detach();\r\n }\r\n }\r\n\r\n /**\r\n * Used to disable an already-enabled feature\r\n * The feature will be disposed and will be recreated once enabled.\r\n * @param featureName the feature to disable\r\n * @returns true if disable was successful\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public disableFeature(featureName: string | { Name: string }): boolean {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n const feature = this._features[name];\r\n if (feature && feature.enabled) {\r\n feature.enabled = false;\r\n this.detachFeature(name);\r\n feature.featureImplementation.dispose();\r\n delete this._features[name];\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * dispose this features manager\r\n */\r\n public dispose(): void {\r\n this.getEnabledFeatures().forEach((feature) => {\r\n this.disableFeature(feature);\r\n });\r\n }\r\n\r\n /**\r\n * Enable a feature using its name and a version. This will enable it in the scene, and will be responsible to attach it when the session starts.\r\n * If used twice, the old version will be disposed and a new one will be constructed. This way you can re-enable with different configuration.\r\n *\r\n * @param featureName the name of the feature to load or the class of the feature\r\n * @param version optional version to load. if not provided the latest version will be enabled\r\n * @param moduleOptions options provided to the module. Ses the module documentation / constructor\r\n * @param attachIfPossible if set to true (default) the feature will be automatically attached, if it is currently possible\r\n * @param required is this feature required to the app. If set to true the session init will fail if the feature is not available.\r\n * @returns a new constructed feature or throws an error if feature not found or conflicts with another enabled feature.\r\n */\r\n public enableFeature(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n featureName: string | { Name: string },\r\n version: number | string = \"latest\",\r\n moduleOptions: any = {},\r\n attachIfPossible: boolean = true,\r\n required: boolean = true\r\n ): IWebXRFeature {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n let versionToLoad = 0;\r\n if (typeof version === \"string\") {\r\n if (!version) {\r\n throw new Error(`Error in provided version - ${name} (${version})`);\r\n }\r\n if (version === \"stable\") {\r\n versionToLoad = WebXRFeaturesManager.GetStableVersionOfFeature(name);\r\n } else if (version === \"latest\") {\r\n versionToLoad = WebXRFeaturesManager.GetLatestVersionOfFeature(name);\r\n } else {\r\n // try loading the number the string represents\r\n versionToLoad = +version;\r\n }\r\n if (versionToLoad === -1 || isNaN(versionToLoad)) {\r\n throw new Error(`feature not found - ${name} (${version})`);\r\n }\r\n } else {\r\n versionToLoad = version;\r\n }\r\n\r\n // check if there is a feature conflict\r\n const conflictingFeature = WebXRFeaturesManager._ConflictingFeatures[name];\r\n if (conflictingFeature !== undefined && this.getEnabledFeatures().indexOf(conflictingFeature) !== -1) {\r\n throw new Error(`Feature ${name} cannot be enabled while ${conflictingFeature} is enabled.`);\r\n }\r\n\r\n // check if already initialized\r\n const feature = this._features[name];\r\n const constructFunction = WebXRFeaturesManager.ConstructFeature(name, versionToLoad, this._xrSessionManager, moduleOptions);\r\n if (!constructFunction) {\r\n // report error?\r\n throw new Error(`feature not found - ${name}`);\r\n }\r\n\r\n /* If the feature is already enabled, detach and dispose it, and create a new one */\r\n if (feature) {\r\n this.disableFeature(name);\r\n }\r\n\r\n const constructed = constructFunction();\r\n if (constructed.dependsOn) {\r\n const dependentsFound = constructed.dependsOn.every((featureName) => !!this._features[featureName]);\r\n if (!dependentsFound) {\r\n throw new Error(`Dependant features missing. Make sure the following features are enabled - ${constructed.dependsOn.join(\", \")}`);\r\n }\r\n }\r\n if (constructed.isCompatible()) {\r\n this._features[name] = {\r\n featureImplementation: constructed,\r\n enabled: true,\r\n version: versionToLoad,\r\n required,\r\n };\r\n\r\n if (attachIfPossible) {\r\n // if session started already, request and enable\r\n if (this._xrSessionManager.session && !this._features[name].featureImplementation.attached) {\r\n // enable feature\r\n this.attachFeature(name);\r\n }\r\n } else {\r\n // disable auto-attach when session starts\r\n this._features[name].featureImplementation.disableAutoAttach = true;\r\n }\r\n\r\n return this._features[name].featureImplementation;\r\n } else {\r\n if (required) {\r\n throw new Error(\"required feature not compatible\");\r\n } else {\r\n Tools.Warn(`Feature ${name} not compatible with the current environment/browser and was not enabled.`);\r\n return constructed;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * get the implementation of an enabled feature.\r\n * @param featureName the name of the feature to load\r\n * @returns the feature class, if found\r\n */\r\n public getEnabledFeature(featureName: string): IWebXRFeature {\r\n return this._features[featureName] && this._features[featureName].featureImplementation;\r\n }\r\n\r\n /**\r\n * Get the list of enabled features\r\n * @returns an array of enabled features\r\n */\r\n public getEnabledFeatures() {\r\n return Object.keys(this._features);\r\n }\r\n\r\n /**\r\n * This function will extend the session creation configuration object with enabled features.\r\n * If, for example, the anchors feature is enabled, it will be automatically added to the optional or required features list,\r\n * according to the defined \"required\" variable, provided during enableFeature call\r\n * @param xrSessionInit the xr Session init object to extend\r\n *\r\n * @returns an extended XRSessionInit object\r\n */\r\n public async _extendXRSessionInitObject(xrSessionInit: XRSessionInit): Promise<XRSessionInit> {\r\n const enabledFeatures = this.getEnabledFeatures();\r\n for (const featureName of enabledFeatures) {\r\n const feature = this._features[featureName];\r\n const nativeName = feature.featureImplementation.xrNativeFeatureName;\r\n if (nativeName) {\r\n if (feature.required) {\r\n xrSessionInit.requiredFeatures = xrSessionInit.requiredFeatures || [];\r\n if (xrSessionInit.requiredFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.requiredFeatures.push(nativeName);\r\n }\r\n } else {\r\n xrSessionInit.optionalFeatures = xrSessionInit.optionalFeatures || [];\r\n if (xrSessionInit.optionalFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.optionalFeatures.push(nativeName);\r\n }\r\n }\r\n }\r\n if (feature.featureImplementation.getXRSessionInitExtension) {\r\n const extended = await feature.featureImplementation.getXRSessionInitExtension();\r\n xrSessionInit = {\r\n ...xrSessionInit,\r\n ...extended,\r\n };\r\n }\r\n }\r\n return xrSessionInit;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"webXRFeaturesManager.js","sourceRoot":"","sources":["../../../../lts/core/generated/XR/webXRFeaturesManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AA4DtC;;GAEG;AACH,MAAM,OAAO,gBAAgB;;AACzB;;GAEG;AACoB,8BAAa,GAAG,kBAAkB,CAAC;AAC1D;;GAEG;AACoB,mCAAkB,GAAG,uBAAuB,CAAC;AACpE;;GAEG;AACoB,yBAAQ,GAAG,aAAa,CAAC;AAChD;;GAEG;AACoB,+BAAc,GAAG,mBA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,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;qBACnD;iBACJ;aACJ;YACD,IAAI,OAAO,CAAC,qBAAqB,CAAC,yBAAyB,EAAE;gBACzD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,qBAAqB,CAAC,yBAAyB,EAAE,CAAC;gBACjF,aAAa,GAAG;oBACZ,GAAG,aAAa;oBAChB,GAAG,QAAQ;iBACd,CAAC;aACL;SACJ;QACD,OAAO,aAAa,CAAC;IACzB,CAAC;;AAxUuB,uCAAkB,GAMtC,EAAE,CAAC;AAWP;;GAEG;AACqB,yCAAoB,GAA8B;IACtE,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,gBAAgB,CAAC,QAAQ;IAC3D,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,aAAa;CAC9D,CAAC","sourcesContent":["import type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport { Tools } from \"../Misc/tools\";\r\n\r\n/**\r\n * Defining the interface required for a (webxr) feature\r\n */\r\nexport interface IWebXRFeature extends IDisposable {\r\n /**\r\n * Is this feature attached\r\n */\r\n attached: boolean;\r\n /**\r\n * Should auto-attach be disabled?\r\n */\r\n disableAutoAttach: boolean;\r\n\r\n /**\r\n * Attach the feature to the session\r\n * Will usually be called by the features manager\r\n *\r\n * @param force should attachment be forced (even when already attached)\r\n * @returns true if successful.\r\n */\r\n attach(force?: boolean): boolean;\r\n /**\r\n * Detach the feature from the session\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n detach(): boolean;\r\n\r\n /**\r\n * This function will be executed during before enabling the feature and can be used to not-allow enabling it.\r\n * Note that at this point the session has NOT started, so this is purely checking if the browser supports it\r\n *\r\n * @returns whether or not the feature is compatible in this environment\r\n */\r\n isCompatible(): boolean;\r\n\r\n /**\r\n * Was this feature disposed;\r\n */\r\n isDisposed: boolean;\r\n\r\n /**\r\n * The name of the native xr feature name, if applicable (like anchor, hit-test, or hand-tracking)\r\n */\r\n xrNativeFeatureName?: string;\r\n\r\n /**\r\n * A list of (Babylon WebXR) features this feature depends on\r\n */\r\n dependsOn?: string[];\r\n\r\n /**\r\n * If this feature requires to extend the XRSessionInit object, this function will return the partial XR session init object\r\n */\r\n getXRSessionInitExtension?: () => Promise<Partial<XRSessionInit>>;\r\n}\r\n\r\n/**\r\n * A list of the currently available features without referencing them\r\n */\r\nexport class WebXRFeatureName {\r\n /**\r\n * The name of the anchor system feature\r\n */\r\n public static readonly ANCHOR_SYSTEM = \"xr-anchor-system\";\r\n /**\r\n * The name of the background remover feature\r\n */\r\n public static readonly BACKGROUND_REMOVER = \"xr-background-remover\";\r\n /**\r\n * The name of the hit test feature\r\n */\r\n public static readonly HIT_TEST = \"xr-hit-test\";\r\n /**\r\n * The name of the mesh detection feature\r\n */\r\n public static readonly MESH_DETECTION = \"xr-mesh-detection\";\r\n /**\r\n * physics impostors for xr controllers feature\r\n */\r\n public static readonly PHYSICS_CONTROLLERS = \"xr-physics-controller\";\r\n /**\r\n * The name of the plane detection feature\r\n */\r\n public static readonly PLANE_DETECTION = \"xr-plane-detection\";\r\n /**\r\n * The name of the pointer selection feature\r\n */\r\n public static readonly POINTER_SELECTION = \"xr-controller-pointer-selection\";\r\n /**\r\n * The name of the teleportation feature\r\n */\r\n public static readonly TELEPORTATION = \"xr-controller-teleportation\";\r\n /**\r\n * The name of the feature points feature.\r\n */\r\n public static readonly FEATURE_POINTS = \"xr-feature-points\";\r\n /**\r\n * The name of the hand tracking feature.\r\n */\r\n public static readonly HAND_TRACKING = \"xr-hand-tracking\";\r\n /**\r\n * The name of the image tracking feature\r\n */\r\n public static readonly IMAGE_TRACKING = \"xr-image-tracking\";\r\n /**\r\n * The name of the near interaction feature\r\n */\r\n public static readonly NEAR_INTERACTION = \"xr-near-interaction\";\r\n /**\r\n * The name of the DOM overlay feature\r\n */\r\n public static readonly DOM_OVERLAY = \"xr-dom-overlay\";\r\n /**\r\n * The name of the movement feature\r\n */\r\n public static readonly MOVEMENT = \"xr-controller-movement\";\r\n /**\r\n * The name of the light estimation feature\r\n */\r\n public static readonly LIGHT_ESTIMATION = \"xr-light-estimation\";\r\n /**\r\n * The name of the eye tracking feature\r\n */\r\n public static readonly EYE_TRACKING = \"xr-eye-tracking\";\r\n /**\r\n * The name of the walking locomotion feature\r\n */\r\n public static readonly WALKING_LOCOMOTION = \"xr-walking-locomotion\";\r\n /**\r\n * The name of the composition layers feature\r\n */\r\n public static readonly LAYERS = \"xr-layers\";\r\n /**\r\n * The name of the depth sensing feature\r\n */\r\n public static readonly DEPTH_SENSING = \"xr-depth-sensing\";\r\n /**\r\n * The name of the WebXR Space Warp feature\r\n */\r\n public static readonly SPACE_WARP = \"xr-space-warp\";\r\n}\r\n\r\n/**\r\n * Defining the constructor of a feature. Used to register the modules.\r\n */\r\nexport type WebXRFeatureConstructor = (xrSessionManager: WebXRSessionManager, options?: any) => () => IWebXRFeature;\r\n\r\n/**\r\n * The WebXR features manager is responsible of enabling or disabling features required for the current XR session.\r\n * It is mainly used in AR sessions.\r\n *\r\n * A feature can have a version that is defined by Babylon (and does not correspond with the webxr version).\r\n */\r\nexport class WebXRFeaturesManager implements IDisposable {\r\n private static readonly _AvailableFeatures: {\r\n [name: string]: {\r\n stable: number;\r\n latest: number;\r\n [version: number]: WebXRFeatureConstructor;\r\n };\r\n } = {};\r\n\r\n private _features: {\r\n [name: string]: {\r\n featureImplementation: IWebXRFeature;\r\n version: number;\r\n enabled: boolean;\r\n required: boolean;\r\n };\r\n } = {};\r\n\r\n /**\r\n * The key is the feature to check and the value is the feature that conflicts.\r\n */\r\n private static readonly _ConflictingFeatures: { [key: string]: string } = {\r\n [WebXRFeatureName.TELEPORTATION]: WebXRFeatureName.MOVEMENT,\r\n [WebXRFeatureName.MOVEMENT]: WebXRFeatureName.TELEPORTATION,\r\n };\r\n\r\n /**\r\n * constructs a new features manages.\r\n *\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n */\r\n constructor(private _xrSessionManager: WebXRSessionManager) {\r\n // when session starts / initialized - attach\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n this.getEnabledFeatures().forEach((featureName) => {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && !feature.featureImplementation.attached && !feature.featureImplementation.disableAutoAttach) {\r\n this.attachFeature(featureName);\r\n }\r\n });\r\n });\r\n\r\n // when session ends - detach\r\n this._xrSessionManager.onXRSessionEnded.add(() => {\r\n this.getEnabledFeatures().forEach((featureName) => {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && feature.featureImplementation.attached) {\r\n // detach, but don't disable!\r\n this.detachFeature(featureName);\r\n }\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Used to register a module. After calling this function a developer can use this feature in the scene.\r\n * Mainly used internally.\r\n *\r\n * @param featureName the name of the feature to register\r\n * @param constructorFunction the function used to construct the module\r\n * @param version the (babylon) version of the module\r\n * @param stable is that a stable version of this module\r\n */\r\n public static AddWebXRFeature(featureName: string, constructorFunction: WebXRFeatureConstructor, version: number = 1, stable: boolean = false) {\r\n this._AvailableFeatures[featureName] = this._AvailableFeatures[featureName] || { latest: version };\r\n if (version > this._AvailableFeatures[featureName].latest) {\r\n this._AvailableFeatures[featureName].latest = version;\r\n }\r\n if (stable) {\r\n this._AvailableFeatures[featureName].stable = version;\r\n }\r\n this._AvailableFeatures[featureName][version] = constructorFunction;\r\n }\r\n\r\n /**\r\n * Returns a constructor of a specific feature.\r\n *\r\n * @param featureName the name of the feature to construct\r\n * @param version the version of the feature to load\r\n * @param xrSessionManager the xrSessionManager. Used to construct the module\r\n * @param options optional options provided to the module.\r\n * @returns a function that, when called, will return a new instance of this feature\r\n */\r\n public static ConstructFeature(featureName: string, version: number = 1, xrSessionManager: WebXRSessionManager, options?: any): () => IWebXRFeature {\r\n const constructorFunction = this._AvailableFeatures[featureName][version];\r\n if (!constructorFunction) {\r\n // throw an error? return nothing?\r\n throw new Error(\"feature not found\");\r\n }\r\n\r\n return constructorFunction(xrSessionManager, options);\r\n }\r\n\r\n /**\r\n * Can be used to return the list of features currently registered\r\n *\r\n * @returns an Array of available features\r\n */\r\n public static GetAvailableFeatures() {\r\n return Object.keys(this._AvailableFeatures);\r\n }\r\n\r\n /**\r\n * Gets the versions available for a specific feature\r\n * @param featureName the name of the feature\r\n * @returns an array with the available versions\r\n */\r\n public static GetAvailableVersions(featureName: string) {\r\n return Object.keys(this._AvailableFeatures[featureName]);\r\n }\r\n\r\n /**\r\n * Return the latest unstable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetLatestVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].latest) || -1;\r\n }\r\n\r\n /**\r\n * Return the latest stable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetStableVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].stable) || -1;\r\n }\r\n\r\n /**\r\n * Attach a feature to the current session. Mainly used when session started to start the feature effect.\r\n * Can be used during a session to start a feature\r\n * @param featureName the name of feature to attach\r\n */\r\n public attachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.enabled && !feature.featureImplementation.attached) {\r\n feature.featureImplementation.attach();\r\n }\r\n }\r\n\r\n /**\r\n * Can be used inside a session or when the session ends to detach a specific feature\r\n * @param featureName the name of the feature to detach\r\n */\r\n public detachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.featureImplementation.attached) {\r\n feature.featureImplementation.detach();\r\n }\r\n }\r\n\r\n /**\r\n * Used to disable an already-enabled feature\r\n * The feature will be disposed and will be recreated once enabled.\r\n * @param featureName the feature to disable\r\n * @returns true if disable was successful\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public disableFeature(featureName: string | { Name: string }): boolean {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n const feature = this._features[name];\r\n if (feature && feature.enabled) {\r\n feature.enabled = false;\r\n this.detachFeature(name);\r\n feature.featureImplementation.dispose();\r\n delete this._features[name];\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * dispose this features manager\r\n */\r\n public dispose(): void {\r\n this.getEnabledFeatures().forEach((feature) => {\r\n this.disableFeature(feature);\r\n });\r\n }\r\n\r\n /**\r\n * Enable a feature using its name and a version. This will enable it in the scene, and will be responsible to attach it when the session starts.\r\n * If used twice, the old version will be disposed and a new one will be constructed. This way you can re-enable with different configuration.\r\n *\r\n * @param featureName the name of the feature to load or the class of the feature\r\n * @param version optional version to load. if not provided the latest version will be enabled\r\n * @param moduleOptions options provided to the module. Ses the module documentation / constructor\r\n * @param attachIfPossible if set to true (default) the feature will be automatically attached, if it is currently possible\r\n * @param required is this feature required to the app. If set to true the session init will fail if the feature is not available.\r\n * @returns a new constructed feature or throws an error if feature not found or conflicts with another enabled feature.\r\n */\r\n public enableFeature(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n featureName: string | { Name: string },\r\n version: number | string = \"latest\",\r\n moduleOptions: any = {},\r\n attachIfPossible: boolean = true,\r\n required: boolean = true\r\n ): IWebXRFeature {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n let versionToLoad = 0;\r\n if (typeof version === \"string\") {\r\n if (!version) {\r\n throw new Error(`Error in provided version - ${name} (${version})`);\r\n }\r\n if (version === \"stable\") {\r\n versionToLoad = WebXRFeaturesManager.GetStableVersionOfFeature(name);\r\n } else if (version === \"latest\") {\r\n versionToLoad = WebXRFeaturesManager.GetLatestVersionOfFeature(name);\r\n } else {\r\n // try loading the number the string represents\r\n versionToLoad = +version;\r\n }\r\n if (versionToLoad === -1 || isNaN(versionToLoad)) {\r\n throw new Error(`feature not found - ${name} (${version})`);\r\n }\r\n } else {\r\n versionToLoad = version;\r\n }\r\n\r\n // check if there is a feature conflict\r\n const conflictingFeature = WebXRFeaturesManager._ConflictingFeatures[name];\r\n if (conflictingFeature !== undefined && this.getEnabledFeatures().indexOf(conflictingFeature) !== -1) {\r\n throw new Error(`Feature ${name} cannot be enabled while ${conflictingFeature} is enabled.`);\r\n }\r\n\r\n // check if already initialized\r\n const feature = this._features[name];\r\n const constructFunction = WebXRFeaturesManager.ConstructFeature(name, versionToLoad, this._xrSessionManager, moduleOptions);\r\n if (!constructFunction) {\r\n // report error?\r\n throw new Error(`feature not found - ${name}`);\r\n }\r\n\r\n /* If the feature is already enabled, detach and dispose it, and create a new one */\r\n if (feature) {\r\n this.disableFeature(name);\r\n }\r\n\r\n const constructed = constructFunction();\r\n if (constructed.dependsOn) {\r\n const dependentsFound = constructed.dependsOn.every((featureName) => !!this._features[featureName]);\r\n if (!dependentsFound) {\r\n throw new Error(`Dependant features missing. Make sure the following features are enabled - ${constructed.dependsOn.join(\", \")}`);\r\n }\r\n }\r\n if (constructed.isCompatible()) {\r\n this._features[name] = {\r\n featureImplementation: constructed,\r\n enabled: true,\r\n version: versionToLoad,\r\n required,\r\n };\r\n\r\n if (attachIfPossible) {\r\n // if session started already, request and enable\r\n if (this._xrSessionManager.session && !this._features[name].featureImplementation.attached) {\r\n // enable feature\r\n this.attachFeature(name);\r\n }\r\n } else {\r\n // disable auto-attach when session starts\r\n this._features[name].featureImplementation.disableAutoAttach = true;\r\n }\r\n\r\n return this._features[name].featureImplementation;\r\n } else {\r\n if (required) {\r\n throw new Error(\"required feature not compatible\");\r\n } else {\r\n Tools.Warn(`Feature ${name} not compatible with the current environment/browser and was not enabled.`);\r\n return constructed;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * get the implementation of an enabled feature.\r\n * @param featureName the name of the feature to load\r\n * @returns the feature class, if found\r\n */\r\n public getEnabledFeature(featureName: string): IWebXRFeature {\r\n return this._features[featureName] && this._features[featureName].featureImplementation;\r\n }\r\n\r\n /**\r\n * Get the list of enabled features\r\n * @returns an array of enabled features\r\n */\r\n public getEnabledFeatures() {\r\n return Object.keys(this._features);\r\n }\r\n\r\n /**\r\n * This function will extend the session creation configuration object with enabled features.\r\n * If, for example, the anchors feature is enabled, it will be automatically added to the optional or required features list,\r\n * according to the defined \"required\" variable, provided during enableFeature call\r\n * @param xrSessionInit the xr Session init object to extend\r\n *\r\n * @returns an extended XRSessionInit object\r\n */\r\n public async _extendXRSessionInitObject(xrSessionInit: XRSessionInit): Promise<XRSessionInit> {\r\n const enabledFeatures = this.getEnabledFeatures();\r\n for (const featureName of enabledFeatures) {\r\n const feature = this._features[featureName];\r\n const nativeName = feature.featureImplementation.xrNativeFeatureName;\r\n if (nativeName) {\r\n if (feature.required) {\r\n xrSessionInit.requiredFeatures = xrSessionInit.requiredFeatures || [];\r\n if (xrSessionInit.requiredFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.requiredFeatures.push(nativeName);\r\n }\r\n } else {\r\n xrSessionInit.optionalFeatures = xrSessionInit.optionalFeatures || [];\r\n if (xrSessionInit.optionalFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.optionalFeatures.push(nativeName);\r\n }\r\n }\r\n }\r\n if (feature.featureImplementation.getXRSessionInitExtension) {\r\n const extended = await feature.featureImplementation.getXRSessionInitExtension();\r\n xrSessionInit = {\r\n ...xrSessionInit,\r\n ...extended,\r\n };\r\n }\r\n }\r\n return xrSessionInit;\r\n }\r\n}\r\n"]}
@@ -171,6 +171,10 @@ export declare class WebXRSessionManager implements IDisposable, IWebXRRenderTar
171
171
  * @internal
172
172
  */
173
173
  _setBaseLayerWrapper(baseLayerWrapper: Nullable<WebXRLayerWrapper>): void;
174
+ /**
175
+ * @internal
176
+ */
177
+ _getBaseLayerWrapper(): Nullable<WebXRLayerWrapper>;
174
178
  /**
175
179
  * Updates the render state of the session
176
180
  * @param state state to set
@@ -307,6 +307,12 @@ export class WebXRSessionManager {
307
307
  this._baseLayerWrapper = baseLayerWrapper;
308
308
  this._baseLayerRTTProvider = ((_b = this._baseLayerWrapper) === null || _b === void 0 ? void 0 : _b.createRenderTargetTextureProvider(this)) || null;
309
309
  }
310
+ /**
311
+ * @internal
312
+ */
313
+ _getBaseLayerWrapper() {
314
+ return this._baseLayerWrapper;
315
+ }
310
316
  /**
311
317
  * Updates the render state of the session
312
318
  * @param state state to set