@babylonjs/core 7.2.2 → 7.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Animations/runtimeAnimation.d.ts +1 -0
- package/Animations/runtimeAnimation.js +12 -3
- package/Animations/runtimeAnimation.js.map +1 -1
- package/Audio/audioEngine.js +2 -2
- package/Audio/audioEngine.js.map +1 -1
- package/Bones/boneLookController.js +3 -0
- package/Bones/boneLookController.js.map +1 -1
- package/Buffers/buffer.d.ts +5 -5
- package/Buffers/buffer.js.map +1 -1
- package/Buffers/storageBuffer.d.ts +2 -2
- package/Buffers/storageBuffer.js.map +1 -1
- package/Cameras/Inputs/arcRotateCameraKeyboardMoveInput.js.map +1 -1
- package/Cameras/Inputs/flyCameraKeyboardInput.js.map +1 -1
- package/Cameras/Inputs/followCameraKeyboardMoveInput.js.map +1 -1
- package/Cameras/Inputs/freeCameraKeyboardMoveInput.js.map +1 -1
- package/Compute/computeEffect.d.ts +3 -3
- package/Compute/computeEffect.js.map +1 -1
- package/Compute/computeShader.d.ts +10 -2
- package/Compute/computeShader.js +53 -35
- package/Compute/computeShader.js.map +1 -1
- package/DeviceInput/InputDevices/deviceSourceManager.d.ts +2 -2
- package/DeviceInput/InputDevices/deviceSourceManager.js.map +1 -1
- package/DeviceInput/internalDeviceSourceManager.d.ts +4 -4
- package/DeviceInput/internalDeviceSourceManager.js.map +1 -1
- package/DeviceInput/webDeviceInputSystem.d.ts +2 -2
- package/DeviceInput/webDeviceInputSystem.js.map +1 -1
- package/Engines/AbstractEngine/abstractEngine.alpha.d.ts +10 -0
- package/Engines/AbstractEngine/abstractEngine.alpha.js +29 -0
- package/Engines/AbstractEngine/abstractEngine.alpha.js.map +1 -0
- package/Engines/AbstractEngine/abstractEngine.cubeTexture.d.ts +17 -0
- package/Engines/AbstractEngine/abstractEngine.cubeTexture.js +138 -0
- package/Engines/AbstractEngine/abstractEngine.cubeTexture.js.map +1 -0
- package/Engines/AbstractEngine/abstractEngine.dom.d.ts +61 -0
- package/Engines/AbstractEngine/abstractEngine.dom.js +27 -0
- package/Engines/AbstractEngine/abstractEngine.dom.js.map +1 -0
- package/Engines/AbstractEngine/abstractEngine.loadingScreen.d.ts +30 -0
- package/Engines/AbstractEngine/abstractEngine.loadingScreen.js +48 -0
- package/Engines/AbstractEngine/abstractEngine.loadingScreen.js.map +1 -0
- package/Engines/AbstractEngine/abstractEngine.query.d.ts +122 -0
- package/Engines/AbstractEngine/abstractEngine.query.js +175 -0
- package/Engines/AbstractEngine/abstractEngine.query.js.map +1 -0
- package/Engines/AbstractEngine/abstractEngine.renderPass.d.ts +26 -0
- package/Engines/AbstractEngine/abstractEngine.renderPass.js +29 -0
- package/Engines/AbstractEngine/abstractEngine.renderPass.js.map +1 -0
- package/Engines/AbstractEngine/abstractEngine.states.d.ts +162 -0
- package/Engines/AbstractEngine/abstractEngine.states.js +105 -0
- package/Engines/AbstractEngine/abstractEngine.states.js.map +1 -0
- package/Engines/AbstractEngine/abstractEngine.texture.d.ts +16 -0
- package/Engines/AbstractEngine/abstractEngine.texture.js +11 -0
- package/Engines/AbstractEngine/abstractEngine.texture.js.map +1 -0
- package/Engines/AbstractEngine/index.d.ts +8 -0
- package/Engines/AbstractEngine/index.js +10 -0
- package/Engines/AbstractEngine/index.js.map +1 -0
- package/Engines/Extensions/engine.alpha.d.ts +0 -24
- package/Engines/Extensions/engine.alpha.js +0 -35
- package/Engines/Extensions/engine.alpha.js.map +1 -1
- package/Engines/Extensions/engine.computeShader.d.ts +15 -2
- package/Engines/Extensions/engine.computeShader.js +5 -1
- package/Engines/Extensions/engine.computeShader.js.map +1 -1
- package/Engines/Extensions/engine.cubeTexture.d.ts +0 -8
- package/Engines/Extensions/engine.cubeTexture.js +2 -135
- package/Engines/Extensions/engine.cubeTexture.js.map +1 -1
- package/Engines/Extensions/engine.debugging.d.ts +2 -2
- package/Engines/Extensions/engine.debugging.js +5 -5
- package/Engines/Extensions/engine.debugging.js.map +1 -1
- package/Engines/Extensions/engine.dynamicTexture.js +3 -2
- package/Engines/Extensions/engine.dynamicTexture.js.map +1 -1
- package/Engines/Extensions/engine.multiview.js.map +1 -1
- package/Engines/Extensions/engine.query.d.ts +5 -120
- package/Engines/Extensions/engine.query.js +14 -150
- package/Engines/Extensions/engine.query.js.map +1 -1
- package/Engines/Extensions/engine.renderTarget.js +0 -9
- package/Engines/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/Extensions/engine.views.d.ts +3 -2
- package/Engines/Extensions/engine.views.js.map +1 -1
- package/Engines/Processors/iShaderProcessor.d.ts +2 -2
- package/Engines/Processors/iShaderProcessor.js.map +1 -1
- package/Engines/Processors/shaderProcessor.d.ts +3 -3
- package/Engines/Processors/shaderProcessor.js.map +1 -1
- package/Engines/WebGL/webGLRenderTargetWrapper.js +12 -9
- package/Engines/WebGL/webGLRenderTargetWrapper.js.map +1 -1
- package/Engines/WebGL/webGLShaderProcessors.d.ts +2 -2
- package/Engines/WebGL/webGLShaderProcessors.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.alpha.d.ts +35 -0
- package/Engines/WebGPU/Extensions/engine.alpha.js +4 -4
- package/Engines/WebGPU/Extensions/engine.alpha.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.computeShader.d.ts +9 -0
- package/Engines/WebGPU/Extensions/engine.computeShader.js +13 -2
- package/Engines/WebGPU/Extensions/engine.computeShader.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.cubeTexture.d.ts +78 -1
- package/Engines/WebGPU/Extensions/engine.cubeTexture.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.dynamicTexture.d.ts +27 -1
- package/Engines/WebGPU/Extensions/engine.dynamicTexture.js +3 -3
- package/Engines/WebGPU/Extensions/engine.dynamicTexture.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.externalTexture.d.ts +16 -0
- package/Engines/WebGPU/Extensions/engine.externalTexture.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.multiRender.d.ts +55 -1
- package/Engines/WebGPU/Extensions/engine.multiRender.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.query.d.ts +1 -1
- package/Engines/WebGPU/Extensions/engine.query.js +1 -0
- package/Engines/WebGPU/Extensions/engine.query.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.rawTexture.d.ts +185 -1
- package/Engines/WebGPU/Extensions/engine.rawTexture.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.readTexture.d.ts +10 -1
- package/Engines/WebGPU/Extensions/engine.readTexture.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.renderTarget.d.ts +38 -1
- package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.renderTargetCube.d.ts +13 -1
- package/Engines/WebGPU/Extensions/engine.renderTargetCube.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.storageBuffer.d.ts +38 -1
- package/Engines/WebGPU/Extensions/engine.storageBuffer.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.textureSampler.d.ts +10 -0
- package/Engines/WebGPU/Extensions/engine.textureSampler.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.videoTexture.d.ts +14 -1
- package/Engines/WebGPU/Extensions/engine.videoTexture.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessorsGLSL.d.ts +2 -2
- package/Engines/WebGPU/webgpuShaderProcessorsGLSL.js.map +1 -1
- package/Engines/abstractEngine.d.ts +1688 -0
- package/Engines/abstractEngine.js +1354 -0
- package/Engines/abstractEngine.js.map +1 -0
- package/Engines/engine.common.d.ts +39 -0
- package/Engines/engine.common.js +226 -0
- package/Engines/engine.common.js.map +1 -0
- package/Engines/engine.d.ts +40 -447
- package/Engines/engine.js +64 -810
- package/Engines/engine.js.map +1 -1
- package/Engines/engineFactory.d.ts +2 -2
- package/Engines/engineFactory.js.map +1 -1
- package/Engines/engineStore.d.ts +4 -4
- package/Engines/engineStore.js.map +1 -1
- package/Engines/index.d.ts +3 -0
- package/Engines/index.js +3 -0
- package/Engines/index.js.map +1 -1
- package/Engines/nativeEngine.d.ts +1 -1
- package/Engines/nativeEngine.js +2 -1
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/nullEngine.d.ts +2 -2
- package/Engines/nullEngine.js +2 -3
- package/Engines/nullEngine.js.map +1 -1
- package/Engines/renderTargetWrapper.d.ts +3 -3
- package/Engines/renderTargetWrapper.js.map +1 -1
- package/Engines/thinEngine.d.ts +35 -591
- package/Engines/thinEngine.js +84 -1134
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.d.ts +149 -109
- package/Engines/webgpuEngine.js +249 -161
- package/Engines/webgpuEngine.js.map +1 -1
- package/Instrumentation/engineInstrumentation.d.ts +5 -4
- package/Instrumentation/engineInstrumentation.js.map +1 -1
- package/Layers/effectLayer.d.ts +2 -2
- package/Layers/effectLayer.js +3 -3
- package/Layers/effectLayer.js.map +1 -1
- package/Layers/effectLayerSceneComponent.js.map +1 -1
- package/Layers/glowLayer.js +3 -3
- package/Layers/glowLayer.js.map +1 -1
- package/Layers/highlightLayer.js +3 -3
- package/Layers/highlightLayer.js.map +1 -1
- package/Layers/layerSceneComponent.js.map +1 -1
- package/Loading/loadingScreen.js +2 -2
- package/Loading/loadingScreen.js.map +1 -1
- package/Loading/sceneLoader.d.ts +3 -3
- package/Loading/sceneLoader.js +1 -1
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/GreasedLine/greasedLinePluginMaterial.js.map +1 -1
- package/Materials/Textures/Filtering/hdrFiltering.d.ts +2 -2
- package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
- package/Materials/Textures/Loaders/basisTextureLoader.js +2 -2
- package/Materials/Textures/Loaders/basisTextureLoader.js.map +1 -1
- package/Materials/Textures/MultiviewRenderTarget.d.ts +1 -0
- package/Materials/Textures/MultiviewRenderTarget.js +1 -0
- package/Materials/Textures/MultiviewRenderTarget.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.js +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
- package/Materials/Textures/baseTexture.d.ts +3 -3
- package/Materials/Textures/baseTexture.js.map +1 -1
- package/Materials/Textures/colorGradingTexture.d.ts +2 -2
- package/Materials/Textures/colorGradingTexture.js.map +1 -1
- package/Materials/Textures/cubeTexture.d.ts +3 -2
- package/Materials/Textures/cubeTexture.js +1 -0
- package/Materials/Textures/cubeTexture.js.map +1 -1
- package/Materials/Textures/hdrCubeTexture.d.ts +2 -2
- package/Materials/Textures/hdrCubeTexture.js.map +1 -1
- package/Materials/Textures/htmlElementTexture.d.ts +2 -2
- package/Materials/Textures/htmlElementTexture.js.map +1 -1
- package/Materials/Textures/internalTexture.d.ts +3 -3
- package/Materials/Textures/internalTexture.js.map +1 -1
- package/Materials/Textures/rawTexture.d.ts +10 -10
- package/Materials/Textures/rawTexture.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.d.ts +4 -4
- package/Materials/Textures/renderTargetTexture.js +4 -4
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/Textures/texture.d.ts +2 -2
- package/Materials/Textures/texture.js.map +1 -1
- package/Materials/Textures/thinTexture.d.ts +3 -3
- package/Materials/Textures/thinTexture.js +1 -1
- package/Materials/Textures/thinTexture.js.map +1 -1
- package/Materials/drawWrapper.d.ts +2 -3
- package/Materials/drawWrapper.functions.d.ts +8 -0
- package/Materials/drawWrapper.functions.js +9 -0
- package/Materials/drawWrapper.functions.js.map +1 -0
- package/Materials/drawWrapper.js +0 -3
- package/Materials/drawWrapper.js.map +1 -1
- package/Materials/effect.d.ts +4 -5
- package/Materials/effect.js.map +1 -1
- package/Materials/effectRenderer.d.ts +4 -4
- package/Materials/effectRenderer.js.map +1 -1
- package/Materials/index.d.ts +1 -0
- package/Materials/index.js +1 -0
- package/Materials/index.js.map +1 -1
- package/Materials/materialHelper.functions.d.ts +2 -2
- package/Materials/materialHelper.functions.js.map +1 -1
- package/Materials/materialPluginBase.d.ts +4 -4
- package/Materials/materialPluginBase.js.map +1 -1
- package/Materials/materialPluginManager.d.ts +2 -2
- package/Materials/materialPluginManager.js.map +1 -1
- package/Materials/meshDebugPluginMaterial.js +1 -1
- package/Materials/meshDebugPluginMaterial.js.map +1 -1
- package/Materials/uniformBuffer.d.ts +2 -2
- package/Materials/uniformBuffer.js.map +1 -1
- package/Meshes/Builders/greasedLineBuilder.d.ts +6 -0
- package/Meshes/Builders/greasedLineBuilder.js +15 -8
- package/Meshes/Builders/greasedLineBuilder.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineBaseMesh.d.ts +2 -2
- package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineMesh.js +1 -1
- package/Meshes/GreasedLine/greasedLineMesh.js.map +1 -1
- package/Meshes/geometry.d.ts +2 -2
- package/Meshes/geometry.js +3 -2
- package/Meshes/geometry.js.map +1 -1
- package/Meshes/instancedMesh.js.map +1 -1
- package/Meshes/mesh.d.ts +3 -3
- package/Meshes/mesh.js.map +1 -1
- package/Meshes/subMesh.d.ts +2 -2
- package/Meshes/subMesh.js.map +1 -1
- package/Misc/PerformanceViewer/performanceViewerCollectionStrategies.js.map +1 -1
- package/Misc/copyTextureToTexture.d.ts +2 -2
- package/Misc/copyTextureToTexture.js.map +1 -1
- package/Misc/dds.d.ts +3 -2
- package/Misc/dds.js +2 -1
- package/Misc/dds.js.map +1 -1
- package/Misc/dumpTools.d.ts +2 -2
- package/Misc/dumpTools.js.map +1 -1
- package/Misc/fileTools.js +3 -3
- package/Misc/fileTools.js.map +1 -1
- package/Misc/khronosTextureContainer2.d.ts +8 -2
- package/Misc/khronosTextureContainer2.js +3 -2
- package/Misc/khronosTextureContainer2.js.map +1 -1
- package/Misc/minMaxReducer.d.ts +2 -2
- package/Misc/minMaxReducer.js.map +1 -1
- package/Misc/textureTools.js.map +1 -1
- package/Misc/tools.d.ts +7 -7
- package/Misc/tools.functions.d.ts +26 -0
- package/Misc/tools.functions.js +62 -0
- package/Misc/tools.functions.js.map +1 -1
- package/Misc/tools.js.map +1 -1
- package/Misc/videoRecorder.d.ts +3 -3
- package/Misc/videoRecorder.js.map +1 -1
- package/Particles/baseParticleSystem.d.ts +2 -2
- package/Particles/baseParticleSystem.js.map +1 -1
- package/Particles/computeShaderParticleSystem.d.ts +2 -2
- package/Particles/computeShaderParticleSystem.js.map +1 -1
- package/Particles/gpuParticleSystem.d.ts +3 -3
- package/Particles/gpuParticleSystem.js +2 -2
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/particle.js +1 -1
- package/Particles/particle.js.map +1 -1
- package/Particles/particleSystem.d.ts +3 -3
- package/Particles/particleSystem.js +3 -3
- package/Particles/particleSystem.js.map +1 -1
- package/Particles/particleSystemComponent.d.ts +2 -2
- package/Particles/particleSystemComponent.js +2 -2
- package/Particles/particleSystemComponent.js.map +1 -1
- package/Particles/subEmitter.d.ts +3 -3
- package/Particles/subEmitter.js.map +1 -1
- package/Particles/thinParticleSystem.d.ts +2 -2
- package/Particles/thinParticleSystem.js.map +1 -1
- package/Physics/v2/physicsBody.js +3 -3
- package/Physics/v2/physicsBody.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/postProcessRenderEffect.d.ts +2 -2
- package/PostProcesses/RenderPipeline/postProcessRenderEffect.js.map +1 -1
- package/PostProcesses/RenderPipeline/postProcessRenderPipeline.d.ts +2 -2
- package/PostProcesses/RenderPipeline/postProcessRenderPipeline.js.map +1 -1
- package/PostProcesses/blackAndWhitePostProcess.d.ts +2 -2
- package/PostProcesses/blackAndWhitePostProcess.js.map +1 -1
- package/PostProcesses/bloomMergePostProcess.d.ts +2 -2
- package/PostProcesses/bloomMergePostProcess.js.map +1 -1
- package/PostProcesses/blurPostProcess.d.ts +2 -2
- package/PostProcesses/blurPostProcess.js.map +1 -1
- package/PostProcesses/chromaticAberrationPostProcess.d.ts +2 -2
- package/PostProcesses/chromaticAberrationPostProcess.js.map +1 -1
- package/PostProcesses/circleOfConfusionPostProcess.d.ts +2 -2
- package/PostProcesses/circleOfConfusionPostProcess.js.map +1 -1
- package/PostProcesses/colorCorrectionPostProcess.d.ts +2 -2
- package/PostProcesses/colorCorrectionPostProcess.js.map +1 -1
- package/PostProcesses/convolutionPostProcess.d.ts +2 -2
- package/PostProcesses/convolutionPostProcess.js.map +1 -1
- package/PostProcesses/depthOfFieldBlurPostProcess.d.ts +2 -2
- package/PostProcesses/depthOfFieldBlurPostProcess.js.map +1 -1
- package/PostProcesses/depthOfFieldEffect.js +1 -1
- package/PostProcesses/depthOfFieldEffect.js.map +1 -1
- package/PostProcesses/depthOfFieldMergePostProcess.d.ts +2 -2
- package/PostProcesses/depthOfFieldMergePostProcess.js.map +1 -1
- package/PostProcesses/displayPassPostProcess.d.ts +2 -2
- package/PostProcesses/displayPassPostProcess.js.map +1 -1
- package/PostProcesses/extractHighlightsPostProcess.d.ts +2 -2
- package/PostProcesses/extractHighlightsPostProcess.js.map +1 -1
- package/PostProcesses/filterPostProcess.d.ts +2 -2
- package/PostProcesses/filterPostProcess.js.map +1 -1
- package/PostProcesses/fxaaPostProcess.d.ts +2 -2
- package/PostProcesses/fxaaPostProcess.js +2 -2
- package/PostProcesses/fxaaPostProcess.js.map +1 -1
- package/PostProcesses/grainPostProcess.d.ts +2 -2
- package/PostProcesses/grainPostProcess.js.map +1 -1
- package/PostProcesses/imageProcessingPostProcess.d.ts +2 -2
- package/PostProcesses/imageProcessingPostProcess.js.map +1 -1
- package/PostProcesses/motionBlurPostProcess.d.ts +2 -2
- package/PostProcesses/motionBlurPostProcess.js.map +1 -1
- package/PostProcesses/passPostProcess.d.ts +3 -3
- package/PostProcesses/passPostProcess.js +2 -2
- package/PostProcesses/passPostProcess.js.map +1 -1
- package/PostProcesses/postProcess.d.ts +4 -4
- package/PostProcesses/postProcess.js +3 -3
- package/PostProcesses/postProcess.js.map +1 -1
- package/PostProcesses/refractionPostProcess.d.ts +2 -2
- package/PostProcesses/refractionPostProcess.js.map +1 -1
- package/PostProcesses/screenSpaceCurvaturePostProcess.d.ts +2 -2
- package/PostProcesses/screenSpaceCurvaturePostProcess.js.map +1 -1
- package/PostProcesses/screenSpaceReflectionPostProcess.d.ts +2 -2
- package/PostProcesses/screenSpaceReflectionPostProcess.js.map +1 -1
- package/PostProcesses/sharpenPostProcess.d.ts +2 -2
- package/PostProcesses/sharpenPostProcess.js.map +1 -1
- package/PostProcesses/subSurfaceScatteringPostProcess.d.ts +2 -2
- package/PostProcesses/subSurfaceScatteringPostProcess.js.map +1 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.d.ts +2 -2
- package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
- package/Rendering/GlobalIllumination/giRSMManager.js.map +1 -1
- package/Rendering/depthPeelingRenderer.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderer.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.d.ts +2 -2
- package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderingObject.d.ts +2 -2
- package/Rendering/fluidRenderer/fluidRenderingObject.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.d.ts +2 -2
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderingTextures.d.ts +2 -2
- package/Rendering/fluidRenderer/fluidRenderingTextures.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js +24 -18
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Rendering/outlineRenderer.js.map +1 -1
- package/Rendering/prePassRenderer.js.map +1 -1
- package/Sprites/spriteRenderer.d.ts +2 -2
- package/Sprites/spriteRenderer.js.map +1 -1
- package/XR/features/WebXRDepthSensing.js.map +1 -1
- package/XR/features/WebXRImageTracking.js.map +1 -1
- package/XR/features/WebXRLayers.d.ts +2 -2
- package/XR/features/WebXRLayers.js.map +1 -1
- package/XR/features/WebXRLightEstimation.js.map +1 -1
- package/XR/features/WebXRRawCameraAccess.d.ts +1 -1
- package/XR/features/WebXRRawCameraAccess.js.map +1 -1
- package/XR/features/WebXRSpaceWarp.js +1 -3
- package/XR/features/WebXRSpaceWarp.js.map +1 -1
- package/XR/features/WebXRWalkingLocomotion.js.map +1 -1
- package/XR/webXRExperienceHelper.js.map +1 -1
- package/XR/webXRManagedOutputCanvas.d.ts +2 -2
- package/XR/webXRManagedOutputCanvas.js.map +1 -1
- package/XR/webXRRenderTargetTextureProvider.js.map +1 -1
- package/XR/webXRSessionManager.js.map +1 -1
- package/assetContainer.js.map +1 -1
- package/node.d.ts +2 -2
- package/node.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +3 -3
- package/scene.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebXRImageTracking.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRImageTracking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAuDzC;;GAEG;AACH,IAAK,wBAOJ;AAPD,WAAK,wBAAwB;IACzB,6DAA6D;IAC7D,qFAAW,CAAA;IACX,8FAA8F;IAC9F,6EAAO,CAAA;IACP,gEAAgE;IAChE,+EAAQ,CAAA;AACZ,CAAC,EAPI,wBAAwB,KAAxB,wBAAwB,QAO5B;AAED;;;GAGG;AACH,MAA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AC,WAAW,CAAC,CAAC;aACrE;SACJ;QAED,IAAI,CAAC,qBAAqB,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC,wBAAwB,CAAC,WAAW,CAAC;IACnI,CAAC;;AAjND;;GAEG;AACoB,uBAAI,GAAG,gBAAgB,CAAC,cAAc,AAAlC,CAAmC;AAC9D;;;;GAIG;AACoB,0BAAO,GAAG,CAAC,AAAJ,CAAK;AA2MvC,qBAAqB;AACrB,oBAAoB,CAAC,eAAe,CAChC,kBAAkB,CAAC,IAAI,EACvB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,kBAAkB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC,EACD,kBAAkB,CAAC,OAAO,EAC1B,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Options interface for the background remover plugin\r\n */\r\nexport interface IWebXRImageTrackingOptions {\r\n /**\r\n * A required array with images to track\r\n */\r\n images: {\r\n /**\r\n * The source of the image. can be a URL or an image bitmap\r\n */\r\n src: string | ImageBitmap;\r\n /**\r\n * The estimated width in the real world (in meters)\r\n */\r\n estimatedRealWorldWidth: number; // In meters!\r\n }[];\r\n}\r\n\r\n/**\r\n * An object representing an image tracked by the system\r\n */\r\nexport interface IWebXRTrackedImage {\r\n /**\r\n * The ID of this image (which is the same as the position in the array that was used to initialize the feature)\r\n */\r\n id: number;\r\n /**\r\n * Is the transformation provided emulated. If it is, the system \"guesses\" its real position. Otherwise it can be considered as exact position.\r\n */\r\n emulated?: boolean;\r\n /**\r\n * Just in case it is needed - the image bitmap that is being tracked\r\n */\r\n originalBitmap: ImageBitmap;\r\n /**\r\n * The native XR result image tracking result, untouched\r\n */\r\n xrTrackingResult?: XRImageTrackingResult;\r\n /**\r\n * Width in real world (meters)\r\n */\r\n realWorldWidth?: number;\r\n /**\r\n * A transformation matrix of this current image in the current reference space.\r\n */\r\n transformationMatrix: Matrix;\r\n /**\r\n * The width/height ratio of this image. can be used to calculate the size of the detected object/image\r\n */\r\n ratio?: number;\r\n}\r\n\r\n/**\r\n * Enum that describes the state of the image trackability score status for this session.\r\n */\r\nenum ImageTrackingScoreStatus {\r\n // AR Session has not yet assessed image trackability scores.\r\n NotReceived,\r\n // A request to retrieve trackability scores has been sent, but no response has been received.\r\n Waiting,\r\n // Image trackability scores have been received for this session\r\n Received,\r\n}\r\n\r\n/**\r\n * Image tracking for immersive AR sessions.\r\n * Providing a list of images and their estimated widths will enable tracking those images in the real world.\r\n */\r\nexport class WebXRImageTracking extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.IMAGE_TRACKING;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * This will be triggered if the underlying system deems an image untrackable.\r\n * The index is the index of the image from the array used to initialize the feature.\r\n */\r\n public onUntrackableImageFoundObservable: Observable<number> = new Observable();\r\n /**\r\n * An image was deemed trackable, and the system will start tracking it.\r\n */\r\n public onTrackableImageFoundObservable: Observable<IWebXRTrackedImage> = new Observable();\r\n /**\r\n * The image was found and its state was updated.\r\n */\r\n public onTrackedImageUpdatedObservable: Observable<IWebXRTrackedImage> = new Observable();\r\n\r\n private _trackableScoreStatus: ImageTrackingScoreStatus = ImageTrackingScoreStatus.NotReceived;\r\n private _trackedImages: IWebXRTrackedImage[] = [];\r\n\r\n private _originalTrackingRequest: XRTrackedImageInit[];\r\n\r\n /**\r\n * constructs the image tracking feature\r\n * @param _xrSessionManager the session manager for this module\r\n * @param options read-only options to be used in this module\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n /**\r\n * read-only options to be used in this module\r\n */\r\n public readonly options: IWebXRImageTrackingOptions\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"image-tracking\";\r\n }\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n return super.attach();\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n return super.detach();\r\n }\r\n\r\n /**\r\n * Get a tracked image by its ID.\r\n *\r\n * @param id the id of the image to load (position in the init array)\r\n * @returns a trackable image, if exists in this location\r\n */\r\n public getTrackedImageById(id: number): Nullable<IWebXRTrackedImage> {\r\n return this._trackedImages[id] || null;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n this._trackedImages.forEach((trackedImage) => {\r\n trackedImage.originalBitmap.close();\r\n });\r\n this._trackedImages.length = 0;\r\n this.onTrackableImageFoundObservable.clear();\r\n this.onUntrackableImageFoundObservable.clear();\r\n this.onTrackedImageUpdatedObservable.clear();\r\n }\r\n\r\n /**\r\n * Extends the session init object if needed\r\n * @returns augmentation object fo the xr session init object.\r\n */\r\n public async getXRSessionInitExtension(): Promise<Partial<XRSessionInit>> {\r\n if (!this.options.images || !this.options.images.length) {\r\n return {};\r\n }\r\n const promises = this.options.images.map((image) => {\r\n if (typeof image.src === \"string\") {\r\n return this._xrSessionManager.scene.getEngine()._createImageBitmapFromSource(image.src);\r\n } else {\r\n return Promise.resolve(image.src); // resolve is probably unneeded\r\n }\r\n });\r\n\r\n try {\r\n const images = await Promise.all(promises);\r\n\r\n this._originalTrackingRequest = images.map((image, idx) => {\r\n return {\r\n image,\r\n widthInMeters: this.options.images[idx].estimatedRealWorldWidth,\r\n };\r\n });\r\n\r\n return {\r\n trackedImages: this._originalTrackingRequest,\r\n };\r\n } catch (ex) {\r\n Tools.Error(\"Error loading images for tracking, WebXRImageTracking disabled for this session.\");\r\n return {};\r\n }\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame) {\r\n if (!_xrFrame.getImageTrackingResults || this._trackableScoreStatus === ImageTrackingScoreStatus.Waiting) {\r\n return;\r\n }\r\n\r\n // Image tracking scores may be generated a few frames after the XR Session initializes.\r\n // If we haven't received scores yet, then kick off the task to check scores and return immediately.\r\n if (this._trackableScoreStatus === ImageTrackingScoreStatus.NotReceived) {\r\n this._checkScoresAsync();\r\n return;\r\n }\r\n\r\n const imageTrackedResults = _xrFrame.getImageTrackingResults();\r\n for (const result of imageTrackedResults) {\r\n let changed = false;\r\n const imageIndex = result.index;\r\n\r\n const imageObject = this._trackedImages[imageIndex];\r\n if (!imageObject) {\r\n // something went wrong!\r\n continue;\r\n }\r\n\r\n imageObject.xrTrackingResult = result;\r\n if (imageObject.realWorldWidth !== result.measuredWidthInMeters) {\r\n imageObject.realWorldWidth = result.measuredWidthInMeters;\r\n changed = true;\r\n }\r\n\r\n // Get the pose of the image relative to a reference space.\r\n const pose = _xrFrame.getPose(result.imageSpace, this._xrSessionManager.referenceSpace);\r\n\r\n if (pose) {\r\n const mat = imageObject.transformationMatrix;\r\n Matrix.FromArrayToRef(pose.transform.matrix, 0, mat);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n mat.toggleModelMatrixHandInPlace();\r\n }\r\n changed = true;\r\n }\r\n\r\n const state = result.trackingState;\r\n const emulated = state === \"emulated\";\r\n\r\n if (imageObject.emulated !== emulated) {\r\n imageObject.emulated = emulated;\r\n changed = true;\r\n }\r\n if (changed) {\r\n this.onTrackedImageUpdatedObservable.notifyObservers(imageObject);\r\n }\r\n }\r\n }\r\n\r\n private async _checkScoresAsync(): Promise<void> {\r\n if (!this._xrSessionManager.session.getTrackedImageScores || this._trackableScoreStatus !== ImageTrackingScoreStatus.NotReceived) {\r\n return;\r\n }\r\n\r\n this._trackableScoreStatus = ImageTrackingScoreStatus.Waiting;\r\n const imageScores = await this._xrSessionManager.session.getTrackedImageScores();\r\n if (!imageScores || imageScores.length === 0) {\r\n this._trackableScoreStatus = ImageTrackingScoreStatus.NotReceived;\r\n return;\r\n }\r\n\r\n // check the scores for all\r\n for (let idx = 0; idx < imageScores.length; ++idx) {\r\n if (imageScores[idx] == \"untrackable\") {\r\n this.onUntrackableImageFoundObservable.notifyObservers(idx);\r\n } else {\r\n const originalBitmap = this._originalTrackingRequest[idx].image;\r\n const imageObject: IWebXRTrackedImage = {\r\n id: idx,\r\n originalBitmap,\r\n transformationMatrix: new Matrix(),\r\n ratio: originalBitmap.width / originalBitmap.height,\r\n };\r\n this._trackedImages[idx] = imageObject;\r\n this.onTrackableImageFoundObservable.notifyObservers(imageObject);\r\n }\r\n }\r\n\r\n this._trackableScoreStatus = imageScores.length > 0 ? ImageTrackingScoreStatus.Received : ImageTrackingScoreStatus.NotReceived;\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRImageTracking.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRImageTracking(xrSessionManager, options);\r\n },\r\n WebXRImageTracking.Version,\r\n false\r\n);\r\n"]}
|
|
1
|
+
{"version":3,"file":"WebXRImageTracking.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRImageTracking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,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AC,KAAK,CAAC;gBAChE,MAAM,WAAW,GAAuB;oBACpC,EAAE,EAAE,GAAG;oBACP,cAAc;oBACd,oBAAoB,EAAE,IAAI,MAAM,EAAE;oBAClC,KAAK,EAAE,cAAc,CAAC,KAAK,GAAG,cAAc,CAAC,MAAM;iBACtD,CAAC;gBACF,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;gBACvC,IAAI,CAAC,+BAA+B,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;aACrE;SACJ;QAED,IAAI,CAAC,qBAAqB,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC,wBAAwB,CAAC,WAAW,CAAC;IACnI,CAAC;;AAjND;;GAEG;AACoB,uBAAI,GAAG,gBAAgB,CAAC,cAAc,AAAlC,CAAmC;AAC9D;;;;GAIG;AACoB,0BAAO,GAAG,CAAC,AAAJ,CAAK;AA2MvC,qBAAqB;AACrB,oBAAoB,CAAC,eAAe,CAChC,kBAAkB,CAAC,IAAI,EACvB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,kBAAkB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC,EACD,kBAAkB,CAAC,OAAO,EAC1B,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Engine } from \"../../Engines/engine\";\r\n\r\n/**\r\n * Options interface for the background remover plugin\r\n */\r\nexport interface IWebXRImageTrackingOptions {\r\n /**\r\n * A required array with images to track\r\n */\r\n images: {\r\n /**\r\n * The source of the image. can be a URL or an image bitmap\r\n */\r\n src: string | ImageBitmap;\r\n /**\r\n * The estimated width in the real world (in meters)\r\n */\r\n estimatedRealWorldWidth: number; // In meters!\r\n }[];\r\n}\r\n\r\n/**\r\n * An object representing an image tracked by the system\r\n */\r\nexport interface IWebXRTrackedImage {\r\n /**\r\n * The ID of this image (which is the same as the position in the array that was used to initialize the feature)\r\n */\r\n id: number;\r\n /**\r\n * Is the transformation provided emulated. If it is, the system \"guesses\" its real position. Otherwise it can be considered as exact position.\r\n */\r\n emulated?: boolean;\r\n /**\r\n * Just in case it is needed - the image bitmap that is being tracked\r\n */\r\n originalBitmap: ImageBitmap;\r\n /**\r\n * The native XR result image tracking result, untouched\r\n */\r\n xrTrackingResult?: XRImageTrackingResult;\r\n /**\r\n * Width in real world (meters)\r\n */\r\n realWorldWidth?: number;\r\n /**\r\n * A transformation matrix of this current image in the current reference space.\r\n */\r\n transformationMatrix: Matrix;\r\n /**\r\n * The width/height ratio of this image. can be used to calculate the size of the detected object/image\r\n */\r\n ratio?: number;\r\n}\r\n\r\n/**\r\n * Enum that describes the state of the image trackability score status for this session.\r\n */\r\nenum ImageTrackingScoreStatus {\r\n // AR Session has not yet assessed image trackability scores.\r\n NotReceived,\r\n // A request to retrieve trackability scores has been sent, but no response has been received.\r\n Waiting,\r\n // Image trackability scores have been received for this session\r\n Received,\r\n}\r\n\r\n/**\r\n * Image tracking for immersive AR sessions.\r\n * Providing a list of images and their estimated widths will enable tracking those images in the real world.\r\n */\r\nexport class WebXRImageTracking extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.IMAGE_TRACKING;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * This will be triggered if the underlying system deems an image untrackable.\r\n * The index is the index of the image from the array used to initialize the feature.\r\n */\r\n public onUntrackableImageFoundObservable: Observable<number> = new Observable();\r\n /**\r\n * An image was deemed trackable, and the system will start tracking it.\r\n */\r\n public onTrackableImageFoundObservable: Observable<IWebXRTrackedImage> = new Observable();\r\n /**\r\n * The image was found and its state was updated.\r\n */\r\n public onTrackedImageUpdatedObservable: Observable<IWebXRTrackedImage> = new Observable();\r\n\r\n private _trackableScoreStatus: ImageTrackingScoreStatus = ImageTrackingScoreStatus.NotReceived;\r\n private _trackedImages: IWebXRTrackedImage[] = [];\r\n\r\n private _originalTrackingRequest: XRTrackedImageInit[];\r\n\r\n /**\r\n * constructs the image tracking feature\r\n * @param _xrSessionManager the session manager for this module\r\n * @param options read-only options to be used in this module\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n /**\r\n * read-only options to be used in this module\r\n */\r\n public readonly options: IWebXRImageTrackingOptions\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"image-tracking\";\r\n }\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n return super.attach();\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n return super.detach();\r\n }\r\n\r\n /**\r\n * Get a tracked image by its ID.\r\n *\r\n * @param id the id of the image to load (position in the init array)\r\n * @returns a trackable image, if exists in this location\r\n */\r\n public getTrackedImageById(id: number): Nullable<IWebXRTrackedImage> {\r\n return this._trackedImages[id] || null;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n this._trackedImages.forEach((trackedImage) => {\r\n trackedImage.originalBitmap.close();\r\n });\r\n this._trackedImages.length = 0;\r\n this.onTrackableImageFoundObservable.clear();\r\n this.onUntrackableImageFoundObservable.clear();\r\n this.onTrackedImageUpdatedObservable.clear();\r\n }\r\n\r\n /**\r\n * Extends the session init object if needed\r\n * @returns augmentation object fo the xr session init object.\r\n */\r\n public async getXRSessionInitExtension(): Promise<Partial<XRSessionInit>> {\r\n if (!this.options.images || !this.options.images.length) {\r\n return {};\r\n }\r\n const promises = this.options.images.map((image) => {\r\n if (typeof image.src === \"string\") {\r\n return (this._xrSessionManager.scene.getEngine() as Engine)._createImageBitmapFromSource(image.src);\r\n } else {\r\n return Promise.resolve(image.src); // resolve is probably unneeded\r\n }\r\n });\r\n\r\n try {\r\n const images = await Promise.all(promises);\r\n\r\n this._originalTrackingRequest = images.map((image, idx) => {\r\n return {\r\n image,\r\n widthInMeters: this.options.images[idx].estimatedRealWorldWidth,\r\n };\r\n });\r\n\r\n return {\r\n trackedImages: this._originalTrackingRequest,\r\n };\r\n } catch (ex) {\r\n Tools.Error(\"Error loading images for tracking, WebXRImageTracking disabled for this session.\");\r\n return {};\r\n }\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame) {\r\n if (!_xrFrame.getImageTrackingResults || this._trackableScoreStatus === ImageTrackingScoreStatus.Waiting) {\r\n return;\r\n }\r\n\r\n // Image tracking scores may be generated a few frames after the XR Session initializes.\r\n // If we haven't received scores yet, then kick off the task to check scores and return immediately.\r\n if (this._trackableScoreStatus === ImageTrackingScoreStatus.NotReceived) {\r\n this._checkScoresAsync();\r\n return;\r\n }\r\n\r\n const imageTrackedResults = _xrFrame.getImageTrackingResults();\r\n for (const result of imageTrackedResults) {\r\n let changed = false;\r\n const imageIndex = result.index;\r\n\r\n const imageObject = this._trackedImages[imageIndex];\r\n if (!imageObject) {\r\n // something went wrong!\r\n continue;\r\n }\r\n\r\n imageObject.xrTrackingResult = result;\r\n if (imageObject.realWorldWidth !== result.measuredWidthInMeters) {\r\n imageObject.realWorldWidth = result.measuredWidthInMeters;\r\n changed = true;\r\n }\r\n\r\n // Get the pose of the image relative to a reference space.\r\n const pose = _xrFrame.getPose(result.imageSpace, this._xrSessionManager.referenceSpace);\r\n\r\n if (pose) {\r\n const mat = imageObject.transformationMatrix;\r\n Matrix.FromArrayToRef(pose.transform.matrix, 0, mat);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n mat.toggleModelMatrixHandInPlace();\r\n }\r\n changed = true;\r\n }\r\n\r\n const state = result.trackingState;\r\n const emulated = state === \"emulated\";\r\n\r\n if (imageObject.emulated !== emulated) {\r\n imageObject.emulated = emulated;\r\n changed = true;\r\n }\r\n if (changed) {\r\n this.onTrackedImageUpdatedObservable.notifyObservers(imageObject);\r\n }\r\n }\r\n }\r\n\r\n private async _checkScoresAsync(): Promise<void> {\r\n if (!this._xrSessionManager.session.getTrackedImageScores || this._trackableScoreStatus !== ImageTrackingScoreStatus.NotReceived) {\r\n return;\r\n }\r\n\r\n this._trackableScoreStatus = ImageTrackingScoreStatus.Waiting;\r\n const imageScores = await this._xrSessionManager.session.getTrackedImageScores();\r\n if (!imageScores || imageScores.length === 0) {\r\n this._trackableScoreStatus = ImageTrackingScoreStatus.NotReceived;\r\n return;\r\n }\r\n\r\n // check the scores for all\r\n for (let idx = 0; idx < imageScores.length; ++idx) {\r\n if (imageScores[idx] == \"untrackable\") {\r\n this.onUntrackableImageFoundObservable.notifyObservers(idx);\r\n } else {\r\n const originalBitmap = this._originalTrackingRequest[idx].image;\r\n const imageObject: IWebXRTrackedImage = {\r\n id: idx,\r\n originalBitmap,\r\n transformationMatrix: new Matrix(),\r\n ratio: originalBitmap.width / originalBitmap.height,\r\n };\r\n this._trackedImages[idx] = imageObject;\r\n this.onTrackableImageFoundObservable.notifyObservers(imageObject);\r\n }\r\n }\r\n\r\n this._trackableScoreStatus = imageScores.length > 0 ? ImageTrackingScoreStatus.Received : ImageTrackingScoreStatus.NotReceived;\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRImageTracking.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRImageTracking(xrSessionManager, options);\r\n },\r\n WebXRImageTracking.Version,\r\n false\r\n);\r\n"]}
|
|
@@ -4,8 +4,8 @@ import type { WebXRLayerWrapper } from "../webXRLayerWrapper";
|
|
|
4
4
|
import { WebXRWebGLLayerWrapper } from "../webXRWebGLLayer";
|
|
5
5
|
import { WebXRProjectionLayerWrapper } from "./Layers/WebXRProjectionLayer";
|
|
6
6
|
import { WebXRCompositionLayerWrapper } from "./Layers/WebXRCompositionLayer";
|
|
7
|
-
import type { DynamicTexture } from "../../Materials/Textures/dynamicTexture
|
|
8
|
-
import type { LensFlareSystem } from "../../LensFlares/lensFlareSystem
|
|
7
|
+
import type { DynamicTexture } from "../../Materials/Textures/dynamicTexture";
|
|
8
|
+
import type { LensFlareSystem } from "../../LensFlares/lensFlareSystem";
|
|
9
9
|
/**
|
|
10
10
|
* Configuration options of the layers feature
|
|
11
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebXRLayers.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRLayers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC1G,OAAO,EAAE,gDAAgD,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAGhI,OAAO,EAAE,MAAM,EAAE,kCAA8B;AAG/C,MAAM,uBAAuB,GAAqB,EAAE,CAAC;AAkBrD;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,oBAAoB;IAwBjD,YACI,iBAAsC,EACrB,WAAgC,EAAE;QAEnD,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAFR,aAAQ,GAAR,QAAQ,CAA0B;QAfvD;;WAEG;QACK,oBAAe,GAAwB,EAAE,CA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AC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;oBAC3E,IAAI,IAAI,EAAE;wBACN,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;wBACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;4BACnC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;4BACtB,WAAW,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC;yBACnD;qBACJ;iBACJ;qBAAM;oBACH,WAAW,CAAC,6BAA6B,EAAE,CAAC;iBAC/C;aACJ;SACJ;IACL,CAAC;;AAjVD;;GAEG;AACoB,gBAAI,GAAG,gBAAgB,CAAC,MAAM,AAA1B,CAA2B;AACtD;;;;GAIG;AACoB,mBAAO,GAAG,CAAC,AAAJ,CAAK;AA2UvC,qBAAqB;AACrB,oBAAoB,CAAC,eAAe,CAChC,WAAW,CAAC,IAAI,EAChB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,WAAW,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAC5D,CAAC,EACD,WAAW,CAAC,OAAO,EACnB,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { WebXRLayerWrapper } from \"../webXRLayerWrapper\";\r\nimport { WebXRWebGLLayerWrapper } from \"../webXRWebGLLayer\";\r\nimport { WebXRProjectionLayerWrapper, defaultXRProjectionLayerInit } from \"./Layers/WebXRProjectionLayer\";\r\nimport { WebXRCompositionLayerRenderTargetTextureProvider, WebXRCompositionLayerWrapper } from \"./Layers/WebXRCompositionLayer\";\r\nimport type { ThinTexture } from \"core/Materials/Textures/thinTexture\";\r\nimport type { DynamicTexture } from \"core/Materials/Textures/dynamicTexture\";\r\nimport { Color4 } from \"core/Maths/math.color\";\r\nimport type { LensFlareSystem } from \"core/LensFlares/lensFlareSystem\";\r\n\r\nconst defaultXRWebGLLayerInit: XRWebGLLayerInit = {};\r\n\r\n/**\r\n * Configuration options of the layers feature\r\n */\r\nexport interface IWebXRLayersOptions {\r\n /**\r\n * Whether to try initializing the base projection layer as a multiview render target, if multiview is supported.\r\n * Defaults to false.\r\n */\r\n preferMultiviewOnInit?: boolean;\r\n\r\n /**\r\n * Optional configuration for the base projection layer.\r\n */\r\n projectionLayerInit?: Partial<XRProjectionLayerInit>;\r\n}\r\n\r\n/**\r\n * Exposes the WebXR Layers API.\r\n */\r\nexport class WebXRLayers extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.LAYERS;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n /**\r\n * Already-created layers\r\n */\r\n private _existingLayers: WebXRLayerWrapper[] = [];\r\n\r\n private _glContext: WebGLRenderingContext | WebGL2RenderingContext;\r\n private _xrWebGLBinding: XRWebGLBinding;\r\n private _isMultiviewEnabled = false;\r\n private _projectionLayerInitialized = false;\r\n\r\n private _compositionLayerTextureMapping: WeakMap<XRCompositionLayer, ThinTexture> = new WeakMap();\r\n private _layerToRTTProviderMapping: WeakMap<XRCompositionLayer, WebXRCompositionLayerRenderTargetTextureProvider> = new WeakMap();\r\n\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n private readonly _options: IWebXRLayersOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"layers\";\r\n }\r\n\r\n /**\r\n * Attach this feature.\r\n * Will usually be called by the features manager.\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n const engine = this._xrSessionManager.scene.getEngine();\r\n this._glContext = engine._gl;\r\n this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n this._existingLayers.length = 0;\r\n\r\n const projectionLayerInit = { ...defaultXRProjectionLayerInit, ...this._options.projectionLayerInit };\r\n this._isMultiviewEnabled = this._options.preferMultiviewOnInit && engine.getCaps().multiview;\r\n this.createProjectionLayer(projectionLayerInit /*, projectionLayerMultiview*/);\r\n this._projectionLayerInitialized = true;\r\n\r\n return true;\r\n }\r\n\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n this._existingLayers.forEach((layer) => {\r\n layer.dispose();\r\n });\r\n this._existingLayers.length = 0;\r\n this._projectionLayerInitialized = false;\r\n return true;\r\n }\r\n\r\n /**\r\n * Creates a new XRWebGLLayer.\r\n * @param params an object providing configuration options for the new XRWebGLLayer\r\n * @returns the XRWebGLLayer\r\n */\r\n public createXRWebGLLayer(params = defaultXRWebGLLayerInit): WebXRWebGLLayerWrapper {\r\n const layer = new XRWebGLLayer(this._xrSessionManager.session, this._glContext, params);\r\n return new WebXRWebGLLayerWrapper(layer);\r\n }\r\n\r\n private _validateLayerInit(params: XRProjectionLayerInit | XRQuadLayerInit, multiview = this._isMultiviewEnabled): void {\r\n // check if we are in session\r\n if (!this._xrSessionManager.inXRSession) {\r\n throw new Error(\"Cannot create a layer outside of a WebXR session. Make sure the session has started before creating layers.\");\r\n }\r\n if (multiview && params.textureType !== \"texture-array\") {\r\n throw new Error(\"Projection layers can only be made multiview if they use texture arrays. Set the textureType parameter to 'texture-array'.\");\r\n }\r\n\r\n // TODO (rgerd): Support RTT's that are bound to sub-images in the texture array.\r\n if (!multiview && params.textureType === \"texture-array\") {\r\n throw new Error(\"We currently only support multiview rendering when the textureType parameter is set to 'texture-array'.\");\r\n }\r\n }\r\n\r\n private _extendXRLayerInit(params: XRProjectionLayerInit | XRQuadLayerInit, multiview = this._isMultiviewEnabled): XRProjectionLayerInit | XRQuadLayerInit {\r\n if (multiview) {\r\n params.textureType = \"texture-array\";\r\n }\r\n return params;\r\n }\r\n\r\n /**\r\n * Creates a new XRProjectionLayer.\r\n * @param params an object providing configuration options for the new XRProjectionLayer.\r\n * @param multiview whether the projection layer should render with multiview. Will be tru automatically if the extension initialized with multiview.\r\n * @returns the projection layer\r\n */\r\n public createProjectionLayer(params = defaultXRProjectionLayerInit, multiview = this._isMultiviewEnabled): WebXRProjectionLayerWrapper {\r\n this._extendXRLayerInit(params, multiview);\r\n this._validateLayerInit(params, multiview);\r\n\r\n const projLayer = this._xrWebGLBinding.createProjectionLayer(params);\r\n const layer = new WebXRProjectionLayerWrapper(projLayer, multiview, this._xrWebGLBinding);\r\n this.addXRSessionLayer(layer);\r\n return layer;\r\n }\r\n\r\n /**\r\n * Note about making it private - this function will be exposed once I decide on a proper API to support all of the XR layers' options\r\n * @param options an object providing configuration options for the new XRQuadLayer.\r\n * @param babylonTexture the texture to display in the layer\r\n * @returns the quad layer\r\n */\r\n private _createQuadLayer(options: { params: Partial<XRQuadLayerInit> } = { params: {} }, babylonTexture?: ThinTexture): WebXRCompositionLayerWrapper {\r\n this._extendXRLayerInit(options.params, false);\r\n const width = (this._existingLayers[0].layer as XRProjectionLayer).textureWidth;\r\n const height = (this._existingLayers[0].layer as XRProjectionLayer).textureHeight;\r\n const populatedParams: XRQuadLayerInit = {\r\n space: this._xrSessionManager.referenceSpace,\r\n viewPixelWidth: width,\r\n viewPixelHeight: height,\r\n clearOnAccess: true,\r\n ...options.params,\r\n };\r\n this._validateLayerInit(populatedParams, false);\r\n const quadLayer = this._xrWebGLBinding.createQuadLayer(populatedParams);\r\n\r\n quadLayer.width = this._isMultiviewEnabled ? 1 : 2;\r\n quadLayer.height = 1;\r\n // this wrapper is not really needed, but it's here for consistency\r\n const wrapper: WebXRCompositionLayerWrapper = new WebXRCompositionLayerWrapper(\r\n () => quadLayer.width,\r\n () => quadLayer.height,\r\n quadLayer,\r\n \"XRQuadLayer\",\r\n false,\r\n (sessionManager) => new WebXRCompositionLayerRenderTargetTextureProvider(sessionManager, this._xrWebGLBinding, wrapper)\r\n );\r\n\r\n if (babylonTexture) {\r\n this._compositionLayerTextureMapping.set(quadLayer, babylonTexture);\r\n }\r\n const rtt = wrapper.createRenderTargetTextureProvider(this._xrSessionManager) as WebXRCompositionLayerRenderTargetTextureProvider;\r\n this._layerToRTTProviderMapping.set(quadLayer, rtt);\r\n this.addXRSessionLayer(wrapper);\r\n return wrapper;\r\n }\r\n\r\n /**\r\n * @experimental\r\n * This will support full screen ADT when used with WebXR Layers. This API might change in the future.\r\n * Note that no interaction will be available with the ADT when using this method\r\n * @param texture the texture to display in the layer\r\n * @param options optional parameters for the layer\r\n * @returns a composition layer containing the texture\r\n */\r\n public addFullscreenAdvancedDynamicTexture(texture: DynamicTexture, options: { distanceFromHeadset: number } = { distanceFromHeadset: 1.5 }): WebXRCompositionLayerWrapper {\r\n const wrapper = this._createQuadLayer(\r\n {\r\n params: {\r\n space: this._xrSessionManager.viewerReferenceSpace,\r\n textureType: \"texture\",\r\n layout: \"mono\",\r\n },\r\n },\r\n texture\r\n );\r\n\r\n const layer = wrapper.layer as XRQuadLayer;\r\n const distance = Math.max(0.1, options.distanceFromHeadset);\r\n const pos = { x: 0, y: 0, z: -distance };\r\n const orient = { x: 0, y: 0, z: 0, w: 1 };\r\n layer.transform = new XRRigidTransform(pos, orient);\r\n\r\n const rttProvider = this._layerToRTTProviderMapping.get(layer);\r\n if (!rttProvider) {\r\n throw new Error(\"Could not find the RTT provider for the layer\");\r\n }\r\n const babylonLayer = this._xrSessionManager.scene.layers.find((babylonLayer) => {\r\n return babylonLayer.texture === texture;\r\n });\r\n if (!babylonLayer) {\r\n throw new Error(\"Could not find the babylon layer for the texture\");\r\n }\r\n rttProvider.onRenderTargetTextureCreatedObservable.add((data) => {\r\n if (data.eye && data.eye === \"right\") {\r\n return;\r\n }\r\n data.texture.clearColor = new Color4(0, 0, 0, 0);\r\n babylonLayer.renderTargetTextures.push(data.texture);\r\n babylonLayer.renderOnlyInRenderTargetTextures = true;\r\n // for stereo (not for gui) it should be onBeforeCameraRenderObservable\r\n this._xrSessionManager.scene.onBeforeRenderObservable.add(() => {\r\n data.texture.render();\r\n });\r\n babylonLayer.renderTargetTextures.push(data.texture);\r\n babylonLayer.renderOnlyInRenderTargetTextures = true;\r\n // add it back when the session ends\r\n this._xrSessionManager.onXRSessionEnded.addOnce(() => {\r\n babylonLayer.renderTargetTextures.splice(babylonLayer.renderTargetTextures.indexOf(data.texture), 1);\r\n babylonLayer.renderOnlyInRenderTargetTextures = false;\r\n });\r\n });\r\n return wrapper;\r\n }\r\n\r\n /**\r\n * @experimental\r\n * This functions allows you to add a lens flare system to the XR scene.\r\n * Note - this will remove the lens flare system from the scene and add it to the XR scene.\r\n * This feature is experimental and might change in the future.\r\n * @param flareSystem the flare system to add\r\n * @returns a composition layer containing the flare system\r\n */\r\n protected _addLensFlareSystem(flareSystem: LensFlareSystem): WebXRCompositionLayerWrapper {\r\n const wrapper = this._createQuadLayer({\r\n params: {\r\n space: this._xrSessionManager.viewerReferenceSpace,\r\n textureType: \"texture\",\r\n layout: \"mono\",\r\n },\r\n });\r\n\r\n const layer = wrapper.layer as XRQuadLayer;\r\n layer.width = 2;\r\n layer.height = 1;\r\n const distance = 10;\r\n const pos = { x: 0, y: 0, z: -distance };\r\n const orient = { x: 0, y: 0, z: 0, w: 1 };\r\n layer.transform = new XRRigidTransform(pos, orient);\r\n\r\n // get the rtt wrapper\r\n const rttProvider = this._layerToRTTProviderMapping.get(layer);\r\n if (!rttProvider) {\r\n throw new Error(\"Could not find the RTT provider for the layer\");\r\n }\r\n // render the flare system to the rtt\r\n rttProvider.onRenderTargetTextureCreatedObservable.add((data) => {\r\n data.texture.clearColor = new Color4(0, 0, 0, 0);\r\n data.texture.customRenderFunction = () => {\r\n flareSystem.render();\r\n };\r\n\r\n // add to the scene's render targets\r\n // this._xrSessionManager.scene.onBeforeCameraRenderObservable.add(() => {\r\n // data.texture.render();\r\n // });\r\n });\r\n // remove the lens flare system from the scene\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n this._xrSessionManager.scene.lensFlareSystems.splice(this._xrSessionManager.scene.lensFlareSystems.indexOf(flareSystem), 1);\r\n });\r\n // add it back when the session ends\r\n this._xrSessionManager.onXRSessionEnded.add(() => {\r\n this._xrSessionManager.scene.lensFlareSystems.push(flareSystem);\r\n });\r\n\r\n return wrapper;\r\n }\r\n\r\n /**\r\n * Add a new layer to the already-existing list of layers\r\n * @param wrappedLayer the new layer to add to the existing ones\r\n */\r\n public addXRSessionLayer(wrappedLayer: WebXRLayerWrapper) {\r\n this._existingLayers.push(wrappedLayer);\r\n this.setXRSessionLayers(this._existingLayers);\r\n }\r\n\r\n /**\r\n * Sets the layers to be used by the XR session.\r\n * Note that you must call this function with any layers you wish to render to\r\n * since it adds them to the XR session's render state\r\n * (replacing any layers that were added in a previous call to setXRSessionLayers or updateRenderState).\r\n * This method also sets up the session manager's render target texture provider\r\n * as the first layer in the array, which feeds the WebXR camera(s) attached to the session.\r\n * @param wrappedLayers An array of WebXRLayerWrapper, usually returned from the WebXRLayers createLayer functions.\r\n */\r\n public setXRSessionLayers(wrappedLayers: Array<WebXRLayerWrapper> = this._existingLayers): void {\r\n // this._existingLayers = wrappedLayers;\r\n const renderStateInit: XRRenderStateInit = { ...this._xrSessionManager.session.renderState };\r\n // Clear out the layer-related fields.\r\n renderStateInit.baseLayer = undefined;\r\n renderStateInit.layers = wrappedLayers.map((wrappedLayer) => wrappedLayer.layer);\r\n this._xrSessionManager.updateRenderState(renderStateInit);\r\n if (!this._projectionLayerInitialized) {\r\n this._xrSessionManager._setBaseLayerWrapper(wrappedLayers.length > 0 ? wrappedLayers.at(0)! : null);\r\n }\r\n }\r\n\r\n public isCompatible(): boolean {\r\n // TODO (rgerd): Add native support.\r\n return !this._xrSessionManager.isNative && typeof XRWebGLBinding !== \"undefined\" && !!XRWebGLBinding.prototype.createProjectionLayer;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached.\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n // Replace once the mapped internal texture of each available composition layer, apart from the last one, which is the projection layer that needs an RTT\r\n const layers = this._existingLayers;\r\n for (let i = 0; i < layers.length; ++i) {\r\n const layer = layers[i];\r\n if (layer.layerType !== \"XRProjectionLayer\") {\r\n // get the rtt provider\r\n const rttProvider = this._layerToRTTProviderMapping.get(layer.layer as XRCompositionLayer);\r\n if (!rttProvider) {\r\n continue;\r\n }\r\n\r\n if (rttProvider.layerWrapper.isMultiview) {\r\n // get the views, if we are in multiview\r\n const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (pose) {\r\n const views = pose.views;\r\n for (let j = 0; j < views.length; ++j) {\r\n const view = views[j];\r\n rttProvider.getRenderTargetTextureForView(view);\r\n }\r\n }\r\n } else {\r\n rttProvider.getRenderTargetTextureForView();\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRLayers.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRLayers(xrSessionManager, options);\r\n },\r\n WebXRLayers.Version,\r\n false\r\n);\r\n"]}
|
|
1
|
+
{"version":3,"file":"WebXRLayers.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRLayers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC1G,OAAO,EAAE,gDAAgD,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AA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I,KAAK,CAAC,SAAS,KAAK,mBAAmB,EAAE;gBACzC,uBAAuB;gBACvB,MAAM,WAAW,GAAG,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,KAAK,CAAC,KAA2B,CAAC,CAAC;gBAC3F,IAAI,CAAC,WAAW,EAAE;oBACd,SAAS;iBACZ;gBAED,IAAI,WAAW,CAAC,YAAY,CAAC,WAAW,EAAE;oBACtC,wCAAwC;oBACxC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;oBAC3E,IAAI,IAAI,EAAE;wBACN,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;wBACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;4BACnC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;4BACtB,WAAW,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC;yBACnD;qBACJ;iBACJ;qBAAM;oBACH,WAAW,CAAC,6BAA6B,EAAE,CAAC;iBAC/C;aACJ;SACJ;IACL,CAAC;;AAjVD;;GAEG;AACoB,gBAAI,GAAG,gBAAgB,CAAC,MAAM,AAA1B,CAA2B;AACtD;;;;GAIG;AACoB,mBAAO,GAAG,CAAC,AAAJ,CAAK;AA2UvC,qBAAqB;AACrB,oBAAoB,CAAC,eAAe,CAChC,WAAW,CAAC,IAAI,EAChB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,WAAW,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAC5D,CAAC,EACD,WAAW,CAAC,OAAO,EACnB,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { WebXRLayerWrapper } from \"../webXRLayerWrapper\";\r\nimport { WebXRWebGLLayerWrapper } from \"../webXRWebGLLayer\";\r\nimport { WebXRProjectionLayerWrapper, defaultXRProjectionLayerInit } from \"./Layers/WebXRProjectionLayer\";\r\nimport { WebXRCompositionLayerRenderTargetTextureProvider, WebXRCompositionLayerWrapper } from \"./Layers/WebXRCompositionLayer\";\r\nimport type { ThinTexture } from \"../../Materials/Textures/thinTexture\";\r\nimport type { DynamicTexture } from \"../../Materials/Textures/dynamicTexture\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport type { LensFlareSystem } from \"../../LensFlares/lensFlareSystem\";\r\nimport type { ThinEngine } from \"../../Engines\";\r\n\r\nconst defaultXRWebGLLayerInit: XRWebGLLayerInit = {};\r\n\r\n/**\r\n * Configuration options of the layers feature\r\n */\r\nexport interface IWebXRLayersOptions {\r\n /**\r\n * Whether to try initializing the base projection layer as a multiview render target, if multiview is supported.\r\n * Defaults to false.\r\n */\r\n preferMultiviewOnInit?: boolean;\r\n\r\n /**\r\n * Optional configuration for the base projection layer.\r\n */\r\n projectionLayerInit?: Partial<XRProjectionLayerInit>;\r\n}\r\n\r\n/**\r\n * Exposes the WebXR Layers API.\r\n */\r\nexport class WebXRLayers extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.LAYERS;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n /**\r\n * Already-created layers\r\n */\r\n private _existingLayers: WebXRLayerWrapper[] = [];\r\n\r\n private _glContext: WebGLRenderingContext | WebGL2RenderingContext;\r\n private _xrWebGLBinding: XRWebGLBinding;\r\n private _isMultiviewEnabled = false;\r\n private _projectionLayerInitialized = false;\r\n\r\n private _compositionLayerTextureMapping: WeakMap<XRCompositionLayer, ThinTexture> = new WeakMap();\r\n private _layerToRTTProviderMapping: WeakMap<XRCompositionLayer, WebXRCompositionLayerRenderTargetTextureProvider> = new WeakMap();\r\n\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n private readonly _options: IWebXRLayersOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"layers\";\r\n }\r\n\r\n /**\r\n * Attach this feature.\r\n * Will usually be called by the features manager.\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n const engine = this._xrSessionManager.scene.getEngine();\r\n this._glContext = (engine as ThinEngine)._gl;\r\n this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n this._existingLayers.length = 0;\r\n\r\n const projectionLayerInit = { ...defaultXRProjectionLayerInit, ...this._options.projectionLayerInit };\r\n this._isMultiviewEnabled = this._options.preferMultiviewOnInit && engine.getCaps().multiview;\r\n this.createProjectionLayer(projectionLayerInit /*, projectionLayerMultiview*/);\r\n this._projectionLayerInitialized = true;\r\n\r\n return true;\r\n }\r\n\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n this._existingLayers.forEach((layer) => {\r\n layer.dispose();\r\n });\r\n this._existingLayers.length = 0;\r\n this._projectionLayerInitialized = false;\r\n return true;\r\n }\r\n\r\n /**\r\n * Creates a new XRWebGLLayer.\r\n * @param params an object providing configuration options for the new XRWebGLLayer\r\n * @returns the XRWebGLLayer\r\n */\r\n public createXRWebGLLayer(params = defaultXRWebGLLayerInit): WebXRWebGLLayerWrapper {\r\n const layer = new XRWebGLLayer(this._xrSessionManager.session, this._glContext, params);\r\n return new WebXRWebGLLayerWrapper(layer);\r\n }\r\n\r\n private _validateLayerInit(params: XRProjectionLayerInit | XRQuadLayerInit, multiview = this._isMultiviewEnabled): void {\r\n // check if we are in session\r\n if (!this._xrSessionManager.inXRSession) {\r\n throw new Error(\"Cannot create a layer outside of a WebXR session. Make sure the session has started before creating layers.\");\r\n }\r\n if (multiview && params.textureType !== \"texture-array\") {\r\n throw new Error(\"Projection layers can only be made multiview if they use texture arrays. Set the textureType parameter to 'texture-array'.\");\r\n }\r\n\r\n // TODO (rgerd): Support RTT's that are bound to sub-images in the texture array.\r\n if (!multiview && params.textureType === \"texture-array\") {\r\n throw new Error(\"We currently only support multiview rendering when the textureType parameter is set to 'texture-array'.\");\r\n }\r\n }\r\n\r\n private _extendXRLayerInit(params: XRProjectionLayerInit | XRQuadLayerInit, multiview = this._isMultiviewEnabled): XRProjectionLayerInit | XRQuadLayerInit {\r\n if (multiview) {\r\n params.textureType = \"texture-array\";\r\n }\r\n return params;\r\n }\r\n\r\n /**\r\n * Creates a new XRProjectionLayer.\r\n * @param params an object providing configuration options for the new XRProjectionLayer.\r\n * @param multiview whether the projection layer should render with multiview. Will be tru automatically if the extension initialized with multiview.\r\n * @returns the projection layer\r\n */\r\n public createProjectionLayer(params = defaultXRProjectionLayerInit, multiview = this._isMultiviewEnabled): WebXRProjectionLayerWrapper {\r\n this._extendXRLayerInit(params, multiview);\r\n this._validateLayerInit(params, multiview);\r\n\r\n const projLayer = this._xrWebGLBinding.createProjectionLayer(params);\r\n const layer = new WebXRProjectionLayerWrapper(projLayer, multiview, this._xrWebGLBinding);\r\n this.addXRSessionLayer(layer);\r\n return layer;\r\n }\r\n\r\n /**\r\n * Note about making it private - this function will be exposed once I decide on a proper API to support all of the XR layers' options\r\n * @param options an object providing configuration options for the new XRQuadLayer.\r\n * @param babylonTexture the texture to display in the layer\r\n * @returns the quad layer\r\n */\r\n private _createQuadLayer(options: { params: Partial<XRQuadLayerInit> } = { params: {} }, babylonTexture?: ThinTexture): WebXRCompositionLayerWrapper {\r\n this._extendXRLayerInit(options.params, false);\r\n const width = (this._existingLayers[0].layer as XRProjectionLayer).textureWidth;\r\n const height = (this._existingLayers[0].layer as XRProjectionLayer).textureHeight;\r\n const populatedParams: XRQuadLayerInit = {\r\n space: this._xrSessionManager.referenceSpace,\r\n viewPixelWidth: width,\r\n viewPixelHeight: height,\r\n clearOnAccess: true,\r\n ...options.params,\r\n };\r\n this._validateLayerInit(populatedParams, false);\r\n const quadLayer = this._xrWebGLBinding.createQuadLayer(populatedParams);\r\n\r\n quadLayer.width = this._isMultiviewEnabled ? 1 : 2;\r\n quadLayer.height = 1;\r\n // this wrapper is not really needed, but it's here for consistency\r\n const wrapper: WebXRCompositionLayerWrapper = new WebXRCompositionLayerWrapper(\r\n () => quadLayer.width,\r\n () => quadLayer.height,\r\n quadLayer,\r\n \"XRQuadLayer\",\r\n false,\r\n (sessionManager) => new WebXRCompositionLayerRenderTargetTextureProvider(sessionManager, this._xrWebGLBinding, wrapper)\r\n );\r\n\r\n if (babylonTexture) {\r\n this._compositionLayerTextureMapping.set(quadLayer, babylonTexture);\r\n }\r\n const rtt = wrapper.createRenderTargetTextureProvider(this._xrSessionManager) as WebXRCompositionLayerRenderTargetTextureProvider;\r\n this._layerToRTTProviderMapping.set(quadLayer, rtt);\r\n this.addXRSessionLayer(wrapper);\r\n return wrapper;\r\n }\r\n\r\n /**\r\n * @experimental\r\n * This will support full screen ADT when used with WebXR Layers. This API might change in the future.\r\n * Note that no interaction will be available with the ADT when using this method\r\n * @param texture the texture to display in the layer\r\n * @param options optional parameters for the layer\r\n * @returns a composition layer containing the texture\r\n */\r\n public addFullscreenAdvancedDynamicTexture(texture: DynamicTexture, options: { distanceFromHeadset: number } = { distanceFromHeadset: 1.5 }): WebXRCompositionLayerWrapper {\r\n const wrapper = this._createQuadLayer(\r\n {\r\n params: {\r\n space: this._xrSessionManager.viewerReferenceSpace,\r\n textureType: \"texture\",\r\n layout: \"mono\",\r\n },\r\n },\r\n texture\r\n );\r\n\r\n const layer = wrapper.layer as XRQuadLayer;\r\n const distance = Math.max(0.1, options.distanceFromHeadset);\r\n const pos = { x: 0, y: 0, z: -distance };\r\n const orient = { x: 0, y: 0, z: 0, w: 1 };\r\n layer.transform = new XRRigidTransform(pos, orient);\r\n\r\n const rttProvider = this._layerToRTTProviderMapping.get(layer);\r\n if (!rttProvider) {\r\n throw new Error(\"Could not find the RTT provider for the layer\");\r\n }\r\n const babylonLayer = this._xrSessionManager.scene.layers.find((babylonLayer) => {\r\n return babylonLayer.texture === texture;\r\n });\r\n if (!babylonLayer) {\r\n throw new Error(\"Could not find the babylon layer for the texture\");\r\n }\r\n rttProvider.onRenderTargetTextureCreatedObservable.add((data) => {\r\n if (data.eye && data.eye === \"right\") {\r\n return;\r\n }\r\n data.texture.clearColor = new Color4(0, 0, 0, 0);\r\n babylonLayer.renderTargetTextures.push(data.texture);\r\n babylonLayer.renderOnlyInRenderTargetTextures = true;\r\n // for stereo (not for gui) it should be onBeforeCameraRenderObservable\r\n this._xrSessionManager.scene.onBeforeRenderObservable.add(() => {\r\n data.texture.render();\r\n });\r\n babylonLayer.renderTargetTextures.push(data.texture);\r\n babylonLayer.renderOnlyInRenderTargetTextures = true;\r\n // add it back when the session ends\r\n this._xrSessionManager.onXRSessionEnded.addOnce(() => {\r\n babylonLayer.renderTargetTextures.splice(babylonLayer.renderTargetTextures.indexOf(data.texture), 1);\r\n babylonLayer.renderOnlyInRenderTargetTextures = false;\r\n });\r\n });\r\n return wrapper;\r\n }\r\n\r\n /**\r\n * @experimental\r\n * This functions allows you to add a lens flare system to the XR scene.\r\n * Note - this will remove the lens flare system from the scene and add it to the XR scene.\r\n * This feature is experimental and might change in the future.\r\n * @param flareSystem the flare system to add\r\n * @returns a composition layer containing the flare system\r\n */\r\n protected _addLensFlareSystem(flareSystem: LensFlareSystem): WebXRCompositionLayerWrapper {\r\n const wrapper = this._createQuadLayer({\r\n params: {\r\n space: this._xrSessionManager.viewerReferenceSpace,\r\n textureType: \"texture\",\r\n layout: \"mono\",\r\n },\r\n });\r\n\r\n const layer = wrapper.layer as XRQuadLayer;\r\n layer.width = 2;\r\n layer.height = 1;\r\n const distance = 10;\r\n const pos = { x: 0, y: 0, z: -distance };\r\n const orient = { x: 0, y: 0, z: 0, w: 1 };\r\n layer.transform = new XRRigidTransform(pos, orient);\r\n\r\n // get the rtt wrapper\r\n const rttProvider = this._layerToRTTProviderMapping.get(layer);\r\n if (!rttProvider) {\r\n throw new Error(\"Could not find the RTT provider for the layer\");\r\n }\r\n // render the flare system to the rtt\r\n rttProvider.onRenderTargetTextureCreatedObservable.add((data) => {\r\n data.texture.clearColor = new Color4(0, 0, 0, 0);\r\n data.texture.customRenderFunction = () => {\r\n flareSystem.render();\r\n };\r\n\r\n // add to the scene's render targets\r\n // this._xrSessionManager.scene.onBeforeCameraRenderObservable.add(() => {\r\n // data.texture.render();\r\n // });\r\n });\r\n // remove the lens flare system from the scene\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n this._xrSessionManager.scene.lensFlareSystems.splice(this._xrSessionManager.scene.lensFlareSystems.indexOf(flareSystem), 1);\r\n });\r\n // add it back when the session ends\r\n this._xrSessionManager.onXRSessionEnded.add(() => {\r\n this._xrSessionManager.scene.lensFlareSystems.push(flareSystem);\r\n });\r\n\r\n return wrapper;\r\n }\r\n\r\n /**\r\n * Add a new layer to the already-existing list of layers\r\n * @param wrappedLayer the new layer to add to the existing ones\r\n */\r\n public addXRSessionLayer(wrappedLayer: WebXRLayerWrapper) {\r\n this._existingLayers.push(wrappedLayer);\r\n this.setXRSessionLayers(this._existingLayers);\r\n }\r\n\r\n /**\r\n * Sets the layers to be used by the XR session.\r\n * Note that you must call this function with any layers you wish to render to\r\n * since it adds them to the XR session's render state\r\n * (replacing any layers that were added in a previous call to setXRSessionLayers or updateRenderState).\r\n * This method also sets up the session manager's render target texture provider\r\n * as the first layer in the array, which feeds the WebXR camera(s) attached to the session.\r\n * @param wrappedLayers An array of WebXRLayerWrapper, usually returned from the WebXRLayers createLayer functions.\r\n */\r\n public setXRSessionLayers(wrappedLayers: Array<WebXRLayerWrapper> = this._existingLayers): void {\r\n // this._existingLayers = wrappedLayers;\r\n const renderStateInit: XRRenderStateInit = { ...this._xrSessionManager.session.renderState };\r\n // Clear out the layer-related fields.\r\n renderStateInit.baseLayer = undefined;\r\n renderStateInit.layers = wrappedLayers.map((wrappedLayer) => wrappedLayer.layer);\r\n this._xrSessionManager.updateRenderState(renderStateInit);\r\n if (!this._projectionLayerInitialized) {\r\n this._xrSessionManager._setBaseLayerWrapper(wrappedLayers.length > 0 ? wrappedLayers.at(0)! : null);\r\n }\r\n }\r\n\r\n public isCompatible(): boolean {\r\n // TODO (rgerd): Add native support.\r\n return !this._xrSessionManager.isNative && typeof XRWebGLBinding !== \"undefined\" && !!XRWebGLBinding.prototype.createProjectionLayer;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached.\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n // Replace once the mapped internal texture of each available composition layer, apart from the last one, which is the projection layer that needs an RTT\r\n const layers = this._existingLayers;\r\n for (let i = 0; i < layers.length; ++i) {\r\n const layer = layers[i];\r\n if (layer.layerType !== \"XRProjectionLayer\") {\r\n // get the rtt provider\r\n const rttProvider = this._layerToRTTProviderMapping.get(layer.layer as XRCompositionLayer);\r\n if (!rttProvider) {\r\n continue;\r\n }\r\n\r\n if (rttProvider.layerWrapper.isMultiview) {\r\n // get the views, if we are in multiview\r\n const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (pose) {\r\n const views = pose.views;\r\n for (let j = 0; j < views.length; ++j) {\r\n const view = views[j];\r\n rttProvider.getRenderTargetTextureForView(view);\r\n }\r\n }\r\n } else {\r\n rttProvider.getRenderTargetTextureForView();\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRLayers.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRLayers(xrSessionManager, options);\r\n },\r\n WebXRLayers.Version,\r\n false\r\n);\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebXRLightEstimation.js","sourceRoot":"","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BAA0B,EAAE;oBACrE,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,GAAG,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,IAAI,IAAI,mBAAmB,EAAE,CAAC;oBACvH,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;iBAC9F;gBAED,yCAAyC;gBACzC,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,CAAC;gBACrC,wCAAwC;gBACxC,IAAI,IAAI,CAAC,gBAAgB,EAAE;oBACvB,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;oBAC/D,IAAI,CAAC,gBAAgB,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;oBACjE,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;iBAC5D;aACJ;SACJ;IACL,CAAC;;AA/RD;;GAEG;AACoB,yBAAI,GAAG,gBAAgB,CAAC,gBAAgB,AAApC,CAAqC;AAChE;;;;GAIG;AACoB,4BAAO,GAAG,CAAC,AAAJ,CAAK;AAyRvC,sBAAsB;AACtB,oBAAoB,CAAC,eAAe,CAChC,oBAAoB,CAAC,IAAI,EACzB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,oBAAoB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC,EACD,oBAAoB,CAAC,OAAO,EAC5B,KAAK,CACR,CAAC","sourcesContent":["import { WebGLHardwareTexture } from \"../../Engines/WebGL/webGLHardwareTexture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { DirectionalLight } from \"../../Lights/directionalLight\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { SphericalHarmonics, SphericalPolynomial } from \"../../Maths/sphericalPolynomial\";\r\nimport { LightConstants } from \"../../Lights/lightConstants\";\r\nimport { HDRFiltering } from \"core/Materials/Textures/Filtering/hdrFiltering\";\r\n\r\n/**\r\n * Options for Light Estimation feature\r\n */\r\nexport interface IWebXRLightEstimationOptions {\r\n /**\r\n * Disable the cube map reflection feature. In this case only light direction and color will be updated\r\n */\r\n disableCubeMapReflection?: boolean;\r\n /**\r\n * Should the scene's env texture be set to the cube map reflection texture\r\n * Note that this doesn't work is disableCubeMapReflection if set to false\r\n */\r\n setSceneEnvironmentTexture?: boolean;\r\n /**\r\n * How often should the cubemap update in ms.\r\n * If not set the cubemap will be updated every time the underlying system updates the environment texture.\r\n */\r\n cubeMapPollInterval?: number;\r\n /**\r\n * How often should the light estimation properties update in ms.\r\n * If not set the light estimation properties will be updated on every frame (depending on the underlying system)\r\n */\r\n lightEstimationPollInterval?: number;\r\n /**\r\n * Should a directional light source be created.\r\n * If created, this light source will be updated whenever the light estimation values change\r\n */\r\n createDirectionalLightSource?: boolean;\r\n /**\r\n * Define the format to be used for the light estimation texture.\r\n */\r\n reflectionFormat?: XRReflectionFormat;\r\n /**\r\n * Should the light estimation's needed vectors be constructed on each frame.\r\n * Use this when you use those vectors and don't want their values to change outside of the light estimation feature\r\n */\r\n disableVectorReuse?: boolean;\r\n\r\n /**\r\n * disable applying the spherical polynomial to the cube map texture\r\n */\r\n disableSphericalPolynomial?: boolean;\r\n\r\n /**\r\n * disable prefiltering the cube map texture\r\n */\r\n disablePreFiltering?: boolean;\r\n}\r\n\r\n/**\r\n * An interface describing the result of a light estimation\r\n */\r\nexport interface IWebXRLightEstimation {\r\n /**\r\n * The intensity of the light source\r\n */\r\n lightIntensity: number;\r\n /**\r\n * Color of light source\r\n */\r\n lightColor: Color3;\r\n /**\r\n * The direction from the light source\r\n */\r\n lightDirection: Vector3;\r\n /**\r\n * Spherical harmonics coefficients of the light source\r\n */\r\n sphericalHarmonics: SphericalHarmonics;\r\n}\r\n\r\n/**\r\n * Light Estimation Feature\r\n *\r\n * @since 5.0.0\r\n */\r\nexport class WebXRLightEstimation extends WebXRAbstractFeature {\r\n private _canvasContext: Nullable<WebGLRenderingContext | WebGL2RenderingContext> = null;\r\n private _reflectionCubeMap: Nullable<BaseTexture> = null;\r\n private _xrLightEstimate: Nullable<XRLightEstimate> = null;\r\n private _xrLightProbe: Nullable<XRLightProbe> = null;\r\n private _xrWebGLBinding: Nullable<XRWebGLBinding> = null;\r\n private _lightDirection: Vector3 = Vector3.Up().negateInPlace();\r\n private _lightColor: Color3 = Color3.White();\r\n private _intensity: number = 1;\r\n private _sphericalHarmonics: SphericalHarmonics = new SphericalHarmonics();\r\n private _cubeMapPollTime = Date.now();\r\n private _lightEstimationPollTime = Date.now();\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.LIGHT_ESTIMATION;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * ARCore's reflection cube map size is 16x16.\r\n * Once other systems support this feature we will need to change this to be dynamic.\r\n * see https://github.com/immersive-web/lighting-estimation/blob/main/lighting-estimation-explainer.md#cube-map-open-questions\r\n */\r\n private _reflectionCubeMapTextureSize: number = 16;\r\n\r\n private _hdrFilter: HDRFiltering;\r\n\r\n /**\r\n * If createDirectionalLightSource is set to true this light source will be created automatically.\r\n * Otherwise this can be set with an external directional light source.\r\n * This light will be updated whenever the light estimation values change.\r\n */\r\n public directionalLight: Nullable<DirectionalLight> = null;\r\n\r\n /**\r\n * This observable will notify when the reflection cube map is updated.\r\n */\r\n public onReflectionCubeMapUpdatedObservable: Observable<BaseTexture> = new Observable();\r\n\r\n /**\r\n * Creates a new instance of the light estimation feature\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param options options to use when constructing this feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n /**\r\n * options to use when constructing this feature\r\n */\r\n public readonly options: IWebXRLightEstimationOptions\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"light-estimation\";\r\n\r\n if (this.options.createDirectionalLightSource) {\r\n this.directionalLight = new DirectionalLight(\"light estimation directional\", this._lightDirection, this._xrSessionManager.scene);\r\n this.directionalLight.position = new Vector3(0, 8, 0);\r\n // intensity will be set later\r\n this.directionalLight.intensity = 0;\r\n this.directionalLight.falloffType = LightConstants.FALLOFF_GLTF;\r\n }\r\n\r\n this._hdrFilter = new HDRFiltering(this._xrSessionManager.scene.getEngine());\r\n\r\n // https://immersive-web.github.io/lighting-estimation/\r\n Tools.Warn(\"light-estimation is an experimental and unstable feature.\");\r\n }\r\n\r\n /**\r\n * While the estimated cube map is expected to update over time to better reflect the user's environment as they move around those changes are unlikely to happen with every XRFrame.\r\n * Since creating and processing the cube map is potentially expensive, especially if mip maps are needed, you can listen to the onReflectionCubeMapUpdatedObservable to determine\r\n * when it has been updated.\r\n */\r\n public get reflectionCubeMapTexture(): Nullable<BaseTexture> {\r\n return this._reflectionCubeMap;\r\n }\r\n\r\n /**\r\n * The most recent light estimate. Available starting on the first frame where the device provides a light probe.\r\n */\r\n public get xrLightingEstimate(): Nullable<IWebXRLightEstimation> {\r\n if (this._xrLightEstimate) {\r\n return {\r\n lightColor: this._lightColor,\r\n lightDirection: this._lightDirection,\r\n lightIntensity: this._intensity,\r\n sphericalHarmonics: this._sphericalHarmonics,\r\n };\r\n }\r\n return this._xrLightEstimate;\r\n }\r\n\r\n private _getCanvasContext(): WebGLRenderingContext | WebGL2RenderingContext {\r\n if (this._canvasContext === null) {\r\n this._canvasContext = this._xrSessionManager.scene.getEngine()._gl;\r\n }\r\n return this._canvasContext;\r\n }\r\n\r\n private _getXRGLBinding(): XRWebGLBinding {\r\n if (this._xrWebGLBinding === null) {\r\n const context = this._getCanvasContext();\r\n this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, context);\r\n }\r\n return this._xrWebGLBinding;\r\n }\r\n\r\n /**\r\n * Event Listener for \"reflectionchange\" events.\r\n */\r\n private _updateReflectionCubeMap = (): void => {\r\n if (!this._xrLightProbe) {\r\n return;\r\n }\r\n // check poll time, do not update if it has not been long enough\r\n if (this.options.cubeMapPollInterval) {\r\n const now = Date.now();\r\n if (now - this._cubeMapPollTime < this.options.cubeMapPollInterval) {\r\n return;\r\n }\r\n this._cubeMapPollTime = now;\r\n }\r\n const lp = this._getXRGLBinding().getReflectionCubeMap(this._xrLightProbe);\r\n if (lp && this._reflectionCubeMap) {\r\n if (!this._reflectionCubeMap._texture) {\r\n const internalTexture = new InternalTexture(this._xrSessionManager.scene.getEngine(), InternalTextureSource.Unknown);\r\n internalTexture.isCube = true;\r\n internalTexture.invertY = false;\r\n internalTexture._useSRGBBuffer = this.options.reflectionFormat === \"srgba8\";\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.generateMipMaps = true;\r\n internalTexture.type = this.options.reflectionFormat !== \"srgba8\" ? Constants.TEXTURETYPE_HALF_FLOAT : Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.samplingMode = Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR;\r\n internalTexture.width = this._reflectionCubeMapTextureSize;\r\n internalTexture.height = this._reflectionCubeMapTextureSize;\r\n internalTexture._cachedWrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._cachedWrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(lp, this._getCanvasContext() as WebGLRenderingContext);\r\n this._reflectionCubeMap._texture = internalTexture;\r\n } else {\r\n this._reflectionCubeMap._texture._hardwareTexture?.set(lp);\r\n this._reflectionCubeMap._texture.getEngine().resetTextureCache();\r\n }\r\n this._reflectionCubeMap._texture.isReady = true;\r\n if (!this.options.disablePreFiltering) {\r\n this._xrLightProbe!.removeEventListener(\"reflectionchange\", this._updateReflectionCubeMap);\r\n this._hdrFilter.prefilter(this._reflectionCubeMap).then(() => {\r\n this._xrSessionManager.scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n this.onReflectionCubeMapUpdatedObservable.notifyObservers(this._reflectionCubeMap!);\r\n this._xrLightProbe!.addEventListener(\"reflectionchange\", this._updateReflectionCubeMap);\r\n });\r\n } else {\r\n this._xrSessionManager.scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n\r\n this.onReflectionCubeMapUpdatedObservable.notifyObservers(this._reflectionCubeMap);\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n const reflectionFormat = this.options.reflectionFormat ?? (this._xrSessionManager.session.preferredReflectionFormat || \"srgba8\");\r\n this.options.reflectionFormat = reflectionFormat;\r\n this._xrSessionManager.session\r\n .requestLightProbe({\r\n reflectionFormat,\r\n })\r\n .then((xrLightProbe: XRLightProbe) => {\r\n this._xrLightProbe = xrLightProbe;\r\n if (!this.options.disableCubeMapReflection) {\r\n if (!this._reflectionCubeMap) {\r\n this._reflectionCubeMap = new BaseTexture(this._xrSessionManager.scene);\r\n this._reflectionCubeMap._isCube = true;\r\n this._reflectionCubeMap.coordinatesMode = Constants.TEXTURE_CUBIC_MODE;\r\n if (this.options.setSceneEnvironmentTexture) {\r\n this._xrSessionManager.scene.environmentTexture = this._reflectionCubeMap;\r\n }\r\n }\r\n this._xrLightProbe.addEventListener(\"reflectionchange\", this._updateReflectionCubeMap);\r\n }\r\n });\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n const detached = super.detach();\r\n\r\n if (this._xrLightProbe !== null && !this.options.disableCubeMapReflection) {\r\n this._xrLightProbe.removeEventListener(\"reflectionchange\", this._updateReflectionCubeMap);\r\n this._xrLightProbe = null;\r\n }\r\n\r\n this._canvasContext = null;\r\n this._xrLightEstimate = null;\r\n // When the session ends (on detach) we must clear our XRWebGLBinging instance, which references the ended session.\r\n this._xrWebGLBinding = null;\r\n\r\n return detached;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n\r\n this.onReflectionCubeMapUpdatedObservable.clear();\r\n\r\n if (this.directionalLight) {\r\n this.directionalLight.dispose();\r\n this.directionalLight = null;\r\n }\r\n\r\n if (this._reflectionCubeMap !== null) {\r\n if (this._reflectionCubeMap._texture) {\r\n this._reflectionCubeMap._texture.dispose();\r\n }\r\n this._reflectionCubeMap.dispose();\r\n this._reflectionCubeMap = null;\r\n }\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n if (this._xrLightProbe !== null) {\r\n if (this.options.lightEstimationPollInterval) {\r\n const now = Date.now();\r\n if (now - this._lightEstimationPollTime < this.options.lightEstimationPollInterval) {\r\n return;\r\n }\r\n this._lightEstimationPollTime = now;\r\n }\r\n this._xrLightEstimate = _xrFrame.getLightEstimate(this._xrLightProbe);\r\n if (this._xrLightEstimate) {\r\n this._intensity = Math.max(\r\n 1.0,\r\n this._xrLightEstimate.primaryLightIntensity.x,\r\n this._xrLightEstimate.primaryLightIntensity.y,\r\n this._xrLightEstimate.primaryLightIntensity.z\r\n );\r\n\r\n const rhsFactor = this._xrSessionManager.scene.useRightHandedSystem ? 1.0 : -1.0;\r\n\r\n // recreate the vector caches, so that the last one provided to the user will persist\r\n if (this.options.disableVectorReuse) {\r\n this._lightDirection = new Vector3();\r\n this._lightColor = new Color3();\r\n if (this.directionalLight) {\r\n this.directionalLight.direction = this._lightDirection;\r\n this.directionalLight.diffuse = this._lightColor;\r\n }\r\n }\r\n\r\n this._lightDirection.copyFromFloats(\r\n this._xrLightEstimate.primaryLightDirection.x,\r\n this._xrLightEstimate.primaryLightDirection.y,\r\n this._xrLightEstimate.primaryLightDirection.z * rhsFactor\r\n );\r\n this._lightColor.copyFromFloats(\r\n this._xrLightEstimate.primaryLightIntensity.x / this._intensity,\r\n this._xrLightEstimate.primaryLightIntensity.y / this._intensity,\r\n this._xrLightEstimate.primaryLightIntensity.z / this._intensity\r\n );\r\n this._sphericalHarmonics.updateFromFloatsArray(this._xrLightEstimate.sphericalHarmonicsCoefficients);\r\n if (this._reflectionCubeMap && !this.options.disableSphericalPolynomial) {\r\n this._reflectionCubeMap.sphericalPolynomial = this._reflectionCubeMap.sphericalPolynomial || new SphericalPolynomial();\r\n this._reflectionCubeMap.sphericalPolynomial?.updateFromHarmonics(this._sphericalHarmonics);\r\n }\r\n\r\n // direction from instead of direction to\r\n this._lightDirection.negateInPlace();\r\n // set the values after calculating them\r\n if (this.directionalLight) {\r\n this.directionalLight.direction.copyFrom(this._lightDirection);\r\n this.directionalLight.intensity = Math.min(this._intensity, 1.0);\r\n this.directionalLight.diffuse.copyFrom(this._lightColor);\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\n// register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRLightEstimation.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRLightEstimation(xrSessionManager, options);\r\n },\r\n WebXRLightEstimation.Version,\r\n false\r\n);\r\n"]}
|
|
1
|
+
{"version":3,"file":"WebXRLightEstimation.js","sourceRoot":"","sources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BAA0B,EAAE;oBACrE,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,GAAG,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,IAAI,IAAI,mBAAmB,EAAE,CAAC;oBACvH,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;iBAC9F;gBAED,yCAAyC;gBACzC,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,CAAC;gBACrC,wCAAwC;gBACxC,IAAI,IAAI,CAAC,gBAAgB,EAAE;oBACvB,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;oBAC/D,IAAI,CAAC,gBAAgB,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;oBACjE,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;iBAC5D;aACJ;SACJ;IACL,CAAC;;AA/RD;;GAEG;AACoB,yBAAI,GAAG,gBAAgB,CAAC,gBAAgB,AAApC,CAAqC;AAChE;;;;GAIG;AACoB,4BAAO,GAAG,CAAC,AAAJ,CAAK;AAyRvC,sBAAsB;AACtB,oBAAoB,CAAC,eAAe,CAChC,oBAAoB,CAAC,IAAI,EACzB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,oBAAoB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC,EACD,oBAAoB,CAAC,OAAO,EAC5B,KAAK,CACR,CAAC","sourcesContent":["import { WebGLHardwareTexture } from \"../../Engines/WebGL/webGLHardwareTexture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { DirectionalLight } from \"../../Lights/directionalLight\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { SphericalHarmonics, SphericalPolynomial } from \"../../Maths/sphericalPolynomial\";\r\nimport { LightConstants } from \"../../Lights/lightConstants\";\r\nimport { HDRFiltering } from \"core/Materials/Textures/Filtering/hdrFiltering\";\r\nimport type { ThinEngine } from \"core/Engines\";\r\n\r\n/**\r\n * Options for Light Estimation feature\r\n */\r\nexport interface IWebXRLightEstimationOptions {\r\n /**\r\n * Disable the cube map reflection feature. In this case only light direction and color will be updated\r\n */\r\n disableCubeMapReflection?: boolean;\r\n /**\r\n * Should the scene's env texture be set to the cube map reflection texture\r\n * Note that this doesn't work is disableCubeMapReflection if set to false\r\n */\r\n setSceneEnvironmentTexture?: boolean;\r\n /**\r\n * How often should the cubemap update in ms.\r\n * If not set the cubemap will be updated every time the underlying system updates the environment texture.\r\n */\r\n cubeMapPollInterval?: number;\r\n /**\r\n * How often should the light estimation properties update in ms.\r\n * If not set the light estimation properties will be updated on every frame (depending on the underlying system)\r\n */\r\n lightEstimationPollInterval?: number;\r\n /**\r\n * Should a directional light source be created.\r\n * If created, this light source will be updated whenever the light estimation values change\r\n */\r\n createDirectionalLightSource?: boolean;\r\n /**\r\n * Define the format to be used for the light estimation texture.\r\n */\r\n reflectionFormat?: XRReflectionFormat;\r\n /**\r\n * Should the light estimation's needed vectors be constructed on each frame.\r\n * Use this when you use those vectors and don't want their values to change outside of the light estimation feature\r\n */\r\n disableVectorReuse?: boolean;\r\n\r\n /**\r\n * disable applying the spherical polynomial to the cube map texture\r\n */\r\n disableSphericalPolynomial?: boolean;\r\n\r\n /**\r\n * disable prefiltering the cube map texture\r\n */\r\n disablePreFiltering?: boolean;\r\n}\r\n\r\n/**\r\n * An interface describing the result of a light estimation\r\n */\r\nexport interface IWebXRLightEstimation {\r\n /**\r\n * The intensity of the light source\r\n */\r\n lightIntensity: number;\r\n /**\r\n * Color of light source\r\n */\r\n lightColor: Color3;\r\n /**\r\n * The direction from the light source\r\n */\r\n lightDirection: Vector3;\r\n /**\r\n * Spherical harmonics coefficients of the light source\r\n */\r\n sphericalHarmonics: SphericalHarmonics;\r\n}\r\n\r\n/**\r\n * Light Estimation Feature\r\n *\r\n * @since 5.0.0\r\n */\r\nexport class WebXRLightEstimation extends WebXRAbstractFeature {\r\n private _canvasContext: Nullable<WebGLRenderingContext | WebGL2RenderingContext> = null;\r\n private _reflectionCubeMap: Nullable<BaseTexture> = null;\r\n private _xrLightEstimate: Nullable<XRLightEstimate> = null;\r\n private _xrLightProbe: Nullable<XRLightProbe> = null;\r\n private _xrWebGLBinding: Nullable<XRWebGLBinding> = null;\r\n private _lightDirection: Vector3 = Vector3.Up().negateInPlace();\r\n private _lightColor: Color3 = Color3.White();\r\n private _intensity: number = 1;\r\n private _sphericalHarmonics: SphericalHarmonics = new SphericalHarmonics();\r\n private _cubeMapPollTime = Date.now();\r\n private _lightEstimationPollTime = Date.now();\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.LIGHT_ESTIMATION;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * ARCore's reflection cube map size is 16x16.\r\n * Once other systems support this feature we will need to change this to be dynamic.\r\n * see https://github.com/immersive-web/lighting-estimation/blob/main/lighting-estimation-explainer.md#cube-map-open-questions\r\n */\r\n private _reflectionCubeMapTextureSize: number = 16;\r\n\r\n private _hdrFilter: HDRFiltering;\r\n\r\n /**\r\n * If createDirectionalLightSource is set to true this light source will be created automatically.\r\n * Otherwise this can be set with an external directional light source.\r\n * This light will be updated whenever the light estimation values change.\r\n */\r\n public directionalLight: Nullable<DirectionalLight> = null;\r\n\r\n /**\r\n * This observable will notify when the reflection cube map is updated.\r\n */\r\n public onReflectionCubeMapUpdatedObservable: Observable<BaseTexture> = new Observable();\r\n\r\n /**\r\n * Creates a new instance of the light estimation feature\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param options options to use when constructing this feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n /**\r\n * options to use when constructing this feature\r\n */\r\n public readonly options: IWebXRLightEstimationOptions\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"light-estimation\";\r\n\r\n if (this.options.createDirectionalLightSource) {\r\n this.directionalLight = new DirectionalLight(\"light estimation directional\", this._lightDirection, this._xrSessionManager.scene);\r\n this.directionalLight.position = new Vector3(0, 8, 0);\r\n // intensity will be set later\r\n this.directionalLight.intensity = 0;\r\n this.directionalLight.falloffType = LightConstants.FALLOFF_GLTF;\r\n }\r\n\r\n this._hdrFilter = new HDRFiltering(this._xrSessionManager.scene.getEngine() as ThinEngine);\r\n\r\n // https://immersive-web.github.io/lighting-estimation/\r\n Tools.Warn(\"light-estimation is an experimental and unstable feature.\");\r\n }\r\n\r\n /**\r\n * While the estimated cube map is expected to update over time to better reflect the user's environment as they move around those changes are unlikely to happen with every XRFrame.\r\n * Since creating and processing the cube map is potentially expensive, especially if mip maps are needed, you can listen to the onReflectionCubeMapUpdatedObservable to determine\r\n * when it has been updated.\r\n */\r\n public get reflectionCubeMapTexture(): Nullable<BaseTexture> {\r\n return this._reflectionCubeMap;\r\n }\r\n\r\n /**\r\n * The most recent light estimate. Available starting on the first frame where the device provides a light probe.\r\n */\r\n public get xrLightingEstimate(): Nullable<IWebXRLightEstimation> {\r\n if (this._xrLightEstimate) {\r\n return {\r\n lightColor: this._lightColor,\r\n lightDirection: this._lightDirection,\r\n lightIntensity: this._intensity,\r\n sphericalHarmonics: this._sphericalHarmonics,\r\n };\r\n }\r\n return this._xrLightEstimate;\r\n }\r\n\r\n private _getCanvasContext(): WebGLRenderingContext | WebGL2RenderingContext {\r\n if (this._canvasContext === null) {\r\n this._canvasContext = (this._xrSessionManager.scene.getEngine() as ThinEngine)._gl;\r\n }\r\n return this._canvasContext;\r\n }\r\n\r\n private _getXRGLBinding(): XRWebGLBinding {\r\n if (this._xrWebGLBinding === null) {\r\n const context = this._getCanvasContext();\r\n this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, context);\r\n }\r\n return this._xrWebGLBinding;\r\n }\r\n\r\n /**\r\n * Event Listener for \"reflectionchange\" events.\r\n */\r\n private _updateReflectionCubeMap = (): void => {\r\n if (!this._xrLightProbe) {\r\n return;\r\n }\r\n // check poll time, do not update if it has not been long enough\r\n if (this.options.cubeMapPollInterval) {\r\n const now = Date.now();\r\n if (now - this._cubeMapPollTime < this.options.cubeMapPollInterval) {\r\n return;\r\n }\r\n this._cubeMapPollTime = now;\r\n }\r\n const lp = this._getXRGLBinding().getReflectionCubeMap(this._xrLightProbe);\r\n if (lp && this._reflectionCubeMap) {\r\n if (!this._reflectionCubeMap._texture) {\r\n const internalTexture = new InternalTexture(this._xrSessionManager.scene.getEngine(), InternalTextureSource.Unknown);\r\n internalTexture.isCube = true;\r\n internalTexture.invertY = false;\r\n internalTexture._useSRGBBuffer = this.options.reflectionFormat === \"srgba8\";\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.generateMipMaps = true;\r\n internalTexture.type = this.options.reflectionFormat !== \"srgba8\" ? Constants.TEXTURETYPE_HALF_FLOAT : Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.samplingMode = Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR;\r\n internalTexture.width = this._reflectionCubeMapTextureSize;\r\n internalTexture.height = this._reflectionCubeMapTextureSize;\r\n internalTexture._cachedWrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._cachedWrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(lp, this._getCanvasContext() as WebGLRenderingContext);\r\n this._reflectionCubeMap._texture = internalTexture;\r\n } else {\r\n this._reflectionCubeMap._texture._hardwareTexture?.set(lp);\r\n this._reflectionCubeMap._texture.getEngine().resetTextureCache();\r\n }\r\n this._reflectionCubeMap._texture.isReady = true;\r\n if (!this.options.disablePreFiltering) {\r\n this._xrLightProbe!.removeEventListener(\"reflectionchange\", this._updateReflectionCubeMap);\r\n this._hdrFilter.prefilter(this._reflectionCubeMap).then(() => {\r\n this._xrSessionManager.scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n this.onReflectionCubeMapUpdatedObservable.notifyObservers(this._reflectionCubeMap!);\r\n this._xrLightProbe!.addEventListener(\"reflectionchange\", this._updateReflectionCubeMap);\r\n });\r\n } else {\r\n this._xrSessionManager.scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n\r\n this.onReflectionCubeMapUpdatedObservable.notifyObservers(this._reflectionCubeMap);\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n const reflectionFormat = this.options.reflectionFormat ?? (this._xrSessionManager.session.preferredReflectionFormat || \"srgba8\");\r\n this.options.reflectionFormat = reflectionFormat;\r\n this._xrSessionManager.session\r\n .requestLightProbe({\r\n reflectionFormat,\r\n })\r\n .then((xrLightProbe: XRLightProbe) => {\r\n this._xrLightProbe = xrLightProbe;\r\n if (!this.options.disableCubeMapReflection) {\r\n if (!this._reflectionCubeMap) {\r\n this._reflectionCubeMap = new BaseTexture(this._xrSessionManager.scene);\r\n this._reflectionCubeMap._isCube = true;\r\n this._reflectionCubeMap.coordinatesMode = Constants.TEXTURE_CUBIC_MODE;\r\n if (this.options.setSceneEnvironmentTexture) {\r\n this._xrSessionManager.scene.environmentTexture = this._reflectionCubeMap;\r\n }\r\n }\r\n this._xrLightProbe.addEventListener(\"reflectionchange\", this._updateReflectionCubeMap);\r\n }\r\n });\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n const detached = super.detach();\r\n\r\n if (this._xrLightProbe !== null && !this.options.disableCubeMapReflection) {\r\n this._xrLightProbe.removeEventListener(\"reflectionchange\", this._updateReflectionCubeMap);\r\n this._xrLightProbe = null;\r\n }\r\n\r\n this._canvasContext = null;\r\n this._xrLightEstimate = null;\r\n // When the session ends (on detach) we must clear our XRWebGLBinging instance, which references the ended session.\r\n this._xrWebGLBinding = null;\r\n\r\n return detached;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n\r\n this.onReflectionCubeMapUpdatedObservable.clear();\r\n\r\n if (this.directionalLight) {\r\n this.directionalLight.dispose();\r\n this.directionalLight = null;\r\n }\r\n\r\n if (this._reflectionCubeMap !== null) {\r\n if (this._reflectionCubeMap._texture) {\r\n this._reflectionCubeMap._texture.dispose();\r\n }\r\n this._reflectionCubeMap.dispose();\r\n this._reflectionCubeMap = null;\r\n }\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n if (this._xrLightProbe !== null) {\r\n if (this.options.lightEstimationPollInterval) {\r\n const now = Date.now();\r\n if (now - this._lightEstimationPollTime < this.options.lightEstimationPollInterval) {\r\n return;\r\n }\r\n this._lightEstimationPollTime = now;\r\n }\r\n this._xrLightEstimate = _xrFrame.getLightEstimate(this._xrLightProbe);\r\n if (this._xrLightEstimate) {\r\n this._intensity = Math.max(\r\n 1.0,\r\n this._xrLightEstimate.primaryLightIntensity.x,\r\n this._xrLightEstimate.primaryLightIntensity.y,\r\n this._xrLightEstimate.primaryLightIntensity.z\r\n );\r\n\r\n const rhsFactor = this._xrSessionManager.scene.useRightHandedSystem ? 1.0 : -1.0;\r\n\r\n // recreate the vector caches, so that the last one provided to the user will persist\r\n if (this.options.disableVectorReuse) {\r\n this._lightDirection = new Vector3();\r\n this._lightColor = new Color3();\r\n if (this.directionalLight) {\r\n this.directionalLight.direction = this._lightDirection;\r\n this.directionalLight.diffuse = this._lightColor;\r\n }\r\n }\r\n\r\n this._lightDirection.copyFromFloats(\r\n this._xrLightEstimate.primaryLightDirection.x,\r\n this._xrLightEstimate.primaryLightDirection.y,\r\n this._xrLightEstimate.primaryLightDirection.z * rhsFactor\r\n );\r\n this._lightColor.copyFromFloats(\r\n this._xrLightEstimate.primaryLightIntensity.x / this._intensity,\r\n this._xrLightEstimate.primaryLightIntensity.y / this._intensity,\r\n this._xrLightEstimate.primaryLightIntensity.z / this._intensity\r\n );\r\n this._sphericalHarmonics.updateFromFloatsArray(this._xrLightEstimate.sphericalHarmonicsCoefficients);\r\n if (this._reflectionCubeMap && !this.options.disableSphericalPolynomial) {\r\n this._reflectionCubeMap.sphericalPolynomial = this._reflectionCubeMap.sphericalPolynomial || new SphericalPolynomial();\r\n this._reflectionCubeMap.sphericalPolynomial?.updateFromHarmonics(this._sphericalHarmonics);\r\n }\r\n\r\n // direction from instead of direction to\r\n this._lightDirection.negateInPlace();\r\n // set the values after calculating them\r\n if (this.directionalLight) {\r\n this.directionalLight.direction.copyFrom(this._lightDirection);\r\n this.directionalLight.intensity = Math.min(this._intensity, 1.0);\r\n this.directionalLight.diffuse.copyFrom(this._lightColor);\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\n// register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRLightEstimation.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRLightEstimation(xrSessionManager, options);\r\n },\r\n WebXRLightEstimation.Version,\r\n false\r\n);\r\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { WebXRSessionManager } from "../webXRSessionManager";
|
|
2
2
|
import { WebXRAbstractFeature } from "./WebXRAbstractFeature";
|
|
3
3
|
import { Observable } from "../../Misc/observable";
|
|
4
|
-
import { BaseTexture } from "../../Materials/Textures/baseTexture
|
|
4
|
+
import { BaseTexture } from "../../Materials/Textures/baseTexture";
|
|
5
5
|
/**
|
|
6
6
|
* Options for raw camera access
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebXRRawCameraAccess.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRRawCameraAccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,WAAW,EAAE,gDAA4C;AAYlE;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,oBAAoB;IAiD1D;;;;OAIG;IACH,YACI,iBAAsC,EACtB,UAAwC,EAAE;QAE1D,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAFT,YAAO,GAAP,OAAO,CAAmC;QAvDtD,4BAAuB,GAAsB,EAAE,CAAC;QACxD;;;;WAIG;QACI,iBAAY,GAAkB,EAAE,CAAC;QACxC;;WAEG;QACI,cAAS,GAAa,EAAE,CAAC;QAEhC;;;WAGG;QACI,qBAAgB,GAUjB,EAAE,CAAC;QAET;;WAEG;QACI,gCAA2B,GAA8B,IAAI,UAAU,EAAE,CAAC;QA2B7E,I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AAoB,CAAC,IAAI,EACzB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,oBAAoB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC,EACD,oBAAoB,CAAC,OAAO,EAC5B,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { WebGLHardwareTexture } from \"../../Engines/WebGL/webGLHardwareTexture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\n/**\r\n * Options for raw camera access\r\n */\r\nexport interface IWebXRRawCameraAccessOptions {\r\n /**\r\n * Keep the created textures and metadata when detaching the feature.\r\n */\r\n doNotDisposeOnDetach?: boolean;\r\n}\r\n\r\n/**\r\n * WebXR Feature for WebXR raw camera access\r\n * @since 6.31.0\r\n * @see https://immersive-web.github.io/raw-camera-access/\r\n */\r\nexport class WebXRRawCameraAccess extends WebXRAbstractFeature {\r\n private _cachedInternalTextures: InternalTexture[] = [];\r\n /**\r\n * This is an array of camera views\r\n * Note that mostly the array will contain a single view\r\n * If you want to know the order of the views, use the `viewIndex` array\r\n */\r\n public texturesData: BaseTexture[] = [];\r\n /**\r\n * If needed, this array will contain the eye definition of each texture in `texturesArray`\r\n */\r\n public viewIndex: string[] = [];\r\n\r\n /**\r\n * If needed, this array will contain the camera's intrinsics\r\n * You can use this data to convert from camera space to screen space and vice versa\r\n */\r\n public cameraIntrinsics: {\r\n u0: number;\r\n v0: number;\r\n ax: number;\r\n ay: number;\r\n gamma: number;\r\n width: number;\r\n height: number;\r\n viewportX: number;\r\n viewportY: number;\r\n }[] = [];\r\n\r\n /**\r\n * An observable that will notify when the camera's textures are updated\r\n */\r\n public onTexturesUpdatedObservable: Observable<BaseTexture[]> = new Observable();\r\n\r\n private _glBinding?: XRWebGLBinding;\r\n private _glContext: WebGLRenderingContext;\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.RAW_CAMERA_ACCESS;\r\n\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Creates a new instance of the feature\r\n * @param _xrSessionManager the WebXRSessionManager\r\n * @param options options for the Feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n public readonly options: IWebXRRawCameraAccessOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"camera-access\";\r\n }\r\n\r\n public attach(force?: boolean | undefined): boolean {\r\n if (!super.attach(force)) {\r\n return false;\r\n }\r\n\r\n this._glContext = this._xrSessionManager.scene.getEngine()._gl;\r\n this._glBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n\r\n return true;\r\n }\r\n\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n this._glBinding = undefined;\r\n if (!this.options.doNotDisposeOnDetach) {\r\n this._cachedInternalTextures.forEach((t) => t.dispose());\r\n this.texturesData.forEach((t) => t.dispose());\r\n this._cachedInternalTextures.length = 0;\r\n this.texturesData.length = 0;\r\n this.cameraIntrinsics.length = 0;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n this.onTexturesUpdatedObservable.clear();\r\n }\r\n\r\n /**\r\n * @see https://github.com/immersive-web/raw-camera-access/blob/main/explainer.md\r\n * @param view the XRView to update\r\n * @param index the index of the view in the views array\r\n */\r\n private _updateCameraIntrinsics(view: XRView, index: number): void {\r\n const cameraViewport = {\r\n width: view.camera!.width,\r\n height: view.camera!.height,\r\n x: 0,\r\n y: 0,\r\n };\r\n const p = view.projectionMatrix;\r\n\r\n // Principal point in pixels (typically at or near the center of the viewport)\r\n const u0 = ((1 - p[8]) * cameraViewport.width) / 2 + cameraViewport.x;\r\n const v0 = ((1 - p[9]) * cameraViewport.height) / 2 + cameraViewport.y;\r\n\r\n // Focal lengths in pixels (these are equal for square pixels)\r\n const ax = (cameraViewport.width / 2) * p[0];\r\n const ay = (cameraViewport.height / 2) * p[5];\r\n\r\n // Skew factor in pixels (nonzero for rhomboid pixels)\r\n const gamma = (cameraViewport.width / 2) * p[4];\r\n this.cameraIntrinsics[index] = {\r\n u0,\r\n v0,\r\n ax,\r\n ay,\r\n gamma,\r\n width: cameraViewport.width,\r\n height: cameraViewport.height,\r\n viewportX: cameraViewport.x,\r\n viewportY: cameraViewport.y,\r\n };\r\n }\r\n\r\n private _updateInternalTextures(view: XRView, index = 0): boolean {\r\n if (!view.camera) {\r\n return false;\r\n }\r\n this.viewIndex[index] = view.eye;\r\n const lp = this._glBinding?.getCameraImage(view.camera);\r\n\r\n if (!this._cachedInternalTextures[index]) {\r\n const internalTexture = new InternalTexture(this._xrSessionManager.scene.getEngine(), InternalTextureSource.Unknown, true);\r\n internalTexture.isCube = true;\r\n internalTexture.invertY = false;\r\n // internalTexture._useSRGBBuffer = this.options.reflectionFormat === \"srgba8\";\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.generateMipMaps = true;\r\n internalTexture.type = Constants.TEXTURETYPE_FLOAT;\r\n internalTexture.samplingMode = Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR;\r\n internalTexture.width = view.camera.width;\r\n internalTexture.height = view.camera.height;\r\n internalTexture._cachedWrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._cachedWrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(lp, this._glContext);\r\n this._cachedInternalTextures[index] = internalTexture;\r\n // create the base texture\r\n const texture = new BaseTexture(this._xrSessionManager.scene);\r\n texture.name = `WebXR Raw Camera Access (${index})`;\r\n texture._texture = this._cachedInternalTextures[index];\r\n this.texturesData[index] = texture;\r\n // get the camera intrinsics\r\n this._updateCameraIntrinsics(view, index);\r\n } else {\r\n // make sure the webgl texture is updated. Should happen automatically\r\n this._cachedInternalTextures[index]._hardwareTexture?.set(lp);\r\n }\r\n this._cachedInternalTextures[index].isReady = true;\r\n return true;\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const referenceSPace = this._xrSessionManager.referenceSpace;\r\n\r\n const pose = _xrFrame.getViewerPose(referenceSPace);\r\n if (!pose || !pose.views) {\r\n return;\r\n }\r\n let updated = true;\r\n pose.views.forEach((view, index) => {\r\n updated = updated && this._updateInternalTextures(view, index);\r\n });\r\n if (updated) {\r\n this.onTexturesUpdatedObservable.notifyObservers(this.texturesData);\r\n }\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRRawCameraAccess.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRRawCameraAccess(xrSessionManager, options);\r\n },\r\n WebXRRawCameraAccess.Version,\r\n false\r\n);\r\n"]}
|
|
1
|
+
{"version":3,"file":"WebXRRawCameraAccess.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRRawCameraAccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,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AO,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC/B,OAAO,GAAG,OAAO,IAAI,IAAI,CAAC,uBAAuB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;QACH,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,2BAA2B,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SACvE;IACL,CAAC;;AAnJD;;GAEG;AACoB,yBAAI,GAAG,gBAAgB,CAAC,iBAAiB,AAArC,CAAsC;AAEjE;;;;GAIG;AACoB,4BAAO,GAAG,CAAC,AAAJ,CAAK;AA4IvC,oBAAoB,CAAC,eAAe,CAChC,oBAAoB,CAAC,IAAI,EACzB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,oBAAoB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC,EACD,oBAAoB,CAAC,OAAO,EAC5B,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { WebGLHardwareTexture } from \"../../Engines/WebGL/webGLHardwareTexture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { ThinEngine } from \"../../Engines\";\r\n\r\n/**\r\n * Options for raw camera access\r\n */\r\nexport interface IWebXRRawCameraAccessOptions {\r\n /**\r\n * Keep the created textures and metadata when detaching the feature.\r\n */\r\n doNotDisposeOnDetach?: boolean;\r\n}\r\n\r\n/**\r\n * WebXR Feature for WebXR raw camera access\r\n * @since 6.31.0\r\n * @see https://immersive-web.github.io/raw-camera-access/\r\n */\r\nexport class WebXRRawCameraAccess extends WebXRAbstractFeature {\r\n private _cachedInternalTextures: InternalTexture[] = [];\r\n /**\r\n * This is an array of camera views\r\n * Note that mostly the array will contain a single view\r\n * If you want to know the order of the views, use the `viewIndex` array\r\n */\r\n public texturesData: BaseTexture[] = [];\r\n /**\r\n * If needed, this array will contain the eye definition of each texture in `texturesArray`\r\n */\r\n public viewIndex: string[] = [];\r\n\r\n /**\r\n * If needed, this array will contain the camera's intrinsics\r\n * You can use this data to convert from camera space to screen space and vice versa\r\n */\r\n public cameraIntrinsics: {\r\n u0: number;\r\n v0: number;\r\n ax: number;\r\n ay: number;\r\n gamma: number;\r\n width: number;\r\n height: number;\r\n viewportX: number;\r\n viewportY: number;\r\n }[] = [];\r\n\r\n /**\r\n * An observable that will notify when the camera's textures are updated\r\n */\r\n public onTexturesUpdatedObservable: Observable<BaseTexture[]> = new Observable();\r\n\r\n private _glBinding?: XRWebGLBinding;\r\n private _glContext: WebGLRenderingContext;\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.RAW_CAMERA_ACCESS;\r\n\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Creates a new instance of the feature\r\n * @param _xrSessionManager the WebXRSessionManager\r\n * @param options options for the Feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n public readonly options: IWebXRRawCameraAccessOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"camera-access\";\r\n }\r\n\r\n public attach(force?: boolean | undefined): boolean {\r\n if (!super.attach(force)) {\r\n return false;\r\n }\r\n\r\n this._glContext = (this._xrSessionManager.scene.getEngine() as ThinEngine)._gl;\r\n this._glBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n\r\n return true;\r\n }\r\n\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n this._glBinding = undefined;\r\n if (!this.options.doNotDisposeOnDetach) {\r\n this._cachedInternalTextures.forEach((t) => t.dispose());\r\n this.texturesData.forEach((t) => t.dispose());\r\n this._cachedInternalTextures.length = 0;\r\n this.texturesData.length = 0;\r\n this.cameraIntrinsics.length = 0;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n this.onTexturesUpdatedObservable.clear();\r\n }\r\n\r\n /**\r\n * @see https://github.com/immersive-web/raw-camera-access/blob/main/explainer.md\r\n * @param view the XRView to update\r\n * @param index the index of the view in the views array\r\n */\r\n private _updateCameraIntrinsics(view: XRView, index: number): void {\r\n const cameraViewport = {\r\n width: view.camera!.width,\r\n height: view.camera!.height,\r\n x: 0,\r\n y: 0,\r\n };\r\n const p = view.projectionMatrix;\r\n\r\n // Principal point in pixels (typically at or near the center of the viewport)\r\n const u0 = ((1 - p[8]) * cameraViewport.width) / 2 + cameraViewport.x;\r\n const v0 = ((1 - p[9]) * cameraViewport.height) / 2 + cameraViewport.y;\r\n\r\n // Focal lengths in pixels (these are equal for square pixels)\r\n const ax = (cameraViewport.width / 2) * p[0];\r\n const ay = (cameraViewport.height / 2) * p[5];\r\n\r\n // Skew factor in pixels (nonzero for rhomboid pixels)\r\n const gamma = (cameraViewport.width / 2) * p[4];\r\n this.cameraIntrinsics[index] = {\r\n u0,\r\n v0,\r\n ax,\r\n ay,\r\n gamma,\r\n width: cameraViewport.width,\r\n height: cameraViewport.height,\r\n viewportX: cameraViewport.x,\r\n viewportY: cameraViewport.y,\r\n };\r\n }\r\n\r\n private _updateInternalTextures(view: XRView, index = 0): boolean {\r\n if (!view.camera) {\r\n return false;\r\n }\r\n this.viewIndex[index] = view.eye;\r\n const lp = this._glBinding?.getCameraImage(view.camera);\r\n\r\n if (!this._cachedInternalTextures[index]) {\r\n const internalTexture = new InternalTexture(this._xrSessionManager.scene.getEngine(), InternalTextureSource.Unknown, true);\r\n internalTexture.isCube = true;\r\n internalTexture.invertY = false;\r\n // internalTexture._useSRGBBuffer = this.options.reflectionFormat === \"srgba8\";\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.generateMipMaps = true;\r\n internalTexture.type = Constants.TEXTURETYPE_FLOAT;\r\n internalTexture.samplingMode = Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR;\r\n internalTexture.width = view.camera.width;\r\n internalTexture.height = view.camera.height;\r\n internalTexture._cachedWrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._cachedWrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(lp, this._glContext);\r\n this._cachedInternalTextures[index] = internalTexture;\r\n // create the base texture\r\n const texture = new BaseTexture(this._xrSessionManager.scene);\r\n texture.name = `WebXR Raw Camera Access (${index})`;\r\n texture._texture = this._cachedInternalTextures[index];\r\n this.texturesData[index] = texture;\r\n // get the camera intrinsics\r\n this._updateCameraIntrinsics(view, index);\r\n } else {\r\n // make sure the webgl texture is updated. Should happen automatically\r\n this._cachedInternalTextures[index]._hardwareTexture?.set(lp);\r\n }\r\n this._cachedInternalTextures[index].isReady = true;\r\n return true;\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const referenceSPace = this._xrSessionManager.referenceSpace;\r\n\r\n const pose = _xrFrame.getViewerPose(referenceSPace);\r\n if (!pose || !pose.views) {\r\n return;\r\n }\r\n let updated = true;\r\n pose.views.forEach((view, index) => {\r\n updated = updated && this._updateInternalTextures(view, index);\r\n });\r\n if (updated) {\r\n this.onTexturesUpdatedObservable.notifyObservers(this.texturesData);\r\n }\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRRawCameraAccess.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRRawCameraAccess(xrSessionManager, options);\r\n },\r\n WebXRRawCameraAccess.Version,\r\n false\r\n);\r\n"]}
|
|
@@ -22,9 +22,7 @@ export class XRSpaceWarpRenderTarget extends RenderTargetTexture {
|
|
|
22
22
|
this._originalPairing = [];
|
|
23
23
|
this._previousWorldMatrices = [];
|
|
24
24
|
this._previousTransforms = [Matrix.Identity(), Matrix.Identity()];
|
|
25
|
-
this._renderTarget = this.getScene()
|
|
26
|
-
.getEngine()
|
|
27
|
-
.createMultiviewRenderTargetTexture(this.getRenderWidth(), this.getRenderHeight(), motionVectorTexture, depthStencilTexture);
|
|
25
|
+
this._renderTarget = this.getScene().getEngine().createMultiviewRenderTargetTexture(this.getRenderWidth(), this.getRenderHeight(), motionVectorTexture, depthStencilTexture);
|
|
28
26
|
this._renderTarget._disposeOnlyFramebuffers = true;
|
|
29
27
|
this._texture = this._renderTarget.texture;
|
|
30
28
|
this._texture.isMultiview = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebXRSpaceWarp.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRSpaceWarp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAIhE,OAAO,iCAAiC,CAAC;AACzC,OAAO,+BAA+B,CAAC;AAGvC;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,mBAAmB;IAM5D;;;;;;OAMG;IACH,YAAY,mBAAiC,EAAE,mBAAiC,EAAE,KAAa,EA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,CAAC,CAAC;SAClD;IACL,CAAC;IAIM,YAAY;QACf,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,CAAC,oBAAoB,IAAI,KAAK,CAAC;IAC5F,CAAC;IAEM,OAAO;QACV,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;IAES,UAAU,CAAC,QAAiB;QAClC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;QAC3E,IAAI,CAAC,IAAI,EAAE;YACP,OAAO;SACV;QAED,sEAAsE;QACtE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,oBAAqB,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC;QACxH,IAAI,CAAC,oBAAqB,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC;;AAnFD;;GAEG;AACoB,mBAAI,GAAG,gBAAgB,CAAC,UAAU,AAA9B,CAA+B;AAC1D;;;;GAIG;AACoB,sBAAO,GAAG,CAAC,AAAJ,CAAK;AA6EvC,qBAAqB;AACrB,oBAAoB,CAAC,eAAe,CAChC,cAAc,CAAC,IAAI,EACnB,CAAC,gBAAgB,EAAE,EAAE;IACjB,OAAO,GAAG,EAAE,CAAC,IAAI,cAAc,CAAC,gBAAgB,CAAC,CAAC;AACtD,CAAC,EACD,cAAc,CAAC,OAAO,EACtB,KAAK,CACR,CAAC","sourcesContent":["import type { Engine } from \"../../Engines/engine\";\r\nimport type { WebGLRenderTargetWrapper } from \"../../Engines/WebGL/webGLRenderTargetWrapper\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IWebXRRenderTargetTextureProvider } from \"../webXRRenderTargetTextureProvider\";\r\nimport type { Viewport } from \"../../Maths/math.viewport\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { ShaderMaterial } from \"../../Materials/shaderMaterial\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Material } from \"../../Materials/material\";\r\n\r\nimport \"../../Shaders/velocity.fragment\";\r\nimport \"../../Shaders/velocity.vertex\";\r\nimport type { Observer } from \"core/Misc/observable\";\r\n\r\n/**\r\n * Used for Space Warp render process\r\n */\r\nexport class XRSpaceWarpRenderTarget extends RenderTargetTexture {\r\n private _velocityMaterial: ShaderMaterial;\r\n private _originalPairing: Array<[AbstractMesh, Nullable<Material>]> = [];\r\n private _previousWorldMatrices: Array<Matrix> = [];\r\n private _previousTransforms: Matrix[] = [Matrix.Identity(), Matrix.Identity()];\r\n\r\n /**\r\n * Creates a Space Warp render target\r\n * @param motionVectorTexture WebGLTexture provided by WebGLSubImage\r\n * @param depthStencilTexture WebGLTexture provided by WebGLSubImage\r\n * @param scene scene used with the render target\r\n * @param size the size of the render target (used for each view)\r\n */\r\n constructor(motionVectorTexture: WebGLTexture, depthStencilTexture: WebGLTexture, scene?: Scene, size: number | { width: number; height: number } | { ratio: number } = 512) {\r\n super(\"spacewarp rtt\", size, scene, false, true, Constants.TEXTURETYPE_HALF_FLOAT, false, undefined, false, false, true, undefined, true);\r\n this._renderTarget = this.getScene()!\r\n .getEngine()\r\n .createMultiviewRenderTargetTexture(this.getRenderWidth(), this.getRenderHeight(), motionVectorTexture, depthStencilTexture);\r\n (this._renderTarget as WebGLRenderTargetWrapper)._disposeOnlyFramebuffers = true;\r\n this._texture = this._renderTarget.texture!;\r\n this._texture.isMultiview = true;\r\n this._texture.format = Constants.TEXTUREFORMAT_RGBA;\r\n\r\n if (scene) {\r\n this._velocityMaterial = new ShaderMaterial(\r\n \"velocity shader material\",\r\n scene,\r\n {\r\n vertex: \"velocity\",\r\n fragment: \"velocity\",\r\n },\r\n {\r\n uniforms: [\"world\", \"previousWorld\", \"viewProjection\", \"viewProjectionR\", \"previousViewProjection\", \"previousViewProjectionR\"],\r\n }\r\n );\r\n this._velocityMaterial._materialHelperNeedsPreviousMatrices = true;\r\n this._velocityMaterial.onBindObservable.add((mesh) => {\r\n // mesh. getWorldMatrix can be incorrect under rare conditions (e.g. when using a effective mesh in the render function).\r\n // If the case arise that will require changing it we will need to change the bind process in the material class to also provide the world matrix as a parameter\r\n this._previousWorldMatrices[mesh.uniqueId] = this._previousWorldMatrices[mesh.uniqueId] || mesh.getWorldMatrix();\r\n this._velocityMaterial.getEffect().setMatrix(\"previousWorld\", this._previousWorldMatrices[mesh.uniqueId]);\r\n this._previousWorldMatrices[mesh.uniqueId] = mesh.getWorldMatrix();\r\n // now set the scene's previous matrix\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjection\", this._previousTransforms[0]);\r\n // multiview for sure\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjectionR\", this._previousTransforms[1]);\r\n\r\n // store the previous (current, to be exact) transforms\r\n this._previousTransforms[0].copyFrom(scene.getTransformMatrix());\r\n this._previousTransforms[1].copyFrom(scene._transformMatrixR);\r\n });\r\n this._velocityMaterial.freeze();\r\n }\r\n }\r\n\r\n public render(useCameraPostProcess: boolean = false, dumpForDebug: boolean = false): void {\r\n // Swap to use velocity material\r\n this._originalPairing.length = 0;\r\n const scene = this.getScene();\r\n // set the velocity material to render the velocity RTT\r\n if (scene && this._velocityMaterial) {\r\n scene.getActiveMeshes().forEach((mesh) => {\r\n this._originalPairing.push([mesh, mesh.material]);\r\n mesh.material = this._velocityMaterial;\r\n });\r\n }\r\n\r\n super.render(useCameraPostProcess, dumpForDebug);\r\n\r\n // Restore original materials\r\n this._originalPairing.forEach((tuple) => {\r\n tuple[0].material = tuple[1];\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bindFrameBuffer() {\r\n if (!this._renderTarget) {\r\n return;\r\n }\r\n this.getScene()!.getEngine().bindSpaceWarpFramebuffer(this._renderTarget);\r\n }\r\n\r\n /**\r\n * Gets the number of views the corresponding to the texture (eg. a SpaceWarpRenderTarget will have > 1)\r\n * @returns the view count\r\n */\r\n public getViewCount() {\r\n return 2;\r\n }\r\n\r\n public dispose(): void {\r\n super.dispose();\r\n this._velocityMaterial.dispose();\r\n this._previousTransforms.length = 0;\r\n this._previousWorldMatrices.length = 0;\r\n this._originalPairing.length = 0;\r\n }\r\n}\r\n\r\n/**\r\n * WebXR Space Warp Render Target Texture Provider\r\n */\r\nexport class WebXRSpaceWarpRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n protected _lastSubImages = new Map<XRView, XRWebGLSubImage>();\r\n protected _renderTargetTextures = new Map<XREye, RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n protected _engine: Engine;\r\n\r\n constructor(\r\n protected readonly _scene: Scene,\r\n protected readonly _xrSessionManager: WebXRSessionManager,\r\n protected readonly _xrWebGLBinding: XRWebGLBinding\r\n ) {\r\n this._engine = _scene.getEngine();\r\n }\r\n\r\n private _getSubImageForView(view: XRView): XRWebGLSubImage {\r\n const layerWrapper = this._xrSessionManager._getBaseLayerWrapper();\r\n if (!layerWrapper) {\r\n throw new Error(\"For Space Warp, the base layer should be a WebXR Projection Layer.\");\r\n }\r\n if (layerWrapper.layerType !== \"XRProjectionLayer\") {\r\n throw new Error('For Space Warp, the base layer type should \"XRProjectionLayer\".');\r\n }\r\n const layer = layerWrapper.layer as XRProjectionLayer;\r\n return this._xrWebGLBinding.getViewSubImage(layer, view);\r\n }\r\n\r\n protected _setViewportForSubImage(viewport: Viewport, subImage: XRWebGLSubImage) {\r\n viewport.x = 0;\r\n viewport.y = 0;\r\n viewport.width = subImage.motionVectorTextureWidth!;\r\n viewport.height = subImage.motionVectorTextureHeight!;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable<WebGLFramebuffer>,\r\n motionVectorTexture: WebGLTexture,\r\n depthStencilTexture: WebGLTexture\r\n ): RenderTargetTexture {\r\n if (!this._engine) {\r\n throw new Error(\"Engine is disposed\");\r\n }\r\n\r\n const textureSize = { width, height };\r\n\r\n // Create render target texture from the internal texture\r\n const renderTargetTexture = new XRSpaceWarpRenderTarget(motionVectorTexture, depthStencilTexture, this._scene, textureSize);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n if (framebuffer) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n renderTargetWrapper._colorTextureArray = motionVectorTexture;\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n\r\n renderTargetTexture.disableRescaling();\r\n renderTargetTexture.renderListPredicate = () => true;\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _getRenderTargetForSubImage(subImage: XRWebGLSubImage, view: XRView) {\r\n const lastSubImage = this._lastSubImages.get(view);\r\n let renderTargetTexture = this._renderTargetTextures.get(view.eye);\r\n\r\n const width = subImage.motionVectorTextureWidth!;\r\n const height = subImage.motionVectorTextureHeight!;\r\n\r\n if (!renderTargetTexture || lastSubImage?.textureWidth !== width || lastSubImage?.textureHeight != height) {\r\n renderTargetTexture = this._createRenderTargetTexture(width, height, null, subImage.motionVectorTexture!, subImage.depthStencilTexture!);\r\n this._renderTargetTextures.set(view.eye, renderTargetTexture);\r\n\r\n this._framebufferDimensions = {\r\n framebufferWidth: width,\r\n framebufferHeight: height,\r\n };\r\n }\r\n\r\n this._lastSubImages.set(view, subImage);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n const subImage = this._lastSubImages.get(view) || this._getSubImageForView(view);\r\n if (subImage) {\r\n this._setViewportForSubImage(viewport, subImage);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Access the motion vector (which will turn on Space Warp)\r\n * @param view the view to access the motion vector texture for\r\n */\r\n public accessMotionVector(view: XRView): void {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n // Meta Quest Browser uses accessing these textures as a sign for turning on Space Warp\r\n subImage.motionVectorTexture;\r\n subImage.depthStencilTexture;\r\n }\r\n }\r\n\r\n public getRenderTargetTextureForEye(_eye: XREye): Nullable<RenderTargetTexture> {\r\n return null;\r\n }\r\n\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n return this._getRenderTargetForSubImage(subImage, view);\r\n }\r\n return null;\r\n }\r\n\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.clear();\r\n }\r\n}\r\n\r\n/**\r\n * the WebXR Space Warp feature.\r\n */\r\nexport class WebXRSpaceWarp extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.SPACE_WARP;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * The space warp provider\r\n */\r\n public spaceWarpRTTProvider: Nullable<WebXRSpaceWarpRenderTargetTextureProvider>;\r\n private _glContext: WebGLRenderingContext | WebGL2RenderingContext;\r\n private _xrWebGLBinding: XRWebGLBinding;\r\n private _renderTargetTexture: Nullable<RenderTargetTexture>;\r\n private _onAfterRenderObserver: Nullable<Observer<Scene>> = null;\r\n\r\n /**\r\n * constructor for the space warp feature\r\n * @param _xrSessionManager the xr session manager for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"space-warp\";\r\n this._xrSessionManager.scene.needsPreviousWorldMatrices = true;\r\n }\r\n\r\n /**\r\n * Attach this feature.\r\n * Will usually be called by the features manager.\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n const engine = this._xrSessionManager.scene.getEngine();\r\n this._glContext = engine._gl;\r\n this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n\r\n this.spaceWarpRTTProvider = new WebXRSpaceWarpRenderTargetTextureProvider(this._xrSessionManager.scene, this._xrSessionManager, this._xrWebGLBinding);\r\n\r\n this._onAfterRenderObserver = this._xrSessionManager.scene.onAfterRenderObservable.add(() => this._onAfterRender());\r\n\r\n return true;\r\n }\r\n\r\n public detach(): boolean {\r\n this._xrSessionManager.scene.onAfterRenderObservable.remove(this._onAfterRenderObserver);\r\n return super.detach();\r\n }\r\n\r\n private _onAfterRender(): void {\r\n if (this.attached && this._renderTargetTexture) {\r\n this._renderTargetTexture.render(false, false);\r\n }\r\n }\r\n\r\n public dependsOn: string[] = [WebXRFeatureName.LAYERS];\r\n\r\n public isCompatible(): boolean {\r\n return this._xrSessionManager.scene.getEngine().getCaps().colorBufferHalfFloat || false;\r\n }\r\n\r\n public dispose(): void {\r\n super.dispose();\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n\r\n // get the first view to which we will create a texture (or update it)\r\n const view = pose.views[0];\r\n this._renderTargetTexture = this._renderTargetTexture || this.spaceWarpRTTProvider!.getRenderTargetTextureForView(view);\r\n this.spaceWarpRTTProvider!.accessMotionVector(view);\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRSpaceWarp.Name,\r\n (xrSessionManager) => {\r\n return () => new WebXRSpaceWarp(xrSessionManager);\r\n },\r\n WebXRSpaceWarp.Version,\r\n false\r\n);\r\n"]}
|
|
1
|
+
{"version":3,"file":"WebXRSpaceWarp.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRSpaceWarp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,iCAAiC,CAAC;AACzC,OAAO,+BAA+B,CAAC;AAIvC;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,mBAAmB;IAM5D;;;;;;OAMG;IACH,YAAY,mBAAiC,EAAE,mBAAiC,EAAE,KAAa,EAAE,OAAuE,GAAG;QACvK,KAAK,CAAC,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,sBAAsB,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QAZtI,qBAAgB,GAA8C,EAAE,CAAC;QACjE,2BAAsB,GAAkB,EAAE,CAAC;QAC3C,wBAAmB,GAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QAW3E,IAAI,CAAC,aAAa,GAAI,IAAI,CAAC,QAAQ,EAAG,CAAC,SAAS,EAAa,CAAC,kCAAkC,CAC5F,IAAI,CAAC,cAAc,EAAE,EACrB,IAAI,CAAC,eAAe,EAAE,EACtB,mBAAmB,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AC,oBAAqB,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC;QACxH,IAAI,CAAC,oBAAqB,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC;;AAnFD;;GAEG;AACoB,mBAAI,GAAG,gBAAgB,CAAC,UAAU,AAA9B,CAA+B;AAC1D;;;;GAIG;AACoB,sBAAO,GAAG,CAAC,AAAJ,CAAK;AA6EvC,qBAAqB;AACrB,oBAAoB,CAAC,eAAe,CAChC,cAAc,CAAC,IAAI,EACnB,CAAC,gBAAgB,EAAE,EAAE;IACjB,OAAO,GAAG,EAAE,CAAC,IAAI,cAAc,CAAC,gBAAgB,CAAC,CAAC;AACtD,CAAC,EACD,cAAc,CAAC,OAAO,EACtB,KAAK,CACR,CAAC","sourcesContent":["import type { Engine } from \"../../Engines/engine\";\r\nimport type { WebGLRenderTargetWrapper } from \"../../Engines/WebGL/webGLRenderTargetWrapper\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IWebXRRenderTargetTextureProvider } from \"../webXRRenderTargetTextureProvider\";\r\nimport type { Viewport } from \"../../Maths/math.viewport\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { ShaderMaterial } from \"../../Materials/shaderMaterial\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Material } from \"../../Materials/material\";\r\nimport \"../../Shaders/velocity.fragment\";\r\nimport \"../../Shaders/velocity.vertex\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\n\r\n/**\r\n * Used for Space Warp render process\r\n */\r\nexport class XRSpaceWarpRenderTarget extends RenderTargetTexture {\r\n private _velocityMaterial: ShaderMaterial;\r\n private _originalPairing: Array<[AbstractMesh, Nullable<Material>]> = [];\r\n private _previousWorldMatrices: Array<Matrix> = [];\r\n private _previousTransforms: Matrix[] = [Matrix.Identity(), Matrix.Identity()];\r\n\r\n /**\r\n * Creates a Space Warp render target\r\n * @param motionVectorTexture WebGLTexture provided by WebGLSubImage\r\n * @param depthStencilTexture WebGLTexture provided by WebGLSubImage\r\n * @param scene scene used with the render target\r\n * @param size the size of the render target (used for each view)\r\n */\r\n constructor(motionVectorTexture: WebGLTexture, depthStencilTexture: WebGLTexture, scene?: Scene, size: number | { width: number; height: number } | { ratio: number } = 512) {\r\n super(\"spacewarp rtt\", size, scene, false, true, Constants.TEXTURETYPE_HALF_FLOAT, false, undefined, false, false, true, undefined, true);\r\n this._renderTarget = (this.getScene()!.getEngine() as Engine).createMultiviewRenderTargetTexture(\r\n this.getRenderWidth(),\r\n this.getRenderHeight(),\r\n motionVectorTexture,\r\n depthStencilTexture\r\n );\r\n (this._renderTarget as WebGLRenderTargetWrapper)._disposeOnlyFramebuffers = true;\r\n this._texture = this._renderTarget.texture!;\r\n this._texture.isMultiview = true;\r\n this._texture.format = Constants.TEXTUREFORMAT_RGBA;\r\n\r\n if (scene) {\r\n this._velocityMaterial = new ShaderMaterial(\r\n \"velocity shader material\",\r\n scene,\r\n {\r\n vertex: \"velocity\",\r\n fragment: \"velocity\",\r\n },\r\n {\r\n uniforms: [\"world\", \"previousWorld\", \"viewProjection\", \"viewProjectionR\", \"previousViewProjection\", \"previousViewProjectionR\"],\r\n }\r\n );\r\n this._velocityMaterial._materialHelperNeedsPreviousMatrices = true;\r\n this._velocityMaterial.onBindObservable.add((mesh) => {\r\n // mesh. getWorldMatrix can be incorrect under rare conditions (e.g. when using a effective mesh in the render function).\r\n // If the case arise that will require changing it we will need to change the bind process in the material class to also provide the world matrix as a parameter\r\n this._previousWorldMatrices[mesh.uniqueId] = this._previousWorldMatrices[mesh.uniqueId] || mesh.getWorldMatrix();\r\n this._velocityMaterial.getEffect().setMatrix(\"previousWorld\", this._previousWorldMatrices[mesh.uniqueId]);\r\n this._previousWorldMatrices[mesh.uniqueId] = mesh.getWorldMatrix();\r\n // now set the scene's previous matrix\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjection\", this._previousTransforms[0]);\r\n // multiview for sure\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjectionR\", this._previousTransforms[1]);\r\n\r\n // store the previous (current, to be exact) transforms\r\n this._previousTransforms[0].copyFrom(scene.getTransformMatrix());\r\n this._previousTransforms[1].copyFrom(scene._transformMatrixR);\r\n });\r\n this._velocityMaterial.freeze();\r\n }\r\n }\r\n\r\n public render(useCameraPostProcess: boolean = false, dumpForDebug: boolean = false): void {\r\n // Swap to use velocity material\r\n this._originalPairing.length = 0;\r\n const scene = this.getScene();\r\n // set the velocity material to render the velocity RTT\r\n if (scene && this._velocityMaterial) {\r\n scene.getActiveMeshes().forEach((mesh) => {\r\n this._originalPairing.push([mesh, mesh.material]);\r\n mesh.material = this._velocityMaterial;\r\n });\r\n }\r\n\r\n super.render(useCameraPostProcess, dumpForDebug);\r\n\r\n // Restore original materials\r\n this._originalPairing.forEach((tuple) => {\r\n tuple[0].material = tuple[1];\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bindFrameBuffer() {\r\n if (!this._renderTarget) {\r\n return;\r\n }\r\n (this.getScene()!.getEngine() as Engine).bindSpaceWarpFramebuffer(this._renderTarget);\r\n }\r\n\r\n /**\r\n * Gets the number of views the corresponding to the texture (eg. a SpaceWarpRenderTarget will have > 1)\r\n * @returns the view count\r\n */\r\n public getViewCount() {\r\n return 2;\r\n }\r\n\r\n public dispose(): void {\r\n super.dispose();\r\n this._velocityMaterial.dispose();\r\n this._previousTransforms.length = 0;\r\n this._previousWorldMatrices.length = 0;\r\n this._originalPairing.length = 0;\r\n }\r\n}\r\n\r\n/**\r\n * WebXR Space Warp Render Target Texture Provider\r\n */\r\nexport class WebXRSpaceWarpRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n protected _lastSubImages = new Map<XRView, XRWebGLSubImage>();\r\n protected _renderTargetTextures = new Map<XREye, RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n protected _engine: Engine;\r\n\r\n constructor(\r\n protected readonly _scene: Scene,\r\n protected readonly _xrSessionManager: WebXRSessionManager,\r\n protected readonly _xrWebGLBinding: XRWebGLBinding\r\n ) {\r\n this._engine = _scene.getEngine() as Engine;\r\n }\r\n\r\n private _getSubImageForView(view: XRView): XRWebGLSubImage {\r\n const layerWrapper = this._xrSessionManager._getBaseLayerWrapper();\r\n if (!layerWrapper) {\r\n throw new Error(\"For Space Warp, the base layer should be a WebXR Projection Layer.\");\r\n }\r\n if (layerWrapper.layerType !== \"XRProjectionLayer\") {\r\n throw new Error('For Space Warp, the base layer type should \"XRProjectionLayer\".');\r\n }\r\n const layer = layerWrapper.layer as XRProjectionLayer;\r\n return this._xrWebGLBinding.getViewSubImage(layer, view);\r\n }\r\n\r\n protected _setViewportForSubImage(viewport: Viewport, subImage: XRWebGLSubImage) {\r\n viewport.x = 0;\r\n viewport.y = 0;\r\n viewport.width = subImage.motionVectorTextureWidth!;\r\n viewport.height = subImage.motionVectorTextureHeight!;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable<WebGLFramebuffer>,\r\n motionVectorTexture: WebGLTexture,\r\n depthStencilTexture: WebGLTexture\r\n ): RenderTargetTexture {\r\n if (!this._engine) {\r\n throw new Error(\"Engine is disposed\");\r\n }\r\n\r\n const textureSize = { width, height };\r\n\r\n // Create render target texture from the internal texture\r\n const renderTargetTexture = new XRSpaceWarpRenderTarget(motionVectorTexture, depthStencilTexture, this._scene, textureSize);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n if (framebuffer) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n renderTargetWrapper._colorTextureArray = motionVectorTexture;\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n\r\n renderTargetTexture.disableRescaling();\r\n renderTargetTexture.renderListPredicate = () => true;\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _getRenderTargetForSubImage(subImage: XRWebGLSubImage, view: XRView) {\r\n const lastSubImage = this._lastSubImages.get(view);\r\n let renderTargetTexture = this._renderTargetTextures.get(view.eye);\r\n\r\n const width = subImage.motionVectorTextureWidth!;\r\n const height = subImage.motionVectorTextureHeight!;\r\n\r\n if (!renderTargetTexture || lastSubImage?.textureWidth !== width || lastSubImage?.textureHeight != height) {\r\n renderTargetTexture = this._createRenderTargetTexture(width, height, null, subImage.motionVectorTexture!, subImage.depthStencilTexture!);\r\n this._renderTargetTextures.set(view.eye, renderTargetTexture);\r\n\r\n this._framebufferDimensions = {\r\n framebufferWidth: width,\r\n framebufferHeight: height,\r\n };\r\n }\r\n\r\n this._lastSubImages.set(view, subImage);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n const subImage = this._lastSubImages.get(view) || this._getSubImageForView(view);\r\n if (subImage) {\r\n this._setViewportForSubImage(viewport, subImage);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Access the motion vector (which will turn on Space Warp)\r\n * @param view the view to access the motion vector texture for\r\n */\r\n public accessMotionVector(view: XRView): void {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n // Meta Quest Browser uses accessing these textures as a sign for turning on Space Warp\r\n subImage.motionVectorTexture;\r\n subImage.depthStencilTexture;\r\n }\r\n }\r\n\r\n public getRenderTargetTextureForEye(_eye: XREye): Nullable<RenderTargetTexture> {\r\n return null;\r\n }\r\n\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n return this._getRenderTargetForSubImage(subImage, view);\r\n }\r\n return null;\r\n }\r\n\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.clear();\r\n }\r\n}\r\n\r\n/**\r\n * the WebXR Space Warp feature.\r\n */\r\nexport class WebXRSpaceWarp extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.SPACE_WARP;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * The space warp provider\r\n */\r\n public spaceWarpRTTProvider: Nullable<WebXRSpaceWarpRenderTargetTextureProvider>;\r\n private _glContext: WebGLRenderingContext | WebGL2RenderingContext;\r\n private _xrWebGLBinding: XRWebGLBinding;\r\n private _renderTargetTexture: Nullable<RenderTargetTexture>;\r\n private _onAfterRenderObserver: Nullable<Observer<Scene>> = null;\r\n\r\n /**\r\n * constructor for the space warp feature\r\n * @param _xrSessionManager the xr session manager for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"space-warp\";\r\n this._xrSessionManager.scene.needsPreviousWorldMatrices = true;\r\n }\r\n\r\n /**\r\n * Attach this feature.\r\n * Will usually be called by the features manager.\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n const engine = this._xrSessionManager.scene.getEngine();\r\n this._glContext = (engine as ThinEngine)._gl;\r\n this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n\r\n this.spaceWarpRTTProvider = new WebXRSpaceWarpRenderTargetTextureProvider(this._xrSessionManager.scene, this._xrSessionManager, this._xrWebGLBinding);\r\n\r\n this._onAfterRenderObserver = this._xrSessionManager.scene.onAfterRenderObservable.add(() => this._onAfterRender());\r\n\r\n return true;\r\n }\r\n\r\n public detach(): boolean {\r\n this._xrSessionManager.scene.onAfterRenderObservable.remove(this._onAfterRenderObserver);\r\n return super.detach();\r\n }\r\n\r\n private _onAfterRender(): void {\r\n if (this.attached && this._renderTargetTexture) {\r\n this._renderTargetTexture.render(false, false);\r\n }\r\n }\r\n\r\n public dependsOn: string[] = [WebXRFeatureName.LAYERS];\r\n\r\n public isCompatible(): boolean {\r\n return this._xrSessionManager.scene.getEngine().getCaps().colorBufferHalfFloat || false;\r\n }\r\n\r\n public dispose(): void {\r\n super.dispose();\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n\r\n // get the first view to which we will create a texture (or update it)\r\n const view = pose.views[0];\r\n this._renderTargetTexture = this._renderTargetTexture || this.spaceWarpRTTProvider!.getRenderTargetTextureForView(view);\r\n this.spaceWarpRTTProvider!.accessMotionVector(view);\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRSpaceWarp.Name,\r\n (xrSessionManager) => {\r\n return () => new WebXRSpaceWarp(xrSessionManager);\r\n },\r\n WebXRSpaceWarp.Version,\r\n false\r\n);\r\n"]}
|