@babylonjs/core 8.8.0 → 8.8.2
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/Actions/actionManager.js +2 -0
- package/Actions/actionManager.js.map +1 -1
- package/Animations/animatable.core.js +1 -1
- package/Animations/animatable.core.js.map +1 -1
- package/Animations/animation.js +4 -2
- package/Animations/animation.js.map +1 -1
- package/Audio/audioEngine.d.ts +1 -1
- package/Audio/audioEngine.js +20 -10
- package/Audio/audioEngine.js.map +1 -1
- package/Audio/audioSceneComponent.js +2 -0
- package/Audio/audioSceneComponent.js.map +1 -1
- package/Audio/sound.js +2 -0
- package/Audio/sound.js.map +1 -1
- package/AudioV2/abstractAudio/audioEngineV2.js +8 -1
- package/AudioV2/abstractAudio/audioEngineV2.js.map +1 -1
- package/AudioV2/abstractAudio/streamingSound.js +3 -1
- package/AudioV2/abstractAudio/streamingSound.js.map +1 -1
- package/AudioV2/abstractAudio/subNodes/abstractAudioSubGraph.js +6 -2
- package/AudioV2/abstractAudio/subNodes/abstractAudioSubGraph.js.map +1 -1
- package/AudioV2/abstractAudio/subProperties/audioAnalyzer.js +3 -0
- package/AudioV2/abstractAudio/subProperties/audioAnalyzer.js.map +1 -1
- package/AudioV2/abstractAudio/subProperties/spatialAudio.js +1 -0
- package/AudioV2/abstractAudio/subProperties/spatialAudio.js.map +1 -1
- package/AudioV2/webAudio/webAudioEngine.js +5 -1
- package/AudioV2/webAudio/webAudioEngine.js.map +1 -1
- package/AudioV2/webAudio/webAudioStaticSound.js +2 -0
- package/AudioV2/webAudio/webAudioStaticSound.js.map +1 -1
- package/AudioV2/webAudio/webAudioStreamingSound.js +3 -0
- package/AudioV2/webAudio/webAudioStreamingSound.js.map +1 -1
- package/AudioV2/webAudio/webAudioUnmuteUI.js +1 -0
- package/AudioV2/webAudio/webAudioUnmuteUI.js.map +1 -1
- package/BakedVertexAnimation/vertexAnimationBaker.d.ts +1 -0
- package/BakedVertexAnimation/vertexAnimationBaker.js +3 -1
- package/BakedVertexAnimation/vertexAnimationBaker.js.map +1 -1
- package/Buffers/buffer.nonFloatVertexBuffers.js +1 -0
- package/Buffers/buffer.nonFloatVertexBuffers.js.map +1 -1
- package/Buffers/storageBuffer.js +1 -1
- package/Buffers/storageBuffer.js.map +1 -1
- package/Cameras/Inputs/arcRotateCameraVRDeviceOrientationInput.js +2 -0
- package/Cameras/Inputs/arcRotateCameraVRDeviceOrientationInput.js.map +1 -1
- package/Cameras/Inputs/freeCameraDeviceOrientationInput.js +6 -1
- package/Cameras/Inputs/freeCameraDeviceOrientationInput.js.map +1 -1
- package/Cameras/VR/vrExperienceHelper.js +2 -0
- package/Cameras/VR/vrExperienceHelper.js.map +1 -1
- package/Collisions/gpuPicker.js +9 -6
- package/Collisions/gpuPicker.js.map +1 -1
- package/Compute/computeShader.js +1 -1
- package/Compute/computeShader.js.map +1 -1
- package/Culling/Helper/boundingInfoHelper.js +3 -3
- package/Culling/Helper/boundingInfoHelper.js.map +1 -1
- package/Culling/Helper/computeShaderBoundingHelper.js +3 -1
- package/Culling/Helper/computeShaderBoundingHelper.js.map +1 -1
- package/Culling/Helper/transformFeedbackBoundingHelper.js +3 -0
- package/Culling/Helper/transformFeedbackBoundingHelper.js.map +1 -1
- package/Debug/debugLayer.js +1 -1
- package/Debug/debugLayer.js.map +1 -1
- package/Engines/AbstractEngine/abstractEngine.cubeTexture.js +1 -0
- package/Engines/AbstractEngine/abstractEngine.cubeTexture.js.map +1 -1
- package/Engines/Extensions/engine.prefilteredCubeTexture.js +1 -0
- package/Engines/Extensions/engine.prefilteredCubeTexture.js.map +1 -1
- package/Engines/Extensions/engine.readTexture.js +1 -0
- package/Engines/Extensions/engine.readTexture.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.computeShader.js +1 -0
- package/Engines/WebGPU/Extensions/engine.computeShader.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.readTexture.js +1 -0
- package/Engines/WebGPU/Extensions/engine.readTexture.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.videoTexture.js +2 -0
- package/Engines/WebGPU/Extensions/engine.videoTexture.js.map +1 -1
- package/Engines/WebGPU/webgpuBufferManager.js +3 -1
- package/Engines/WebGPU/webgpuBufferManager.js.map +1 -1
- package/Engines/WebGPU/webgpuOcclusionQuery.js +1 -0
- package/Engines/WebGPU/webgpuOcclusionQuery.js.map +1 -1
- package/Engines/WebGPU/webgpuQuerySet.js +15 -9
- package/Engines/WebGPU/webgpuQuerySet.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureManager.js +1 -0
- package/Engines/WebGPU/webgpuTextureManager.js.map +1 -1
- package/Engines/WebGPU/webgpuTimestampQuery.js +4 -2
- package/Engines/WebGPU/webgpuTimestampQuery.js.map +1 -1
- package/Engines/WebGPU/webgpuTintWASM.js +1 -0
- package/Engines/WebGPU/webgpuTintWASM.js.map +1 -1
- package/Engines/abstractEngine.js +5 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/constants.d.ts +23 -0
- package/Engines/constants.js +23 -0
- package/Engines/constants.js.map +1 -1
- package/Engines/engine.common.js +7 -1
- package/Engines/engine.common.js.map +1 -1
- package/Engines/engine.js +5 -3
- package/Engines/engine.js.map +1 -1
- package/Engines/engineFactory.js +1 -1
- package/Engines/engineFactory.js.map +1 -1
- package/Engines/nativeEngine.js +19 -11
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.d.ts +1 -0
- package/Engines/thinEngine.js +22 -18
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +30 -11
- package/Engines/webgpuEngine.js.map +1 -1
- package/FlowGraph/flowGraphParser.js +2 -2
- package/FlowGraph/flowGraphParser.js.map +1 -1
- package/FrameGraph/Node/nodeRenderGraph.js +5 -1
- package/FrameGraph/Node/nodeRenderGraph.js.map +1 -1
- package/FrameGraph/Node/nodeRenderGraphBlock.js +1 -1
- package/FrameGraph/Node/nodeRenderGraphBlock.js.map +1 -1
- package/FrameGraph/frameGraph.js +1 -1
- package/FrameGraph/frameGraph.js.map +1 -1
- package/Helpers/sceneHelpers.js +1 -3
- package/Helpers/sceneHelpers.js.map +1 -1
- package/Helpers/videoDome.js +1 -0
- package/Helpers/videoDome.js.map +1 -1
- package/Layers/thinEffectLayer.js +1 -0
- package/Layers/thinEffectLayer.js.map +1 -1
- package/LensFlares/lensFlareSystem.js +1 -0
- package/LensFlares/lensFlareSystem.js.map +1 -1
- package/Lights/Shadows/shadowGenerator.js +3 -2
- package/Lights/Shadows/shadowGenerator.js.map +1 -1
- package/Lights/areaLight.js +2 -0
- package/Lights/areaLight.js.map +1 -1
- package/Loading/sceneLoader.js +56 -22
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.d.ts +15 -1
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js +34 -7
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js.map +1 -1
- package/Materials/Node/Blocks/Dual/clipPlanesBlock.js +1 -0
- package/Materials/Node/Blocks/Dual/clipPlanesBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/fogBlock.js +1 -0
- package/Materials/Node/Blocks/Dual/fogBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/lightBlock.js +1 -0
- package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js +1 -0
- package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js +1 -0
- package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js +1 -0
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/shadowMapBlock.js +1 -0
- package/Materials/Node/Blocks/Fragment/shadowMapBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +9 -11
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/sheenBlock.js +1 -1
- package/Materials/Node/Blocks/PBR/sheenBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/subSurfaceBlock.js +6 -2
- package/Materials/Node/Blocks/PBR/subSurfaceBlock.js.map +1 -1
- package/Materials/Node/Blocks/Vertex/bonesBlock.js +1 -0
- package/Materials/Node/Blocks/Vertex/bonesBlock.js.map +1 -1
- package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js +1 -0
- package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.js +11 -3
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/Node/nodeMaterialBuildState.js +1 -0
- package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
- package/Materials/PBR/pbrBRDFConfiguration.d.ts +11 -0
- package/Materials/PBR/pbrBRDFConfiguration.js +16 -0
- package/Materials/PBR/pbrBRDFConfiguration.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.d.ts +4 -0
- package/Materials/PBR/pbrBaseMaterial.js +12 -8
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/PBR/pbrMaterial.d.ts +8 -0
- package/Materials/PBR/pbrMaterial.js +16 -0
- package/Materials/PBR/pbrMaterial.js.map +1 -1
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.js +1 -0
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.js.map +1 -1
- package/Materials/Textures/Loaders/basisTextureLoader.js +4 -0
- package/Materials/Textures/Loaders/basisTextureLoader.js.map +1 -1
- package/Materials/Textures/Loaders/envTextureLoader.js +1 -0
- package/Materials/Textures/Loaders/envTextureLoader.js.map +1 -1
- package/Materials/Textures/Loaders/exrTextureLoader.js +2 -0
- package/Materials/Textures/Loaders/exrTextureLoader.js.map +1 -1
- package/Materials/Textures/Loaders/ktxTextureLoader.js +1 -0
- package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
- package/Materials/Textures/Loaders/textureLoaderManager.js +9 -9
- package/Materials/Textures/Loaders/textureLoaderManager.js.map +1 -1
- package/Materials/Textures/Packer/packer.js +3 -1
- package/Materials/Textures/Packer/packer.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.js +1 -0
- package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
- package/Materials/Textures/baseTexture.polynomial.js +1 -0
- package/Materials/Textures/baseTexture.polynomial.js.map +1 -1
- package/Materials/Textures/hdrCubeTexture.js +1 -0
- package/Materials/Textures/hdrCubeTexture.js.map +1 -1
- package/Materials/Textures/internalTexture.js +1 -0
- package/Materials/Textures/internalTexture.js.map +1 -1
- package/Materials/Textures/rawCubeTexture.js +3 -0
- package/Materials/Textures/rawCubeTexture.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.js +2 -0
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/Textures/videoTexture.js +6 -0
- package/Materials/Textures/videoTexture.js.map +1 -1
- package/Materials/effect.js +2 -1
- package/Materials/effect.js.map +1 -1
- package/Materials/effect.webgl.functions.js +3 -1
- package/Materials/effect.webgl.functions.js.map +1 -1
- package/Materials/effectRenderer.js +1 -0
- package/Materials/effectRenderer.js.map +1 -1
- package/Materials/material.js +2 -1
- package/Materials/material.js.map +1 -1
- package/Materials/shaderMaterial.js +4 -2
- package/Materials/shaderMaterial.js.map +1 -1
- package/Meshes/Compression/dracoCodec.js +5 -1
- package/Meshes/Compression/dracoCodec.js.map +1 -1
- package/Meshes/Compression/dracoCompression.js +4 -3
- package/Meshes/Compression/dracoCompression.js.map +1 -1
- package/Meshes/Compression/dracoCompressionWorker.js +5 -2
- package/Meshes/Compression/dracoCompressionWorker.js.map +1 -1
- package/Meshes/Compression/dracoDecoder.js +5 -1
- package/Meshes/Compression/dracoDecoder.js.map +1 -1
- package/Meshes/Compression/dracoEncoder.js +3 -2
- package/Meshes/Compression/dracoEncoder.js.map +1 -1
- package/Meshes/Compression/meshoptCompression.js +18 -18
- package/Meshes/Compression/meshoptCompression.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +14 -15
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Meshes/Node/Blocks/Textures/geometryTextureBlock.js +20 -10
- package/Meshes/Node/Blocks/Textures/geometryTextureBlock.js.map +1 -1
- package/Meshes/Node/Blocks/booleanGeometryBlock.js +1 -0
- package/Meshes/Node/Blocks/booleanGeometryBlock.js.map +1 -1
- package/Meshes/Node/nodeGeometry.js +5 -1
- package/Meshes/Node/nodeGeometry.js.map +1 -1
- package/Meshes/mesh.js +2 -2
- package/Meshes/mesh.js.map +1 -1
- package/Meshes/meshUVSpaceRenderer.js +1 -0
- package/Meshes/meshUVSpaceRenderer.js.map +1 -1
- package/Misc/HighDynamicRange/cubemapToSphericalPolynomial.js +1 -0
- package/Misc/HighDynamicRange/cubemapToSphericalPolynomial.js.map +1 -1
- package/Misc/assetsManager.js +2 -1
- package/Misc/assetsManager.js.map +1 -1
- package/Misc/asyncLock.js +5 -2
- package/Misc/asyncLock.js.map +1 -1
- package/Misc/basis.js +9 -2
- package/Misc/basis.js.map +1 -1
- package/Misc/basisWorker.js +3 -1
- package/Misc/basisWorker.js.map +1 -1
- package/Misc/copyTextureToTexture.js +1 -0
- package/Misc/copyTextureToTexture.js.map +1 -1
- package/Misc/coroutine.js +2 -1
- package/Misc/coroutine.js.map +1 -1
- package/Misc/dataReader.js +3 -4
- package/Misc/dataReader.js.map +1 -1
- package/Misc/dumpTools.js +7 -1
- package/Misc/dumpTools.js.map +1 -1
- package/Misc/environmentTextureTools.d.ts +0 -2
- package/Misc/environmentTextureTools.js +20 -7
- package/Misc/environmentTextureTools.js.map +1 -1
- package/Misc/equirectangularCapture.js +2 -1
- package/Misc/equirectangularCapture.js.map +1 -1
- package/Misc/fileTools.js +2 -0
- package/Misc/fileTools.js.map +1 -1
- package/Misc/filesInput.js +5 -1
- package/Misc/filesInput.js.map +1 -1
- package/Misc/khronosTextureContainer2.js +10 -3
- package/Misc/khronosTextureContainer2.js.map +1 -1
- package/Misc/khronosTextureContainer2Worker.js +4 -1
- package/Misc/khronosTextureContainer2Worker.js.map +1 -1
- package/Misc/minMaxReducer.js +1 -0
- package/Misc/minMaxReducer.js.map +1 -1
- package/Misc/observable.extensions.js +3 -1
- package/Misc/observable.extensions.js.map +1 -1
- package/Misc/observable.js +2 -0
- package/Misc/observable.js.map +1 -1
- package/Misc/observableCoroutine.js +1 -0
- package/Misc/observableCoroutine.js.map +1 -1
- package/Misc/reflector.js +1 -0
- package/Misc/reflector.js.map +1 -1
- package/Misc/rgbdTextureTools.js +2 -1
- package/Misc/rgbdTextureTools.js.map +1 -1
- package/Misc/sceneSerializer.js +2 -2
- package/Misc/sceneSerializer.js.map +1 -1
- package/Misc/screenshotTools.js +9 -4
- package/Misc/screenshotTools.js.map +1 -1
- package/Misc/textureTools.js +2 -0
- package/Misc/textureTools.js.map +1 -1
- package/Misc/tools.internals.js +2 -1
- package/Misc/tools.internals.js.map +1 -1
- package/Misc/tools.js +9 -3
- package/Misc/tools.js.map +1 -1
- package/Misc/videoRecorder.js +1 -0
- package/Misc/videoRecorder.js.map +1 -1
- package/Misc/webRequest.fetch.js +2 -1
- package/Misc/webRequest.fetch.js.map +1 -1
- package/Misc/workerPool.js +3 -0
- package/Misc/workerPool.js.map +1 -1
- package/Particles/flowMap.js +1 -1
- package/Particles/flowMap.js.map +1 -1
- package/Particles/particleHelper.js +7 -0
- package/Particles/particleHelper.js.map +1 -1
- package/Particles/pointsCloudSystem.js +7 -7
- package/Particles/pointsCloudSystem.js.map +1 -1
- package/Particles/thinParticleSystem.js +2 -0
- package/Particles/thinParticleSystem.js.map +1 -1
- package/Physics/physicsHelper.js +2 -2
- package/Physics/physicsHelper.js.map +1 -1
- package/Physics/v1/Plugins/oimoJSPlugin.js +1 -1
- package/Physics/v1/Plugins/oimoJSPlugin.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js +1 -0
- package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js.map +1 -1
- package/Rendering/GlobalIllumination/giRSMManager.js +1 -0
- package/Rendering/GlobalIllumination/giRSMManager.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +1 -0
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -1
- package/Rendering/depthRenderer.js +1 -0
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js +3 -1
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderingTextures.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js +1 -0
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Rendering/iblCdfGenerator.js +4 -1
- package/Rendering/iblCdfGenerator.js.map +1 -1
- package/Shaders/ShadersInclude/lightFragment.js +5 -1
- package/Shaders/ShadersInclude/lightFragment.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBRDFFunctions.js +12 -5
- package/Shaders/ShadersInclude/pbrBRDFFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockDirectLighting.js +3 -0
- package/Shaders/ShadersInclude/pbrBlockDirectLighting.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockFinalLitComponents.js +21 -8
- package/Shaders/ShadersInclude/pbrBlockFinalLitComponents.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockFinalUnlitComponents.js +3 -0
- package/Shaders/ShadersInclude/pbrBlockFinalUnlitComponents.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockReflectance.js +6 -6
- package/Shaders/ShadersInclude/pbrBlockReflectance.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockReflectance0.js +2 -7
- package/Shaders/ShadersInclude/pbrBlockReflectance0.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockReflectivity.js +20 -16
- package/Shaders/ShadersInclude/pbrBlockReflectivity.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js +6 -8
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js.map +1 -1
- package/Shaders/ShadersInclude/pbrDebug.js +2 -2
- package/Shaders/ShadersInclude/pbrDebug.js.map +1 -1
- package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js +1 -5
- package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
- package/Shaders/pbr.fragment.js +7 -3
- package/Shaders/pbr.fragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/lightFragment.js +5 -1
- package/ShadersWGSL/ShadersInclude/lightFragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBRDFFunctions.js +5 -5
- package/ShadersWGSL/ShadersInclude/pbrBRDFFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockDirectLighting.js +3 -0
- package/ShadersWGSL/ShadersInclude/pbrBlockDirectLighting.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockFinalLitComponents.js +21 -8
- package/ShadersWGSL/ShadersInclude/pbrBlockFinalLitComponents.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockFinalUnlitComponents.js +3 -0
- package/ShadersWGSL/ShadersInclude/pbrBlockFinalUnlitComponents.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockReflectance.js +6 -6
- package/ShadersWGSL/ShadersInclude/pbrBlockReflectance.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockReflectance0.js +2 -7
- package/ShadersWGSL/ShadersInclude/pbrBlockReflectance0.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockReflectivity.js +22 -15
- package/ShadersWGSL/ShadersInclude/pbrBlockReflectivity.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockSubSurface.js +6 -8
- package/ShadersWGSL/ShadersInclude/pbrBlockSubSurface.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrDebug.js +2 -2
- package/ShadersWGSL/ShadersInclude/pbrDebug.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js +1 -7
- package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
- package/ShadersWGSL/pbr.fragment.js +7 -3
- package/ShadersWGSL/pbr.fragment.js.map +1 -1
- package/Sprites/spriteManager.js +5 -1
- package/Sprites/spriteManager.js.map +1 -1
- package/Sprites/spriteRenderer.js +1 -0
- package/Sprites/spriteRenderer.js.map +1 -1
- package/XR/features/WebXRAnchorSystem.js +4 -3
- package/XR/features/WebXRAnchorSystem.js.map +1 -1
- package/XR/features/WebXRDepthSensing.js +1 -1
- package/XR/features/WebXRDepthSensing.js.map +1 -1
- package/XR/features/WebXRHandTracking.js +4 -1
- package/XR/features/WebXRHandTracking.js.map +1 -1
- package/XR/features/WebXRHitTest.js +4 -1
- package/XR/features/WebXRHitTest.js.map +1 -1
- package/XR/features/WebXRHitTestLegacy.js +6 -5
- package/XR/features/WebXRHitTestLegacy.js.map +1 -1
- package/XR/features/WebXRImageTracking.js +2 -1
- package/XR/features/WebXRImageTracking.js.map +1 -1
- package/XR/features/WebXRLightEstimation.js +3 -0
- package/XR/features/WebXRLightEstimation.js.map +1 -1
- package/XR/features/WebXRNearInteraction.js +2 -0
- package/XR/features/WebXRNearInteraction.js.map +1 -1
- package/XR/features/WebXRPlaneDetector.js +2 -2
- package/XR/features/WebXRPlaneDetector.js.map +1 -1
- package/XR/motionController/webXRAbstractMotionController.js +3 -2
- package/XR/motionController/webXRAbstractMotionController.js.map +1 -1
- package/XR/motionController/webXRMicrosoftMixedRealityController.js +6 -6
- package/XR/motionController/webXRMicrosoftMixedRealityController.js.map +1 -1
- package/XR/motionController/webXRMotionControllerManager.js +15 -9
- package/XR/motionController/webXRMotionControllerManager.js.map +1 -1
- package/XR/motionController/webXRProfiledMotionController.js +1 -1
- package/XR/motionController/webXRProfiledMotionController.js.map +1 -1
- package/XR/native/nativeXRFrame.js +1 -0
- package/XR/native/nativeXRFrame.js.map +1 -1
- package/XR/webXRDefaultExperience.js +10 -12
- package/XR/webXRDefaultExperience.js.map +1 -1
- package/XR/webXREnterExitUI.js +2 -1
- package/XR/webXREnterExitUI.js.map +1 -1
- package/XR/webXRExperienceHelper.js +5 -2
- package/XR/webXRExperienceHelper.js.map +1 -1
- package/XR/webXRFeaturesManager.js +1 -0
- package/XR/webXRFeaturesManager.js.map +1 -1
- package/XR/webXRInput.js +1 -0
- package/XR/webXRInput.js.map +1 -1
- package/XR/webXRInputSource.js +2 -0
- package/XR/webXRInputSource.js.map +1 -1
- package/XR/webXRManagedOutputCanvas.js +5 -1
- package/XR/webXRManagedOutputCanvas.js.map +1 -1
- package/XR/webXRSessionManager.js +56 -60
- package/XR/webXRSessionManager.js.map +1 -1
- package/assetContainer.js +28 -28
- package/assetContainer.js.map +1 -1
- package/package.json +1 -1
- package/scene.js +5 -4
- package/scene.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRProfiledMotionController.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/motionController/webXRProfiledMotionController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAS,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,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ACnC,MAAM,WAAW,GAAG,iBAAiB,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;gBACzE,IAAI,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;gBAC5B,IAAI,WAAW,CAAC,iBAAiB,KAAK,OAAO,EAAE,CAAC;oBAC5C,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC7B,CAAC;qBAAM,IAAI,WAAW,CAAC,iBAAiB,KAAK,OAAO,EAAE,CAAC;oBACnD,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC7B,CAAC;gBACD,IAAI,WAAW,CAAC,iBAAiB,KAAK,WAAW,EAAE,CAAC;oBAChD,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,iBAAiB,KAAK,QAAQ,CAAC,CAAC;gBAC7G,CAAC;qBAAM,CAAC;oBACJ,aAAa;oBACb,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,SAAS,CAAC;oBAC7D,IAAI,SAAS,EAAE,CAAC;wBACZ,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC;oBACjE,CAAC;oBACD,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,CAAC;wBACrC,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC;oBAC1F,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;CACJ","sourcesContent":["import type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { IMotionControllerProfile, IMotionControllerMeshMap } from \"./webXRAbstractMotionController\";\r\nimport { WebXRAbstractMotionController } from \"./webXRAbstractMotionController\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { SceneLoader } from \"../../Loading/sceneLoader\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\nimport { Axis, Space } from \"../../Maths/math.axis\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport { WebXRControllerComponent } from \"./webXRControllerComponent\";\r\nimport { CreateSphere } from \"../../Meshes/Builders/sphereBuilder\";\r\nimport { StandardMaterial } from \"../../Materials/standardMaterial\";\r\nimport { Logger } from \"../../Misc/logger\";\r\n\r\n/**\r\n * A profiled motion controller has its profile loaded from an online repository.\r\n * The class is responsible of loading the model, mapping the keys and enabling model-animations\r\n */\r\nexport class WebXRProfiledMotionController extends WebXRAbstractMotionController {\r\n private _buttonMeshMapping: {\r\n [buttonName: string]: {\r\n mainMesh?: AbstractMesh;\r\n states: {\r\n [state: string]: IMotionControllerMeshMap;\r\n };\r\n };\r\n } = {};\r\n private _touchDots: { [visKey: string]: AbstractMesh } = {};\r\n\r\n /**\r\n * The profile ID of this controller. Will be populated when the controller initializes.\r\n */\r\n public profileId: string;\r\n\r\n constructor(\r\n scene: Scene,\r\n xrInput: XRInputSource,\r\n _profile: IMotionControllerProfile,\r\n private _repositoryUrl: string,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n private controllerCache?: Array<{\r\n filename: string;\r\n path: string;\r\n meshes: AbstractMesh[];\r\n }>\r\n ) {\r\n super(scene, _profile.layouts[xrInput.handedness || \"none\"], xrInput.gamepad as any, xrInput.handedness, undefined, controllerCache);\r\n this.profileId = _profile.profileId;\r\n }\r\n\r\n public override dispose() {\r\n super.dispose();\r\n if (!this.controllerCache) {\r\n const keys = Object.keys(this._touchDots);\r\n for (const visResKey of keys) {\r\n this._touchDots[visResKey].dispose();\r\n }\r\n }\r\n }\r\n\r\n protected _getFilenameAndPath(): { filename: string; path: string } {\r\n return {\r\n filename: this.layout.assetPath,\r\n path: `${this._repositoryUrl}/profiles/${this.profileId}/`,\r\n };\r\n }\r\n\r\n protected _getModelLoadingConstraints(): boolean {\r\n const glbLoaded = SceneLoader.IsPluginForExtensionAvailable(\".glb\");\r\n if (!glbLoaded) {\r\n Logger.Warn(\"glTF / glb loader was not registered, using generic controller instead\");\r\n }\r\n return glbLoaded;\r\n }\r\n\r\n protected _processLoadedModel(_meshes: AbstractMesh[]): void {\r\n const ids = this.getComponentIds();\r\n\r\n for (const type of ids) {\r\n const componentInLayout = this.layout.components[type];\r\n this._buttonMeshMapping[type] = {\r\n mainMesh: this._getChildByName(this.rootMesh!, componentInLayout.rootNodeName),\r\n states: {},\r\n };\r\n const keys = Object.keys(componentInLayout.visualResponses);\r\n for (const visualResponseKey of keys) {\r\n const visResponse = componentInLayout.visualResponses[visualResponseKey];\r\n if (visResponse.valueNodeProperty === \"transform\") {\r\n this._buttonMeshMapping[type].states[visualResponseKey] = {\r\n valueMesh: this._getChildByName(this.rootMesh!, visResponse.valueNodeName!),\r\n minMesh: this._getChildByName(this.rootMesh!, visResponse.minNodeName!),\r\n maxMesh: this._getChildByName(this.rootMesh!, visResponse.maxNodeName!),\r\n };\r\n } else {\r\n // visibility, usually for touchpads\r\n const nameOfMesh =\r\n componentInLayout.type === WebXRControllerComponent.TOUCHPAD_TYPE && componentInLayout.touchPointNodeName\r\n ? componentInLayout.touchPointNodeName\r\n : visResponse.valueNodeName!;\r\n this._buttonMeshMapping[type].states[visualResponseKey] = {\r\n valueMesh: this._getChildByName(this.rootMesh!, nameOfMesh),\r\n };\r\n if (componentInLayout.type === WebXRControllerComponent.TOUCHPAD_TYPE && !this._touchDots[visualResponseKey]) {\r\n const dot = CreateSphere(\r\n visualResponseKey + \"dot\",\r\n {\r\n diameter: 0.0015,\r\n segments: 8,\r\n },\r\n this.scene\r\n );\r\n dot.material = new StandardMaterial(visualResponseKey + \"mat\", this.scene);\r\n (<StandardMaterial>dot.material).diffuseColor = Color3.Red();\r\n dot.parent = this._buttonMeshMapping[type].states[visualResponseKey].valueMesh || null;\r\n dot.isVisible = false;\r\n this._touchDots[visualResponseKey] = dot;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected _setRootMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \"-\" + this.handedness, this.scene);\r\n this.rootMesh.isPickable = false;\r\n let rootMesh;\r\n // Find the root node in the loaded glTF scene, and attach it as a child of 'parentMesh'\r\n for (let i = 0; i < meshes.length; i++) {\r\n const mesh = meshes[i];\r\n\r\n mesh.isPickable = false;\r\n\r\n if (!mesh.parent) {\r\n // Handle root node, attach to the new parentMesh\r\n rootMesh = mesh;\r\n }\r\n }\r\n\r\n if (rootMesh) {\r\n rootMesh.setParent(this.rootMesh);\r\n }\r\n if (!this.scene.useRightHandedSystem) {\r\n this.rootMesh.rotate(Axis.Y, Math.PI, Space.WORLD);\r\n }\r\n }\r\n\r\n protected _updateModel(_xrFrame: XRFrame): void {\r\n if (this.disableAnimation) {\r\n return;\r\n }\r\n const ids = this.getComponentIds();\r\n\r\n for (const id of ids) {\r\n const component = this.getComponent(id);\r\n if (!component.hasChanges) {\r\n return;\r\n }\r\n const meshes = this._buttonMeshMapping[id];\r\n const componentInLayout = this.layout.components[id];\r\n const keys = Object.keys(componentInLayout.visualResponses);\r\n for (const visualResponseKey of keys) {\r\n const visResponse = componentInLayout.visualResponses[visualResponseKey];\r\n let value = component.value;\r\n if (visResponse.componentProperty === \"xAxis\") {\r\n value = component.axes.x;\r\n } else if (visResponse.componentProperty === \"yAxis\") {\r\n value = component.axes.y;\r\n }\r\n if (visResponse.valueNodeProperty === \"transform\") {\r\n this._lerpTransform(meshes.states[visualResponseKey], value, visResponse.componentProperty !== \"button\");\r\n } else {\r\n // visibility\r\n const valueMesh = meshes.states[visualResponseKey].valueMesh;\r\n if (valueMesh) {\r\n valueMesh.isVisible = component.touched || component.pressed;\r\n }\r\n if (this._touchDots[visualResponseKey]) {\r\n this._touchDots[visualResponseKey].isVisible = component.touched || component.pressed;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"webXRProfiledMotionController.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/motionController/webXRProfiledMotionController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAS,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;GAGG;AACH,MAAM,OAAO,6BAA8B,SAAQ,6BAA6B;IAgB5E,YACI,KAAY,EACZ,OAAsB,EACtB,QAAkC,EAC1B,cAAsB;IAC9B,gEAAgE;IACxD,eAIN;QAEF,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,IAAI,MAAM,CAAC,EAAE,OAAO,CAAC,OAAc,EAAE,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;QAR7H,mBAAc,GAAd,cAAc,CAAQ;QAEtB,oBAAe,GAAf,eAAe,CAIrB;QAzBE,uBAAkB,GAOtB,EAAE,CAAC;QACC,eAAU,GAAuC,EAAE,CAAC;QAoBxD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;IACxC,CAAC;IAEe,OAAO;QACnB,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,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AS,EAAE,CAAC;wBACZ,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC;oBACjE,CAAC;oBACD,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,CAAC;wBACrC,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC;oBAC1F,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;CACJ","sourcesContent":["import type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { IMotionControllerProfile, IMotionControllerMeshMap } from \"./webXRAbstractMotionController\";\r\nimport { WebXRAbstractMotionController } from \"./webXRAbstractMotionController\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { SceneLoader } from \"../../Loading/sceneLoader\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\nimport { Axis, Space } from \"../../Maths/math.axis\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport { WebXRControllerComponent } from \"./webXRControllerComponent\";\r\nimport { CreateSphere } from \"../../Meshes/Builders/sphereBuilder\";\r\nimport { StandardMaterial } from \"../../Materials/standardMaterial\";\r\nimport { Logger } from \"../../Misc/logger\";\r\n\r\n/**\r\n * A profiled motion controller has its profile loaded from an online repository.\r\n * The class is responsible of loading the model, mapping the keys and enabling model-animations\r\n */\r\nexport class WebXRProfiledMotionController extends WebXRAbstractMotionController {\r\n private _buttonMeshMapping: {\r\n [buttonName: string]: {\r\n mainMesh?: AbstractMesh;\r\n states: {\r\n [state: string]: IMotionControllerMeshMap;\r\n };\r\n };\r\n } = {};\r\n private _touchDots: { [visKey: string]: AbstractMesh } = {};\r\n\r\n /**\r\n * The profile ID of this controller. Will be populated when the controller initializes.\r\n */\r\n public profileId: string;\r\n\r\n constructor(\r\n scene: Scene,\r\n xrInput: XRInputSource,\r\n _profile: IMotionControllerProfile,\r\n private _repositoryUrl: string,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n private controllerCache?: Array<{\r\n filename: string;\r\n path: string;\r\n meshes: AbstractMesh[];\r\n }>\r\n ) {\r\n super(scene, _profile.layouts[xrInput.handedness || \"none\"], xrInput.gamepad as any, xrInput.handedness, undefined, controllerCache);\r\n this.profileId = _profile.profileId;\r\n }\r\n\r\n public override dispose() {\r\n super.dispose();\r\n if (!this.controllerCache) {\r\n const keys = Object.keys(this._touchDots);\r\n for (const visResKey of keys) {\r\n this._touchDots[visResKey].dispose();\r\n }\r\n }\r\n }\r\n\r\n protected _getFilenameAndPath(): { filename: string; path: string } {\r\n return {\r\n filename: this.layout.assetPath,\r\n path: `${this._repositoryUrl}/profiles/${this.profileId}/`,\r\n };\r\n }\r\n\r\n protected _getModelLoadingConstraints(): boolean {\r\n const glbLoaded = SceneLoader.IsPluginForExtensionAvailable(\".glb\");\r\n if (!glbLoaded) {\r\n Logger.Warn(\"glTF / glb loader was not registered, using generic controller instead\");\r\n }\r\n return glbLoaded;\r\n }\r\n\r\n protected _processLoadedModel(_meshes: AbstractMesh[]): void {\r\n const ids = this.getComponentIds();\r\n\r\n for (const type of ids) {\r\n const componentInLayout = this.layout.components[type];\r\n this._buttonMeshMapping[type] = {\r\n mainMesh: this._getChildByName(this.rootMesh!, componentInLayout.rootNodeName),\r\n states: {},\r\n };\r\n const keys = Object.keys(componentInLayout.visualResponses);\r\n for (const visualResponseKey of keys) {\r\n const visResponse = componentInLayout.visualResponses[visualResponseKey];\r\n if (visResponse.valueNodeProperty === \"transform\") {\r\n this._buttonMeshMapping[type].states[visualResponseKey] = {\r\n valueMesh: this._getChildByName(this.rootMesh!, visResponse.valueNodeName!),\r\n minMesh: this._getChildByName(this.rootMesh!, visResponse.minNodeName!),\r\n maxMesh: this._getChildByName(this.rootMesh!, visResponse.maxNodeName!),\r\n };\r\n } else {\r\n // visibility, usually for touchpads\r\n const nameOfMesh =\r\n componentInLayout.type === WebXRControllerComponent.TOUCHPAD_TYPE && componentInLayout.touchPointNodeName\r\n ? componentInLayout.touchPointNodeName\r\n : visResponse.valueNodeName!;\r\n this._buttonMeshMapping[type].states[visualResponseKey] = {\r\n valueMesh: this._getChildByName(this.rootMesh!, nameOfMesh),\r\n };\r\n if (componentInLayout.type === WebXRControllerComponent.TOUCHPAD_TYPE && !this._touchDots[visualResponseKey]) {\r\n const dot = CreateSphere(\r\n visualResponseKey + \"dot\",\r\n {\r\n diameter: 0.0015,\r\n segments: 8,\r\n },\r\n this.scene\r\n );\r\n dot.material = new StandardMaterial(visualResponseKey + \"mat\", this.scene);\r\n (<StandardMaterial>dot.material).diffuseColor = Color3.Red();\r\n dot.parent = this._buttonMeshMapping[type].states[visualResponseKey].valueMesh || null;\r\n dot.isVisible = false;\r\n this._touchDots[visualResponseKey] = dot;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected _setRootMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \"-\" + this.handedness, this.scene);\r\n this.rootMesh.isPickable = false;\r\n let rootMesh;\r\n // Find the root node in the loaded glTF scene, and attach it as a child of 'parentMesh'\r\n for (let i = 0; i < meshes.length; i++) {\r\n const mesh = meshes[i];\r\n\r\n mesh.isPickable = false;\r\n\r\n if (!mesh.parent) {\r\n // Handle root node, attach to the new parentMesh\r\n rootMesh = mesh;\r\n }\r\n }\r\n\r\n if (rootMesh) {\r\n rootMesh.setParent(this.rootMesh);\r\n }\r\n if (!this.scene.useRightHandedSystem) {\r\n this.rootMesh.rotate(Axis.Y, Math.PI, Space.WORLD);\r\n }\r\n }\r\n\r\n protected _updateModel(_xrFrame: XRFrame): void {\r\n if (this.disableAnimation) {\r\n return;\r\n }\r\n const ids = this.getComponentIds();\r\n\r\n for (const id of ids) {\r\n const component = this.getComponent(id);\r\n if (!component.hasChanges) {\r\n continue;\r\n }\r\n const meshes = this._buttonMeshMapping[id];\r\n const componentInLayout = this.layout.components[id];\r\n const keys = Object.keys(componentInLayout.visualResponses);\r\n for (const visualResponseKey of keys) {\r\n const visResponse = componentInLayout.visualResponses[visualResponseKey];\r\n let value = component.value;\r\n if (visResponse.componentProperty === \"xAxis\") {\r\n value = component.axes.x;\r\n } else if (visResponse.componentProperty === \"yAxis\") {\r\n value = component.axes.y;\r\n }\r\n if (visResponse.valueNodeProperty === \"transform\") {\r\n this._lerpTransform(meshes.states[visualResponseKey], value, visResponse.componentProperty !== \"button\");\r\n } else {\r\n // visibility\r\n const valueMesh = meshes.states[visualResponseKey].valueMesh;\r\n if (valueMesh) {\r\n valueMesh.isVisible = component.touched || component.pressed;\r\n }\r\n if (this._touchDots[visualResponseKey]) {\r\n this._touchDots[visualResponseKey].isVisible = component.touched || component.pressed;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -62,5 +62,6 @@ export class NativeXRFrame {
|
|
|
62
62
|
// return this._nativeImpl.getDepthInformation(view);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
65
66
|
RegisterNativeTypeAsync("NativeXRFrame", NativeXRFrame);
|
|
66
67
|
//# sourceMappingURL=nativeXRFrame.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeXRFrame.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/native/nativeXRFrame.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AASrE,gBAAgB;AAChB,MAAM,OAAO,aAAa;IAStB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;IACpC,CAAC;IAED,YAAoB,WAA2B;QAA3B,gBAAW,GAAX,WAAW,CAAgB;QAZ9B,iBAAY,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACtC,YAAO,GAAW;YAC/B,SAAS,EAAE,IAAI,CAAC,YAAY;YAC5B,gBAAgB,EAAE,KAAK;SAC1B,C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zD,CAAC;CACJ;AAED,uBAAuB,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import { RegisterNativeTypeAsync } from \"../../Engines/nativeEngine\";\r\n\r\n/** @internal */\r\ninterface INativeXRFrame extends XRFrame {\r\n // Native-only helper functions\r\n getPoseData: (space: XRSpace, baseSpace: XRReferenceSpace, vectorBuffer: ArrayBuffer, matrixBuffer: ArrayBuffer) => XRPose;\r\n _imageTrackingResults?: XRImageTrackingResult[];\r\n}\r\n\r\n/** @internal */\r\nexport class NativeXRFrame implements XRFrame {\r\n private readonly _xrTransform = new XRRigidTransform();\r\n private readonly _xrPose: XRPose = {\r\n transform: this._xrTransform,\r\n emulatedPosition: false,\r\n };\r\n // Enough space for position, orientation\r\n private readonly _xrPoseVectorData = new Float32Array(4 + 4);\r\n\r\n public get session(): XRSession {\r\n return this._nativeImpl.session;\r\n }\r\n\r\n constructor(private _nativeImpl: INativeXRFrame) {}\r\n\r\n public getPose(space: XRSpace, baseSpace: XRReferenceSpace): XRPose | undefined {\r\n if (!this._nativeImpl.getPoseData(space, baseSpace, this._xrPoseVectorData.buffer, this._xrTransform.matrix.buffer)) {\r\n return undefined;\r\n }\r\n const position = this._xrTransform.position as DOMPoint;\r\n position.x = this._xrPoseVectorData[0];\r\n position.y = this._xrPoseVectorData[1];\r\n position.z = this._xrPoseVectorData[2];\r\n position.w = this._xrPoseVectorData[3];\r\n\r\n const orientation = this._xrTransform.orientation as DOMPoint;\r\n orientation.x = this._xrPoseVectorData[4];\r\n orientation.y = this._xrPoseVectorData[5];\r\n orientation.z = this._xrPoseVectorData[6];\r\n orientation.w = this._xrPoseVectorData[7];\r\n return this._xrPose;\r\n }\r\n\r\n public readonly fillPoses = this._nativeImpl.fillPoses!.bind(this._nativeImpl);\r\n\r\n public readonly getViewerPose = this._nativeImpl.getViewerPose.bind(this._nativeImpl);\r\n\r\n public readonly getHitTestResults = this._nativeImpl.getHitTestResults.bind(this._nativeImpl);\r\n\r\n public readonly getHitTestResultsForTransientInput = () => {\r\n throw new Error(\"XRFrame.getHitTestResultsForTransientInput not supported on native.\");\r\n };\r\n\r\n public get trackedAnchors(): XRAnchorSet | undefined {\r\n return this._nativeImpl.trackedAnchors;\r\n }\r\n\r\n public readonly createAnchor = this._nativeImpl.createAnchor!.bind(this._nativeImpl);\r\n\r\n public get worldInformation(): XRWorldInformation | undefined {\r\n return this._nativeImpl.worldInformation;\r\n }\r\n\r\n public get detectedPlanes(): XRPlaneSet | undefined {\r\n return this._nativeImpl.detectedPlanes;\r\n }\r\n\r\n public readonly getJointPose = this._nativeImpl.getJointPose!.bind(this._nativeImpl);\r\n\r\n public readonly fillJointRadii = this._nativeImpl.fillJointRadii!.bind(this._nativeImpl);\r\n\r\n public readonly getLightEstimate = () => {\r\n throw new Error(\"XRFrame.getLightEstimate not supported on native.\");\r\n };\r\n\r\n public get featurePointCloud(): number[] | undefined {\r\n return this._nativeImpl.featurePointCloud;\r\n }\r\n\r\n public readonly getImageTrackingResults = (): XRImageTrackingResult[] => {\r\n return this._nativeImpl._imageTrackingResults ?? [];\r\n };\r\n\r\n public getDepthInformation(view: XRView): XRCPUDepthInformation | undefined {\r\n throw new Error(\"This function is not available in Babylon Native\");\r\n // return this._nativeImpl.getDepthInformation(view);\r\n }\r\n}\r\n\r\nRegisterNativeTypeAsync(\"NativeXRFrame\", NativeXRFrame);\r\n"]}
|
|
1
|
+
{"version":3,"file":"nativeXRFrame.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/native/nativeXRFrame.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AASrE,gBAAgB;AAChB,MAAM,OAAO,aAAa;IAStB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;IACpC,CAAC;IAED,YAAoB,WAA2B;QAA3B,gBAAW,GAAX,WAAW,CAAgB;QAZ9B,iBAAY,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACtC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BAAmB,CAAC,IAAY;QACnC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACpE,qDAAqD;IACzD,CAAC;CACJ;AAED,mEAAmE;AACnE,uBAAuB,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import { RegisterNativeTypeAsync } from \"../../Engines/nativeEngine\";\r\n\r\n/** @internal */\r\ninterface INativeXRFrame extends XRFrame {\r\n // Native-only helper functions\r\n getPoseData: (space: XRSpace, baseSpace: XRReferenceSpace, vectorBuffer: ArrayBuffer, matrixBuffer: ArrayBuffer) => XRPose;\r\n _imageTrackingResults?: XRImageTrackingResult[];\r\n}\r\n\r\n/** @internal */\r\nexport class NativeXRFrame implements XRFrame {\r\n private readonly _xrTransform = new XRRigidTransform();\r\n private readonly _xrPose: XRPose = {\r\n transform: this._xrTransform,\r\n emulatedPosition: false,\r\n };\r\n // Enough space for position, orientation\r\n private readonly _xrPoseVectorData = new Float32Array(4 + 4);\r\n\r\n public get session(): XRSession {\r\n return this._nativeImpl.session;\r\n }\r\n\r\n constructor(private _nativeImpl: INativeXRFrame) {}\r\n\r\n public getPose(space: XRSpace, baseSpace: XRReferenceSpace): XRPose | undefined {\r\n if (!this._nativeImpl.getPoseData(space, baseSpace, this._xrPoseVectorData.buffer, this._xrTransform.matrix.buffer)) {\r\n return undefined;\r\n }\r\n const position = this._xrTransform.position as DOMPoint;\r\n position.x = this._xrPoseVectorData[0];\r\n position.y = this._xrPoseVectorData[1];\r\n position.z = this._xrPoseVectorData[2];\r\n position.w = this._xrPoseVectorData[3];\r\n\r\n const orientation = this._xrTransform.orientation as DOMPoint;\r\n orientation.x = this._xrPoseVectorData[4];\r\n orientation.y = this._xrPoseVectorData[5];\r\n orientation.z = this._xrPoseVectorData[6];\r\n orientation.w = this._xrPoseVectorData[7];\r\n return this._xrPose;\r\n }\r\n\r\n public readonly fillPoses = this._nativeImpl.fillPoses!.bind(this._nativeImpl);\r\n\r\n public readonly getViewerPose = this._nativeImpl.getViewerPose.bind(this._nativeImpl);\r\n\r\n public readonly getHitTestResults = this._nativeImpl.getHitTestResults.bind(this._nativeImpl);\r\n\r\n public readonly getHitTestResultsForTransientInput = () => {\r\n throw new Error(\"XRFrame.getHitTestResultsForTransientInput not supported on native.\");\r\n };\r\n\r\n public get trackedAnchors(): XRAnchorSet | undefined {\r\n return this._nativeImpl.trackedAnchors;\r\n }\r\n\r\n public readonly createAnchor = this._nativeImpl.createAnchor!.bind(this._nativeImpl);\r\n\r\n public get worldInformation(): XRWorldInformation | undefined {\r\n return this._nativeImpl.worldInformation;\r\n }\r\n\r\n public get detectedPlanes(): XRPlaneSet | undefined {\r\n return this._nativeImpl.detectedPlanes;\r\n }\r\n\r\n public readonly getJointPose = this._nativeImpl.getJointPose!.bind(this._nativeImpl);\r\n\r\n public readonly fillJointRadii = this._nativeImpl.fillJointRadii!.bind(this._nativeImpl);\r\n\r\n public readonly getLightEstimate = () => {\r\n throw new Error(\"XRFrame.getLightEstimate not supported on native.\");\r\n };\r\n\r\n public get featurePointCloud(): number[] | undefined {\r\n return this._nativeImpl.featurePointCloud;\r\n }\r\n\r\n public readonly getImageTrackingResults = (): XRImageTrackingResult[] => {\r\n return this._nativeImpl._imageTrackingResults ?? [];\r\n };\r\n\r\n public getDepthInformation(view: XRView): XRCPUDepthInformation | undefined {\r\n throw new Error(\"This function is not available in Babylon Native\");\r\n // return this._nativeImpl.getDepthInformation(view);\r\n }\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-floating-promises\r\nRegisterNativeTypeAsync(\"NativeXRFrame\", NativeXRFrame);\r\n"]}
|
|
@@ -43,14 +43,17 @@ export class WebXRDefaultExperience {
|
|
|
43
43
|
}
|
|
44
44
|
result.enterExitUI = new WebXREnterExitUI(scene, uiOptions);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
try {
|
|
47
|
+
// Create base experience
|
|
48
|
+
const xrHelper = await WebXRExperienceHelper.CreateAsync(scene);
|
|
49
|
+
// eslint-disable-next-line require-atomic-updates
|
|
49
50
|
result.baseExperience = xrHelper;
|
|
50
51
|
if (options.ignoreNativeCameraTransformation) {
|
|
52
|
+
// eslint-disable-next-line require-atomic-updates
|
|
51
53
|
result.baseExperience.camera.compensateOnFirstFrame = false;
|
|
52
54
|
}
|
|
53
55
|
// Add controller support
|
|
56
|
+
// eslint-disable-next-line require-atomic-updates
|
|
54
57
|
result.input = new WebXRInput(xrHelper.sessionManager, xrHelper.camera, {
|
|
55
58
|
controllerOptions: {
|
|
56
59
|
renderingGroupId: options.renderingGroupId,
|
|
@@ -98,20 +101,15 @@ export class WebXRDefaultExperience {
|
|
|
98
101
|
result.renderTarget = result.baseExperience.sessionManager.getWebXRRenderTarget(options.outputCanvasOptions);
|
|
99
102
|
if (!options.disableDefaultUI) {
|
|
100
103
|
// Create ui for entering/exiting xr
|
|
101
|
-
|
|
104
|
+
await result.enterExitUI.setHelperAsync(result.baseExperience, result.renderTarget);
|
|
102
105
|
}
|
|
103
|
-
else {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
.then(() => {
|
|
108
106
|
return result;
|
|
109
|
-
}
|
|
110
|
-
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
111
109
|
Logger.Error("Error initializing XR");
|
|
112
110
|
Logger.Error(error);
|
|
113
111
|
return result;
|
|
114
|
-
}
|
|
112
|
+
}
|
|
115
113
|
}
|
|
116
114
|
/**
|
|
117
115
|
* Disposes of the experience helper
|
|
@@ -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,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AC;YAE7G,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;gBAC5B,oCAAoC;gBACpC,OAAO,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;YACzF,CAAC;iBAAM,CAAC;gBACJ,OAAO;YACX,CAAC;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,CAAC;YACtB,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAClC,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QAC/B,CAAC;QACD,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;QAChC,CAAC;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 async 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(async (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"]}
|
|
1
|
+
{"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CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EACnB;oBACvB,OAAO,EAAE,MAAM,CAAC,KAAK;oBACrB,GAAG,OAAO,CAAC,kBAAkB;iBAChC,EACD,SAAS,EACT,KAAK,CACR,CAAC;YACN,CAAC;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,CAAC;gBAC5B,oCAAoC;gBACpC,MAAM,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;YACxF,CAAC;YACD,OAAO,MAAM,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACtC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,MAAM,CAAC;QAClB,CAAC;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAClC,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QAC/B,CAAC;QACD,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;QAChC,CAAC;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 async 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 try {\r\n // Create base experience\r\n const xrHelper = await WebXRExperienceHelper.CreateAsync(scene);\r\n // eslint-disable-next-line require-atomic-updates\r\n result.baseExperience = xrHelper;\r\n\r\n if (options.ignoreNativeCameraTransformation) {\r\n // eslint-disable-next-line require-atomic-updates\r\n result.baseExperience.camera.compensateOnFirstFrame = false;\r\n }\r\n\r\n // Add controller support\r\n // eslint-disable-next-line require-atomic-updates\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 await result.enterExitUI.setHelperAsync(result.baseExperience, result.renderTarget);\r\n }\r\n return result;\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"]}
|
package/XR/webXREnterExitUI.js
CHANGED
|
@@ -74,6 +74,7 @@ export class WebXREnterExitUI {
|
|
|
74
74
|
// });
|
|
75
75
|
// } else
|
|
76
76
|
if (this._helper) {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
77
78
|
this._enterXRWithButtonIndexAsync(0);
|
|
78
79
|
}
|
|
79
80
|
};
|
|
@@ -138,7 +139,7 @@ export class WebXREnterExitUI {
|
|
|
138
139
|
this._helper = helper;
|
|
139
140
|
this._renderTarget = renderTarget;
|
|
140
141
|
const supportedPromises = this._buttons.map(async (btn) => {
|
|
141
|
-
return helper.sessionManager.isSessionSupportedAsync(btn.sessionMode);
|
|
142
|
+
return await helper.sessionManager.isSessionSupportedAsync(btn.sessionMode);
|
|
142
143
|
});
|
|
143
144
|
helper.onStateChangedObservable.add((state) => {
|
|
144
145
|
if (state == 3 /* WebXRState.NOT_IN_XR */) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXREnterExitUI.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXREnterExitUI.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAKhD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAC/B;;;;;OAKG;IACH;IACI,qBAAqB;IACd,OAAoB;IAC3B,+CAA+C;IACxC,WAA0B;IACjC,2BAA2B;IACpB,kBAAwC;QAJxC,YAAO,GAAP,OAAO,CAAa;QAEpB,gBAAW,GAAX,WAAW,CAAe;QAE1B,uBAAkB,GAAlB,kBAAk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AAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,eAAe,EAAE,CAAC;QAC/D,IAAI,YAAY,IAAI,YAAY,CAAC,UAAU,IAAI,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5F,YAAY,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,CAAC,6BAA6B,CAAC,KAAK,EAAE,CAAC;QAC1C,SAAiB,CAAC,EAAE,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACxF,CAAC;IAwBO,cAAc,CAAC,YAA8C;QACjE,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5B,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,6BAA6B,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC3E,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { WebXRExperienceHelper } from \"./webXRExperienceHelper\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport { WebXRState } from \"./webXRTypes\";\r\nimport { Tools } from \"../Misc/tools\";\r\n/**\r\n * Button which can be used to enter a different mode of XR\r\n */\r\nexport class WebXREnterExitUIButton {\r\n /**\r\n * Creates a WebXREnterExitUIButton\r\n * @param element button element\r\n * @param sessionMode XR initialization session mode\r\n * @param referenceSpaceType the type of reference space to be used\r\n */\r\n constructor(\r\n /** button element */\r\n public element: HTMLElement,\r\n /** XR initialization options for the button */\r\n public sessionMode: XRSessionMode,\r\n /** Reference space type */\r\n public referenceSpaceType: XRReferenceSpaceType\r\n ) {}\r\n\r\n /**\r\n * Extendable function which can be used to update the button's visuals when the state changes\r\n * @param activeButton the current active button in the UI\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public update(activeButton: Nullable<WebXREnterExitUIButton>) {}\r\n}\r\n\r\n/**\r\n * Options to create the webXR UI\r\n */\r\nexport class WebXREnterExitUIOptions {\r\n /**\r\n * User provided buttons to enable/disable WebXR. The system will provide default if not set\r\n */\r\n customButtons?: Array<WebXREnterExitUIButton>;\r\n /**\r\n * A reference space type to use when creating the default button.\r\n * Default is local-floor\r\n */\r\n referenceSpaceType?: XRReferenceSpaceType;\r\n /**\r\n * Context to enter xr with\r\n */\r\n renderTarget?: Nullable<WebXRRenderTarget>;\r\n /**\r\n * A session mode to use when creating the default button.\r\n * Default is immersive-vr\r\n */\r\n sessionMode?: XRSessionMode;\r\n\r\n /**\r\n * A list of optional features to init the session with\r\n */\r\n optionalFeatures?: string[];\r\n\r\n /**\r\n * A list of optional features to init the session with\r\n */\r\n requiredFeatures?: string[];\r\n\r\n /**\r\n * If set, the `sessiongranted` event will not be registered. `sessiongranted` is used to move seamlessly between WebXR experiences.\r\n * If set to true the user will be forced to press the \"enter XR\" button even if sessiongranted event was triggered.\r\n * If not set and a sessiongranted event was triggered, the XR session will start automatically.\r\n */\r\n ignoreSessionGrantedEvent?: boolean;\r\n\r\n /**\r\n * If defined, this function will be executed if the UI encounters an error when entering XR\r\n */\r\n onError?: (error: any) => void;\r\n}\r\n/**\r\n * UI to allow the user to enter/exit XR mode\r\n */\r\nexport class WebXREnterExitUI implements IDisposable {\r\n private _activeButton: Nullable<WebXREnterExitUIButton> = null;\r\n private _buttons: Array<WebXREnterExitUIButton> = [];\r\n private _helper: WebXRExperienceHelper;\r\n private _renderTarget?: WebXRRenderTarget;\r\n /**\r\n * The HTML Div Element to which buttons are added.\r\n */\r\n public readonly overlay: HTMLDivElement;\r\n\r\n /**\r\n * Fired every time the active button is changed.\r\n *\r\n * When xr is entered via a button that launches xr that button will be the callback parameter\r\n *\r\n * When exiting xr the callback parameter will be null)\r\n */\r\n public activeButtonChangedObservable = new Observable<Nullable<WebXREnterExitUIButton>>();\r\n\r\n /**\r\n * Construct a new EnterExit UI class\r\n *\r\n * @param _scene babylon scene object to use\r\n * @param options (read-only) version of the options passed to this UI\r\n */\r\n public constructor(\r\n private _scene: Scene,\r\n /** version of the options passed to this UI */\r\n public options: WebXREnterExitUIOptions\r\n ) {\r\n this.overlay = document.createElement(\"div\");\r\n this.overlay.classList.add(\"xr-button-overlay\");\r\n\r\n // prepare for session granted event\r\n if (!options.ignoreSessionGrantedEvent && (navigator as any).xr) {\r\n (navigator as any).xr.addEventListener(\"sessiongranted\", this._onSessionGranted);\r\n }\r\n\r\n // if served over HTTP, warn people.\r\n // Hopefully the browsers will catch up\r\n if (typeof window !== \"undefined\") {\r\n if (window.location && window.location.protocol === \"http:\" && window.location.hostname !== \"localhost\") {\r\n Tools.Warn(\"WebXR can only be served over HTTPS\");\r\n throw new Error(\"WebXR can only be served over HTTPS\");\r\n }\r\n }\r\n\r\n if (options.customButtons) {\r\n this._buttons = options.customButtons;\r\n } else {\r\n this.overlay.style.cssText = \"z-index:11;position: absolute; right: 20px;bottom: 50px;\";\r\n const sessionMode = options.sessionMode || \"immersive-vr\";\r\n const referenceSpaceType = options.referenceSpaceType || \"local-floor\";\r\n const url =\r\n typeof SVGSVGElement === \"undefined\"\r\n ? \"https://cdn.babylonjs.com/Assets/vrButton.png\"\r\n : \"data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%222048%22%20height%3D%221152%22%20viewBox%3D%220%200%202048%201152%22%20version%3D%221.1%22%3E%3Cpath%20transform%3D%22rotate%28180%201024%2C576.0000000000001%29%22%20d%3D%22m1109%2C896q17%2C0%2030%2C-12t13%2C-30t-12.5%2C-30.5t-30.5%2C-12.5l-170%2C0q-18%2C0%20-30.5%2C12.5t-12.5%2C30.5t13%2C30t30%2C12l170%2C0zm-85%2C256q59%2C0%20132.5%2C-1.5t154.5%2C-5.5t164.5%2C-11.5t163%2C-20t150%2C-30t124.5%2C-41.5q23%2C-11%2042%2C-24t38%2C-30q27%2C-25%2041%2C-61.5t14%2C-72.5l0%2C-257q0%2C-123%20-47%2C-232t-128%2C-190t-190%2C-128t-232%2C-47l-81%2C0q-37%2C0%20-68.5%2C14t-60.5%2C34.5t-55.5%2C45t-53%2C45t-53%2C34.5t-55.5%2C14t-55.5%2C-14t-53%2C-34.5t-53%2C-45t-55.5%2C-45t-60.5%2C-34.5t-68.5%2C-14l-81%2C0q-123%2C0%20-232%2C47t-190%2C128t-128%2C190t-47%2C232l0%2C257q0%2C68%2038%2C115t97%2C73q54%2C24%20124.5%2C41.5t150%2C30t163%2C20t164.5%2C11.5t154.5%2C5.5t132.5%2C1.5zm939%2C-298q0%2C39%20-24.5%2C67t-58.5%2C42q-54%2C23%20-122%2C39.5t-143.5%2C28t-155.5%2C19t-157%2C11t-148.5%2C5t-129.5%2C1.5q-59%2C0%20-130%2C-1.5t-148%2C-5t-157%2C-11t-155.5%2C-19t-143.5%2C-28t-122%2C-39.5q-34%2C-14%20-58.5%2C-42t-24.5%2C-67l0%2C-257q0%2C-106%2040.5%2C-199t110%2C-162.5t162.5%2C-109.5t199%2C-40l81%2C0q27%2C0%2052%2C14t50%2C34.5t51%2C44.5t55.5%2C44.5t63.5%2C34.5t74%2C14t74%2C-14t63.5%2C-34.5t55.5%2C-44.5t51%2C-44.5t50%2C-34.5t52%2C-14l14%2C0q37%2C0%2070%2C0.5t64.5%2C4.5t63.5%2C12t68%2C23q71%2C30%20128.5%2C78.5t98.5%2C110t63.5%2C133.5t22.5%2C149l0%2C257z%22%20fill%3D%22white%22%20/%3E%3C/svg%3E%0A\";\r\n let css =\r\n \".babylonVRicon { color: #868686; border-color: #868686; border-style: solid; margin-left: 10px; height: 50px; width: 80px; background-color: rgba(51,51,51,0.7); background-image: url(\" +\r\n url +\r\n \"); background-size: 80%; background-repeat:no-repeat; background-position: center; border: none; outline: none; transition: transform 0.125s ease-out } .babylonVRicon:hover { transform: scale(1.05) } .babylonVRicon:active {background-color: rgba(51,51,51,1) } .babylonVRicon:focus {background-color: rgba(51,51,51,1) }\";\r\n css += '.babylonVRicon.vrdisplaypresenting { background-image: none;} .vrdisplaypresenting::after { content: \"EXIT\"} .xr-error::after { content: \"ERROR\"}';\r\n\r\n const style = document.createElement(\"style\");\r\n style.appendChild(document.createTextNode(css));\r\n document.getElementsByTagName(\"head\")[0].appendChild(style);\r\n const hmdBtn = document.createElement(\"button\");\r\n hmdBtn.className = \"babylonVRicon\";\r\n hmdBtn.title = `${sessionMode} - ${referenceSpaceType}`;\r\n this._buttons.push(new WebXREnterExitUIButton(hmdBtn, sessionMode, referenceSpaceType));\r\n this._buttons[this._buttons.length - 1].update = function (activeButton: WebXREnterExitUIButton) {\r\n this.element.style.display = activeButton === null || activeButton === this ? \"\" : \"none\";\r\n hmdBtn.className = \"babylonVRicon\" + (activeButton === this ? \" vrdisplaypresenting\" : \"\");\r\n };\r\n this._updateButtons(null);\r\n }\r\n\r\n const renderCanvas = _scene.getEngine().getInputElement();\r\n if (renderCanvas && renderCanvas.parentNode) {\r\n renderCanvas.parentNode.appendChild(this.overlay);\r\n _scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Set the helper to be used with this UI component.\r\n * The UI is bound to an experience helper. If not provided the UI can still be used but the events should be registered by the developer.\r\n *\r\n * @param helper the experience helper to attach\r\n * @param renderTarget an optional render target (in case it is created outside of the helper scope)\r\n * @returns a promise that resolves when the ui is ready\r\n */\r\n public async setHelperAsync(helper: WebXRExperienceHelper, renderTarget?: WebXRRenderTarget): Promise<void> {\r\n this._helper = helper;\r\n this._renderTarget = renderTarget;\r\n const supportedPromises = this._buttons.map(async (btn) => {\r\n return helper.sessionManager.isSessionSupportedAsync(btn.sessionMode);\r\n });\r\n helper.onStateChangedObservable.add((state) => {\r\n if (state == WebXRState.NOT_IN_XR) {\r\n this._updateButtons(null);\r\n }\r\n });\r\n const results = await Promise.all(supportedPromises);\r\n for (let i = 0; i < results.length; i++) {\r\n const supported = results[i];\r\n if (supported) {\r\n this.overlay.appendChild(this._buttons[i].element);\r\n this._buttons[i].element.onclick = this._enterXRWithButtonIndexAsync.bind(this, i);\r\n } else {\r\n Tools.Warn(`Session mode \"${this._buttons[i].sessionMode}\" not supported in browser`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Creates UI to allow the user to enter/exit XR mode\r\n * @param scene the scene to add the ui to\r\n * @param helper the xr experience helper to enter/exit xr with\r\n * @param options options to configure the UI\r\n * @returns the created ui\r\n */\r\n public static async CreateAsync(scene: Scene, helper: WebXRExperienceHelper, options: WebXREnterExitUIOptions): Promise<WebXREnterExitUI> {\r\n const ui = new WebXREnterExitUI(scene, options);\r\n await ui.setHelperAsync(helper, options.renderTarget || undefined);\r\n return ui;\r\n }\r\n\r\n private async _enterXRWithButtonIndexAsync(idx: number = 0) {\r\n if (this._helper.state == WebXRState.IN_XR) {\r\n await this._helper.exitXRAsync();\r\n this._updateButtons(null);\r\n } else if (this._helper.state == WebXRState.NOT_IN_XR) {\r\n try {\r\n await this._helper.enterXRAsync(this._buttons[idx].sessionMode, this._buttons[idx].referenceSpaceType, this._renderTarget, {\r\n optionalFeatures: this.options.optionalFeatures,\r\n requiredFeatures: this.options.requiredFeatures,\r\n });\r\n this._updateButtons(this._buttons[idx]);\r\n } catch (e) {\r\n // make sure button is visible\r\n this._updateButtons(null);\r\n const element = this._buttons[idx].element;\r\n const prevTitle = element.title;\r\n element.title = \"Error entering XR session : \" + prevTitle;\r\n element.classList.add(\"xr-error\");\r\n if (this.options.onError) {\r\n this.options.onError(e);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the XR UI component\r\n */\r\n public dispose() {\r\n const renderCanvas = this._scene.getEngine().getInputElement();\r\n if (renderCanvas && renderCanvas.parentNode && renderCanvas.parentNode.contains(this.overlay)) {\r\n renderCanvas.parentNode.removeChild(this.overlay);\r\n }\r\n this.activeButtonChangedObservable.clear();\r\n (navigator as any).xr.removeEventListener(\"sessiongranted\", this._onSessionGranted);\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _onSessionGranted = (evt: { session: XRSession }) => {\r\n // This section is for future reference.\r\n // As per specs, evt.session.mode should have the supported session mode, but no browser supports it for now.\r\n\r\n // // check if the session granted is the same as the one requested\r\n // const grantedMode = (evt.session as any).mode;\r\n // if (grantedMode) {\r\n // this._buttons.some((btn, idx) => {\r\n // if (btn.sessionMode === grantedMode) {\r\n // this._enterXRWithButtonIndex(idx);\r\n // return true;\r\n // }\r\n // return false;\r\n // });\r\n // } else\r\n\r\n if (this._helper) {\r\n this._enterXRWithButtonIndexAsync(0);\r\n }\r\n };\r\n\r\n private _updateButtons(activeButton: Nullable<WebXREnterExitUIButton>) {\r\n this._activeButton = activeButton;\r\n for (const b of this._buttons) {\r\n b.update(this._activeButton);\r\n }\r\n this.activeButtonChangedObservable.notifyObservers(this._activeButton);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"webXREnterExitUI.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXREnterExitUI.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAKhD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAC/B;;;;;OAKG;IACH;IACI,qBAAqB;IACd,OAAoB;IAC3B,+CAA+C;IACxC,WAA0B;IACjC,2BAA2B;IACpB,kBAAwC;QAJxC,YAAO,GAAP,OAAO,CAAa;QAEpB,gBAAW,GAAX,WAAW,CAAe;QAE1B,uBAAkB,GAAlB,kBAAkB,CAAsB;IAChD,CAAC;IAEJ;;;OAGG;IACH,6DAA6D;IACtD,MAAM,CAAC,YAA8C,IAAG,CAA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,IAAI,YAAY,IAAI,YAAY,CAAC,UAAU,IAAI,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5F,YAAY,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,CAAC,6BAA6B,CAAC,KAAK,EAAE,CAAC;QAC1C,SAAiB,CAAC,EAAE,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACxF,CAAC;IAyBO,cAAc,CAAC,YAA8C;QACjE,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5B,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,6BAA6B,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC3E,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { WebXRExperienceHelper } from \"./webXRExperienceHelper\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport { WebXRState } from \"./webXRTypes\";\r\nimport { Tools } from \"../Misc/tools\";\r\n/**\r\n * Button which can be used to enter a different mode of XR\r\n */\r\nexport class WebXREnterExitUIButton {\r\n /**\r\n * Creates a WebXREnterExitUIButton\r\n * @param element button element\r\n * @param sessionMode XR initialization session mode\r\n * @param referenceSpaceType the type of reference space to be used\r\n */\r\n constructor(\r\n /** button element */\r\n public element: HTMLElement,\r\n /** XR initialization options for the button */\r\n public sessionMode: XRSessionMode,\r\n /** Reference space type */\r\n public referenceSpaceType: XRReferenceSpaceType\r\n ) {}\r\n\r\n /**\r\n * Extendable function which can be used to update the button's visuals when the state changes\r\n * @param activeButton the current active button in the UI\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public update(activeButton: Nullable<WebXREnterExitUIButton>) {}\r\n}\r\n\r\n/**\r\n * Options to create the webXR UI\r\n */\r\nexport class WebXREnterExitUIOptions {\r\n /**\r\n * User provided buttons to enable/disable WebXR. The system will provide default if not set\r\n */\r\n customButtons?: Array<WebXREnterExitUIButton>;\r\n /**\r\n * A reference space type to use when creating the default button.\r\n * Default is local-floor\r\n */\r\n referenceSpaceType?: XRReferenceSpaceType;\r\n /**\r\n * Context to enter xr with\r\n */\r\n renderTarget?: Nullable<WebXRRenderTarget>;\r\n /**\r\n * A session mode to use when creating the default button.\r\n * Default is immersive-vr\r\n */\r\n sessionMode?: XRSessionMode;\r\n\r\n /**\r\n * A list of optional features to init the session with\r\n */\r\n optionalFeatures?: string[];\r\n\r\n /**\r\n * A list of optional features to init the session with\r\n */\r\n requiredFeatures?: string[];\r\n\r\n /**\r\n * If set, the `sessiongranted` event will not be registered. `sessiongranted` is used to move seamlessly between WebXR experiences.\r\n * If set to true the user will be forced to press the \"enter XR\" button even if sessiongranted event was triggered.\r\n * If not set and a sessiongranted event was triggered, the XR session will start automatically.\r\n */\r\n ignoreSessionGrantedEvent?: boolean;\r\n\r\n /**\r\n * If defined, this function will be executed if the UI encounters an error when entering XR\r\n */\r\n onError?: (error: any) => void;\r\n}\r\n/**\r\n * UI to allow the user to enter/exit XR mode\r\n */\r\nexport class WebXREnterExitUI implements IDisposable {\r\n private _activeButton: Nullable<WebXREnterExitUIButton> = null;\r\n private _buttons: Array<WebXREnterExitUIButton> = [];\r\n private _helper: WebXRExperienceHelper;\r\n private _renderTarget?: WebXRRenderTarget;\r\n /**\r\n * The HTML Div Element to which buttons are added.\r\n */\r\n public readonly overlay: HTMLDivElement;\r\n\r\n /**\r\n * Fired every time the active button is changed.\r\n *\r\n * When xr is entered via a button that launches xr that button will be the callback parameter\r\n *\r\n * When exiting xr the callback parameter will be null)\r\n */\r\n public activeButtonChangedObservable = new Observable<Nullable<WebXREnterExitUIButton>>();\r\n\r\n /**\r\n * Construct a new EnterExit UI class\r\n *\r\n * @param _scene babylon scene object to use\r\n * @param options (read-only) version of the options passed to this UI\r\n */\r\n public constructor(\r\n private _scene: Scene,\r\n /** version of the options passed to this UI */\r\n public options: WebXREnterExitUIOptions\r\n ) {\r\n this.overlay = document.createElement(\"div\");\r\n this.overlay.classList.add(\"xr-button-overlay\");\r\n\r\n // prepare for session granted event\r\n if (!options.ignoreSessionGrantedEvent && (navigator as any).xr) {\r\n (navigator as any).xr.addEventListener(\"sessiongranted\", this._onSessionGranted);\r\n }\r\n\r\n // if served over HTTP, warn people.\r\n // Hopefully the browsers will catch up\r\n if (typeof window !== \"undefined\") {\r\n if (window.location && window.location.protocol === \"http:\" && window.location.hostname !== \"localhost\") {\r\n Tools.Warn(\"WebXR can only be served over HTTPS\");\r\n throw new Error(\"WebXR can only be served over HTTPS\");\r\n }\r\n }\r\n\r\n if (options.customButtons) {\r\n this._buttons = options.customButtons;\r\n } else {\r\n this.overlay.style.cssText = \"z-index:11;position: absolute; right: 20px;bottom: 50px;\";\r\n const sessionMode = options.sessionMode || \"immersive-vr\";\r\n const referenceSpaceType = options.referenceSpaceType || \"local-floor\";\r\n const url =\r\n typeof SVGSVGElement === \"undefined\"\r\n ? \"https://cdn.babylonjs.com/Assets/vrButton.png\"\r\n : \"data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%222048%22%20height%3D%221152%22%20viewBox%3D%220%200%202048%201152%22%20version%3D%221.1%22%3E%3Cpath%20transform%3D%22rotate%28180%201024%2C576.0000000000001%29%22%20d%3D%22m1109%2C896q17%2C0%2030%2C-12t13%2C-30t-12.5%2C-30.5t-30.5%2C-12.5l-170%2C0q-18%2C0%20-30.5%2C12.5t-12.5%2C30.5t13%2C30t30%2C12l170%2C0zm-85%2C256q59%2C0%20132.5%2C-1.5t154.5%2C-5.5t164.5%2C-11.5t163%2C-20t150%2C-30t124.5%2C-41.5q23%2C-11%2042%2C-24t38%2C-30q27%2C-25%2041%2C-61.5t14%2C-72.5l0%2C-257q0%2C-123%20-47%2C-232t-128%2C-190t-190%2C-128t-232%2C-47l-81%2C0q-37%2C0%20-68.5%2C14t-60.5%2C34.5t-55.5%2C45t-53%2C45t-53%2C34.5t-55.5%2C14t-55.5%2C-14t-53%2C-34.5t-53%2C-45t-55.5%2C-45t-60.5%2C-34.5t-68.5%2C-14l-81%2C0q-123%2C0%20-232%2C47t-190%2C128t-128%2C190t-47%2C232l0%2C257q0%2C68%2038%2C115t97%2C73q54%2C24%20124.5%2C41.5t150%2C30t163%2C20t164.5%2C11.5t154.5%2C5.5t132.5%2C1.5zm939%2C-298q0%2C39%20-24.5%2C67t-58.5%2C42q-54%2C23%20-122%2C39.5t-143.5%2C28t-155.5%2C19t-157%2C11t-148.5%2C5t-129.5%2C1.5q-59%2C0%20-130%2C-1.5t-148%2C-5t-157%2C-11t-155.5%2C-19t-143.5%2C-28t-122%2C-39.5q-34%2C-14%20-58.5%2C-42t-24.5%2C-67l0%2C-257q0%2C-106%2040.5%2C-199t110%2C-162.5t162.5%2C-109.5t199%2C-40l81%2C0q27%2C0%2052%2C14t50%2C34.5t51%2C44.5t55.5%2C44.5t63.5%2C34.5t74%2C14t74%2C-14t63.5%2C-34.5t55.5%2C-44.5t51%2C-44.5t50%2C-34.5t52%2C-14l14%2C0q37%2C0%2070%2C0.5t64.5%2C4.5t63.5%2C12t68%2C23q71%2C30%20128.5%2C78.5t98.5%2C110t63.5%2C133.5t22.5%2C149l0%2C257z%22%20fill%3D%22white%22%20/%3E%3C/svg%3E%0A\";\r\n let css =\r\n \".babylonVRicon { color: #868686; border-color: #868686; border-style: solid; margin-left: 10px; height: 50px; width: 80px; background-color: rgba(51,51,51,0.7); background-image: url(\" +\r\n url +\r\n \"); background-size: 80%; background-repeat:no-repeat; background-position: center; border: none; outline: none; transition: transform 0.125s ease-out } .babylonVRicon:hover { transform: scale(1.05) } .babylonVRicon:active {background-color: rgba(51,51,51,1) } .babylonVRicon:focus {background-color: rgba(51,51,51,1) }\";\r\n css += '.babylonVRicon.vrdisplaypresenting { background-image: none;} .vrdisplaypresenting::after { content: \"EXIT\"} .xr-error::after { content: \"ERROR\"}';\r\n\r\n const style = document.createElement(\"style\");\r\n style.appendChild(document.createTextNode(css));\r\n document.getElementsByTagName(\"head\")[0].appendChild(style);\r\n const hmdBtn = document.createElement(\"button\");\r\n hmdBtn.className = \"babylonVRicon\";\r\n hmdBtn.title = `${sessionMode} - ${referenceSpaceType}`;\r\n this._buttons.push(new WebXREnterExitUIButton(hmdBtn, sessionMode, referenceSpaceType));\r\n this._buttons[this._buttons.length - 1].update = function (activeButton: WebXREnterExitUIButton) {\r\n this.element.style.display = activeButton === null || activeButton === this ? \"\" : \"none\";\r\n hmdBtn.className = \"babylonVRicon\" + (activeButton === this ? \" vrdisplaypresenting\" : \"\");\r\n };\r\n this._updateButtons(null);\r\n }\r\n\r\n const renderCanvas = _scene.getEngine().getInputElement();\r\n if (renderCanvas && renderCanvas.parentNode) {\r\n renderCanvas.parentNode.appendChild(this.overlay);\r\n _scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Set the helper to be used with this UI component.\r\n * The UI is bound to an experience helper. If not provided the UI can still be used but the events should be registered by the developer.\r\n *\r\n * @param helper the experience helper to attach\r\n * @param renderTarget an optional render target (in case it is created outside of the helper scope)\r\n * @returns a promise that resolves when the ui is ready\r\n */\r\n public async setHelperAsync(helper: WebXRExperienceHelper, renderTarget?: WebXRRenderTarget): Promise<void> {\r\n this._helper = helper;\r\n this._renderTarget = renderTarget;\r\n const supportedPromises = this._buttons.map(async (btn) => {\r\n return await helper.sessionManager.isSessionSupportedAsync(btn.sessionMode);\r\n });\r\n helper.onStateChangedObservable.add((state) => {\r\n if (state == WebXRState.NOT_IN_XR) {\r\n this._updateButtons(null);\r\n }\r\n });\r\n const results = await Promise.all(supportedPromises);\r\n for (let i = 0; i < results.length; i++) {\r\n const supported = results[i];\r\n if (supported) {\r\n this.overlay.appendChild(this._buttons[i].element);\r\n this._buttons[i].element.onclick = this._enterXRWithButtonIndexAsync.bind(this, i);\r\n } else {\r\n Tools.Warn(`Session mode \"${this._buttons[i].sessionMode}\" not supported in browser`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Creates UI to allow the user to enter/exit XR mode\r\n * @param scene the scene to add the ui to\r\n * @param helper the xr experience helper to enter/exit xr with\r\n * @param options options to configure the UI\r\n * @returns the created ui\r\n */\r\n public static async CreateAsync(scene: Scene, helper: WebXRExperienceHelper, options: WebXREnterExitUIOptions): Promise<WebXREnterExitUI> {\r\n const ui = new WebXREnterExitUI(scene, options);\r\n await ui.setHelperAsync(helper, options.renderTarget || undefined);\r\n return ui;\r\n }\r\n\r\n private async _enterXRWithButtonIndexAsync(idx: number = 0) {\r\n if (this._helper.state == WebXRState.IN_XR) {\r\n await this._helper.exitXRAsync();\r\n this._updateButtons(null);\r\n } else if (this._helper.state == WebXRState.NOT_IN_XR) {\r\n try {\r\n await this._helper.enterXRAsync(this._buttons[idx].sessionMode, this._buttons[idx].referenceSpaceType, this._renderTarget, {\r\n optionalFeatures: this.options.optionalFeatures,\r\n requiredFeatures: this.options.requiredFeatures,\r\n });\r\n this._updateButtons(this._buttons[idx]);\r\n } catch (e) {\r\n // make sure button is visible\r\n this._updateButtons(null);\r\n const element = this._buttons[idx].element;\r\n const prevTitle = element.title;\r\n element.title = \"Error entering XR session : \" + prevTitle;\r\n element.classList.add(\"xr-error\");\r\n if (this.options.onError) {\r\n this.options.onError(e);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the XR UI component\r\n */\r\n public dispose() {\r\n const renderCanvas = this._scene.getEngine().getInputElement();\r\n if (renderCanvas && renderCanvas.parentNode && renderCanvas.parentNode.contains(this.overlay)) {\r\n renderCanvas.parentNode.removeChild(this.overlay);\r\n }\r\n this.activeButtonChangedObservable.clear();\r\n (navigator as any).xr.removeEventListener(\"sessiongranted\", this._onSessionGranted);\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _onSessionGranted = (evt: { session: XRSession }) => {\r\n // This section is for future reference.\r\n // As per specs, evt.session.mode should have the supported session mode, but no browser supports it for now.\r\n\r\n // // check if the session granted is the same as the one requested\r\n // const grantedMode = (evt.session as any).mode;\r\n // if (grantedMode) {\r\n // this._buttons.some((btn, idx) => {\r\n // if (btn.sessionMode === grantedMode) {\r\n // this._enterXRWithButtonIndex(idx);\r\n // return true;\r\n // }\r\n // return false;\r\n // });\r\n // } else\r\n\r\n if (this._helper) {\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this._enterXRWithButtonIndexAsync(0);\r\n }\r\n };\r\n\r\n private _updateButtons(activeButton: Nullable<WebXREnterExitUIButton>) {\r\n this._activeButton = activeButton;\r\n for (const b of this._buttons) {\r\n b.update(this._activeButton);\r\n }\r\n this.activeButtonChangedObservable.notifyObservers(this._activeButton);\r\n }\r\n}\r\n"]}
|
|
@@ -54,12 +54,14 @@ export class WebXRExperienceHelper {
|
|
|
54
54
|
*/
|
|
55
55
|
static async CreateAsync(scene) {
|
|
56
56
|
const helper = new WebXRExperienceHelper(scene);
|
|
57
|
-
return helper.sessionManager
|
|
57
|
+
return await helper.sessionManager
|
|
58
58
|
.initializeAsync()
|
|
59
|
+
// eslint-disable-next-line github/no-then
|
|
59
60
|
.then(() => {
|
|
60
61
|
helper._supported = true;
|
|
61
62
|
return helper;
|
|
62
63
|
})
|
|
64
|
+
// eslint-disable-next-line github/no-then
|
|
63
65
|
.catch((e) => {
|
|
64
66
|
helper._setState(3 /* WebXRState.NOT_IN_XR */);
|
|
65
67
|
helper.dispose();
|
|
@@ -70,6 +72,7 @@ export class WebXRExperienceHelper {
|
|
|
70
72
|
* Disposes of the experience helper
|
|
71
73
|
*/
|
|
72
74
|
dispose() {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
73
76
|
this.exitXRAsync();
|
|
74
77
|
this.camera.dispose();
|
|
75
78
|
this.onStateChangedObservable.clear();
|
|
@@ -189,7 +192,7 @@ export class WebXRExperienceHelper {
|
|
|
189
192
|
return;
|
|
190
193
|
}
|
|
191
194
|
this._setState(1 /* WebXRState.EXITING_XR */);
|
|
192
|
-
return this.sessionManager.exitXRAsync();
|
|
195
|
+
return await this.sessionManager.exitXRAsync();
|
|
193
196
|
}
|
|
194
197
|
/**
|
|
195
198
|
* Enable spectator mode for desktop VR experiences.
|
|
@@ -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;AAG5C,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;AAE3D,OAAO,EAAE,cAAc,EAAE,qCAAoC;AAiB7D;;;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,G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E,CAAC;IAEO,SAAS,CAAC,GAAe;QAC7B,IAAI,IAAI,CAAC,KAAK,KAAK,GAAG,EAAE,CAAC;YACrB,OAAO;QACX,CAAC;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\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { AbstractEngine } from \"core/Engines/abstractEngine\";\r\n\r\n/**\r\n * Options for setting up XR spectator camera.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\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 async 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 // Vision Pro suspends the audio context when entering XR, so we resume it here if needed.\r\n AbstractEngine.audioEngine?._resumeAudioContextOnStateChange();\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 for (const c of this.camera.rigCameras) {\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 async exitXRAsync() {\r\n // only exit if state is IN_XR\r\n if (this.state !== WebXRState.IN_XR) {\r\n return;\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() as ThinEngine).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"]}
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AC,CAAC,MAAM,EAAE,EAAE;wBACrD,IAAI,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;4BACzB,mDAAmD;4BAClD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAiB,CAAC,2BAA2B,GAAG,IAAI,CAAC;wBAC/E,CAAC;oBACL,CAAC,CAAC,CAAC;gBACP,CAAC;qBAAM,IAAI,IAAI,CAAC,KAAK,kCAA0B,EAAE,CAAC;oBAC9C,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;oBAC9E,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,IAAI,CAAC;gBACrC,CAAC;YACL,CAAC,CAAC;YACF,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAClD,cAAc,EAAE,CAAC;QACrB,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;YAC9E,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9C,CAAC;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,CAAC;YACrB,OAAO;QACX,CAAC;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\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { AbstractEngine } from \"core/Engines/abstractEngine\";\r\n\r\n/**\r\n * Options for setting up XR spectator camera.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\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 async CreateAsync(scene: Scene): Promise<WebXRExperienceHelper> {\r\n const helper = new WebXRExperienceHelper(scene);\r\n return await helper.sessionManager\r\n .initializeAsync()\r\n // eslint-disable-next-line github/no-then\r\n .then(() => {\r\n helper._supported = true;\r\n return helper;\r\n })\r\n // eslint-disable-next-line github/no-then\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 // eslint-disable-next-line @typescript-eslint/no-floating-promises\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 // Vision Pro suspends the audio context when entering XR, so we resume it here if needed.\r\n AbstractEngine.audioEngine?._resumeAudioContextOnStateChange();\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 for (const c of this.camera.rigCameras) {\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 async exitXRAsync() {\r\n // only exit if state is IN_XR\r\n if (this.state !== WebXRState.IN_XR) {\r\n return;\r\n }\r\n this._setState(WebXRState.EXITING_XR);\r\n return await 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() as ThinEngine).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"]}
|
|
@@ -381,6 +381,7 @@ export class WebXRFeaturesManager {
|
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
if (feature.featureImplementation.getXRSessionInitExtension) {
|
|
384
|
+
// eslint-disable-next-line no-await-in-loop
|
|
384
385
|
const extended = await feature.featureImplementation.getXRSessionInitExtension();
|
|
385
386
|
xrSessionInit = {
|
|
386
387
|
...xrSessionInit,
|