@babylonjs/core 6.26.0 → 6.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Behaviors/Meshes/attachToBoxBehavior.js.map +1 -1
- package/Cameras/Inputs/flyCameraMouseInput.js.map +1 -1
- package/Cameras/VR/vrExperienceHelper.js.map +1 -1
- package/Collisions/intersectionInfo.js.map +1 -1
- package/Engines/Processors/Expressions/Operators/shaderDefineArithmeticOperator.js.map +1 -1
- package/Engines/Processors/Expressions/Operators/shaderDefineIsDefinedOperator.js.map +1 -1
- package/Engines/WebGPU/webgpuBundleList.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.d.ts +3 -4
- package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js +5 -6
- package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js.map +1 -1
- package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.d.ts +22 -0
- package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.js +26 -0
- package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.js.map +1 -0
- package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.d.ts +3 -5
- package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js +5 -6
- package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js.map +1 -1
- package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.d.ts +3 -4
- package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js +5 -6
- package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js.map +1 -1
- package/FlowGraph/flowGraphConnection.d.ts +1 -1
- package/FlowGraph/flowGraphConnection.js +2 -1
- package/FlowGraph/flowGraphConnection.js.map +1 -1
- package/FlowGraph/flowGraphContext.d.ts +10 -0
- package/FlowGraph/flowGraphContext.js +14 -0
- package/FlowGraph/flowGraphContext.js.map +1 -1
- package/FlowGraph/flowGraphDataConnection.js.map +1 -1
- package/FlowGraph/flowGraphRichTypes.js.map +1 -1
- package/FlowGraph/flowGraphSignalConnection.js +1 -0
- package/FlowGraph/flowGraphSignalConnection.js.map +1 -1
- package/Layers/highlightLayer.js.map +1 -1
- package/Loading/loadingScreen.js.map +1 -1
- package/Materials/Background/backgroundMaterial.d.ts +16 -0
- package/Materials/Background/backgroundMaterial.js +44 -0
- package/Materials/Background/backgroundMaterial.js.map +1 -1
- package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js +0 -1
- package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.js +6 -2
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineRibbonMesh.js.map +1 -1
- package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.d.ts +10 -1
- package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js +27 -5
- package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js.map +1 -1
- package/Meshes/Node/Blocks/mergeGeometryBlock.js +16 -4
- package/Meshes/Node/Blocks/mergeGeometryBlock.js.map +1 -1
- package/Meshes/Node/Interfaces/nodeGeometryExecutionContext.d.ts +5 -0
- package/Meshes/Node/Interfaces/nodeGeometryExecutionContext.js.map +1 -1
- package/Meshes/Node/nodeGeometryBuildState.js +3 -0
- package/Meshes/Node/nodeGeometryBuildState.js.map +1 -1
- package/Meshes/csg.js.map +1 -1
- package/Meshes/geodesicMesh.js.map +1 -1
- package/Meshes/meshSimplification.js.map +1 -1
- package/Misc/PerformanceViewer/performanceViewerCollector.js.map +1 -1
- package/Misc/fileTools.js.map +1 -1
- package/Physics/physicsHelper.js.map +1 -1
- package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
- package/Physics/v1/Plugins/cannonJSPlugin.js.map +1 -1
- package/Physics/v1/Plugins/oimoJSPlugin.js.map +1 -1
- package/Physics/v1/physicsEngine.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/Physics/v2/physicsEngine.js.map +1 -1
- package/PostProcesses/RenderPipeline/postProcessRenderPipeline.js.map +1 -1
- package/PostProcesses/bloomEffect.js.map +1 -1
- package/Rendering/boundingBoxRenderer.js +6 -2
- package/Rendering/boundingBoxRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/backgroundFragmentDeclaration.js +3 -0
- package/Shaders/ShadersInclude/backgroundFragmentDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/backgroundUboDeclaration.js +1 -8
- package/Shaders/ShadersInclude/backgroundUboDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/helperFunctions.js +1 -1
- package/Shaders/ShadersInclude/helperFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/pbrHelperFunctions.js +1 -3
- package/Shaders/ShadersInclude/pbrHelperFunctions.js.map +1 -1
- package/Shaders/background.fragment.js +11 -1
- package/Shaders/background.fragment.js.map +1 -1
- package/Shaders/default.fragment.js +0 -1
- package/Shaders/default.fragment.js.map +1 -1
- package/XR/features/WebXRAnchorSystem.js.map +1 -1
- package/XR/features/WebXRControllerPhysics.js.map +1 -1
- package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
- package/XR/features/WebXRControllerTeleportation.js.map +1 -1
- package/XR/features/WebXRDepthSensing.js.map +1 -1
- package/XR/features/WebXRLayers.js.map +1 -1
- package/XR/features/WebXRMeshDetector.js.map +1 -1
- package/XR/features/WebXRNearInteraction.js.map +1 -1
- package/XR/features/WebXRPlaneDetector.js.map +1 -1
- package/XR/features/WebXRSpaceWarp.js.map +1 -1
- package/XR/native/nativeXRRenderTarget.js.map +1 -1
- package/XR/webXRCamera.js.map +1 -1
- package/XR/webXRManagedOutputCanvas.js.map +1 -1
- package/XR/webXRRenderTargetTextureProvider.js.map +1 -1
- package/XR/webXRWebGLLayer.js.map +1 -1
- package/assetContainer.js.map +1 -1
- package/package.json +1 -1
|
@@ -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,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,GAAG,IAAI,CAAC,QAAQ,EAAG;aAChC,SAAS,EAAE;aACX,kCAAkC,CA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AAa,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;;AA5FD;;GAEG;AACoB,mBAAI,GAAG,gBAAgB,CAAC,UAAU,AAA9B,CAA+B;AAC1D;;;;GAIG;AACoB,sBAAO,GAAG,CAAC,AAAJ,CAAK;AAsFvC,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 /**\r\n * {@inheritDoc}\r\n */\r\n public render(useCameraPostProcess: boolean = false, dumpForDebug: boolean = false): void {\r\n // Swap to use velocity material\r\n this._originalPairing.length = 0;\r\n const scene = this.getScene();\r\n // set the velocity material to render the velocity RTT\r\n if (scene && this._velocityMaterial) {\r\n scene.getActiveMeshes().forEach((mesh) => {\r\n this._originalPairing.push([mesh, mesh.material]);\r\n mesh.material = this._velocityMaterial;\r\n });\r\n }\r\n\r\n super.render(useCameraPostProcess, dumpForDebug);\r\n\r\n // Restore original materials\r\n this._originalPairing.forEach((tuple) => {\r\n tuple[0].material = tuple[1];\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bindFrameBuffer() {\r\n if (!this._renderTarget) {\r\n return;\r\n }\r\n this.getScene()!.getEngine().bindSpaceWarpFramebuffer(this._renderTarget);\r\n }\r\n\r\n /**\r\n * Gets the number of views the corresponding to the texture (eg. a SpaceWarpRenderTarget will have > 1)\r\n * @returns the view count\r\n */\r\n public getViewCount() {\r\n return 2;\r\n }\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n this._velocityMaterial.dispose();\r\n this._previousTransforms.length = 0;\r\n this._previousWorldMatrices.length = 0;\r\n this._originalPairing.length = 0;\r\n }\r\n}\r\n\r\n/**\r\n * WebXR Space Warp Render Target Texture Provider\r\n */\r\nexport class WebXRSpaceWarpRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n protected _lastSubImages = new Map<XRView, XRWebGLSubImage>();\r\n protected _renderTargetTextures = new Map<XREye, RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n protected _engine: Engine;\r\n\r\n constructor(protected readonly _scene: Scene, protected readonly _xrSessionManager: WebXRSessionManager, protected readonly _xrWebGLBinding: XRWebGLBinding) {\r\n this._engine = _scene.getEngine();\r\n }\r\n\r\n private _getSubImageForView(view: XRView): XRWebGLSubImage {\r\n const layerWrapper = this._xrSessionManager._getBaseLayerWrapper();\r\n if (!layerWrapper) {\r\n throw new Error(\"For Space Warp, the base layer should be a WebXR Projection Layer.\");\r\n }\r\n if (layerWrapper.layerType !== \"XRProjectionLayer\") {\r\n throw new Error('For Space Warp, the base layer type should \"XRProjectionLayer\".');\r\n }\r\n const layer = layerWrapper.layer as XRProjectionLayer;\r\n return this._xrWebGLBinding.getViewSubImage(layer, view);\r\n }\r\n\r\n protected _setViewportForSubImage(viewport: Viewport, subImage: XRWebGLSubImage) {\r\n viewport.x = 0;\r\n viewport.y = 0;\r\n viewport.width = subImage.motionVectorTextureWidth!;\r\n viewport.height = subImage.motionVectorTextureHeight!;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable<WebGLFramebuffer>,\r\n motionVectorTexture: WebGLTexture,\r\n depthStencilTexture: WebGLTexture\r\n ): RenderTargetTexture {\r\n if (!this._engine) {\r\n throw new Error(\"Engine is disposed\");\r\n }\r\n\r\n const textureSize = { width, height };\r\n\r\n // Create render target texture from the internal texture\r\n const renderTargetTexture = new XRSpaceWarpRenderTarget(motionVectorTexture, depthStencilTexture, this._scene, textureSize);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n if (framebuffer) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n renderTargetWrapper._colorTextureArray = motionVectorTexture;\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n\r\n renderTargetTexture.disableRescaling();\r\n renderTargetTexture.renderListPredicate = () => true;\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _getRenderTargetForSubImage(subImage: XRWebGLSubImage, view: XRView) {\r\n const lastSubImage = this._lastSubImages.get(view);\r\n let renderTargetTexture = this._renderTargetTextures.get(view.eye);\r\n\r\n const width = subImage.motionVectorTextureWidth!;\r\n const height = subImage.motionVectorTextureHeight!;\r\n\r\n if (!renderTargetTexture || lastSubImage?.textureWidth !== width || lastSubImage?.textureHeight != height) {\r\n renderTargetTexture = this._createRenderTargetTexture(width, height, null, subImage.motionVectorTexture!, subImage.depthStencilTexture!);\r\n this._renderTargetTextures.set(view.eye, renderTargetTexture);\r\n\r\n this._framebufferDimensions = {\r\n framebufferWidth: width,\r\n framebufferHeight: height,\r\n };\r\n }\r\n\r\n this._lastSubImages.set(view, subImage);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n const subImage = this._lastSubImages.get(view) || this._getSubImageForView(view);\r\n if (subImage) {\r\n this._setViewportForSubImage(viewport, subImage);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Access the motion vector (which will turn on Space Warp)\r\n * @param view the view to access the motion vector texture for\r\n */\r\n public accessMotionVector(view: XRView): void {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n // Meta Quest Browser uses accessing these textures as a sign for turning on Space Warp\r\n subImage.motionVectorTexture;\r\n subImage.depthStencilTexture;\r\n }\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public getRenderTargetTextureForEye(_eye: XREye): Nullable<RenderTargetTexture> {\r\n return null;\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n return this._getRenderTargetForSubImage(subImage, view);\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.clear();\r\n }\r\n}\r\n\r\n/**\r\n * the WebXR Space Warp feature.\r\n */\r\nexport class WebXRSpaceWarp extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.SPACE_WARP;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * The space warp provider\r\n */\r\n public spaceWarpRTTProvider: Nullable<WebXRSpaceWarpRenderTargetTextureProvider>;\r\n private _glContext: WebGLRenderingContext | WebGL2RenderingContext;\r\n private _xrWebGLBinding: XRWebGLBinding;\r\n private _renderTargetTexture: Nullable<RenderTargetTexture>;\r\n 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 /**\r\n * {@inheritdoc}\r\n */\r\n public dependsOn: string[] = [WebXRFeatureName.LAYERS];\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public isCompatible(): boolean {\r\n return this._xrSessionManager.scene.getEngine().getCaps().colorBufferHalfFloat || false;\r\n }\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n\r\n // get the first view to which we will create a texture (or update it)\r\n const view = pose.views[0];\r\n this._renderTargetTexture = this._renderTargetTexture || this.spaceWarpRTTProvider!.getRenderTargetTextureForView(view);\r\n this.spaceWarpRTTProvider!.accessMotionVector(view);\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRSpaceWarp.Name,\r\n (xrSessionManager) => {\r\n return () => new WebXRSpaceWarp(xrSessionManager);\r\n },\r\n W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AAM,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;;AA5FD;;GAEG;AACoB,mBAAI,GAAG,gBAAgB,CAAC,UAAU,AAA9B,CAA+B;AAC1D;;;;GAIG;AACoB,sBAAO,GAAG,CAAC,AAAJ,CAAK;AAsFvC,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 /**\r\n * {@inheritDoc}\r\n */\r\n public render(useCameraPostProcess: boolean = false, dumpForDebug: boolean = false): void {\r\n // Swap to use velocity material\r\n this._originalPairing.length = 0;\r\n const scene = this.getScene();\r\n // set the velocity material to render the velocity RTT\r\n if (scene && this._velocityMaterial) {\r\n scene.getActiveMeshes().forEach((mesh) => {\r\n this._originalPairing.push([mesh, mesh.material]);\r\n mesh.material = this._velocityMaterial;\r\n });\r\n }\r\n\r\n super.render(useCameraPostProcess, dumpForDebug);\r\n\r\n // Restore original materials\r\n this._originalPairing.forEach((tuple) => {\r\n tuple[0].material = tuple[1];\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bindFrameBuffer() {\r\n if (!this._renderTarget) {\r\n return;\r\n }\r\n this.getScene()!.getEngine().bindSpaceWarpFramebuffer(this._renderTarget);\r\n }\r\n\r\n /**\r\n * Gets the number of views the corresponding to the texture (eg. a SpaceWarpRenderTarget will have > 1)\r\n * @returns the view count\r\n */\r\n public getViewCount() {\r\n return 2;\r\n }\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n this._velocityMaterial.dispose();\r\n this._previousTransforms.length = 0;\r\n this._previousWorldMatrices.length = 0;\r\n this._originalPairing.length = 0;\r\n }\r\n}\r\n\r\n/**\r\n * WebXR Space Warp Render Target Texture Provider\r\n */\r\nexport class WebXRSpaceWarpRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n protected _lastSubImages = new Map<XRView, XRWebGLSubImage>();\r\n protected _renderTargetTextures = new Map<XREye, RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n protected _engine: Engine;\r\n\r\n constructor(\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 /**\r\n * {@inheritDoc}\r\n */\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n const subImage = this._lastSubImages.get(view) || this._getSubImageForView(view);\r\n if (subImage) {\r\n this._setViewportForSubImage(viewport, subImage);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Access the motion vector (which will turn on Space Warp)\r\n * @param view the view to access the motion vector texture for\r\n */\r\n public accessMotionVector(view: XRView): void {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n // Meta Quest Browser uses accessing these textures as a sign for turning on Space Warp\r\n subImage.motionVectorTexture;\r\n subImage.depthStencilTexture;\r\n }\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public getRenderTargetTextureForEye(_eye: XREye): Nullable<RenderTargetTexture> {\r\n return null;\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n return this._getRenderTargetForSubImage(subImage, view);\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.clear();\r\n }\r\n}\r\n\r\n/**\r\n * the WebXR Space Warp feature.\r\n */\r\nexport class WebXRSpaceWarp extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.SPACE_WARP;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * The space warp provider\r\n */\r\n public spaceWarpRTTProvider: Nullable<WebXRSpaceWarpRenderTargetTextureProvider>;\r\n private _glContext: WebGLRenderingContext | WebGL2RenderingContext;\r\n private _xrWebGLBinding: XRWebGLBinding;\r\n private _renderTargetTexture: Nullable<RenderTargetTexture>;\r\n 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 /**\r\n * {@inheritdoc}\r\n */\r\n public dependsOn: string[] = [WebXRFeatureName.LAYERS];\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public isCompatible(): boolean {\r\n return this._xrSessionManager.scene.getEngine().getCaps().colorBufferHalfFloat || false;\r\n }\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n\r\n // get the first view to which we will create a texture (or update it)\r\n const view = pose.views[0];\r\n this._renderTargetTexture = this._renderTargetTexture || this.spaceWarpRTTProvider!.getRenderTargetTextureForView(view);\r\n this.spaceWarpRTTProvider!.accessMotionVector(view);\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRSpaceWarp.Name,\r\n (xrSessionManager) => {\r\n return () => new WebXRSpaceWarp(xrSessionManager);\r\n },\r\n WebXRSpaceWarp.Version,\r\n false\r\n);\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeXRRenderTarget.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/native/nativeXRRenderTarget.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,qCAAqC,EAAE,MAAM,qCAAqC,CAAC;AAI5F;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,iBAAiB;IACvD,YAA4B,KAAmB;QAC3C,KAAK,CACD,GAAG,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAC5B,GAAG,EAAE,CAAC,KAAK,CAAC,iBAAiB,EAC7B,KAAK,EACL,cAAc,EACd,CAAC,cAAc,EAAE,EAAE,CAAC,IAAI,wCAAwC,CAAC,cAAc,EAAE,IAAI,CAAC,CACzF,CAAC;QAPsB,UAAK,GAAL,KAAK,CAAc;IAQ/C,CAAC;CACJ;AAED;;;GAGG;AACH,MAAM,OAAO,wCAAyC,SAAQ,qCAAqC;IAI/F,
|
|
1
|
+
{"version":3,"file":"nativeXRRenderTarget.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/native/nativeXRRenderTarget.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,qCAAqC,EAAE,MAAM,qCAAqC,CAAC;AAI5F;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,iBAAiB;IACvD,YAA4B,KAAmB;QAC3C,KAAK,CACD,GAAG,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAC5B,GAAG,EAAE,CAAC,KAAK,CAAC,iBAAiB,EAC7B,KAAK,EACL,cAAc,EACd,CAAC,cAAc,EAAE,EAAE,CAAC,IAAI,wCAAwC,CAAC,cAAc,EAAE,IAAI,CAAC,CACzF,CAAC;QAPsB,UAAK,GAAL,KAAK,CAAc;IAQ/C,CAAC;CACJ;AAED;;;GAGG;AACH,MAAM,OAAO,wCAAyC,SAAQ,qCAAqC;IAI/F,YACI,cAAmC,EACnB,YAAkC;Q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KAAK,CAAC,sBAAsB,CAAC,SAAoB;QACpD,MAAM,IAAI,CAAC,mBAAmB,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;QACjE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC,OAAQ,CAAC;QACjD,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,OAAO;QACH,WAAW;IACf,CAAC;CACJ","sourcesContent":["import type { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport type { Viewport } from \"../../Maths/math.viewport\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { WebXRLayerWrapper } from \"../webXRLayerWrapper\";\r\nimport { WebXRLayerRenderTargetTextureProvider } from \"../webXRRenderTargetTextureProvider\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport type { WebXRRenderTarget } from \"../webXRTypes\";\r\n\r\n/**\r\n * Wraps XRWebGLLayer's created by Babylon Native.\r\n * @internal\r\n */\r\nexport class NativeXRLayerWrapper extends WebXRLayerWrapper {\r\n constructor(public readonly layer: XRWebGLLayer) {\r\n super(\r\n () => layer.framebufferWidth,\r\n () => layer.framebufferHeight,\r\n layer,\r\n \"XRWebGLLayer\",\r\n (sessionManager) => new NativeXRLayerRenderTargetTextureProvider(sessionManager, this)\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * Provides render target textures for layers created by Babylon Native.\r\n * @internal\r\n */\r\nexport class NativeXRLayerRenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {\r\n private _nativeRTTProvider: WebXRLayerRenderTargetTextureProvider;\r\n private _nativeLayer: XRWebGLLayer;\r\n\r\n constructor(\r\n sessionManager: WebXRSessionManager,\r\n public readonly layerWrapper: NativeXRLayerWrapper\r\n ) {\r\n super(sessionManager.scene, layerWrapper);\r\n this._nativeRTTProvider = (navigator as any).xr.getNativeRenderTargetProvider(\r\n sessionManager.session,\r\n this._createRenderTargetTexture.bind(this),\r\n this._destroyRenderTargetTexture.bind(this)\r\n );\r\n this._nativeLayer = layerWrapper.layer;\r\n }\r\n\r\n public trySetViewportForView(viewport: Viewport): boolean {\r\n viewport.x = 0;\r\n viewport.y = 0;\r\n viewport.width = 1;\r\n viewport.height = 1;\r\n return true;\r\n }\r\n\r\n public getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture> {\r\n // TODO (rgerd): Update the contract on the BabylonNative side to call this \"getRenderTargetTextureForEye\"\r\n return (this._nativeRTTProvider as any).getRenderTargetForEye(eye);\r\n }\r\n\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n return (this._nativeRTTProvider as any).getRenderTargetForEye(view.eye);\r\n }\r\n\r\n public getFramebufferDimensions(): Nullable<{ framebufferWidth: number; framebufferHeight: number }> {\r\n return {\r\n framebufferWidth: this._nativeLayer.framebufferWidth,\r\n framebufferHeight: this._nativeLayer.framebufferHeight,\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Creates the xr layer that will be used as the xr session's base layer.\r\n * @internal\r\n */\r\nexport class NativeXRRenderTarget implements WebXRRenderTarget {\r\n public canvasContext: WebGLRenderingContext;\r\n public xrLayer: Nullable<XRWebGLLayer>;\r\n\r\n private _nativeRenderTarget: WebXRRenderTarget;\r\n\r\n constructor(_xrSessionManager: WebXRSessionManager) {\r\n this._nativeRenderTarget = (navigator as any).xr.getWebXRRenderTarget(_xrSessionManager.scene.getEngine());\r\n }\r\n\r\n public async initializeXRLayerAsync(xrSession: XRSession): Promise<XRWebGLLayer> {\r\n await this._nativeRenderTarget.initializeXRLayerAsync(xrSession);\r\n this.xrLayer = this._nativeRenderTarget.xrLayer!;\r\n return this.xrLayer;\r\n }\r\n\r\n dispose(): void {\r\n /* empty */\r\n }\r\n}\r\n"]}
|
package/XR/webXRCamera.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRCamera.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRCamera.ts"],"names":[],"mappings":"A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oBAAoB,CAAC,CAAC;gBAC9B,CAAC,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;aACjC,CACJ,CAAC;YACF,IAAI,CAAC,iBAAiB,CAAC,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;SACpH;IACL,CAAC;;AAlWc,0BAAc,GAAG,OAAO,CAAC,GAAG,EAAE,AAAhB,CAAiB","sourcesContent":["import { Vector3, Matrix, Quaternion, TmpVectors } from \"../Maths/math.vector\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport { FreeCamera } from \"../Cameras/freeCamera\";\r\nimport { TargetCamera } from \"../Cameras/targetCamera\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { Viewport } from \"../Maths/math.viewport\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { WebXRTrackingState } from \"./webXRTypes\";\r\n\r\n/**\r\n * WebXR Camera which holds the views for the xrSession\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRCamera\r\n */\r\nexport class WebXRCamera extends FreeCamera {\r\n private static _ScaleReadOnly = Vector3.One();\r\n\r\n private _firstFrame = false;\r\n private _referenceQuaternion: Quaternion = Quaternion.Identity();\r\n private _referencedPosition: Vector3 = new Vector3();\r\n private _trackingState: WebXRTrackingState = WebXRTrackingState.NOT_TRACKING;\r\n\r\n /**\r\n * This will be triggered after the first XR Frame initialized the camera,\r\n * including the right number of views and their rendering parameters\r\n */\r\n public onXRCameraInitializedObservable = new Observable<WebXRCamera>();\r\n\r\n /**\r\n * Observable raised before camera teleportation\r\n */\r\n public onBeforeCameraTeleport = new Observable<Vector3>();\r\n\r\n /**\r\n * Observable raised after camera teleportation\r\n */\r\n public onAfterCameraTeleport = new Observable<Vector3>();\r\n\r\n /**\r\n * Notifies when the camera's tracking state has changed.\r\n * Notice - will also be triggered when tracking has started (at the beginning of the session)\r\n */\r\n public onTrackingStateChanged = new Observable<WebXRTrackingState>();\r\n /**\r\n * Should position compensation execute on first frame.\r\n * This is used when copying the position from a native (non XR) camera\r\n */\r\n public compensateOnFirstFrame: boolean = true;\r\n\r\n /**\r\n * The last XRViewerPose from the current XRFrame\r\n * @internal\r\n */\r\n public _lastXRViewerPose?: XRViewerPose;\r\n\r\n /**\r\n * Creates a new webXRCamera, this should only be set at the camera after it has been updated by the xrSessionManager\r\n * @param name the name of the camera\r\n * @param scene the scene to add the camera to\r\n * @param _xrSessionManager a constructed xr session manager\r\n */\r\n constructor(name: string, scene: Scene, private _xrSessionManager: WebXRSessionManager) {\r\n super(name, Vector3.Zero(), scene);\r\n\r\n // Initial camera configuration\r\n this.minZ = 0.1;\r\n this.rotationQuaternion = new Quaternion();\r\n this.cameraRigMode = Camera.RIG_MODE_CUSTOM;\r\n this.updateUpVectorFromRotation = true;\r\n this._updateNumberOfRigCameras(1);\r\n // freeze projection matrix, which will be copied later\r\n this.freezeProjectionMatrix();\r\n this._deferOnly = true;\r\n\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n this._referencedPosition.copyFromFloats(0, 0, 0);\r\n this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);\r\n // first frame - camera's y position should be 0 for the correct offset\r\n this._firstFrame = this.compensateOnFirstFrame;\r\n });\r\n\r\n // Check transformation changes on each frame. Callback is added to be first so that the transformation will be\r\n // applied to the rest of the elements using the referenceSpace object\r\n this._xrSessionManager.onXRFrameObservable.add(\r\n () => {\r\n if (this._firstFrame) {\r\n this._updateFromXRSession();\r\n }\r\n if (this.onXRCameraInitializedObservable.hasObservers()) {\r\n this.onXRCameraInitializedObservable.notifyObservers(this);\r\n this.onXRCameraInitializedObservable.clear();\r\n }\r\n\r\n if (this._deferredUpdated) {\r\n this.position.copyFrom(this._deferredPositionUpdate);\r\n this.rotationQuaternion.copyFrom(this._deferredRotationQuaternionUpdate);\r\n }\r\n\r\n this._updateReferenceSpace();\r\n this._updateFromXRSession();\r\n },\r\n undefined,\r\n true\r\n );\r\n }\r\n\r\n /**\r\n * Get the current XR tracking state of the camera\r\n */\r\n public get trackingState(): WebXRTrackingState {\r\n return this._trackingState;\r\n }\r\n\r\n private _setTrackingState(newState: WebXRTrackingState) {\r\n if (this._trackingState !== newState) {\r\n this._trackingState = newState;\r\n this.onTrackingStateChanged.notifyObservers(newState);\r\n }\r\n }\r\n\r\n /**\r\n * Return the user's height, unrelated to the current ground.\r\n * This will be the y position of this camera, when ground level is 0.\r\n */\r\n public get realWorldHeight(): number {\r\n const basePose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(this._xrSessionManager.baseReferenceSpace);\r\n if (basePose && basePose.transform) {\r\n return basePose.transform.position.y;\r\n } else {\r\n return 0;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _updateForDualEyeDebugging(/*pupilDistance = 0.01*/) {\r\n // Create initial camera rigs\r\n this._updateNumberOfRigCameras(2);\r\n this.rigCameras[0].viewport = new Viewport(0, 0, 0.5, 1.0);\r\n // this.rigCameras[0].position.x = -pupilDistance / 2;\r\n this.rigCameras[0].outputRenderTarget = null;\r\n this.rigCameras[1].viewport = new Viewport(0.5, 0, 0.5, 1.0);\r\n // this.rigCameras[1].position.x = pupilDistance / 2;\r\n this.rigCameras[1].outputRenderTarget = null;\r\n }\r\n\r\n /**\r\n * Sets this camera's transformation based on a non-vr camera\r\n * @param otherCamera the non-vr camera to copy the transformation from\r\n * @param resetToBaseReferenceSpace should XR reset to the base reference space\r\n */\r\n public setTransformationFromNonVRCamera(otherCamera: Camera = this.getScene().activeCamera!, resetToBaseReferenceSpace: boolean = true) {\r\n if (!otherCamera || otherCamera === this) {\r\n return;\r\n }\r\n const mat = otherCamera.computeWorldMatrix();\r\n mat.decompose(undefined, this.rotationQuaternion, this.position);\r\n // set the ground level\r\n this.position.y = 0;\r\n Quaternion.FromEulerAnglesToRef(0, this.rotationQuaternion.toEulerAngles().y, 0, this.rotationQuaternion);\r\n this._firstFrame = true;\r\n if (resetToBaseReferenceSpace) {\r\n this._xrSessionManager.resetReferenceSpace();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current instance class name (\"WebXRCamera\").\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"WebXRCamera\";\r\n }\r\n\r\n /**\r\n * Set the target for the camera to look at.\r\n * Note that this only rotates around the Y axis, as opposed to the default behavior of other cameras\r\n * @param target the target to set the camera to look at\r\n */\r\n public setTarget(target: Vector3): void {\r\n // only rotate around the y axis!\r\n const tmpVector = TmpVectors.Vector3[1];\r\n target.subtractToRef(this.position, tmpVector);\r\n tmpVector.y = 0;\r\n tmpVector.normalize();\r\n const yRotation = Math.atan2(tmpVector.x, tmpVector.z);\r\n this.rotationQuaternion.toEulerAnglesToRef(tmpVector);\r\n Quaternion.FromEulerAnglesToRef(tmpVector.x, yRotation, tmpVector.z, this.rotationQuaternion);\r\n }\r\n\r\n public dispose() {\r\n super.dispose();\r\n this._lastXRViewerPose = undefined;\r\n }\r\n\r\n private _rotate180 = new Quaternion(0, 1, 0, 0);\r\n\r\n private _updateFromXRSession() {\r\n const pose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n this._lastXRViewerPose = pose || undefined;\r\n if (!pose) {\r\n this._setTrackingState(WebXRTrackingState.NOT_TRACKING);\r\n return;\r\n }\r\n\r\n // Set the tracking state. if it didn't change it is a no-op\r\n const trackingState = pose.emulatedPosition ? WebXRTrackingState.TRACKING_LOST : WebXRTrackingState.TRACKING;\r\n this._setTrackingState(trackingState);\r\n\r\n // check min/max Z and update if not the same as in cache\r\n if (this.minZ !== this._cache.minZ || this.maxZ !== this._cache.maxZ) {\r\n const xrRenderState: XRRenderStateInit = {\r\n // if maxZ is 0 it should be \"Infinity\", but it doesn't work with the WebXR API. Setting to a large number.\r\n depthFar: this.maxZ || 10000,\r\n depthNear: this.minZ,\r\n };\r\n\r\n this._xrSessionManager.updateRenderState(xrRenderState);\r\n this._cache.minZ = this.minZ;\r\n this._cache.maxZ = this.maxZ;\r\n }\r\n\r\n if (pose.transform) {\r\n const orientation = pose.transform.orientation;\r\n if (pose.transform.orientation.x === undefined) {\r\n // Babylon native polyfill can return an undefined orientation value\r\n // When not initialized\r\n return;\r\n }\r\n const pos = pose.transform.position;\r\n this._referencedPosition.set(pos.x, pos.y, pos.z);\r\n\r\n this._referenceQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this._referencedPosition.z *= -1;\r\n this._referenceQuaternion.z *= -1;\r\n this._referenceQuaternion.w *= -1;\r\n }\r\n\r\n if (this._firstFrame) {\r\n this._firstFrame = false;\r\n // we have the XR reference, now use this to find the offset to get the camera to be\r\n // in the right position\r\n\r\n // set the height to correlate to the current height\r\n this.position.y += this._referencedPosition.y;\r\n // avoid using the head rotation on the first frame.\r\n this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);\r\n } else {\r\n // update position and rotation as reference\r\n this.rotationQuaternion.copyFrom(this._referenceQuaternion);\r\n this.position.copyFrom(this._referencedPosition);\r\n }\r\n }\r\n\r\n // Update camera rigs\r\n if (this.rigCameras.length !== pose.views.length) {\r\n this._updateNumberOfRigCameras(pose.views.length);\r\n }\r\n\r\n pose.views.forEach((view: XRView, i: number) => {\r\n const currentRig = <TargetCamera>this.rigCameras[i];\r\n // update right and left, where applicable\r\n if (!currentRig.isLeftCamera && !currentRig.isRightCamera) {\r\n if (view.eye === \"right\") {\r\n currentRig._isRightCamera = true;\r\n } else if (view.eye === \"left\") {\r\n currentRig._isLeftCamera = true;\r\n }\r\n }\r\n // Update view/projection matrix\r\n const pos = view.transform.position;\r\n const orientation = view.transform.orientation;\r\n\r\n currentRig.parent = this.parent;\r\n\r\n currentRig.position.set(pos.x, pos.y, pos.z);\r\n currentRig.rotationQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n currentRig.position.z *= -1;\r\n currentRig.rotationQuaternion.z *= -1;\r\n currentRig.rotationQuaternion.w *= -1;\r\n } else {\r\n currentRig.rotationQuaternion.multiplyInPlace(this._rotate180);\r\n }\r\n Matrix.FromFloat32ArrayToRefScaled(view.projectionMatrix, 0, 1, currentRig._projectionMatrix);\r\n\r\n if (!this._scene.useRightHandedSystem) {\r\n currentRig._projectionMatrix.toggleProjectionMatrixHandInPlace();\r\n }\r\n\r\n // first camera?\r\n if (i === 0) {\r\n this._projectionMatrix.copyFrom(currentRig._projectionMatrix);\r\n }\r\n\r\n const renderTargetTexture = this._xrSessionManager.getRenderTargetTextureForView(view);\r\n this._renderingMultiview = renderTargetTexture?._texture?.isMultiview || false;\r\n if (this._renderingMultiview) {\r\n // For multiview, the render target texture is the same per-view (just the slice index is different),\r\n // so we only need to set the output render target once for the rig parent.\r\n if (i == 0) {\r\n this._xrSessionManager.trySetViewportForView(this.viewport, view);\r\n this.outputRenderTarget = renderTargetTexture;\r\n }\r\n } else {\r\n // Update viewport\r\n this._xrSessionManager.trySetViewportForView(currentRig.viewport, view);\r\n\r\n // Set cameras to render to the session's render target\r\n currentRig.outputRenderTarget = renderTargetTexture || this._xrSessionManager.getRenderTargetTextureForView(view);\r\n }\r\n\r\n // Replicate parent rig camera behavior\r\n currentRig.layerMask = this.layerMask;\r\n });\r\n }\r\n\r\n private _updateNumberOfRigCameras(viewCount = 1) {\r\n while (this.rigCameras.length < viewCount) {\r\n const newCamera = new TargetCamera(\"XR-RigCamera: \" + this.rigCameras.length, Vector3.Zero(), this.getScene());\r\n newCamera.minZ = 0.1;\r\n newCamera.rotationQuaternion = new Quaternion();\r\n newCamera.updateUpVectorFromRotation = true;\r\n newCamera.isRigCamera = true;\r\n newCamera.rigParent = this;\r\n // do not compute projection matrix, provided by XR\r\n newCamera.freezeProjectionMatrix();\r\n this.rigCameras.push(newCamera);\r\n }\r\n while (this.rigCameras.length > viewCount) {\r\n const removedCamera = this.rigCameras.pop();\r\n if (removedCamera) {\r\n removedCamera.dispose();\r\n }\r\n }\r\n }\r\n\r\n private _updateReferenceSpace() {\r\n // were position & rotation updated OUTSIDE of the xr update loop\r\n if (!this.position.equals(this._referencedPosition) || !this.rotationQuaternion.equals(this._referenceQuaternion)) {\r\n const referencedMat = TmpVectors.Matrix[0];\r\n const poseMat = TmpVectors.Matrix[1];\r\n const transformMat = TmpVectors.Matrix[2];\r\n\r\n Matrix.ComposeToRef(WebXRCamera._ScaleReadOnly, this._referenceQuaternion, this._referencedPosition, referencedMat);\r\n Matrix.ComposeToRef(WebXRCamera._ScaleReadOnly, this.rotationQuaternion, this.position, poseMat);\r\n referencedMat.invert().multiplyToRef(poseMat, transformMat);\r\n transformMat.invert();\r\n\r\n if (!this._scene.useRightHandedSystem) {\r\n transformMat.toggleModelMatrixHandInPlace();\r\n }\r\n\r\n transformMat.decompose(undefined, this._referenceQuaternion, this._referencedPosition);\r\n const transform = new XRRigidTransform(\r\n {\r\n x: this._referencedPosition.x,\r\n y: this._referencedPosition.y,\r\n z: this._referencedPosition.z,\r\n },\r\n {\r\n x: this._referenceQuaternion.x,\r\n y: this._referenceQuaternion.y,\r\n z: this._referenceQuaternion.z,\r\n w: this._referenceQuaternion.w,\r\n }\r\n );\r\n this._xrSessionManager.referenceSpace = this._xrSessionManager.referenceSpace.getOffsetReferenceSpace(transform);\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"webXRCamera.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRCamera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE/E,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CA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esContent":["import { Vector3, Matrix, Quaternion, TmpVectors } from \"../Maths/math.vector\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport { FreeCamera } from \"../Cameras/freeCamera\";\r\nimport { TargetCamera } from \"../Cameras/targetCamera\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { Viewport } from \"../Maths/math.viewport\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { WebXRTrackingState } from \"./webXRTypes\";\r\n\r\n/**\r\n * WebXR Camera which holds the views for the xrSession\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRCamera\r\n */\r\nexport class WebXRCamera extends FreeCamera {\r\n private static _ScaleReadOnly = Vector3.One();\r\n\r\n private _firstFrame = false;\r\n private _referenceQuaternion: Quaternion = Quaternion.Identity();\r\n private _referencedPosition: Vector3 = new Vector3();\r\n private _trackingState: WebXRTrackingState = WebXRTrackingState.NOT_TRACKING;\r\n\r\n /**\r\n * This will be triggered after the first XR Frame initialized the camera,\r\n * including the right number of views and their rendering parameters\r\n */\r\n public onXRCameraInitializedObservable = new Observable<WebXRCamera>();\r\n\r\n /**\r\n * Observable raised before camera teleportation\r\n */\r\n public onBeforeCameraTeleport = new Observable<Vector3>();\r\n\r\n /**\r\n * Observable raised after camera teleportation\r\n */\r\n public onAfterCameraTeleport = new Observable<Vector3>();\r\n\r\n /**\r\n * Notifies when the camera's tracking state has changed.\r\n * Notice - will also be triggered when tracking has started (at the beginning of the session)\r\n */\r\n public onTrackingStateChanged = new Observable<WebXRTrackingState>();\r\n /**\r\n * Should position compensation execute on first frame.\r\n * This is used when copying the position from a native (non XR) camera\r\n */\r\n public compensateOnFirstFrame: boolean = true;\r\n\r\n /**\r\n * The last XRViewerPose from the current XRFrame\r\n * @internal\r\n */\r\n public _lastXRViewerPose?: XRViewerPose;\r\n\r\n /**\r\n * Creates a new webXRCamera, this should only be set at the camera after it has been updated by the xrSessionManager\r\n * @param name the name of the camera\r\n * @param scene the scene to add the camera to\r\n * @param _xrSessionManager a constructed xr session manager\r\n */\r\n constructor(\r\n name: string,\r\n scene: Scene,\r\n private _xrSessionManager: WebXRSessionManager\r\n ) {\r\n super(name, Vector3.Zero(), scene);\r\n\r\n // Initial camera configuration\r\n this.minZ = 0.1;\r\n this.rotationQuaternion = new Quaternion();\r\n this.cameraRigMode = Camera.RIG_MODE_CUSTOM;\r\n this.updateUpVectorFromRotation = true;\r\n this._updateNumberOfRigCameras(1);\r\n // freeze projection matrix, which will be copied later\r\n this.freezeProjectionMatrix();\r\n this._deferOnly = true;\r\n\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n this._referencedPosition.copyFromFloats(0, 0, 0);\r\n this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);\r\n // first frame - camera's y position should be 0 for the correct offset\r\n this._firstFrame = this.compensateOnFirstFrame;\r\n });\r\n\r\n // Check transformation changes on each frame. Callback is added to be first so that the transformation will be\r\n // applied to the rest of the elements using the referenceSpace object\r\n this._xrSessionManager.onXRFrameObservable.add(\r\n () => {\r\n if (this._firstFrame) {\r\n this._updateFromXRSession();\r\n }\r\n if (this.onXRCameraInitializedObservable.hasObservers()) {\r\n this.onXRCameraInitializedObservable.notifyObservers(this);\r\n this.onXRCameraInitializedObservable.clear();\r\n }\r\n\r\n if (this._deferredUpdated) {\r\n this.position.copyFrom(this._deferredPositionUpdate);\r\n this.rotationQuaternion.copyFrom(this._deferredRotationQuaternionUpdate);\r\n }\r\n\r\n this._updateReferenceSpace();\r\n this._updateFromXRSession();\r\n },\r\n undefined,\r\n true\r\n );\r\n }\r\n\r\n /**\r\n * Get the current XR tracking state of the camera\r\n */\r\n public get trackingState(): WebXRTrackingState {\r\n return this._trackingState;\r\n }\r\n\r\n private _setTrackingState(newState: WebXRTrackingState) {\r\n if (this._trackingState !== newState) {\r\n this._trackingState = newState;\r\n this.onTrackingStateChanged.notifyObservers(newState);\r\n }\r\n }\r\n\r\n /**\r\n * Return the user's height, unrelated to the current ground.\r\n * This will be the y position of this camera, when ground level is 0.\r\n */\r\n public get realWorldHeight(): number {\r\n const basePose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(this._xrSessionManager.baseReferenceSpace);\r\n if (basePose && basePose.transform) {\r\n return basePose.transform.position.y;\r\n } else {\r\n return 0;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _updateForDualEyeDebugging(/*pupilDistance = 0.01*/) {\r\n // Create initial camera rigs\r\n this._updateNumberOfRigCameras(2);\r\n this.rigCameras[0].viewport = new Viewport(0, 0, 0.5, 1.0);\r\n // this.rigCameras[0].position.x = -pupilDistance / 2;\r\n this.rigCameras[0].outputRenderTarget = null;\r\n this.rigCameras[1].viewport = new Viewport(0.5, 0, 0.5, 1.0);\r\n // this.rigCameras[1].position.x = pupilDistance / 2;\r\n this.rigCameras[1].outputRenderTarget = null;\r\n }\r\n\r\n /**\r\n * Sets this camera's transformation based on a non-vr camera\r\n * @param otherCamera the non-vr camera to copy the transformation from\r\n * @param resetToBaseReferenceSpace should XR reset to the base reference space\r\n */\r\n public setTransformationFromNonVRCamera(otherCamera: Camera = this.getScene().activeCamera!, resetToBaseReferenceSpace: boolean = true) {\r\n if (!otherCamera || otherCamera === this) {\r\n return;\r\n }\r\n const mat = otherCamera.computeWorldMatrix();\r\n mat.decompose(undefined, this.rotationQuaternion, this.position);\r\n // set the ground level\r\n this.position.y = 0;\r\n Quaternion.FromEulerAnglesToRef(0, this.rotationQuaternion.toEulerAngles().y, 0, this.rotationQuaternion);\r\n this._firstFrame = true;\r\n if (resetToBaseReferenceSpace) {\r\n this._xrSessionManager.resetReferenceSpace();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current instance class name (\"WebXRCamera\").\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"WebXRCamera\";\r\n }\r\n\r\n /**\r\n * Set the target for the camera to look at.\r\n * Note that this only rotates around the Y axis, as opposed to the default behavior of other cameras\r\n * @param target the target to set the camera to look at\r\n */\r\n public setTarget(target: Vector3): void {\r\n // only rotate around the y axis!\r\n const tmpVector = TmpVectors.Vector3[1];\r\n target.subtractToRef(this.position, tmpVector);\r\n tmpVector.y = 0;\r\n tmpVector.normalize();\r\n const yRotation = Math.atan2(tmpVector.x, tmpVector.z);\r\n this.rotationQuaternion.toEulerAnglesToRef(tmpVector);\r\n Quaternion.FromEulerAnglesToRef(tmpVector.x, yRotation, tmpVector.z, this.rotationQuaternion);\r\n }\r\n\r\n public dispose() {\r\n super.dispose();\r\n this._lastXRViewerPose = undefined;\r\n }\r\n\r\n private _rotate180 = new Quaternion(0, 1, 0, 0);\r\n\r\n private _updateFromXRSession() {\r\n const pose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n this._lastXRViewerPose = pose || undefined;\r\n if (!pose) {\r\n this._setTrackingState(WebXRTrackingState.NOT_TRACKING);\r\n return;\r\n }\r\n\r\n // Set the tracking state. if it didn't change it is a no-op\r\n const trackingState = pose.emulatedPosition ? WebXRTrackingState.TRACKING_LOST : WebXRTrackingState.TRACKING;\r\n this._setTrackingState(trackingState);\r\n\r\n // check min/max Z and update if not the same as in cache\r\n if (this.minZ !== this._cache.minZ || this.maxZ !== this._cache.maxZ) {\r\n const xrRenderState: XRRenderStateInit = {\r\n // if maxZ is 0 it should be \"Infinity\", but it doesn't work with the WebXR API. Setting to a large number.\r\n depthFar: this.maxZ || 10000,\r\n depthNear: this.minZ,\r\n };\r\n\r\n this._xrSessionManager.updateRenderState(xrRenderState);\r\n this._cache.minZ = this.minZ;\r\n this._cache.maxZ = this.maxZ;\r\n }\r\n\r\n if (pose.transform) {\r\n const orientation = pose.transform.orientation;\r\n if (pose.transform.orientation.x === undefined) {\r\n // Babylon native polyfill can return an undefined orientation value\r\n // When not initialized\r\n return;\r\n }\r\n const pos = pose.transform.position;\r\n this._referencedPosition.set(pos.x, pos.y, pos.z);\r\n\r\n this._referenceQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this._referencedPosition.z *= -1;\r\n this._referenceQuaternion.z *= -1;\r\n this._referenceQuaternion.w *= -1;\r\n }\r\n\r\n if (this._firstFrame) {\r\n this._firstFrame = false;\r\n // we have the XR reference, now use this to find the offset to get the camera to be\r\n // in the right position\r\n\r\n // set the height to correlate to the current height\r\n this.position.y += this._referencedPosition.y;\r\n // avoid using the head rotation on the first frame.\r\n this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);\r\n } else {\r\n // update position and rotation as reference\r\n this.rotationQuaternion.copyFrom(this._referenceQuaternion);\r\n this.position.copyFrom(this._referencedPosition);\r\n }\r\n }\r\n\r\n // Update camera rigs\r\n if (this.rigCameras.length !== pose.views.length) {\r\n this._updateNumberOfRigCameras(pose.views.length);\r\n }\r\n\r\n pose.views.forEach((view: XRView, i: number) => {\r\n const currentRig = <TargetCamera>this.rigCameras[i];\r\n // update right and left, where applicable\r\n if (!currentRig.isLeftCamera && !currentRig.isRightCamera) {\r\n if (view.eye === \"right\") {\r\n currentRig._isRightCamera = true;\r\n } else if (view.eye === \"left\") {\r\n currentRig._isLeftCamera = true;\r\n }\r\n }\r\n // Update view/projection matrix\r\n const pos = view.transform.position;\r\n const orientation = view.transform.orientation;\r\n\r\n currentRig.parent = this.parent;\r\n\r\n currentRig.position.set(pos.x, pos.y, pos.z);\r\n currentRig.rotationQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n currentRig.position.z *= -1;\r\n currentRig.rotationQuaternion.z *= -1;\r\n currentRig.rotationQuaternion.w *= -1;\r\n } else {\r\n currentRig.rotationQuaternion.multiplyInPlace(this._rotate180);\r\n }\r\n Matrix.FromFloat32ArrayToRefScaled(view.projectionMatrix, 0, 1, currentRig._projectionMatrix);\r\n\r\n if (!this._scene.useRightHandedSystem) {\r\n currentRig._projectionMatrix.toggleProjectionMatrixHandInPlace();\r\n }\r\n\r\n // first camera?\r\n if (i === 0) {\r\n this._projectionMatrix.copyFrom(currentRig._projectionMatrix);\r\n }\r\n\r\n const renderTargetTexture = this._xrSessionManager.getRenderTargetTextureForView(view);\r\n this._renderingMultiview = renderTargetTexture?._texture?.isMultiview || false;\r\n if (this._renderingMultiview) {\r\n // For multiview, the render target texture is the same per-view (just the slice index is different),\r\n // so we only need to set the output render target once for the rig parent.\r\n if (i == 0) {\r\n this._xrSessionManager.trySetViewportForView(this.viewport, view);\r\n this.outputRenderTarget = renderTargetTexture;\r\n }\r\n } else {\r\n // Update viewport\r\n this._xrSessionManager.trySetViewportForView(currentRig.viewport, view);\r\n\r\n // Set cameras to render to the session's render target\r\n currentRig.outputRenderTarget = renderTargetTexture || this._xrSessionManager.getRenderTargetTextureForView(view);\r\n }\r\n\r\n // Replicate parent rig camera behavior\r\n currentRig.layerMask = this.layerMask;\r\n });\r\n }\r\n\r\n private _updateNumberOfRigCameras(viewCount = 1) {\r\n while (this.rigCameras.length < viewCount) {\r\n const newCamera = new TargetCamera(\"XR-RigCamera: \" + this.rigCameras.length, Vector3.Zero(), this.getScene());\r\n newCamera.minZ = 0.1;\r\n newCamera.rotationQuaternion = new Quaternion();\r\n newCamera.updateUpVectorFromRotation = true;\r\n newCamera.isRigCamera = true;\r\n newCamera.rigParent = this;\r\n // do not compute projection matrix, provided by XR\r\n newCamera.freezeProjectionMatrix();\r\n this.rigCameras.push(newCamera);\r\n }\r\n while (this.rigCameras.length > viewCount) {\r\n const removedCamera = this.rigCameras.pop();\r\n if (removedCamera) {\r\n removedCamera.dispose();\r\n }\r\n }\r\n }\r\n\r\n private _updateReferenceSpace() {\r\n // were position & rotation updated OUTSIDE of the xr update loop\r\n if (!this.position.equals(this._referencedPosition) || !this.rotationQuaternion.equals(this._referenceQuaternion)) {\r\n const referencedMat = TmpVectors.Matrix[0];\r\n const poseMat = TmpVectors.Matrix[1];\r\n const transformMat = TmpVectors.Matrix[2];\r\n\r\n Matrix.ComposeToRef(WebXRCamera._ScaleReadOnly, this._referenceQuaternion, this._referencedPosition, referencedMat);\r\n Matrix.ComposeToRef(WebXRCamera._ScaleReadOnly, this.rotationQuaternion, this.position, poseMat);\r\n referencedMat.invert().multiplyToRef(poseMat, transformMat);\r\n transformMat.invert();\r\n\r\n if (!this._scene.useRightHandedSystem) {\r\n transformMat.toggleModelMatrixHandInPlace();\r\n }\r\n\r\n transformMat.decompose(undefined, this._referenceQuaternion, this._referencedPosition);\r\n const transform = new XRRigidTransform(\r\n {\r\n x: this._referencedPosition.x,\r\n y: this._referencedPosition.y,\r\n z: this._referencedPosition.z,\r\n },\r\n {\r\n x: this._referenceQuaternion.x,\r\n y: this._referenceQuaternion.y,\r\n z: this._referenceQuaternion.z,\r\n w: this._referenceQuaternion.w,\r\n }\r\n );\r\n this._xrSessionManager.referenceSpace = this._xrSessionManager.referenceSpace.getOffsetReferenceSpace(transform);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRManagedOutputCanvas.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRManagedOutputCanvas.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D;;GAEG;AACH,MAAM,OAAO,+BAA+B;IAexC;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAC,MAAmB;QACzC,MAAM,QAAQ,GAAG,IAAI,+BAA+B,EAAE,CAAC;QACvD,QAAQ,CAAC,aAAa,GAAG;YACrB,SAAS,EAAE,IAAI;YACf,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI;YAC/C,KAAK,EAAE,IAAI;YACX,sBAAsB,EAAE,CAAC;SAC5B,CA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AC,mBAAmB,EAAE;gBAC1B,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE;oBACpD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,KAAK,GAAG,IAAI,CAAC;oBACjE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,mBAAmB,CAAC,MAAM,GAAG,IAAI,CAAC;iBACtE;qBAAM;oBACH,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;iBACzF;aACJ;SACJ;IACL,CAAC;IAEO,uBAAuB,CAAC,MAAmC;QAC/D,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,EAAE;YACT,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACnB,IAAI,CAAC,aAAqB,GAAG,IAAI,CAAC;SACtC;aAAM;YACH,IAAI,CAAC,mBAAmB,GAAG;gBACvB,KAAK,EAAE,MAAM,CAAC,WAAW;gBACzB,MAAM,EAAE,MAAM,CAAC,YAAY;aAC9B,CAAC;YACF,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;YACtB,IAAI,CAAC,aAAa,GAAQ,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YAC5D,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;gBACrB,IAAI,CAAC,aAAa,GAAQ,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;aAC9D;SACJ;IACL,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\nimport { WebXRWebGLLayerWrapper } from \"./webXRWebGLLayer\";\r\n\r\n/**\r\n * Configuration object for WebXR output canvas\r\n */\r\nexport class WebXRManagedOutputCanvasOptions {\r\n /**\r\n * An optional canvas in case you wish to create it yourself and provide it here.\r\n * If not provided, a new canvas will be created\r\n */\r\n public canvasElement?: HTMLCanvasElement;\r\n /**\r\n * Options for this XR Layer output\r\n */\r\n public canvasOptions?: XRWebGLLayerInit;\r\n /**\r\n * CSS styling for a newly created canvas (if not provided)\r\n */\r\n public newCanvasCssStyle?: string;\r\n\r\n /**\r\n * Get the default values of the configuration object\r\n * @param engine defines the engine to use (can be null)\r\n * @returns default values of this configuration object\r\n */\r\n public static GetDefaults(engine?: ThinEngine): WebXRManagedOutputCanvasOptions {\r\n const defaults = new WebXRManagedOutputCanvasOptions();\r\n defaults.canvasOptions = {\r\n antialias: true,\r\n depth: true,\r\n stencil: engine ? engine.isStencilEnable : true,\r\n alpha: true,\r\n framebufferScaleFactor: 1,\r\n };\r\n\r\n defaults.newCanvasCssStyle = \"position:absolute; bottom:0px;right:0px;z-index:10;width:90%;height:100%;background-color: #000000;\";\r\n\r\n return defaults;\r\n }\r\n}\r\n/**\r\n * Creates a canvas that is added/removed from the webpage when entering/exiting XR\r\n */\r\nexport class WebXRManagedOutputCanvas implements WebXRRenderTarget {\r\n private _canvas: Nullable<HTMLCanvasElement> = null;\r\n private _engine: Nullable<ThinEngine> = null;\r\n private _originalCanvasSize: {\r\n width: number;\r\n height: number;\r\n };\r\n\r\n /**\r\n * Rendering context of the canvas which can be used to display/mirror xr content\r\n */\r\n public canvasContext: WebGLRenderingContext;\r\n\r\n /**\r\n * xr layer for the canvas\r\n */\r\n public xrLayer: Nullable<XRWebGLLayer> = null;\r\n\r\n private _xrLayerWrapper: Nullable<WebXRLayerWrapper> = null;\r\n\r\n /**\r\n * Observers registered here will be triggered when the xr layer was initialized\r\n */\r\n public onXRLayerInitObservable: Observable<XRWebGLLayer> = new Observable();\r\n\r\n /**\r\n * Initializes the canvas to be added/removed upon entering/exiting xr\r\n * @param _xrSessionManager The XR Session manager\r\n * @param _options optional configuration for this canvas output. defaults will be used if not provided\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, private _options: WebXRManagedOutputCanvasOptions = WebXRManagedOutputCanvasOptions.GetDefaults()) {\r\n this._engine = _xrSessionManager.scene.getEngine();\r\n this._engine.onDisposeObservable.addOnce(() => {\r\n this._engine = null;\r\n });\r\n\r\n if (!_options.canvasElement) {\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.style.cssText = this._options.newCanvasCssStyle || \"position:absolute; bottom:0px;right:0px;\";\r\n this._setManagedOutputCanvas(canvas);\r\n } else {\r\n this._setManagedOutputCanvas(_options.canvasElement);\r\n }\r\n\r\n _xrSessionManager.onXRSessionInit.add(() => {\r\n this._addCanvas();\r\n });\r\n\r\n _xrSessionManager.onXRSessionEnded.add(() => {\r\n this._removeCanvas();\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n this._removeCanvas();\r\n this._setManagedOutputCanvas(null);\r\n }\r\n\r\n /**\r\n * Initializes a XRWebGLLayer to be used as the session's baseLayer.\r\n * @param xrSession xr session\r\n * @returns a promise that will resolve once the XR Layer has been created\r\n */\r\n public async initializeXRLayerAsync(xrSession: XRSession): Promise<XRWebGLLayer> {\r\n const createLayer = () => {\r\n this.xrLayer = new XRWebGLLayer(xrSession, this.canvasContext, this._options.canvasOptions);\r\n this._xrLayerWrapper = new WebXRWebGLLayerWrapper(this.xrLayer);\r\n this.onXRLayerInitObservable.notifyObservers(this.xrLayer);\r\n return this.xrLayer;\r\n };\r\n\r\n // support canvases without makeXRCompatible\r\n if (!(this.canvasContext as any).makeXRCompatible) {\r\n return Promise.resolve(createLayer());\r\n }\r\n\r\n return (this.canvasContext as any)\r\n .makeXRCompatible()\r\n .then(\r\n // catch any error and continue. When using the emulator is throws this error for no apparent reason.\r\n () => {},\r\n () => {\r\n // log the error, continue nonetheless!\r\n Tools.Warn(\"Error executing makeXRCompatible. This does not mean that the session will work incorrectly.\");\r\n }\r\n )\r\n .then(() => {\r\n return createLayer();\r\n });\r\n }\r\n\r\n private _addCanvas() {\r\n if (this._canvas && this._engine && this._canvas !== this._engine.getRenderingCanvas()) {\r\n document.body.appendChild(this._canvas);\r\n }\r\n if (this.xrLayer) {\r\n this._setCanvasSize(true);\r\n } else {\r\n this.onXRLayerInitObservable.addOnce(() => {\r\n this._setCanvasSize(true);\r\n });\r\n }\r\n }\r\n\r\n private _removeCanvas() {\r\n if (this._canvas && this._engine && document.body.contains(this._canvas) && this._canvas !== this._engine.getRenderingCanvas()) {\r\n document.body.removeChild(this._canvas);\r\n }\r\n this._setCanvasSize(false);\r\n }\r\n\r\n private _setCanvasSize(init: boolean = true, xrLayer = this._xrLayerWrapper) {\r\n if (!this._canvas || !this._engine) {\r\n return;\r\n }\r\n if (init) {\r\n if (xrLayer) {\r\n if (this._canvas !== this._engine.getRenderingCanvas()) {\r\n this._canvas.style.width = xrLayer.getWidth() + \"px\";\r\n this._canvas.style.height = xrLayer.getHeight() + \"px\";\r\n } else {\r\n this._engine.setSize(xrLayer.getWidth(), xrLayer.getHeight());\r\n }\r\n }\r\n } else {\r\n if (this._originalCanvasSize) {\r\n if (this._canvas !== this._engine.getRenderingCanvas()) {\r\n this._canvas.style.width = this._originalCanvasSize.width + \"px\";\r\n this._canvas.style.height = this._originalCanvasSize.height + \"px\";\r\n } else {\r\n this._engine.setSize(this._originalCanvasSize.width, this._originalCanvasSize.height);\r\n }\r\n }\r\n }\r\n }\r\n\r\n private _setManagedOutputCanvas(canvas: Nullable<HTMLCanvasElement>) {\r\n this._removeCanvas();\r\n if (!canvas) {\r\n this._canvas = null;\r\n (this.canvasContext as any) = null;\r\n } else {\r\n this._originalCanvasSize = {\r\n width: canvas.offsetWidth,\r\n height: canvas.offsetHeight,\r\n };\r\n this._canvas = canvas;\r\n this.canvasContext = <any>this._canvas.getContext(\"webgl2\");\r\n if (!this.canvasContext) {\r\n this.canvasContext = <any>this._canvas.getContext(\"webgl\");\r\n }\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"webXRManagedOutputCanvas.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRManagedOutputCanvas.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D;;GAEG;AACH,MAAM,OAAO,+BAA+B;IAexC;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAC,MAAmB;QACzC,MAAM,QAAQ,GAAG,IAAI,+BAA+B,EAAE,CAAC;QACvD,QAAQ,CAAC,aAAa,GAAG;YACrB,SAAS,EAAE,IAAI;YACf,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI;YAC/C,KAAK,EAAE,IAAI;YACX,sBAAsB,EAAE,CAAC;SAC5B,CAAC;QAEF,QAAQ,CAAC,iBAAiB,GAAG,qGAAqG,CAAC;QAEnI,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AACD;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAyBjC;;;;OAIG;IACH,YACI,iBAAsC,EAC9B,WAA4C,+BAA+B,CAAC,WAAW,EAAE;QAAzF,aAAQ,GAAR,QAAQ,CAAiF;QA/B7F,YAAO,GAAgC,IAAI,CAAC;QAC5C,YAAO,GAAyB,IAAI,CAAC;QAW7C;;WAEG;QACI,YAAO,GAA2B,IAAI,CAAC;QAEtC,oBAAe,GAAgC,IAAI,CAAC;QAE5D;;WAEG;QACI,4BAAuB,GAA6B,IAAI,UAAU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AAM,CAAC,CAAC;iBACzF;aACJ;SACJ;IACL,CAAC;IAEO,uBAAuB,CAAC,MAAmC;QAC/D,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,EAAE;YACT,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACnB,IAAI,CAAC,aAAqB,GAAG,IAAI,CAAC;SACtC;aAAM;YACH,IAAI,CAAC,mBAAmB,GAAG;gBACvB,KAAK,EAAE,MAAM,CAAC,WAAW;gBACzB,MAAM,EAAE,MAAM,CAAC,YAAY;aAC9B,CAAC;YACF,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;YACtB,IAAI,CAAC,aAAa,GAAQ,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YAC5D,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;gBACrB,IAAI,CAAC,aAAa,GAAQ,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;aAC9D;SACJ;IACL,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\nimport { WebXRWebGLLayerWrapper } from \"./webXRWebGLLayer\";\r\n\r\n/**\r\n * Configuration object for WebXR output canvas\r\n */\r\nexport class WebXRManagedOutputCanvasOptions {\r\n /**\r\n * An optional canvas in case you wish to create it yourself and provide it here.\r\n * If not provided, a new canvas will be created\r\n */\r\n public canvasElement?: HTMLCanvasElement;\r\n /**\r\n * Options for this XR Layer output\r\n */\r\n public canvasOptions?: XRWebGLLayerInit;\r\n /**\r\n * CSS styling for a newly created canvas (if not provided)\r\n */\r\n public newCanvasCssStyle?: string;\r\n\r\n /**\r\n * Get the default values of the configuration object\r\n * @param engine defines the engine to use (can be null)\r\n * @returns default values of this configuration object\r\n */\r\n public static GetDefaults(engine?: ThinEngine): WebXRManagedOutputCanvasOptions {\r\n const defaults = new WebXRManagedOutputCanvasOptions();\r\n defaults.canvasOptions = {\r\n antialias: true,\r\n depth: true,\r\n stencil: engine ? engine.isStencilEnable : true,\r\n alpha: true,\r\n framebufferScaleFactor: 1,\r\n };\r\n\r\n defaults.newCanvasCssStyle = \"position:absolute; bottom:0px;right:0px;z-index:10;width:90%;height:100%;background-color: #000000;\";\r\n\r\n return defaults;\r\n }\r\n}\r\n/**\r\n * Creates a canvas that is added/removed from the webpage when entering/exiting XR\r\n */\r\nexport class WebXRManagedOutputCanvas implements WebXRRenderTarget {\r\n private _canvas: Nullable<HTMLCanvasElement> = null;\r\n private _engine: Nullable<ThinEngine> = null;\r\n private _originalCanvasSize: {\r\n width: number;\r\n height: number;\r\n };\r\n\r\n /**\r\n * Rendering context of the canvas which can be used to display/mirror xr content\r\n */\r\n public canvasContext: WebGLRenderingContext;\r\n\r\n /**\r\n * xr layer for the canvas\r\n */\r\n public xrLayer: Nullable<XRWebGLLayer> = null;\r\n\r\n private _xrLayerWrapper: Nullable<WebXRLayerWrapper> = null;\r\n\r\n /**\r\n * Observers registered here will be triggered when the xr layer was initialized\r\n */\r\n public onXRLayerInitObservable: Observable<XRWebGLLayer> = new Observable();\r\n\r\n /**\r\n * Initializes the canvas to be added/removed upon entering/exiting xr\r\n * @param _xrSessionManager The XR Session manager\r\n * @param _options optional configuration for this canvas output. defaults will be used if not provided\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n private _options: WebXRManagedOutputCanvasOptions = WebXRManagedOutputCanvasOptions.GetDefaults()\r\n ) {\r\n this._engine = _xrSessionManager.scene.getEngine();\r\n this._engine.onDisposeObservable.addOnce(() => {\r\n this._engine = null;\r\n });\r\n\r\n if (!_options.canvasElement) {\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.style.cssText = this._options.newCanvasCssStyle || \"position:absolute; bottom:0px;right:0px;\";\r\n this._setManagedOutputCanvas(canvas);\r\n } else {\r\n this._setManagedOutputCanvas(_options.canvasElement);\r\n }\r\n\r\n _xrSessionManager.onXRSessionInit.add(() => {\r\n this._addCanvas();\r\n });\r\n\r\n _xrSessionManager.onXRSessionEnded.add(() => {\r\n this._removeCanvas();\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n this._removeCanvas();\r\n this._setManagedOutputCanvas(null);\r\n }\r\n\r\n /**\r\n * Initializes a XRWebGLLayer to be used as the session's baseLayer.\r\n * @param xrSession xr session\r\n * @returns a promise that will resolve once the XR Layer has been created\r\n */\r\n public async initializeXRLayerAsync(xrSession: XRSession): Promise<XRWebGLLayer> {\r\n const createLayer = () => {\r\n this.xrLayer = new XRWebGLLayer(xrSession, this.canvasContext, this._options.canvasOptions);\r\n this._xrLayerWrapper = new WebXRWebGLLayerWrapper(this.xrLayer);\r\n this.onXRLayerInitObservable.notifyObservers(this.xrLayer);\r\n return this.xrLayer;\r\n };\r\n\r\n // support canvases without makeXRCompatible\r\n if (!(this.canvasContext as any).makeXRCompatible) {\r\n return Promise.resolve(createLayer());\r\n }\r\n\r\n return (this.canvasContext as any)\r\n .makeXRCompatible()\r\n .then(\r\n // catch any error and continue. When using the emulator is throws this error for no apparent reason.\r\n () => {},\r\n () => {\r\n // log the error, continue nonetheless!\r\n Tools.Warn(\"Error executing makeXRCompatible. This does not mean that the session will work incorrectly.\");\r\n }\r\n )\r\n .then(() => {\r\n return createLayer();\r\n });\r\n }\r\n\r\n private _addCanvas() {\r\n if (this._canvas && this._engine && this._canvas !== this._engine.getRenderingCanvas()) {\r\n document.body.appendChild(this._canvas);\r\n }\r\n if (this.xrLayer) {\r\n this._setCanvasSize(true);\r\n } else {\r\n this.onXRLayerInitObservable.addOnce(() => {\r\n this._setCanvasSize(true);\r\n });\r\n }\r\n }\r\n\r\n private _removeCanvas() {\r\n if (this._canvas && this._engine && document.body.contains(this._canvas) && this._canvas !== this._engine.getRenderingCanvas()) {\r\n document.body.removeChild(this._canvas);\r\n }\r\n this._setCanvasSize(false);\r\n }\r\n\r\n private _setCanvasSize(init: boolean = true, xrLayer = this._xrLayerWrapper) {\r\n if (!this._canvas || !this._engine) {\r\n return;\r\n }\r\n if (init) {\r\n if (xrLayer) {\r\n if (this._canvas !== this._engine.getRenderingCanvas()) {\r\n this._canvas.style.width = xrLayer.getWidth() + \"px\";\r\n this._canvas.style.height = xrLayer.getHeight() + \"px\";\r\n } else {\r\n this._engine.setSize(xrLayer.getWidth(), xrLayer.getHeight());\r\n }\r\n }\r\n } else {\r\n if (this._originalCanvasSize) {\r\n if (this._canvas !== this._engine.getRenderingCanvas()) {\r\n this._canvas.style.width = this._originalCanvasSize.width + \"px\";\r\n this._canvas.style.height = this._originalCanvasSize.height + \"px\";\r\n } else {\r\n this._engine.setSize(this._originalCanvasSize.width, this._originalCanvasSize.height);\r\n }\r\n }\r\n }\r\n }\r\n\r\n private _setManagedOutputCanvas(canvas: Nullable<HTMLCanvasElement>) {\r\n this._removeCanvas();\r\n if (!canvas) {\r\n this._canvas = null;\r\n (this.canvasContext as any) = null;\r\n } else {\r\n this._originalCanvasSize = {\r\n width: canvas.offsetWidth,\r\n height: canvas.offsetHeight,\r\n };\r\n this._canvas = canvas;\r\n this.canvasContext = <any>this._canvas.getContext(\"webgl2\");\r\n if (!this.canvasContext) {\r\n this.canvasContext = <any>this._canvas.getContext(\"webgl\");\r\n }\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRRenderTargetTextureProvider.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRRenderTargetTextureProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAgChF;;;GAGG;AACH,MAAM,OAAgB,qCAAqC;IAUvD,
|
|
1
|
+
{"version":3,"file":"webXRRenderTargetTextureProvider.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRRenderTargetTextureProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAgChF;;;GAGG;AACH,MAAM,OAAgB,qCAAqC;IAUvD,YACqB,MAAa,EACd,YAA+B;QAD9B,WAAM,GAAN,MAAM,CAAO;QACd,iBAAY,GAAZ,YAAY,CAAmB;QAPzC,0BAAqB,GAAG,IAAI,KAAK,EAAuB,CAAC;QAS/D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAEO,sBAAsB,CAAC,WAA8C,EAAE,OAAqB;QAChG,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,qBAAqB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC/F,eAAe,CAAC,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC;QAC1C,eAAe,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;QAC5C,eAAe,CAAC,gBAAgB,GAAG,IAAI,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACvF,eAAe,CAAC,OAAO,GAAG,IAAI,CAAC;QAC/B,OAAO,eAAe,CAAC;IAC3B,CAAC;IAES,0BAA0B,CAChC,KA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C,gBAAgB,EAAE,CAAC;QACvC,gHAAgH;QAChH,IAAI,OAAO,cAAc,KAAK,WAAW,EAAE;YACvC,4BAA4B;YAC5B,mBAAmB,CAAC,gBAAgB,GAAG,IAAI,CAAC;SAC/C;QAED,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAErD,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAES,2BAA2B,CAAC,mBAAwC;QAC1E,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9F,mBAAmB,CAAC,OAAO,EAAE,CAAC;IAClC,CAAC;IAEM,wBAAwB;QAC3B,OAAO,IAAI,CAAC,sBAAsB,CAAC;IACvC,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,qBAAqB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1C,CAAC;CACJ","sourcesContent":["import type { Engine } from \"../Engines/engine\";\r\nimport { WebGLHardwareTexture } from \"../Engines/WebGL/webGLHardwareTexture\";\r\nimport type { WebGLRenderTargetWrapper } from \"../Engines/WebGL/webGLRenderTargetWrapper\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport { MultiviewRenderTarget } from \"../Materials/Textures/MultiviewRenderTarget\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Viewport } from \"../Maths/math.viewport\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\n\r\n/**\r\n * An interface for objects that provide render target textures for XR rendering.\r\n */\r\nexport interface IWebXRRenderTargetTextureProvider extends IDisposable {\r\n /**\r\n * Attempts to set the framebuffer-size-normalized viewport to be rendered this frame for this view.\r\n * In the event of a failure, the supplied viewport is not updated.\r\n * @param viewport the viewport to which the view will be rendered\r\n * @param view the view for which to set the viewport\r\n * @returns whether the operation was successful\r\n */\r\n trySetViewportForView(viewport: Viewport, view: XRView): boolean;\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this eye\r\n * @param eye the eye for which to get the render target\r\n * @returns the render target for the specified eye or null if not available\r\n */\r\n getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture>;\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this view\r\n * @param view the view for which to get the render target\r\n * @returns the render target for the specified view or null if not available\r\n */\r\n getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture>;\r\n}\r\n\r\n/**\r\n * Provides render target textures and other important rendering information for a given XRLayer.\r\n * @internal\r\n */\r\nexport abstract class WebXRLayerRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n public abstract trySetViewportForView(viewport: Viewport, view: XRView): boolean;\r\n public abstract getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture>;\r\n public abstract getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture>;\r\n\r\n protected _renderTargetTextures = new Array<RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n\r\n private _engine: Engine;\r\n\r\n constructor(\r\n private readonly _scene: Scene,\r\n public readonly layerWrapper: WebXRLayerWrapper\r\n ) {\r\n this._engine = _scene.getEngine();\r\n }\r\n\r\n private _createInternalTexture(textureSize: { width: number; height: number }, texture: WebGLTexture): InternalTexture {\r\n const internalTexture = new InternalTexture(this._engine, InternalTextureSource.Unknown, true);\r\n internalTexture.width = textureSize.width;\r\n internalTexture.height = textureSize.height;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(texture, this._engine._gl);\r\n internalTexture.isReady = true;\r\n return internalTexture;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable<WebGLFramebuffer>,\r\n colorTexture?: WebGLTexture,\r\n depthStencilTexture?: WebGLTexture,\r\n multiview?: boolean\r\n ): RenderTargetTexture {\r\n if (!this._engine) {\r\n throw new Error(\"Engine is disposed\");\r\n }\r\n\r\n const textureSize = { width, height };\r\n\r\n // Create render target texture from the internal texture\r\n const renderTargetTexture = multiview ? new MultiviewRenderTarget(this._scene, textureSize) : new RenderTargetTexture(\"XR renderTargetTexture\", textureSize, this._scene);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n renderTargetWrapper._samples = renderTargetTexture.samples;\r\n // Set the framebuffer, make sure it works in all scenarios - emulator, no layers and layers\r\n if (framebuffer || !colorTexture) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n if (colorTexture) {\r\n if (multiview) {\r\n renderTargetWrapper._colorTextureArray = colorTexture;\r\n } else {\r\n const internalTexture = this._createInternalTexture(textureSize, colorTexture);\r\n renderTargetWrapper.setTexture(internalTexture, 0);\r\n renderTargetTexture._texture = internalTexture;\r\n }\r\n }\r\n\r\n if (depthStencilTexture) {\r\n if (multiview) {\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n } else {\r\n renderTargetWrapper._depthStencilTexture = this._createInternalTexture(textureSize, depthStencilTexture);\r\n }\r\n }\r\n\r\n renderTargetTexture.disableRescaling();\r\n // Firefox reality fails if skipInitialClear is set to true, so make sure only modern XR implementations set it.\r\n if (typeof XRWebGLBinding !== \"undefined\") {\r\n // WebXR pre-clears textures\r\n renderTargetTexture.skipInitialClear = true;\r\n }\r\n\r\n this._renderTargetTextures.push(renderTargetTexture);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _destroyRenderTargetTexture(renderTargetTexture: RenderTargetTexture) {\r\n this._renderTargetTextures.splice(this._renderTargetTextures.indexOf(renderTargetTexture), 1);\r\n renderTargetTexture.dispose();\r\n }\r\n\r\n public getFramebufferDimensions(): Nullable<{ framebufferWidth: number; framebufferHeight: number }> {\r\n return this._framebufferDimensions;\r\n }\r\n\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.length = 0;\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRWebGLLayer.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRWebGLLayer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,qCAAqC,EAAE,MAAM,oCAAoC,CAAC;AAE3F;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,iBAAiB;IACzD;;;OAGG;IACH,YAA4B,KAAmB;QAC3C,KAAK,CACD,GAAG,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAC5B,GAAG,EAAE,CAAC,KAAK,CAAC,iBAAiB,EAC7B,KAAK,EACL,cAAc,EACd,CAAC,cAAc,EAAE,EAAE,CAAC,IAAI,0CAA0C,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CACjG,CAAC;QAPsB,UAAK,GAAL,KAAK,CAAc;IAQ/C,CAAC;CACJ;AAED;;;GAGG;AACH,MAAM,OAAO,0CAA2C,SAAQ,qCAAqC;IAOjG,
|
|
1
|
+
{"version":3,"file":"webXRWebGLLayer.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRWebGLLayer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,qCAAqC,EAAE,MAAM,oCAAoC,CAAC;AAE3F;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,iBAAiB;IACzD;;;OAGG;IACH,YAA4B,KAAmB;QAC3C,KAAK,CACD,GAAG,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAC5B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;IAED,6DAA6D;IACtD,4BAA4B,CAAC,GAAU;QAC1C,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;QAChD,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;QAClD,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QAE5C,IACI,CAAC,IAAI,CAAC,IAAI;YACV,UAAU,KAAK,IAAI,CAAC,sBAAsB,CAAC,gBAAgB;YAC3D,WAAW,KAAK,IAAI,CAAC,sBAAsB,CAAC,iBAAiB;YAC7D,WAAW,KAAK,IAAI,CAAC,YAAY,EACnC;YACE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,0BAA0B,CAAC,UAAU,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;YAClF,IAAI,CAAC,sBAAsB,CAAC,gBAAgB,GAAG,UAAU,CAAC;YAC1D,IAAI,CAAC,sBAAsB,CAAC,iBAAiB,GAAG,WAAW,CAAC;YAC5D,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;SACnC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAEM,6BAA6B,CAAC,IAAY;QAC7C,OAAO,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvD,CAAC;CACJ","sourcesContent":["import type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Viewport } from \"../Maths/math.viewport\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\nimport { WebXRLayerRenderTargetTextureProvider } from \"./webXRRenderTargetTextureProvider\";\r\n\r\n/**\r\n * Wraps xr webgl layers.\r\n * @internal\r\n */\r\nexport class WebXRWebGLLayerWrapper extends WebXRLayerWrapper {\r\n /**\r\n * @param layer is the layer to be wrapped.\r\n * @returns a new WebXRLayerWrapper wrapping the provided XRWebGLLayer.\r\n */\r\n constructor(public readonly layer: XRWebGLLayer) {\r\n super(\r\n () => layer.framebufferWidth,\r\n () => layer.framebufferHeight,\r\n layer,\r\n \"XRWebGLLayer\",\r\n (sessionManager) => new WebXRWebGLLayerRenderTargetTextureProvider(sessionManager.scene, this)\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * Provides render target textures and other important rendering information for a given XRWebGLLayer.\r\n * @internal\r\n */\r\nexport class WebXRWebGLLayerRenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {\r\n // The dimensions will always be defined in this class.\r\n protected _framebufferDimensions: { framebufferWidth: number; framebufferHeight: number };\r\n private _rtt: Nullable<RenderTargetTexture>;\r\n private _framebuffer: WebGLFramebuffer;\r\n private _layer: XRWebGLLayer;\r\n\r\n constructor(\r\n scene: Scene,\r\n public readonly layerWrapper: WebXRWebGLLayerWrapper\r\n ) {\r\n super(scene, layerWrapper);\r\n this._layer = layerWrapper.layer;\r\n this._framebufferDimensions = {\r\n framebufferWidth: this._layer.framebufferWidth,\r\n framebufferHeight: this._layer.framebufferHeight,\r\n };\r\n }\r\n\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n const xrViewport = this._layer.getViewport(view);\r\n if (!xrViewport) {\r\n return false;\r\n }\r\n const framebufferWidth = this._framebufferDimensions.framebufferWidth;\r\n const framebufferHeight = this._framebufferDimensions.framebufferHeight;\r\n viewport.x = xrViewport.x / framebufferWidth;\r\n viewport.y = xrViewport.y / framebufferHeight;\r\n viewport.width = xrViewport.width / framebufferWidth;\r\n viewport.height = xrViewport.height / framebufferHeight;\r\n return true;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture> {\r\n const layerWidth = this._layer.framebufferWidth;\r\n const layerHeight = this._layer.framebufferHeight;\r\n const framebuffer = this._layer.framebuffer;\r\n\r\n if (\r\n !this._rtt ||\r\n layerWidth !== this._framebufferDimensions.framebufferWidth ||\r\n layerHeight !== this._framebufferDimensions.framebufferHeight ||\r\n framebuffer !== this._framebuffer\r\n ) {\r\n this._rtt = this._createRenderTargetTexture(layerWidth, layerHeight, framebuffer);\r\n this._framebufferDimensions.framebufferWidth = layerWidth;\r\n this._framebufferDimensions.framebufferHeight = layerHeight;\r\n this._framebuffer = framebuffer;\r\n }\r\n\r\n return this._rtt;\r\n }\r\n\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n return this.getRenderTargetTextureForEye(view.eye);\r\n }\r\n}\r\n"]}
|