immersive-web / webxr-samples

Samples to demonstrate use of the WebXR Device API
https://immersive-web.github.io/webxr-samples/
MIT License
995 stars 479 forks source link

baseLayer remains null after session.updateRenderState() #46

Closed faaaaabi closed 4 years ago

faaaaabi commented 4 years ago

First of all thanks a lo for the sample applications.

I'm trying to incorporate THREE.js as render engine. I tried this based on this proposal

As stated in the webxr-explainer, if have to set the sessions baseLayer via the sessions updateRenderState method.

Now when I try to set the sessions baseLayer, it remains null. There is no error thrown which would indicate that session.updateRenderState didn't work.

Here is the code which is executed when a immersive-ar session is successfully started:

onSessionStarted = async session => {
    session.addEventListener('end', this.onSessionEnded);
    this.THREEjsRenderer = new THREE.WebGLRenderer({
      ...
    });
    this.THREEjsRenderer.autoClear = false;
    this.THREEjsRenderer.shadowMap.enabled = true;

    this.THREEjsGL = this.THREEjsRenderer.getContext();
    await this.THREEjsGL.makeXRCompatible();

    this.xrRefSpace = await session.requestReferenceSpace('local');

    session.updateRenderState({ baseLayer: new XRWebGLLayer(session, this.THREEjsGL) });
    const {framebuffer} = session.renderState.baseLayer; // <--- XRSession creation failed: Cannot read property 'framebuffer' of null

    this.THREEjsCamera = new THREE.PerspectiveCamera();
    this.THREEjsCamera.matrixAutoUpdate = false;

    session.requestAnimationFrame(this.onXRFrame);
  };

Am I missing something important? Or may that be browser specific? I'm using Chorme Canary 79..0.3939.0

faaaaabi commented 4 years ago

This seems to be my fault. As the baseLayer is available after session.requestAnimationFrame().