Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webxr] How do I render cesium scene to webxr? #11298

Closed
YHIsMyLove opened this issue May 21, 2023 · 2 comments
Closed

[webxr] How do I render cesium scene to webxr? #11298

YHIsMyLove opened this issue May 21, 2023 · 2 comments

Comments

@YHIsMyLove
Copy link

I’m trying to make the scene displayed on my oculus quest 2 vr headset using WebXR API. I’ve searched the forum and the internet and the solution I got all seems outdated.
I wrote a demo using raw webgl where i call gl.clear and gl.drawArrays in the xrSession.requestAnimationFrame callback function and it works fine. But when I replace them with cesium’s render method, the headset screen only shows the clear color I set with gl.clearColor and nothing else.
Currently I only need to make the scene shown on the headset screen. What should I do to achieve this?

Here are part of my code

function initVR() {
var gl = viewer.scene.context._gl;
navigator.xr.requestSession('immersive-vr').then((xrSession) => {
xrSession.requestReferenceSpace("local").then((xrReferenceSpace) => {  
    const xrWebGLLayer = new XRWebGLLayer(xrSession, gl,)
    xrSession.updateRenderState({ baseLayer: xrWebGLLayer })
    xrSession.requestAnimationFrame(animate)
    function animate() {
        xrSession.requestAnimationFrame((time, xrFrame) => {
             let poses = xrFrame.getViewerPose(xrReferenceSpace);
              // gl.clearColor(1,0,1,1)
               gl.bindFramebuffer(gl.FRAMEBUFFER, xrSession.renderState.baseLayer.framebuffer);
                // **draw call here**
                viewer.scene.render()
                 for (let xrView of poses.views) {
                        let xrViewport = xrWebGLLayer.getViewport(xrView);
                         gl.viewport(xrViewport.x, xrViewport.y, xrViewport.width, xrViewport.height);
                  }
                 animate()
             });
         }
       }).catch((err) => {
          console.log(err)
       });
       }).catch((err) => {
          console.log(err)
        });
 }
@ggetz
Copy link
Contributor

ggetz commented May 24, 2023

Hi @YHIsMyLove, a feature request for WebXR support is documented in #3422.

I'm going to close this issue as a duplicate, and would ask that you continue the conversation over in that issue to keep information in one place.

As an offhand suggestion, is the viewer rendering to the correct canvas that WebXR expects?

@ggetz ggetz closed this as completed May 24, 2023
@pupitetris
Copy link

@YHIsMyLove check this pull request: #11372

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants