@babylonjs/core 6.43.0 → 6.45.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.
- package/Animations/animatable.js +2 -2
- package/Animations/animatable.js.map +1 -1
- package/Animations/animationGroup.d.ts +4 -2
- package/Animations/animationGroup.js +22 -2
- package/Animations/animationGroup.js.map +1 -1
- package/Buffers/buffer.d.ts +22 -22
- package/Buffers/buffer.js +16 -15
- package/Buffers/buffer.js.map +1 -1
- package/Cameras/camera.d.ts +5 -5
- package/Cameras/camera.js +19 -19
- package/Cameras/camera.js.map +1 -1
- package/Culling/ray.d.ts +12 -1
- package/Culling/ray.js +20 -3
- package/Culling/ray.js.map +1 -1
- package/Debug/skeletonViewer.d.ts +2 -0
- package/Debug/skeletonViewer.js +111 -50
- package/Debug/skeletonViewer.js.map +1 -1
- package/Engines/ICanvas.d.ts +2 -1
- package/Engines/ICanvas.js.map +1 -1
- package/Engines/constants.d.ts +96 -0
- package/Engines/constants.js +96 -0
- package/Engines/constants.js.map +1 -1
- package/Engines/engine.d.ts +14 -3
- package/Engines/engine.js +11 -0
- package/Engines/engine.js.map +1 -1
- package/Engines/nullEngine.d.ts +2 -0
- package/Engines/nullEngine.js +3 -0
- package/Engines/nullEngine.js.map +1 -1
- package/Engines/thinEngine.d.ts +4 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Gizmos/gizmo.d.ts +14 -0
- package/Gizmos/gizmo.js +16 -0
- package/Gizmos/gizmo.js.map +1 -1
- package/Gizmos/gizmoManager.d.ts +12 -0
- package/Gizmos/gizmoManager.js +26 -0
- package/Gizmos/gizmoManager.js.map +1 -1
- package/Gizmos/positionGizmo.d.ts +16 -2
- package/Gizmos/positionGizmo.js +12 -2
- package/Gizmos/positionGizmo.js.map +1 -1
- package/Gizmos/rotationGizmo.d.ts +8 -0
- package/Gizmos/rotationGizmo.js +9 -0
- package/Gizmos/rotationGizmo.js.map +1 -1
- package/Gizmos/scaleGizmo.d.ts +15 -1
- package/Gizmos/scaleGizmo.js +11 -1
- package/Gizmos/scaleGizmo.js.map +1 -1
- package/Inputs/scene.inputManager.js +2 -2
- package/Inputs/scene.inputManager.js.map +1 -1
- package/Layers/effectLayer.js +4 -4
- package/Layers/effectLayer.js.map +1 -1
- package/Lights/Shadows/shadowGenerator.js +5 -5
- package/Lights/Shadows/shadowGenerator.js.map +1 -1
- package/Materials/Background/backgroundMaterial.js +16 -16
- package/Materials/Background/backgroundMaterial.js.map +1 -1
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js +8 -8
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js.map +1 -1
- package/Materials/Node/Blocks/Dual/fogBlock.js +2 -2
- package/Materials/Node/Blocks/Dual/fogBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/lightBlock.js +6 -6
- package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +2 -2
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +7 -7
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
- package/Materials/Node/Blocks/Vertex/bonesBlock.js +3 -3
- package/Materials/Node/Blocks/Vertex/bonesBlock.js.map +1 -1
- package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js +3 -3
- package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +50 -0
- package/Materials/Node/nodeMaterial.js +53 -3
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/PBR/pbrAnisotropicConfiguration.js +3 -3
- package/Materials/PBR/pbrAnisotropicConfiguration.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.js +41 -41
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/PBR/pbrClearCoatConfiguration.js +10 -10
- package/Materials/PBR/pbrClearCoatConfiguration.js.map +1 -1
- package/Materials/PBR/pbrIridescenceConfiguration.js +6 -6
- package/Materials/PBR/pbrIridescenceConfiguration.js.map +1 -1
- package/Materials/PBR/pbrSheenConfiguration.js +6 -6
- package/Materials/PBR/pbrSheenConfiguration.js.map +1 -1
- package/Materials/PBR/pbrSubSurfaceConfiguration.js +7 -7
- package/Materials/PBR/pbrSubSurfaceConfiguration.js.map +1 -1
- package/Materials/Textures/Loaders/ktxTextureLoader.js +1 -1
- package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
- package/Materials/Textures/dynamicTexture.js +1 -1
- package/Materials/Textures/dynamicTexture.js.map +1 -1
- package/Materials/Textures/texture.js +1 -1
- package/Materials/Textures/texture.js.map +1 -1
- package/Materials/index.d.ts +1 -0
- package/Materials/index.js +1 -0
- package/Materials/index.js.map +1 -1
- package/Materials/material.decalMapConfiguration.js +3 -3
- package/Materials/material.decalMapConfiguration.js.map +1 -1
- package/Materials/material.detailMapConfiguration.js +3 -3
- package/Materials/material.detailMapConfiguration.js.map +1 -1
- package/Materials/material.js +2 -2
- package/Materials/material.js.map +1 -1
- package/Materials/materialHelper.d.ts +1 -4
- package/Materials/materialHelper.functions.d.ts +275 -0
- package/Materials/materialHelper.functions.js +823 -0
- package/Materials/materialHelper.functions.js.map +1 -0
- package/Materials/materialHelper.js +64 -589
- package/Materials/materialHelper.js.map +1 -1
- package/Materials/materialPluginBase.d.ts +1 -1
- package/Materials/materialPluginBase.js +1 -1
- package/Materials/materialPluginBase.js.map +1 -1
- package/Materials/shaderMaterial.js +8 -8
- package/Materials/shaderMaterial.js.map +1 -1
- package/Materials/standardMaterial.js +33 -33
- package/Materials/standardMaterial.js.map +1 -1
- package/Meshes/Compression/dracoCompression.d.ts +23 -2
- package/Meshes/Compression/dracoCompression.js +76 -236
- package/Meshes/Compression/dracoCompression.js.map +1 -1
- package/Meshes/Compression/dracoCompressionWorker.d.ts +44 -0
- package/Meshes/Compression/dracoCompressionWorker.js +189 -0
- package/Meshes/Compression/dracoCompressionWorker.js.map +1 -0
- package/Meshes/GreasedLine/greasedLineBaseMesh.d.ts +3 -1
- package/Meshes/GreasedLine/greasedLineBaseMesh.js +4 -2
- package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
- package/Meshes/Node/Blocks/geometryDistanceBlock.d.ts +30 -0
- package/Meshes/Node/Blocks/geometryDistanceBlock.js +63 -0
- package/Meshes/Node/Blocks/geometryDistanceBlock.js.map +1 -0
- package/Meshes/Node/Blocks/geometryDotBlock.d.ts +30 -0
- package/Meshes/Node/Blocks/geometryDotBlock.js +63 -0
- package/Meshes/Node/Blocks/geometryDotBlock.js.map +1 -0
- package/Meshes/Node/Blocks/geometryLengthBlock.d.ts +26 -0
- package/Meshes/Node/Blocks/geometryLengthBlock.js +52 -0
- package/Meshes/Node/Blocks/geometryLengthBlock.js.map +1 -0
- package/Meshes/Node/Blocks/geometryPosterizeBlock.d.ts +31 -0
- package/Meshes/Node/Blocks/geometryPosterizeBlock.js +63 -0
- package/Meshes/Node/Blocks/geometryPosterizeBlock.js.map +1 -0
- package/Meshes/Node/Blocks/geometryReplaceColorBlock.d.ts +38 -0
- package/Meshes/Node/Blocks/geometryReplaceColorBlock.js +88 -0
- package/Meshes/Node/Blocks/geometryReplaceColorBlock.js.map +1 -0
- package/Meshes/Node/Blocks/geometryRotate2dBlock.d.ts +30 -0
- package/Meshes/Node/Blocks/geometryRotate2dBlock.js +59 -0
- package/Meshes/Node/Blocks/geometryRotate2dBlock.js.map +1 -0
- package/Meshes/Node/index.d.ts +6 -0
- package/Meshes/Node/index.js +6 -0
- package/Meshes/Node/index.js.map +1 -1
- package/Meshes/trailMesh.js +1 -1
- package/Meshes/trailMesh.js.map +1 -1
- package/Misc/basis.d.ts +6 -1
- package/Misc/basis.js +11 -231
- package/Misc/basis.js.map +1 -1
- package/Misc/basisWorker.d.ts +13 -0
- package/Misc/basisWorker.js +249 -0
- package/Misc/basisWorker.js.map +1 -0
- package/Misc/khronosTextureContainer2.d.ts +25 -3
- package/Misc/khronosTextureContainer2.js +35 -106
- package/Misc/khronosTextureContainer2.js.map +1 -1
- package/Misc/khronosTextureContainer2Worker.d.ts +12 -0
- package/Misc/khronosTextureContainer2Worker.js +136 -0
- package/Misc/khronosTextureContainer2Worker.js.map +1 -0
- package/Navigation/Plugins/recastJSPlugin.d.ts +1 -1
- package/Navigation/Plugins/recastJSPlugin.js.map +1 -1
- package/Particles/gpuParticleSystem.js +3 -3
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/particleSystem.js +7 -3
- package/Particles/particleSystem.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +8 -0
- package/Physics/v2/IPhysicsEnginePlugin.js +9 -0
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.d.ts +7 -1
- package/Physics/v2/Plugins/havokPlugin.js +19 -1
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.js +2 -2
- package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
- package/Rendering/depthRenderer.js +4 -4
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js +5 -5
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Rendering/outlineRenderer.js +4 -4
- package/Rendering/outlineRenderer.js.map +1 -1
- package/XR/features/Layers/WebXRCompositionLayer.d.ts +48 -0
- package/XR/features/Layers/WebXRCompositionLayer.js +94 -0
- package/XR/features/Layers/WebXRCompositionLayer.js.map +1 -0
- package/XR/features/Layers/WebXRProjectionLayer.d.ts +10 -0
- package/XR/features/Layers/WebXRProjectionLayer.js +51 -0
- package/XR/features/Layers/WebXRProjectionLayer.js.map +1 -0
- package/XR/features/WebXRControllerPointerSelection.js +4 -1
- package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
- package/XR/features/WebXRControllerTeleportation.js +11 -10
- package/XR/features/WebXRControllerTeleportation.js.map +1 -1
- package/XR/features/WebXRHandTracking.d.ts +7 -1
- package/XR/features/WebXRHandTracking.js +28 -26
- package/XR/features/WebXRHandTracking.js.map +1 -1
- package/XR/features/WebXRLayers.d.ts +44 -26
- package/XR/features/WebXRLayers.js +204 -153
- package/XR/features/WebXRLayers.js.map +1 -1
- package/XR/features/WebXRNearInteraction.js +16 -1
- package/XR/features/WebXRNearInteraction.js.map +1 -1
- package/XR/webXRCamera.js +10 -0
- package/XR/webXRCamera.js.map +1 -1
- package/XR/webXRDefaultExperience.d.ts +9 -0
- package/XR/webXRDefaultExperience.js +8 -0
- package/XR/webXRDefaultExperience.js.map +1 -1
- package/XR/webXRExperienceHelper.js +1 -1
- package/XR/webXRExperienceHelper.js.map +1 -1
- package/XR/webXRFeaturesManager.js +8 -2
- package/XR/webXRFeaturesManager.js.map +1 -1
- package/XR/webXRLayerWrapper.d.ts +12 -3
- package/XR/webXRLayerWrapper.js +18 -2
- package/XR/webXRLayerWrapper.js.map +1 -1
- package/XR/webXRRenderTargetTextureProvider.js +0 -5
- package/XR/webXRRenderTargetTextureProvider.js.map +1 -1
- package/XR/webXRSessionManager.d.ts +9 -1
- package/XR/webXRSessionManager.js +24 -5
- package/XR/webXRSessionManager.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +13 -5
- package/scene.js +4 -4
- package/scene.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRDefaultExperience.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRDefaultExperience.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,+BAA+B,EAAE,MAAM,4CAA4C,CAAC;AAE7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EAAE,gBAAgB,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C;SACjC;QACD,IAAI,IAAI,CAAC,KAAK,EAAE;YACZ,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;SACxB;QACD,IAAI,IAAI,CAAC,WAAW,EAAE;YAClB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;SAC9B;QACD,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;SAC/B;IACL,CAAC;CACJ","sourcesContent":["import { WebXRExperienceHelper } from \"./webXRExperienceHelper\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { IWebXRInputOptions } from \"./webXRInput\";\r\nimport { WebXRInput } from \"./webXRInput\";\r\nimport type { IWebXRControllerPointerSelectionOptions } from \"./features/WebXRControllerPointerSelection\";\r\nimport { WebXRControllerPointerSelection } from \"./features/WebXRControllerPointerSelection\";\r\nimport type { IWebXRNearInteractionOptions } from \"./features/WebXRNearInteraction\";\r\nimport { WebXRNearInteraction } from \"./features/WebXRNearInteraction\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport type { WebXREnterExitUIOptions } from \"./webXREnterExitUI\";\r\nimport { WebXREnterExitUI } from \"./webXREnterExitUI\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { WebXRManagedOutputCanvasOptions } from \"./webXRManagedOutputCanvas\";\r\nimport type { IWebXRTeleportationOptions } from \"./features/WebXRControllerTeleportation\";\r\nimport { WebXRMotionControllerTeleportation } from \"./features/WebXRControllerTeleportation\";\r\nimport { Logger } from \"../Misc/logger\";\r\n\r\n/**\r\n * Options for the default xr helper\r\n */\r\nexport class WebXRDefaultExperienceOptions {\r\n /**\r\n * Enable or disable default UI to enter XR\r\n */\r\n public disableDefaultUI?: boolean;\r\n /**\r\n * Should pointer selection not initialize.\r\n * Note that disabling pointer selection also disables teleportation.\r\n * Defaults to false.\r\n */\r\n public disablePointerSelection?: boolean;\r\n /**\r\n * Should teleportation not initialize. Defaults to false.\r\n */\r\n public disableTeleportation?: boolean;\r\n /**\r\n * Should nearInteraction not initialize. Defaults to false.\r\n */\r\n public disableNearInteraction?: boolean;\r\n /**\r\n * Floor meshes that will be used for teleport\r\n */\r\n public floorMeshes?: Array<AbstractMesh>;\r\n /**\r\n * If set to true, the first frame will not be used to reset position\r\n * The first frame is mainly used when copying transformation from the old camera\r\n * Mainly used in AR\r\n */\r\n public ignoreNativeCameraTransformation?: boolean;\r\n /**\r\n * Optional configuration for the XR input object\r\n */\r\n public inputOptions?: Partial<IWebXRInputOptions>;\r\n /**\r\n * optional configuration for pointer selection\r\n */\r\n public pointerSelectionOptions?: Partial<IWebXRControllerPointerSelectionOptions>;\r\n /**\r\n * optional configuration for near interaction\r\n */\r\n public nearInteractionOptions?: Partial<IWebXRNearInteractionOptions>;\r\n /**\r\n * optional configuration for teleportation\r\n */\r\n public teleportationOptions?: Partial<IWebXRTeleportationOptions>;\r\n /**\r\n * optional configuration for the output canvas\r\n */\r\n public outputCanvasOptions?: WebXRManagedOutputCanvasOptions;\r\n /**\r\n * optional UI options. This can be used among other to change session mode and reference space type\r\n */\r\n public uiOptions?: Partial<WebXREnterExitUIOptions>;\r\n /**\r\n * When loading teleportation and pointer select, use stable versions instead of latest.\r\n */\r\n public useStablePlugins?: boolean;\r\n\r\n /**\r\n * An optional rendering group id that will be set globally for teleportation, pointer selection and default controller meshes\r\n */\r\n public renderingGroupId?: number;\r\n\r\n /**\r\n * A list of optional features to init the session with\r\n * If set to true, all features we support will be added\r\n */\r\n public optionalFeatures?: boolean | string[];\r\n}\r\n\r\n/**\r\n * Default experience for webxr\r\n */\r\nexport class WebXRDefaultExperience {\r\n /**\r\n * Base experience\r\n */\r\n public baseExperience: WebXRExperienceHelper;\r\n /**\r\n * Enables ui for entering/exiting xr\r\n */\r\n public enterExitUI: WebXREnterExitUI;\r\n /**\r\n * Input experience extension\r\n */\r\n public input: WebXRInput;\r\n /**\r\n * Enables laser pointer and selection\r\n */\r\n public pointerSelection: WebXRControllerPointerSelection;\r\n /**\r\n * Default target xr should render to\r\n */\r\n public renderTarget: WebXRRenderTarget;\r\n /**\r\n * Enables teleportation\r\n */\r\n public teleportation: WebXRMotionControllerTeleportation;\r\n\r\n /**\r\n * Enables near interaction for hands/controllers\r\n */\r\n public nearInteraction: WebXRNearInteraction;\r\n\r\n private constructor() {}\r\n\r\n /**\r\n * Creates the default xr experience\r\n * @param scene scene\r\n * @param options options for basic configuration\r\n * @returns resulting WebXRDefaultExperience\r\n */\r\n public static CreateAsync(scene: Scene, options: WebXRDefaultExperienceOptions = {}) {\r\n const result = new WebXRDefaultExperience();\r\n scene.onDisposeObservable.addOnce(() => {\r\n result.dispose();\r\n });\r\n // init the UI right after construction\r\n if (!options.disableDefaultUI) {\r\n const uiOptions: WebXREnterExitUIOptions = {\r\n renderTarget: result.renderTarget,\r\n ...(options.uiOptions || {}),\r\n };\r\n if (options.optionalFeatures) {\r\n if (typeof options.optionalFeatures === \"boolean\") {\r\n uiOptions.optionalFeatures = [\"hit-test\", \"anchors\", \"plane-detection\", \"hand-tracking\"];\r\n } else {\r\n uiOptions.optionalFeatures = options.optionalFeatures;\r\n }\r\n }\r\n result.enterExitUI = new WebXREnterExitUI(scene, uiOptions);\r\n }\r\n\r\n // Create base experience\r\n return WebXRExperienceHelper.CreateAsync(scene)\r\n .then((xrHelper) => {\r\n result.baseExperience = xrHelper;\r\n\r\n if (options.ignoreNativeCameraTransformation) {\r\n result.baseExperience.camera.compensateOnFirstFrame = false;\r\n }\r\n\r\n // Add controller support\r\n result.input = new WebXRInput(xrHelper.sessionManager, xrHelper.camera, {\r\n controllerOptions: {\r\n renderingGroupId: options.renderingGroupId,\r\n },\r\n ...(options.inputOptions || {}),\r\n });\r\n\r\n if (!options.disablePointerSelection) {\r\n // Add default pointer selection\r\n const pointerSelectionOptions = {\r\n ...options.pointerSelectionOptions,\r\n xrInput: result.input,\r\n renderingGroupId: options.renderingGroupId,\r\n };\r\n\r\n result.pointerSelection = <WebXRControllerPointerSelection>(\r\n result.baseExperience.featuresManager.enableFeature(\r\n WebXRControllerPointerSelection.Name,\r\n options.useStablePlugins ? \"stable\" : \"latest\",\r\n <IWebXRControllerPointerSelectionOptions>pointerSelectionOptions\r\n )\r\n );\r\n\r\n if (!options.disableTeleportation) {\r\n // Add default teleportation, including rotation\r\n result.teleportation = <WebXRMotionControllerTeleportation>result.baseExperience.featuresManager.enableFeature(\r\n WebXRMotionControllerTeleportation.Name,\r\n options.useStablePlugins ? \"stable\" : \"latest\",\r\n <IWebXRTeleportationOptions>{\r\n floorMeshes: options.floorMeshes,\r\n xrInput: result.input,\r\n renderingGroupId: options.renderingGroupId,\r\n ...options.teleportationOptions,\r\n }\r\n );\r\n result.teleportation.setSelectionFeature(result.pointerSelection);\r\n }\r\n }\r\n\r\n if (!options.disableNearInteraction) {\r\n // Add default pointer selection\r\n result.nearInteraction = <WebXRNearInteraction>result.baseExperience.featuresManager.enableFeature(\r\n WebXRNearInteraction.Name,\r\n options.useStablePlugins ? \"stable\" : \"latest\",\r\n <IWebXRNearInteractionOptions>{\r\n xrInput: result.input,\r\n farInteractionFeature: result.pointerSelection,\r\n renderingGroupId: options.renderingGroupId,\r\n useUtilityLayer: true,\r\n enableNearInteractionOnAllControllers: true,\r\n ...options.nearInteractionOptions,\r\n }\r\n );\r\n }\r\n\r\n // Create the WebXR output target\r\n result.renderTarget = result.baseExperience.sessionManager.getWebXRRenderTarget(options.outputCanvasOptions);\r\n\r\n if (!options.disableDefaultUI) {\r\n // Create ui for entering/exiting xr\r\n return result.enterExitUI.setHelperAsync(result.baseExperience, result.renderTarget);\r\n } else {\r\n return;\r\n }\r\n })\r\n .then(() => {\r\n return result;\r\n })\r\n .catch((error) => {\r\n Logger.Error(\"Error initializing XR\");\r\n Logger.Error(error);\r\n return result;\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the experience helper\r\n */\r\n public dispose() {\r\n if (this.baseExperience) {\r\n this.baseExperience.dispose();\r\n }\r\n if (this.input) {\r\n this.input.dispose();\r\n }\r\n if (this.enterExitUI) {\r\n this.enterExitUI.dispose();\r\n }\r\n if (this.renderTarget) {\r\n this.renderTarget.dispose();\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"webXRDefaultExperience.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRDefaultExperience.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,+BAA+B,EAAE,MAAM,4CAA4C,CAAC;AAE7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD,OAAO,EAAE,iBAAiB,EAAkC,MAAM,8BAA8B,CAAC;AACjG,OAAO,EAAE,kCAAkC,EAAE,MAAM,yCAAyC,CAAC;AAC7F,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC;;GAEG;AACH,MAAM,OAAO,6BAA6B;CA8EzC;AAED;;GAEG;AACH,MAAM,OAAO,sBAAsB;IA+B/B,gBAAuB,CAAC;IAExB;;;;;OAKG;IACI,MAAM,CAAC,WAAW,CAAC,KAAY,EAAE,UAAyC,EAAE;QAC/E,MAAM,MAAM,GAAG,IAAI,sBAAsB,EAAE,CAAC;QAC5C,KAAK,CAAC,mBAAmB,CAAC,OAAO,CAAC,GAAG,EAAE;YACnC,MAAM,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,uCAAuC;QACvC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE;YAC3B,MAAM,SAAS,GAA4B;gBACvC,YAAY,EAAE,MAAM,CAAC,YAAY;gBACjC,GAAG,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;aAC/B,CAAC;YACF,IAAI,OAAO,CAAC,gBAAgB,EAAE;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AAQ,CAAC,CAAC,CAAC,QAAQ,EACnB;oBACvB,OAAO,EAAE,MAAM,CAAC,KAAK;oBACrB,GAAG,OAAO,CAAC,kBAAkB;iBAChC,EACD,SAAS,EACT,KAAK,CACR,CAAC;aACL;YAED,iCAAiC;YACjC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,cAAc,CAAC,oBAAoB,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;YAE7G,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE;gBAC3B,oCAAoC;gBACpC,OAAO,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;aACxF;iBAAM;gBACH,OAAO;aACV;QACL,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,EAAE;YACP,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACb,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACtC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC,CAAC;IACX,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,cAAc,EAAE;YACrB,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;SACjC;QACD,IAAI,IAAI,CAAC,KAAK,EAAE;YACZ,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;SACxB;QACD,IAAI,IAAI,CAAC,WAAW,EAAE;YAClB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;SAC9B;QACD,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;SAC/B;IACL,CAAC;CACJ","sourcesContent":["import { WebXRExperienceHelper } from \"./webXRExperienceHelper\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { IWebXRInputOptions } from \"./webXRInput\";\r\nimport { WebXRInput } from \"./webXRInput\";\r\nimport type { IWebXRControllerPointerSelectionOptions } from \"./features/WebXRControllerPointerSelection\";\r\nimport { WebXRControllerPointerSelection } from \"./features/WebXRControllerPointerSelection\";\r\nimport type { IWebXRNearInteractionOptions } from \"./features/WebXRNearInteraction\";\r\nimport { WebXRNearInteraction } from \"./features/WebXRNearInteraction\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport type { WebXREnterExitUIOptions } from \"./webXREnterExitUI\";\r\nimport { WebXREnterExitUI } from \"./webXREnterExitUI\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { WebXRManagedOutputCanvasOptions } from \"./webXRManagedOutputCanvas\";\r\nimport type { IWebXRTeleportationOptions } from \"./features/WebXRControllerTeleportation\";\r\nimport { WebXRHandTracking, type IWebXRHandTrackingOptions } from \"./features/WebXRHandTracking\";\r\nimport { WebXRMotionControllerTeleportation } from \"./features/WebXRControllerTeleportation\";\r\nimport { Logger } from \"../Misc/logger\";\r\n\r\n/**\r\n * Options for the default xr helper\r\n */\r\nexport class WebXRDefaultExperienceOptions {\r\n /**\r\n * Enable or disable default UI to enter XR\r\n */\r\n public disableDefaultUI?: boolean;\r\n /**\r\n * Should pointer selection not initialize.\r\n * Note that disabling pointer selection also disables teleportation.\r\n * Defaults to false.\r\n */\r\n public disablePointerSelection?: boolean;\r\n /**\r\n * Should teleportation not initialize. Defaults to false.\r\n */\r\n public disableTeleportation?: boolean;\r\n /**\r\n * Should nearInteraction not initialize. Defaults to false.\r\n */\r\n public disableNearInteraction?: boolean;\r\n\r\n /**\r\n * Should hand tracking be disabled. Defaults to false.\r\n */\r\n public disableHandTracking?: boolean;\r\n /**\r\n * Floor meshes that will be used for teleport\r\n */\r\n public floorMeshes?: Array<AbstractMesh>;\r\n /**\r\n * If set to true, the first frame will not be used to reset position\r\n * The first frame is mainly used when copying transformation from the old camera\r\n * Mainly used in AR\r\n */\r\n public ignoreNativeCameraTransformation?: boolean;\r\n /**\r\n * Optional configuration for the XR input object\r\n */\r\n public inputOptions?: Partial<IWebXRInputOptions>;\r\n /**\r\n * optional configuration for pointer selection\r\n */\r\n public pointerSelectionOptions?: Partial<IWebXRControllerPointerSelectionOptions>;\r\n /**\r\n * optional configuration for near interaction\r\n */\r\n public nearInteractionOptions?: Partial<IWebXRNearInteractionOptions>;\r\n\r\n /**\r\n * optional configuration for hand tracking\r\n */\r\n public handSupportOptions?: Partial<IWebXRHandTrackingOptions>;\r\n /**\r\n * optional configuration for teleportation\r\n */\r\n public teleportationOptions?: Partial<IWebXRTeleportationOptions>;\r\n /**\r\n * optional configuration for the output canvas\r\n */\r\n public outputCanvasOptions?: WebXRManagedOutputCanvasOptions;\r\n /**\r\n * optional UI options. This can be used among other to change session mode and reference space type\r\n */\r\n public uiOptions?: Partial<WebXREnterExitUIOptions>;\r\n /**\r\n * When loading teleportation and pointer select, use stable versions instead of latest.\r\n */\r\n public useStablePlugins?: boolean;\r\n\r\n /**\r\n * An optional rendering group id that will be set globally for teleportation, pointer selection and default controller meshes\r\n */\r\n public renderingGroupId?: number;\r\n\r\n /**\r\n * A list of optional features to init the session with\r\n * If set to true, all features we support will be added\r\n */\r\n public optionalFeatures?: boolean | string[];\r\n}\r\n\r\n/**\r\n * Default experience for webxr\r\n */\r\nexport class WebXRDefaultExperience {\r\n /**\r\n * Base experience\r\n */\r\n public baseExperience: WebXRExperienceHelper;\r\n /**\r\n * Enables ui for entering/exiting xr\r\n */\r\n public enterExitUI: WebXREnterExitUI;\r\n /**\r\n * Input experience extension\r\n */\r\n public input: WebXRInput;\r\n /**\r\n * Enables laser pointer and selection\r\n */\r\n public pointerSelection: WebXRControllerPointerSelection;\r\n /**\r\n * Default target xr should render to\r\n */\r\n public renderTarget: WebXRRenderTarget;\r\n /**\r\n * Enables teleportation\r\n */\r\n public teleportation: WebXRMotionControllerTeleportation;\r\n\r\n /**\r\n * Enables near interaction for hands/controllers\r\n */\r\n public nearInteraction: WebXRNearInteraction;\r\n\r\n private constructor() {}\r\n\r\n /**\r\n * Creates the default xr experience\r\n * @param scene scene\r\n * @param options options for basic configuration\r\n * @returns resulting WebXRDefaultExperience\r\n */\r\n public static CreateAsync(scene: Scene, options: WebXRDefaultExperienceOptions = {}) {\r\n const result = new WebXRDefaultExperience();\r\n scene.onDisposeObservable.addOnce(() => {\r\n result.dispose();\r\n });\r\n // init the UI right after construction\r\n if (!options.disableDefaultUI) {\r\n const uiOptions: WebXREnterExitUIOptions = {\r\n renderTarget: result.renderTarget,\r\n ...(options.uiOptions || {}),\r\n };\r\n if (options.optionalFeatures) {\r\n if (typeof options.optionalFeatures === \"boolean\") {\r\n uiOptions.optionalFeatures = [\"hit-test\", \"anchors\", \"plane-detection\", \"hand-tracking\"];\r\n } else {\r\n uiOptions.optionalFeatures = options.optionalFeatures;\r\n }\r\n }\r\n result.enterExitUI = new WebXREnterExitUI(scene, uiOptions);\r\n }\r\n\r\n // Create base experience\r\n return WebXRExperienceHelper.CreateAsync(scene)\r\n .then((xrHelper) => {\r\n result.baseExperience = xrHelper;\r\n\r\n if (options.ignoreNativeCameraTransformation) {\r\n result.baseExperience.camera.compensateOnFirstFrame = false;\r\n }\r\n\r\n // Add controller support\r\n result.input = new WebXRInput(xrHelper.sessionManager, xrHelper.camera, {\r\n controllerOptions: {\r\n renderingGroupId: options.renderingGroupId,\r\n },\r\n ...(options.inputOptions || {}),\r\n });\r\n\r\n if (!options.disablePointerSelection) {\r\n // Add default pointer selection\r\n const pointerSelectionOptions = {\r\n ...options.pointerSelectionOptions,\r\n xrInput: result.input,\r\n renderingGroupId: options.renderingGroupId,\r\n };\r\n\r\n result.pointerSelection = <WebXRControllerPointerSelection>(\r\n result.baseExperience.featuresManager.enableFeature(\r\n WebXRControllerPointerSelection.Name,\r\n options.useStablePlugins ? \"stable\" : \"latest\",\r\n <IWebXRControllerPointerSelectionOptions>pointerSelectionOptions\r\n )\r\n );\r\n\r\n if (!options.disableTeleportation) {\r\n // Add default teleportation, including rotation\r\n result.teleportation = <WebXRMotionControllerTeleportation>result.baseExperience.featuresManager.enableFeature(\r\n WebXRMotionControllerTeleportation.Name,\r\n options.useStablePlugins ? \"stable\" : \"latest\",\r\n <IWebXRTeleportationOptions>{\r\n floorMeshes: options.floorMeshes,\r\n xrInput: result.input,\r\n renderingGroupId: options.renderingGroupId,\r\n ...options.teleportationOptions,\r\n }\r\n );\r\n result.teleportation.setSelectionFeature(result.pointerSelection);\r\n }\r\n }\r\n\r\n if (!options.disableNearInteraction) {\r\n // Add default pointer selection\r\n result.nearInteraction = <WebXRNearInteraction>result.baseExperience.featuresManager.enableFeature(\r\n WebXRNearInteraction.Name,\r\n options.useStablePlugins ? \"stable\" : \"latest\",\r\n <IWebXRNearInteractionOptions>{\r\n xrInput: result.input,\r\n farInteractionFeature: result.pointerSelection,\r\n renderingGroupId: options.renderingGroupId,\r\n useUtilityLayer: true,\r\n enableNearInteractionOnAllControllers: true,\r\n ...options.nearInteractionOptions,\r\n }\r\n );\r\n }\r\n\r\n if (!options.disableHandTracking) {\r\n // Add default hand tracking\r\n result.baseExperience.featuresManager.enableFeature(\r\n WebXRHandTracking.Name,\r\n options.useStablePlugins ? \"stable\" : \"latest\",\r\n <IWebXRHandTrackingOptions>{\r\n xrInput: result.input,\r\n ...options.handSupportOptions,\r\n },\r\n undefined,\r\n false\r\n );\r\n }\r\n\r\n // Create the WebXR output target\r\n result.renderTarget = result.baseExperience.sessionManager.getWebXRRenderTarget(options.outputCanvasOptions);\r\n\r\n if (!options.disableDefaultUI) {\r\n // Create ui for entering/exiting xr\r\n return result.enterExitUI.setHelperAsync(result.baseExperience, result.renderTarget);\r\n } else {\r\n return;\r\n }\r\n })\r\n .then(() => {\r\n return result;\r\n })\r\n .catch((error) => {\r\n Logger.Error(\"Error initializing XR\");\r\n Logger.Error(error);\r\n return result;\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the experience helper\r\n */\r\n public dispose() {\r\n if (this.baseExperience) {\r\n this.baseExperience.dispose();\r\n }\r\n if (this.input) {\r\n this.input.dispose();\r\n }\r\n if (this.enterExitUI) {\r\n this.enterExitUI.dispose();\r\n }\r\n if (this.renderTarget) {\r\n this.renderTarget.dispose();\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -107,7 +107,6 @@ export class WebXRExperienceHelper {
|
|
|
107
107
|
try {
|
|
108
108
|
await this.sessionManager.initializeSessionAsync(sessionMode, sessionCreationOptions);
|
|
109
109
|
await this.sessionManager.setReferenceSpaceTypeAsync(referenceSpaceType);
|
|
110
|
-
const baseLayer = await renderTarget.initializeXRLayerAsync(this.sessionManager.session);
|
|
111
110
|
const xrRenderState = {
|
|
112
111
|
// if maxZ is 0 it should be "Infinity", but it doesn't work with the WebXR API. Setting to a large number.
|
|
113
112
|
depthFar: this.camera.maxZ || 10000,
|
|
@@ -115,6 +114,7 @@ export class WebXRExperienceHelper {
|
|
|
115
114
|
};
|
|
116
115
|
// The layers feature will have already initialized the xr session's layers on session init.
|
|
117
116
|
if (!this.featuresManager.getEnabledFeature(WebXRFeatureName.LAYERS)) {
|
|
117
|
+
const baseLayer = await renderTarget.initializeXRLayerAsync(this.sessionManager.session);
|
|
118
118
|
xrRenderState.baseLayer = baseLayer;
|
|
119
119
|
}
|
|
120
120
|
this.sessionManager.updateRenderState(xrRenderState);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRExperienceHelper.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRExperienceHelper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,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YAClD,cAAc,EAAE,CAAC;SACpB;aAAM;YACH,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;YAC9E,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAC7C;IACL,CAAC;IAEO,gBAAgB;QACpB,IAAI,CAAC,MAAM,CAAC,gCAAgC,CAAC,IAAI,CAAC,YAAa,CAAC,CAAC;QACjE,IAAI,CAAC,4BAA4B,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnE,CAAC;IAEO,SAAS,CAAC,GAAe;QAC7B,IAAI,IAAI,CAAC,KAAK,KAAK,GAAG,EAAE;YACpB,OAAO;SACV;QACD,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;QACjB,IAAI,CAAC,wBAAwB,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { WebXRCamera } from \"./webXRCamera\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport { WebXRState } from \"./webXRTypes\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"./webXRFeaturesManager\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { UniversalCamera } from \"../Cameras/universalCamera\";\r\nimport { Quaternion, Vector3 } from \"../Maths/math.vector\";\r\n\r\n/**\r\n * Options for setting up XR spectator camera.\r\n */\r\nexport interface WebXRSpectatorModeOption {\r\n /**\r\n * Expected refresh rate (frames per sec) for a spectator camera.\r\n */\r\n fps?: number;\r\n /**\r\n * The index of rigCameras array in a WebXR camera.\r\n */\r\n preferredCameraIndex?: number;\r\n}\r\n\r\n/**\r\n * Base set of functionality needed to create an XR experience (WebXRSessionManager, Camera, StateManagement, etc.)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRExperienceHelpers\r\n */\r\nexport class WebXRExperienceHelper implements IDisposable {\r\n private _nonVRCamera: Nullable<Camera> = null;\r\n private _attachedToElement: boolean = false;\r\n private _spectatorCamera: Nullable<UniversalCamera> = null;\r\n private _originalSceneAutoClear = true;\r\n private _supported = false;\r\n private _spectatorMode = false;\r\n private _lastTimestamp = 0;\r\n\r\n /**\r\n * Camera used to render xr content\r\n */\r\n public camera: WebXRCamera;\r\n /** A features manager for this xr session */\r\n public featuresManager: WebXRFeaturesManager;\r\n /**\r\n * Observers registered here will be triggered after the camera's initial transformation is set\r\n * This can be used to set a different ground level or an extra rotation.\r\n *\r\n * Note that ground level is considered to be at 0. The height defined by the XR camera will be added\r\n * to the position set after this observable is done executing.\r\n */\r\n public onInitialXRPoseSetObservable = new Observable<WebXRCamera>();\r\n /**\r\n * Fires when the state of the experience helper has changed\r\n */\r\n public onStateChangedObservable = new Observable<WebXRState>();\r\n /** Session manager used to keep track of xr session */\r\n public sessionManager: WebXRSessionManager;\r\n /**\r\n * The current state of the XR experience (eg. transitioning, in XR or not in XR)\r\n */\r\n public state: WebXRState = WebXRState.NOT_IN_XR;\r\n\r\n /**\r\n * Creates a WebXRExperienceHelper\r\n * @param _scene The scene the helper should be created in\r\n */\r\n private constructor(private _scene: Scene) {\r\n this.sessionManager = new WebXRSessionManager(_scene);\r\n this.camera = new WebXRCamera(\"webxr\", _scene, this.sessionManager);\r\n this.featuresManager = new WebXRFeaturesManager(this.sessionManager);\r\n\r\n _scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Creates the experience helper\r\n * @param scene the scene to attach the experience helper to\r\n * @returns a promise for the experience helper\r\n */\r\n public static CreateAsync(scene: Scene): Promise<WebXRExperienceHelper> {\r\n const helper = new WebXRExperienceHelper(scene);\r\n return helper.sessionManager\r\n .initializeAsync()\r\n .then(() => {\r\n helper._supported = true;\r\n return helper;\r\n })\r\n .catch((e) => {\r\n helper._setState(WebXRState.NOT_IN_XR);\r\n helper.dispose();\r\n throw e;\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the experience helper\r\n */\r\n public dispose() {\r\n this.exitXRAsync();\r\n this.camera.dispose();\r\n this.onStateChangedObservable.clear();\r\n this.onInitialXRPoseSetObservable.clear();\r\n this.sessionManager.dispose();\r\n this._spectatorCamera?.dispose();\r\n if (this._nonVRCamera) {\r\n this._scene.activeCamera = this._nonVRCamera;\r\n }\r\n }\r\n\r\n /**\r\n * Enters XR mode (This must be done within a user interaction in most browsers eg. button click)\r\n * @param sessionMode options for the XR session\r\n * @param referenceSpaceType frame of reference of the XR session\r\n * @param renderTarget the output canvas that will be used to enter XR mode\r\n * @param sessionCreationOptions optional XRSessionInit object to init the session with\r\n * @returns promise that resolves after xr mode has entered\r\n */\r\n public async enterXRAsync(\r\n sessionMode: XRSessionMode,\r\n referenceSpaceType: XRReferenceSpaceType,\r\n renderTarget: WebXRRenderTarget = this.sessionManager.getWebXRRenderTarget(),\r\n sessionCreationOptions: XRSessionInit = {}\r\n ): Promise<WebXRSessionManager> {\r\n if (!this._supported) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"WebXR not supported in this browser or environment\";\r\n }\r\n this._setState(WebXRState.ENTERING_XR);\r\n if (referenceSpaceType !== \"viewer\" && referenceSpaceType !== \"local\") {\r\n sessionCreationOptions.optionalFeatures = sessionCreationOptions.optionalFeatures || [];\r\n sessionCreationOptions.optionalFeatures.push(referenceSpaceType);\r\n }\r\n sessionCreationOptions = await this.featuresManager._extendXRSessionInitObject(sessionCreationOptions);\r\n // we currently recommend \"unbounded\" space in AR (#7959)\r\n if (sessionMode === \"immersive-ar\" && referenceSpaceType !== \"unbounded\") {\r\n Logger.Warn(\"We recommend using 'unbounded' reference space type when using 'immersive-ar' session mode\");\r\n }\r\n // make sure that the session mode is supported\r\n try {\r\n await this.sessionManager.initializeSessionAsync(sessionMode, sessionCreationOptions);\r\n await this.sessionManager.setReferenceSpaceTypeAsync(referenceSpaceType);\r\n const baseLayer = await renderTarget.initializeXRLayerAsync(this.sessionManager.session);\r\n\r\n const xrRenderState: XRRenderStateInit = {\r\n // if maxZ is 0 it should be \"Infinity\", but it doesn't work with the WebXR API. Setting to a large number.\r\n depthFar: this.camera.maxZ || 10000,\r\n depthNear: this.camera.minZ,\r\n };\r\n\r\n // The layers feature will have already initialized the xr session's layers on session init.\r\n if (!this.featuresManager.getEnabledFeature(WebXRFeatureName.LAYERS)) {\r\n xrRenderState.baseLayer = baseLayer;\r\n }\r\n\r\n this.sessionManager.updateRenderState(xrRenderState);\r\n // run the render loop\r\n this.sessionManager.runXRRenderLoop();\r\n // Cache pre xr scene settings\r\n this._originalSceneAutoClear = this._scene.autoClear;\r\n this._nonVRCamera = this._scene.activeCamera;\r\n this._attachedToElement = !!this._nonVRCamera?.inputs?.attachedToElement;\r\n this._nonVRCamera?.detachControl();\r\n\r\n this._scene.activeCamera = this.camera;\r\n // do not compensate when AR session is used\r\n if (sessionMode !== \"immersive-ar\") {\r\n this._nonXRToXRCamera();\r\n } else {\r\n // Kept here, TODO - check if needed\r\n this._scene.autoClear = false;\r\n this.camera.compensateOnFirstFrame = false;\r\n // reset the camera's position to the origin\r\n this.camera.position.set(0, 0, 0);\r\n this.camera.rotationQuaternion.set(0, 0, 0, 1);\r\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\r\n }\r\n\r\n this.sessionManager.onXRSessionEnded.addOnce(() => {\r\n // when using the back button and not the exit button (default on mobile), the session is ending but the EXITING state was not set\r\n if (this.state !== WebXRState.EXITING_XR) {\r\n this._setState(WebXRState.EXITING_XR);\r\n }\r\n // Reset camera rigs output render target to ensure sessions render target is not drawn after it ends\r\n this.camera.rigCameras.forEach((c) => {\r\n c.outputRenderTarget = null;\r\n });\r\n\r\n // Restore scene settings\r\n this._scene.autoClear = this._originalSceneAutoClear;\r\n this._scene.activeCamera = this._nonVRCamera;\r\n if (this._attachedToElement && this._nonVRCamera) {\r\n this._nonVRCamera.attachControl(!!this._nonVRCamera.inputs.noPreventDefault);\r\n }\r\n if (sessionMode !== \"immersive-ar\" && this.camera.compensateOnFirstFrame) {\r\n if ((<any>this._nonVRCamera).setPosition) {\r\n (<any>this._nonVRCamera).setPosition(this.camera.position);\r\n } else {\r\n this._nonVRCamera!.position.copyFrom(this.camera.position);\r\n }\r\n }\r\n\r\n this._setState(WebXRState.NOT_IN_XR);\r\n });\r\n\r\n // Wait until the first frame arrives before setting state to in xr\r\n this.sessionManager.onXRFrameObservable.addOnce(() => {\r\n this._setState(WebXRState.IN_XR);\r\n });\r\n return this.sessionManager;\r\n } catch (e) {\r\n Logger.Log(e);\r\n Logger.Log(e.message);\r\n this._setState(WebXRState.NOT_IN_XR);\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Exits XR mode and returns the scene to its original state\r\n * @returns promise that resolves after xr mode has exited\r\n */\r\n public exitXRAsync() {\r\n // only exit if state is IN_XR\r\n if (this.state !== WebXRState.IN_XR) {\r\n return Promise.resolve();\r\n }\r\n this._setState(WebXRState.EXITING_XR);\r\n return this.sessionManager.exitXRAsync();\r\n }\r\n\r\n /**\r\n * Enable spectator mode for desktop VR experiences.\r\n * When spectator mode is enabled a camera will be attached to the desktop canvas and will\r\n * display the first rig camera's view on the desktop canvas.\r\n * Please note that this will degrade performance, as it requires another camera render.\r\n * It is also not recommended to enable this in devices like the quest, as it brings no benefit there.\r\n * @param options giving WebXRSpectatorModeOption for specutator camera to setup when the spectator mode is enabled.\r\n */\r\n public enableSpectatorMode(options?: WebXRSpectatorModeOption): void {\r\n if (!this._spectatorMode) {\r\n this._spectatorMode = true;\r\n this._switchSpectatorMode(options);\r\n }\r\n }\r\n\r\n /**\r\n * Disable spectator mode for desktop VR experiences.\r\n */\r\n public disableSpecatatorMode(): void {\r\n if (this._spectatorMode) {\r\n this._spectatorMode = false;\r\n this._switchSpectatorMode();\r\n }\r\n }\r\n\r\n private _switchSpectatorMode(options?: WebXRSpectatorModeOption): void {\r\n const fps = options?.fps ? options.fps : 1000.0;\r\n const refreshRate = (1.0 / fps) * 1000.0;\r\n const cameraIndex = options?.preferredCameraIndex ? options?.preferredCameraIndex : 0;\r\n\r\n const updateSpectatorCamera = () => {\r\n if (this._spectatorCamera) {\r\n const delta = this.sessionManager.currentTimestamp - this._lastTimestamp;\r\n if (delta >= refreshRate) {\r\n this._lastTimestamp = this.sessionManager.currentTimestamp;\r\n this._spectatorCamera.position.copyFrom(this.camera.rigCameras[cameraIndex].globalPosition);\r\n this._spectatorCamera.rotationQuaternion.copyFrom(this.camera.rigCameras[cameraIndex].absoluteRotation);\r\n }\r\n }\r\n };\r\n if (this._spectatorMode) {\r\n if (cameraIndex >= this.camera.rigCameras.length) {\r\n throw new Error(\"the preferred camera index is beyond the length of rig camera array.\");\r\n }\r\n const onStateChanged = () => {\r\n if (this.state === WebXRState.IN_XR) {\r\n this._spectatorCamera = new UniversalCamera(\"webxr-spectator\", Vector3.Zero(), this._scene);\r\n this._spectatorCamera.rotationQuaternion = new Quaternion();\r\n this._scene.activeCameras = [this.camera, this._spectatorCamera];\r\n this.sessionManager.onXRFrameObservable.add(updateSpectatorCamera);\r\n this._scene.onAfterRenderCameraObservable.add((camera) => {\r\n if (camera === this.camera) {\r\n // reset the dimensions object for correct resizing\r\n this._scene.getEngine().framebufferDimensionsObject = null;\r\n }\r\n });\r\n } else if (this.state === WebXRState.EXITING_XR) {\r\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\r\n this._scene.activeCameras = null;\r\n }\r\n };\r\n this.onStateChangedObservable.add(onStateChanged);\r\n onStateChanged();\r\n } else {\r\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\r\n this._scene.activeCameras = [this.camera];\r\n }\r\n }\r\n\r\n private _nonXRToXRCamera() {\r\n this.camera.setTransformationFromNonVRCamera(this._nonVRCamera!);\r\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\r\n }\r\n\r\n private _setState(val: WebXRState) {\r\n if (this.state === val) {\r\n return;\r\n }\r\n this.state = val;\r\n this.onStateChangedObservable.notifyObservers(this.state);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"webXRExperienceHelper.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRExperienceHelper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAgB3D;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IAkC9B;;;OAGG;IACH,YAA4B,MAAa;QAAb,WAAM,GAAN,MAAM,CAAO;QArCjC,iBAAY,GAAqB,IAAI,CAAC;QACtC,uBAAkB,GAAY,KAAK,CAAC;QACpC,qBAAgB,GAA8B,IAAI,CAAC;QACnD,4BAAuB,GAAG,IAAI,CAAC;QAC/B,eAAU,GAAG,KAAK,CAAC;QACnB,mBAAc,GAAG,KAAK,CAAC;QACvB,mBAAc,GAAG,CAAC,CAAC;QAQ3B;;;;;;WAMG;QACI,iCAA4B,GAAG,IAAI,UAAU,EAAe,CAAC;QACpE;;WAEG;QACI,6BAAwB,GAAG,IAAI,UAAU,EAAc,CAAC;QAG/D;;WAEG;QACI,UAAK,GAAe,UAAU,CAAC,SAAS,CAAC;QAO5C,IAAI,CAAC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AAI,CAAC,MAAM,CAAC,6BAA6B,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;wBACrD,IAAI,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE;4BACxB,mDAAmD;4BACnD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,2BAA2B,GAAG,IAAI,CAAC;yBAC9D;oBACL,CAAC,CAAC,CAAC;iBACN;qBAAM,IAAI,IAAI,CAAC,KAAK,KAAK,UAAU,CAAC,UAAU,EAAE;oBAC7C,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;oBAC9E,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,IAAI,CAAC;iBACpC;YACL,CAAC,CAAC;YACF,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAClD,cAAc,EAAE,CAAC;SACpB;aAAM;YACH,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;YAC9E,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAC7C;IACL,CAAC;IAEO,gBAAgB;QACpB,IAAI,CAAC,MAAM,CAAC,gCAAgC,CAAC,IAAI,CAAC,YAAa,CAAC,CAAC;QACjE,IAAI,CAAC,4BAA4B,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnE,CAAC;IAEO,SAAS,CAAC,GAAe;QAC7B,IAAI,IAAI,CAAC,KAAK,KAAK,GAAG,EAAE;YACpB,OAAO;SACV;QACD,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;QACjB,IAAI,CAAC,wBAAwB,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { WebXRCamera } from \"./webXRCamera\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport { WebXRState } from \"./webXRTypes\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"./webXRFeaturesManager\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { UniversalCamera } from \"../Cameras/universalCamera\";\r\nimport { Quaternion, Vector3 } from \"../Maths/math.vector\";\r\n\r\n/**\r\n * Options for setting up XR spectator camera.\r\n */\r\nexport interface WebXRSpectatorModeOption {\r\n /**\r\n * Expected refresh rate (frames per sec) for a spectator camera.\r\n */\r\n fps?: number;\r\n /**\r\n * The index of rigCameras array in a WebXR camera.\r\n */\r\n preferredCameraIndex?: number;\r\n}\r\n\r\n/**\r\n * Base set of functionality needed to create an XR experience (WebXRSessionManager, Camera, StateManagement, etc.)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRExperienceHelpers\r\n */\r\nexport class WebXRExperienceHelper implements IDisposable {\r\n private _nonVRCamera: Nullable<Camera> = null;\r\n private _attachedToElement: boolean = false;\r\n private _spectatorCamera: Nullable<UniversalCamera> = null;\r\n private _originalSceneAutoClear = true;\r\n private _supported = false;\r\n private _spectatorMode = false;\r\n private _lastTimestamp = 0;\r\n\r\n /**\r\n * Camera used to render xr content\r\n */\r\n public camera: WebXRCamera;\r\n /** A features manager for this xr session */\r\n public featuresManager: WebXRFeaturesManager;\r\n /**\r\n * Observers registered here will be triggered after the camera's initial transformation is set\r\n * This can be used to set a different ground level or an extra rotation.\r\n *\r\n * Note that ground level is considered to be at 0. The height defined by the XR camera will be added\r\n * to the position set after this observable is done executing.\r\n */\r\n public onInitialXRPoseSetObservable = new Observable<WebXRCamera>();\r\n /**\r\n * Fires when the state of the experience helper has changed\r\n */\r\n public onStateChangedObservable = new Observable<WebXRState>();\r\n /** Session manager used to keep track of xr session */\r\n public sessionManager: WebXRSessionManager;\r\n /**\r\n * The current state of the XR experience (eg. transitioning, in XR or not in XR)\r\n */\r\n public state: WebXRState = WebXRState.NOT_IN_XR;\r\n\r\n /**\r\n * Creates a WebXRExperienceHelper\r\n * @param _scene The scene the helper should be created in\r\n */\r\n private constructor(private _scene: Scene) {\r\n this.sessionManager = new WebXRSessionManager(_scene);\r\n this.camera = new WebXRCamera(\"webxr\", _scene, this.sessionManager);\r\n this.featuresManager = new WebXRFeaturesManager(this.sessionManager);\r\n\r\n _scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Creates the experience helper\r\n * @param scene the scene to attach the experience helper to\r\n * @returns a promise for the experience helper\r\n */\r\n public static CreateAsync(scene: Scene): Promise<WebXRExperienceHelper> {\r\n const helper = new WebXRExperienceHelper(scene);\r\n return helper.sessionManager\r\n .initializeAsync()\r\n .then(() => {\r\n helper._supported = true;\r\n return helper;\r\n })\r\n .catch((e) => {\r\n helper._setState(WebXRState.NOT_IN_XR);\r\n helper.dispose();\r\n throw e;\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the experience helper\r\n */\r\n public dispose() {\r\n this.exitXRAsync();\r\n this.camera.dispose();\r\n this.onStateChangedObservable.clear();\r\n this.onInitialXRPoseSetObservable.clear();\r\n this.sessionManager.dispose();\r\n this._spectatorCamera?.dispose();\r\n if (this._nonVRCamera) {\r\n this._scene.activeCamera = this._nonVRCamera;\r\n }\r\n }\r\n\r\n /**\r\n * Enters XR mode (This must be done within a user interaction in most browsers eg. button click)\r\n * @param sessionMode options for the XR session\r\n * @param referenceSpaceType frame of reference of the XR session\r\n * @param renderTarget the output canvas that will be used to enter XR mode\r\n * @param sessionCreationOptions optional XRSessionInit object to init the session with\r\n * @returns promise that resolves after xr mode has entered\r\n */\r\n public async enterXRAsync(\r\n sessionMode: XRSessionMode,\r\n referenceSpaceType: XRReferenceSpaceType,\r\n renderTarget: WebXRRenderTarget = this.sessionManager.getWebXRRenderTarget(),\r\n sessionCreationOptions: XRSessionInit = {}\r\n ): Promise<WebXRSessionManager> {\r\n if (!this._supported) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"WebXR not supported in this browser or environment\";\r\n }\r\n this._setState(WebXRState.ENTERING_XR);\r\n if (referenceSpaceType !== \"viewer\" && referenceSpaceType !== \"local\") {\r\n sessionCreationOptions.optionalFeatures = sessionCreationOptions.optionalFeatures || [];\r\n sessionCreationOptions.optionalFeatures.push(referenceSpaceType);\r\n }\r\n sessionCreationOptions = await this.featuresManager._extendXRSessionInitObject(sessionCreationOptions);\r\n // we currently recommend \"unbounded\" space in AR (#7959)\r\n if (sessionMode === \"immersive-ar\" && referenceSpaceType !== \"unbounded\") {\r\n Logger.Warn(\"We recommend using 'unbounded' reference space type when using 'immersive-ar' session mode\");\r\n }\r\n // make sure that the session mode is supported\r\n try {\r\n await this.sessionManager.initializeSessionAsync(sessionMode, sessionCreationOptions);\r\n await this.sessionManager.setReferenceSpaceTypeAsync(referenceSpaceType);\r\n\r\n const xrRenderState: XRRenderStateInit = {\r\n // if maxZ is 0 it should be \"Infinity\", but it doesn't work with the WebXR API. Setting to a large number.\r\n depthFar: this.camera.maxZ || 10000,\r\n depthNear: this.camera.minZ,\r\n };\r\n\r\n // The layers feature will have already initialized the xr session's layers on session init.\r\n if (!this.featuresManager.getEnabledFeature(WebXRFeatureName.LAYERS)) {\r\n const baseLayer = await renderTarget.initializeXRLayerAsync(this.sessionManager.session);\r\n xrRenderState.baseLayer = baseLayer;\r\n }\r\n\r\n this.sessionManager.updateRenderState(xrRenderState);\r\n // run the render loop\r\n this.sessionManager.runXRRenderLoop();\r\n // Cache pre xr scene settings\r\n this._originalSceneAutoClear = this._scene.autoClear;\r\n this._nonVRCamera = this._scene.activeCamera;\r\n this._attachedToElement = !!this._nonVRCamera?.inputs?.attachedToElement;\r\n this._nonVRCamera?.detachControl();\r\n\r\n this._scene.activeCamera = this.camera;\r\n // do not compensate when AR session is used\r\n if (sessionMode !== \"immersive-ar\") {\r\n this._nonXRToXRCamera();\r\n } else {\r\n // Kept here, TODO - check if needed\r\n this._scene.autoClear = false;\r\n this.camera.compensateOnFirstFrame = false;\r\n // reset the camera's position to the origin\r\n this.camera.position.set(0, 0, 0);\r\n this.camera.rotationQuaternion.set(0, 0, 0, 1);\r\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\r\n }\r\n\r\n this.sessionManager.onXRSessionEnded.addOnce(() => {\r\n // when using the back button and not the exit button (default on mobile), the session is ending but the EXITING state was not set\r\n if (this.state !== WebXRState.EXITING_XR) {\r\n this._setState(WebXRState.EXITING_XR);\r\n }\r\n // Reset camera rigs output render target to ensure sessions render target is not drawn after it ends\r\n this.camera.rigCameras.forEach((c) => {\r\n c.outputRenderTarget = null;\r\n });\r\n\r\n // Restore scene settings\r\n this._scene.autoClear = this._originalSceneAutoClear;\r\n this._scene.activeCamera = this._nonVRCamera;\r\n if (this._attachedToElement && this._nonVRCamera) {\r\n this._nonVRCamera.attachControl(!!this._nonVRCamera.inputs.noPreventDefault);\r\n }\r\n if (sessionMode !== \"immersive-ar\" && this.camera.compensateOnFirstFrame) {\r\n if ((<any>this._nonVRCamera).setPosition) {\r\n (<any>this._nonVRCamera).setPosition(this.camera.position);\r\n } else {\r\n this._nonVRCamera!.position.copyFrom(this.camera.position);\r\n }\r\n }\r\n\r\n this._setState(WebXRState.NOT_IN_XR);\r\n });\r\n\r\n // Wait until the first frame arrives before setting state to in xr\r\n this.sessionManager.onXRFrameObservable.addOnce(() => {\r\n this._setState(WebXRState.IN_XR);\r\n });\r\n return this.sessionManager;\r\n } catch (e) {\r\n Logger.Log(e);\r\n Logger.Log(e.message);\r\n this._setState(WebXRState.NOT_IN_XR);\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Exits XR mode and returns the scene to its original state\r\n * @returns promise that resolves after xr mode has exited\r\n */\r\n public exitXRAsync() {\r\n // only exit if state is IN_XR\r\n if (this.state !== WebXRState.IN_XR) {\r\n return Promise.resolve();\r\n }\r\n this._setState(WebXRState.EXITING_XR);\r\n return this.sessionManager.exitXRAsync();\r\n }\r\n\r\n /**\r\n * Enable spectator mode for desktop VR experiences.\r\n * When spectator mode is enabled a camera will be attached to the desktop canvas and will\r\n * display the first rig camera's view on the desktop canvas.\r\n * Please note that this will degrade performance, as it requires another camera render.\r\n * It is also not recommended to enable this in devices like the quest, as it brings no benefit there.\r\n * @param options giving WebXRSpectatorModeOption for specutator camera to setup when the spectator mode is enabled.\r\n */\r\n public enableSpectatorMode(options?: WebXRSpectatorModeOption): void {\r\n if (!this._spectatorMode) {\r\n this._spectatorMode = true;\r\n this._switchSpectatorMode(options);\r\n }\r\n }\r\n\r\n /**\r\n * Disable spectator mode for desktop VR experiences.\r\n */\r\n public disableSpecatatorMode(): void {\r\n if (this._spectatorMode) {\r\n this._spectatorMode = false;\r\n this._switchSpectatorMode();\r\n }\r\n }\r\n\r\n private _switchSpectatorMode(options?: WebXRSpectatorModeOption): void {\r\n const fps = options?.fps ? options.fps : 1000.0;\r\n const refreshRate = (1.0 / fps) * 1000.0;\r\n const cameraIndex = options?.preferredCameraIndex ? options?.preferredCameraIndex : 0;\r\n\r\n const updateSpectatorCamera = () => {\r\n if (this._spectatorCamera) {\r\n const delta = this.sessionManager.currentTimestamp - this._lastTimestamp;\r\n if (delta >= refreshRate) {\r\n this._lastTimestamp = this.sessionManager.currentTimestamp;\r\n this._spectatorCamera.position.copyFrom(this.camera.rigCameras[cameraIndex].globalPosition);\r\n this._spectatorCamera.rotationQuaternion.copyFrom(this.camera.rigCameras[cameraIndex].absoluteRotation);\r\n }\r\n }\r\n };\r\n if (this._spectatorMode) {\r\n if (cameraIndex >= this.camera.rigCameras.length) {\r\n throw new Error(\"the preferred camera index is beyond the length of rig camera array.\");\r\n }\r\n const onStateChanged = () => {\r\n if (this.state === WebXRState.IN_XR) {\r\n this._spectatorCamera = new UniversalCamera(\"webxr-spectator\", Vector3.Zero(), this._scene);\r\n this._spectatorCamera.rotationQuaternion = new Quaternion();\r\n this._scene.activeCameras = [this.camera, this._spectatorCamera];\r\n this.sessionManager.onXRFrameObservable.add(updateSpectatorCamera);\r\n this._scene.onAfterRenderCameraObservable.add((camera) => {\r\n if (camera === this.camera) {\r\n // reset the dimensions object for correct resizing\r\n this._scene.getEngine().framebufferDimensionsObject = null;\r\n }\r\n });\r\n } else if (this.state === WebXRState.EXITING_XR) {\r\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\r\n this._scene.activeCameras = null;\r\n }\r\n };\r\n this.onStateChangedObservable.add(onStateChanged);\r\n onStateChanged();\r\n } else {\r\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\r\n this._scene.activeCameras = [this.camera];\r\n }\r\n }\r\n\r\n private _nonXRToXRCamera() {\r\n this.camera.setTransformationFromNonVRCamera(this._nonVRCamera!);\r\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\r\n }\r\n\r\n private _setState(val: WebXRState) {\r\n if (this.state === val) {\r\n return;\r\n }\r\n this.state = val;\r\n this.onStateChangedObservable.notifyObservers(this.state);\r\n }\r\n}\r\n"]}
|
|
@@ -199,7 +199,10 @@ export class WebXRFeaturesManager {
|
|
|
199
199
|
attachFeature(featureName) {
|
|
200
200
|
const feature = this._features[featureName];
|
|
201
201
|
if (feature && feature.enabled && !feature.featureImplementation.attached) {
|
|
202
|
-
feature.featureImplementation.attach();
|
|
202
|
+
const attached = feature.featureImplementation.attach();
|
|
203
|
+
if (!attached) {
|
|
204
|
+
Tools.Warn(`Feature ${featureName} failed to attach`);
|
|
205
|
+
}
|
|
203
206
|
}
|
|
204
207
|
}
|
|
205
208
|
/**
|
|
@@ -209,7 +212,10 @@ export class WebXRFeaturesManager {
|
|
|
209
212
|
detachFeature(featureName) {
|
|
210
213
|
const feature = this._features[featureName];
|
|
211
214
|
if (feature && feature.featureImplementation.attached) {
|
|
212
|
-
feature.featureImplementation.detach();
|
|
215
|
+
const detached = feature.featureImplementation.detach();
|
|
216
|
+
if (!detached) {
|
|
217
|
+
Tools.Warn(`Feature ${featureName} failed to detach`);
|
|
218
|
+
}
|
|
213
219
|
}
|
|
214
220
|
}
|
|
215
221
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRFeaturesManager.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRFeaturesManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAsEtC;;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,mBAAmB,CAAC;AAC5D;;GAEG;AACoB,oCAAmB,GAAG,uBAAuB,CAAC;AACrE;;GAEG;AACoB,gCAAe,GAAG,oBAAoB,CAAC;AAC9D;;GAEG;AACoB,kCAAiB,GAAG,iCAAiC,CAAC;AAC7E;;GAEG;AACoB,8BAAa,GAAG,6BAA6B,CAAC;AACrE;;GAEG;AACoB,+BAAc,GAAG,mBAAmB,CAAC;AAC5D;;GAEG;AACoB,8BAAa,GAAG,kBAAkB,CAAC;AAC1D;;GAEG;AACoB,+BAAc,GAAG,mBAAmB,CAAC;AAC5D;;GAEG;AACoB,iCAAgB,GAAG,qBAAqB,CAAC;AAChE;;GAEG;AACoB,4BAAW,GAAG,gBAAgB,CAAC;AACtD;;GAEG;AACoB,yBAAQ,GAAG,wBAAwB,CAAC;AAC3D;;GAEG;AACoB,iCAAgB,GAAG,qBAAqB,CAAC;AAChE;;GAEG;AACoB,6BAAY,GAAG,iBAAiB,CAAC;AACxD;;GAEG;AACoB,mCAAkB,GAAG,uBAAuB,CAAC;AACpE;;GAEG;AACoB,uBAAM,GAAG,WAAW,CAAC;AAC5C;;GAEG;AACoB,8BAAa,GAAG,kB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AC,CAAC;YAC5C,MAAM,UAAU,GAAG,OAAO,CAAC,qBAAqB,CAAC,mBAAmB,CAAC;YACrE,IAAI,UAAU,EAAE;gBACZ,IAAI,OAAO,CAAC,QAAQ,EAAE;oBAClB,aAAa,CAAC,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,IAAI,EAAE,CAAC;oBACtE,IAAI,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE;wBAC3D,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;qBACnD;iBACJ;qBAAM;oBACH,aAAa,CAAC,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,IAAI,EAAE,CAAC;oBACtE,IAAI,aAAa,CAAC,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,AANoC,CAMnC;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,AAH2C,CAG1C","sourcesContent":["import type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { Observable } from \"core/Misc/observable\";\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 * Triggered when the feature is attached\r\n */\r\n onFeatureAttachObservable: Observable<IWebXRFeature>;\r\n /**\r\n * Triggered when the feature is detached\r\n */\r\n onFeatureDetachObservable: Observable<IWebXRFeature>;\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 * The name of the WebXR Raw Camera Access feature\r\n */\r\n public static readonly RAW_CAMERA_ACCESS = \"xr-raw-camera-access\";\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":["../../../../dev/core/src/XR/webXRFeaturesManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAsEtC;;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,mBAAmB,CAAC;AAC5D;;GAEG;AACoB,oCAAmB,GAAG,uBAAuB,CAAC;AACrE;;GAEG;AACoB,gCAAe,GAAG,oBAAoB,CAAC;AAC9D;;GAEG;AACoB,kCAAiB,GAAG,iCAAiC,CAAC;AAC7E;;GAEG;AACoB,8BAAa,GAAG,6BAA6B,CAAC;AACrE;;GAEG;AACoB,+BAAc,GAAG,mBAAmB,CAAC;AAC5D;;GAEG;AACoB,8BAAa,GAAG,kBAAkB,CAAC;AAC1D;;GAEG;AACoB,+BAAc,GAAG,mBAAmB,CAAC;AAC5D;;GAEG;AACoB,iCAAgB,GAAG,qBAAqB,CAAC;AACh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;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;;AA9UuB,uCAAkB,GAMtC,EAAE,AANoC,CAMnC;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,AAH2C,CAG1C","sourcesContent":["import type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { Observable } from \"core/Misc/observable\";\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 * Triggered when the feature is attached\r\n */\r\n onFeatureAttachObservable: Observable<IWebXRFeature>;\r\n /**\r\n * Triggered when the feature is detached\r\n */\r\n onFeatureDetachObservable: Observable<IWebXRFeature>;\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 * The name of the WebXR Raw Camera Access feature\r\n */\r\n public static readonly RAW_CAMERA_ACCESS = \"xr-raw-camera-access\";\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 const attached = feature.featureImplementation.attach();\r\n if (!attached) {\r\n Tools.Warn(`Feature ${featureName} failed to attach`);\r\n }\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 const detached = feature.featureImplementation.detach();\r\n if (!detached) {\r\n Tools.Warn(`Feature ${featureName} failed to detach`);\r\n }\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"]}
|
|
@@ -3,8 +3,9 @@ import type { WebXRLayerRenderTargetTextureProvider } from "./webXRRenderTargetT
|
|
|
3
3
|
import type { WebXRSessionManager } from "./webXRSessionManager";
|
|
4
4
|
/** Covers all supported subclasses of WebXR's XRCompositionLayer */
|
|
5
5
|
export type WebXRCompositionLayerType = "XRProjectionLayer";
|
|
6
|
+
export type WebXRQuadLayerType = "XRQuadLayer";
|
|
6
7
|
/** Covers all supported subclasses of WebXR's XRLayer */
|
|
7
|
-
export type WebXRLayerType = "XRWebGLLayer" | WebXRCompositionLayerType;
|
|
8
|
+
export type WebXRLayerType = "XRWebGLLayer" | WebXRCompositionLayerType | WebXRQuadLayerType;
|
|
8
9
|
/**
|
|
9
10
|
* Wrapper over subclasses of XRLayer.
|
|
10
11
|
* @internal
|
|
@@ -19,7 +20,8 @@ export declare class WebXRLayerWrapper {
|
|
|
19
20
|
/** The type of XR layer that is being wrapped. */
|
|
20
21
|
readonly layerType: WebXRLayerType;
|
|
21
22
|
/** Create a render target provider for the wrapped layer. */
|
|
22
|
-
|
|
23
|
+
private _createRenderTargetTextureProvider;
|
|
24
|
+
private _rttWrapper;
|
|
23
25
|
/**
|
|
24
26
|
* Check if fixed foveation is supported on this device
|
|
25
27
|
*/
|
|
@@ -34,6 +36,13 @@ export declare class WebXRLayerWrapper {
|
|
|
34
36
|
* This value will be normalized to be between 0 and 1, 1 being max foveation, 0 being no foveation
|
|
35
37
|
*/
|
|
36
38
|
set fixedFoveation(value: Nullable<number>);
|
|
39
|
+
/**
|
|
40
|
+
* Create a render target provider for the wrapped layer.
|
|
41
|
+
* @param xrSessionManager The XR Session Manager
|
|
42
|
+
* @returns A new render target texture provider for the wrapped layer.
|
|
43
|
+
*/
|
|
44
|
+
createRenderTargetTextureProvider(xrSessionManager: WebXRSessionManager): WebXRLayerRenderTargetTextureProvider;
|
|
45
|
+
dispose(): void;
|
|
37
46
|
protected constructor(
|
|
38
47
|
/** The width of the layer's framebuffer. */
|
|
39
48
|
getWidth: () => number,
|
|
@@ -44,5 +53,5 @@ export declare class WebXRLayerWrapper {
|
|
|
44
53
|
/** The type of XR layer that is being wrapped. */
|
|
45
54
|
layerType: WebXRLayerType,
|
|
46
55
|
/** Create a render target provider for the wrapped layer. */
|
|
47
|
-
|
|
56
|
+
_createRenderTargetTextureProvider: (xrSessionManager: WebXRSessionManager) => WebXRLayerRenderTargetTextureProvider);
|
|
48
57
|
}
|
package/XR/webXRLayerWrapper.js
CHANGED
|
@@ -29,6 +29,21 @@ export class WebXRLayerWrapper {
|
|
|
29
29
|
this.layer.fixedFoveation = val;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a render target provider for the wrapped layer.
|
|
34
|
+
* @param xrSessionManager The XR Session Manager
|
|
35
|
+
* @returns A new render target texture provider for the wrapped layer.
|
|
36
|
+
*/
|
|
37
|
+
createRenderTargetTextureProvider(xrSessionManager) {
|
|
38
|
+
this._rttWrapper = this._createRenderTargetTextureProvider(xrSessionManager);
|
|
39
|
+
return this._rttWrapper;
|
|
40
|
+
}
|
|
41
|
+
dispose() {
|
|
42
|
+
if (this._rttWrapper) {
|
|
43
|
+
this._rttWrapper.dispose();
|
|
44
|
+
this._rttWrapper = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
32
47
|
constructor(
|
|
33
48
|
/** The width of the layer's framebuffer. */
|
|
34
49
|
getWidth,
|
|
@@ -39,12 +54,13 @@ export class WebXRLayerWrapper {
|
|
|
39
54
|
/** The type of XR layer that is being wrapped. */
|
|
40
55
|
layerType,
|
|
41
56
|
/** Create a render target provider for the wrapped layer. */
|
|
42
|
-
|
|
57
|
+
_createRenderTargetTextureProvider) {
|
|
43
58
|
this.getWidth = getWidth;
|
|
44
59
|
this.getHeight = getHeight;
|
|
45
60
|
this.layer = layer;
|
|
46
61
|
this.layerType = layerType;
|
|
47
|
-
this.
|
|
62
|
+
this._createRenderTargetTextureProvider = _createRenderTargetTextureProvider;
|
|
63
|
+
this._rttWrapper = null;
|
|
48
64
|
}
|
|
49
65
|
}
|
|
50
66
|
//# sourceMappingURL=webXRLayerWrapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRLayerWrapper.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRLayerWrapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webXRLayerWrapper.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRLayerWrapper.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAE1B;;OAEG;IACH,IAAW,yBAAyB;QAChC,OAAO,IAAI,CAAC,SAAS,IAAI,cAAc,IAAI,OAAQ,IAAI,CAAC,KAAsB,CAAC,cAAc,IAAI,QAAQ,CAAC;IAC9G,CAAC;IAED;;;OAGG;IACH,IAAW,cAAc;QACrB,IAAI,IAAI,CAAC,yBAAyB,EAAE;YAChC,OAAQ,IAAI,CAAC,KAAsB,CAAC,cAAe,CAAC;SACvD;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,IAAW,cAAc,CAAC,KAAuB;QAC7C,IAAI,IAAI,CAAC,yBAAyB,EAAE;YAChC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;YAChD,IAAI,CAAC,KAAsB,CAAC,cAAc,GAAG,GAAG,CAAC;SACrD;IACL,CAAC;IAED;;;;OAIG;IACI,iCAAiC,CAAC,gBAAqC;QAC1E,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,kCAAkC,CAAC,gBAAgB,CAAC,CAAC;QAC7E,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAEM,OAAO;QACV,IAAI,IAAI,CAAC,WAAW,EAAE;YAClB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;YAC3B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;SAC3B;IACL,CAAC;IAED;IACI,4CAA4C;IACrC,QAAsB;IAC7B,6CAA6C;IACtC,SAAuB;IAC9B,sDAAsD;IACtC,KAAc;IAC9B,kDAAkD;IAClC,SAAyB;IACzC,6DAA6D;IACrD,kCAAoH;QARrH,aAAQ,GAAR,QAAQ,CAAc;QAEtB,cAAS,GAAT,SAAS,CAAc;QAEd,UAAK,GAAL,KAAK,CAAS;QAEd,cAAS,GAAT,SAAS,CAAgB;QAEjC,uCAAkC,GAAlC,kCAAkC,CAAkF;QAzDxH,gBAAW,GAAoD,IAAI,CAAC;IA0DzE,CAAC;CACP","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { WebXRLayerRenderTargetTextureProvider } from \"./webXRRenderTargetTextureProvider\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\n\r\n/** Covers all supported subclasses of WebXR's XRCompositionLayer */\r\n// TODO (rgerd): Extend for all other subclasses of XRCompositionLayer.\r\nexport type WebXRCompositionLayerType = \"XRProjectionLayer\";\r\nexport type WebXRQuadLayerType = \"XRQuadLayer\";\r\n\r\n/** Covers all supported subclasses of WebXR's XRLayer */\r\nexport type WebXRLayerType = \"XRWebGLLayer\" | WebXRCompositionLayerType | WebXRQuadLayerType;\r\n\r\n/**\r\n * Wrapper over subclasses of XRLayer.\r\n * @internal\r\n */\r\nexport class WebXRLayerWrapper {\r\n private _rttWrapper: Nullable<WebXRLayerRenderTargetTextureProvider> = null;\r\n /**\r\n * Check if fixed foveation is supported on this device\r\n */\r\n public get isFixedFoveationSupported(): boolean {\r\n return this.layerType == \"XRWebGLLayer\" && typeof (this.layer as XRWebGLLayer).fixedFoveation == \"number\";\r\n }\r\n\r\n /**\r\n * Get the fixed foveation currently set, as specified by the webxr specs\r\n * If this returns null, then fixed foveation is not supported\r\n */\r\n public get fixedFoveation(): Nullable<number> {\r\n if (this.isFixedFoveationSupported) {\r\n return (this.layer as XRWebGLLayer).fixedFoveation!;\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Set the fixed foveation to the specified value, as specified by the webxr specs\r\n * This value will be normalized to be between 0 and 1, 1 being max foveation, 0 being no foveation\r\n */\r\n public set fixedFoveation(value: Nullable<number>) {\r\n if (this.isFixedFoveationSupported) {\r\n const val = Math.max(0, Math.min(1, value || 0));\r\n (this.layer as XRWebGLLayer).fixedFoveation = val;\r\n }\r\n }\r\n\r\n /**\r\n * Create a render target provider for the wrapped layer.\r\n * @param xrSessionManager The XR Session Manager\r\n * @returns A new render target texture provider for the wrapped layer.\r\n */\r\n public createRenderTargetTextureProvider(xrSessionManager: WebXRSessionManager): WebXRLayerRenderTargetTextureProvider {\r\n this._rttWrapper = this._createRenderTargetTextureProvider(xrSessionManager);\r\n return this._rttWrapper;\r\n }\r\n\r\n public dispose(): void {\r\n if (this._rttWrapper) {\r\n this._rttWrapper.dispose();\r\n this._rttWrapper = null;\r\n }\r\n }\r\n\r\n protected constructor(\r\n /** The width of the layer's framebuffer. */\r\n public getWidth: () => number,\r\n /** The height of the layer's framebuffer. */\r\n public getHeight: () => number,\r\n /** The XR layer that this WebXRLayerWrapper wraps. */\r\n public readonly layer: XRLayer,\r\n /** The type of XR layer that is being wrapped. */\r\n public readonly layerType: WebXRLayerType,\r\n /** Create a render target provider for the wrapped layer. */\r\n private _createRenderTargetTextureProvider: (xrSessionManager: WebXRSessionManager) => WebXRLayerRenderTargetTextureProvider\r\n ) {}\r\n}\r\n"]}
|
|
@@ -54,11 +54,6 @@ export class WebXRLayerRenderTargetTextureProvider {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
renderTargetTexture.disableRescaling();
|
|
57
|
-
// Firefox reality fails if skipInitialClear is set to true, so make sure only modern XR implementations set it.
|
|
58
|
-
if (typeof XRWebGLBinding !== "undefined") {
|
|
59
|
-
// WebXR pre-clears textures
|
|
60
|
-
renderTargetTexture.skipInitialClear = true;
|
|
61
|
-
}
|
|
62
57
|
this._renderTargetTextures.push(renderTargetTexture);
|
|
63
58
|
return renderTargetTexture;
|
|
64
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRRenderT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E,KAAK,EAAE,MAAM,EAAE,CAAC;QAEtC,yDAAyD;QACzD,MAAM,mBAAmB,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,qBAAqB,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,mBAAmB,CAAC,wBAAwB,EAAE,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1K,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,YAAwC,CAAC;QACzF,mBAAmB,CAAC,QAAQ,GAAG,mBAAmB,CAAC,OAAO,CAAC;QAC3D,4FAA4F;QAC5F,IAAI,WAAW,IAAI,CAAC,YAAY,EAAE;YAC9B,mBAAmB,CAAC,YAAY,GAAG,WAAW,CAAC;SAClD;QAED,0BAA0B;QAC1B,IAAI,YAAY,EAAE;YACd,IAAI,SAAS,EAAE;gBACX,mBAAmB,CAAC,kBAAkB,GAAG,YAAY,CAAC;aACzD;iBAAM;gBACH,MAAM,eAAe,GAAG,IAAI,CAAC,sBAAsB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;gBAC/E,mBAAmB,CAAC,UAAU,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;gBACnD,mBAAmB,CAAC,QAAQ,GAAG,eAAe,CAAC;aAClD;SACJ;QAED,IAAI,mBAAmB,EAAE;YACrB,IAAI,SAAS,EAAE;gBACX,mBAAmB,CAAC,yBAAyB,GAAG,mBAAmB,CAAC;aACvE;iBAAM;gBACH,mBAAmB,CAAC,oBAAoB,GAAG,IAAI,CAAC,sBAAsB,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;aAC5G;SACJ;QAED,mBAAmB,CAAC,gBAAgB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"webXRRenderTargetTextureProvider.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRRenderTargetTextureProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AA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IAEM,wBAAwB;QAC3B,OAAO,IAAI,CAAC,sBAAsB,CAAC;IACvC,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,qBAAqB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1C,CAAC;CACJ","sourcesContent":["import type { Engine } from \"../Engines/engine\";\r\nimport { WebGLHardwareTexture } from \"../Engines/WebGL/webGLHardwareTexture\";\r\nimport type { WebGLRenderTargetWrapper } from \"../Engines/WebGL/webGLRenderTargetWrapper\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport { MultiviewRenderTarget } from \"../Materials/Textures/MultiviewRenderTarget\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Viewport } from \"../Maths/math.viewport\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\n\r\n/**\r\n * An interface for objects that provide render target textures for XR rendering.\r\n */\r\nexport interface IWebXRRenderTargetTextureProvider extends IDisposable {\r\n /**\r\n * Attempts to set the framebuffer-size-normalized viewport to be rendered this frame for this view.\r\n * In the event of a failure, the supplied viewport is not updated.\r\n * @param viewport the viewport to which the view will be rendered\r\n * @param view the view for which to set the viewport\r\n * @returns whether the operation was successful\r\n */\r\n trySetViewportForView(viewport: Viewport, view: XRView): boolean;\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this eye\r\n * @param eye the eye for which to get the render target\r\n * @returns the render target for the specified eye or null if not available\r\n */\r\n getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture>;\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this view\r\n * @param view the view for which to get the render target\r\n * @returns the render target for the specified view or null if not available\r\n */\r\n getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture>;\r\n}\r\n\r\n/**\r\n * Provides render target textures and other important rendering information for a given XRLayer.\r\n * @internal\r\n */\r\nexport abstract class WebXRLayerRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n public abstract trySetViewportForView(viewport: Viewport, view: XRView): boolean;\r\n public abstract getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture>;\r\n public abstract getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture>;\r\n\r\n protected _renderTargetTextures = new Array<RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n\r\n private _engine: Engine;\r\n\r\n constructor(\r\n private readonly _scene: Scene,\r\n public readonly layerWrapper: WebXRLayerWrapper\r\n ) {\r\n this._engine = _scene.getEngine();\r\n }\r\n\r\n private _createInternalTexture(textureSize: { width: number; height: number }, texture: WebGLTexture): InternalTexture {\r\n const internalTexture = new InternalTexture(this._engine, InternalTextureSource.Unknown, true);\r\n internalTexture.width = textureSize.width;\r\n internalTexture.height = textureSize.height;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(texture, this._engine._gl);\r\n internalTexture.isReady = true;\r\n return internalTexture;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable<WebGLFramebuffer>,\r\n colorTexture?: WebGLTexture,\r\n depthStencilTexture?: WebGLTexture,\r\n multiview?: boolean\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 = multiview ? new MultiviewRenderTarget(this._scene, textureSize) : new RenderTargetTexture(\"XR renderTargetTexture\", textureSize, this._scene);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n renderTargetWrapper._samples = renderTargetTexture.samples;\r\n // Set the framebuffer, make sure it works in all scenarios - emulator, no layers and layers\r\n if (framebuffer || !colorTexture) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n if (colorTexture) {\r\n if (multiview) {\r\n renderTargetWrapper._colorTextureArray = colorTexture;\r\n } else {\r\n const internalTexture = this._createInternalTexture(textureSize, colorTexture);\r\n renderTargetWrapper.setTexture(internalTexture, 0);\r\n renderTargetTexture._texture = internalTexture;\r\n }\r\n }\r\n\r\n if (depthStencilTexture) {\r\n if (multiview) {\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n } else {\r\n renderTargetWrapper._depthStencilTexture = this._createInternalTexture(textureSize, depthStencilTexture);\r\n }\r\n }\r\n\r\n renderTargetTexture.disableRescaling();\r\n\r\n this._renderTargetTextures.push(renderTargetTexture);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _destroyRenderTargetTexture(renderTargetTexture: RenderTargetTexture) {\r\n this._renderTargetTextures.splice(this._renderTargetTextures.indexOf(renderTargetTexture), 1);\r\n renderTargetTexture.dispose();\r\n }\r\n\r\n public getFramebufferDimensions(): Nullable<{ framebufferWidth: number; framebufferHeight: number }> {\r\n return this._framebufferDimensions;\r\n }\r\n\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.length = 0;\r\n }\r\n}\r\n"]}
|
|
@@ -53,6 +53,14 @@ export declare class WebXRSessionManager implements IDisposable, IWebXRRenderTar
|
|
|
53
53
|
* Fires when the xr session is initialized: right after requestSession was called and returned with a successful result
|
|
54
54
|
*/
|
|
55
55
|
onXRSessionInit: Observable<XRSession>;
|
|
56
|
+
/**
|
|
57
|
+
* Fires when the xr reference space has been initialized
|
|
58
|
+
*/
|
|
59
|
+
onXRReferenceSpaceInitialized: Observable<XRReferenceSpace>;
|
|
60
|
+
/**
|
|
61
|
+
* Fires when the session manager is rendering the first frame
|
|
62
|
+
*/
|
|
63
|
+
onXRReady: Observable<WebXRSessionManager>;
|
|
56
64
|
/**
|
|
57
65
|
* Underlying xr session
|
|
58
66
|
*/
|
|
@@ -177,7 +185,7 @@ export declare class WebXRSessionManager implements IDisposable, IWebXRRenderTar
|
|
|
177
185
|
* Note that this is deprecated in favor of WebXRSessionManager.updateRenderState().
|
|
178
186
|
* @param state state to set
|
|
179
187
|
* @returns a promise that resolves once the render state has been updated
|
|
180
|
-
* @deprecated
|
|
188
|
+
* @deprecated Use updateRenderState() instead.
|
|
181
189
|
*/
|
|
182
190
|
updateRenderStateAsync(state: XRRenderState): Promise<void>;
|
|
183
191
|
/**
|