WebXR Depth Sensing API dont work in three js r168

Hello everyone,

I’m working with the WebXR Depth Sensing API to obtain depth data in my project. I’ve been using Three.js version r148 with the following session initialization:

const sessionInit = {
  requiredFeatures: ["hit-test", "local-floor", "depth-sensing"],
  optionalFeatures: ["dom-overlay", "light-estimation", "anchors"],
  depthSensing: {
    usagePreference: ["cpu-optimized", "gpu-optimized"],
    dataFormatPreference: ["luminance-alpha", "float32"],
  },
  domOverlay: {
    root: elementsOverlay as HTMLElement,
  },
};

With this setup, everything works perfectly.

Recently, I needed to update Three.js to the latest version (r168). However, after updating, the WebXR session no longer starts, and I receive the following error:

Cannot read properties of null (reading 'getDepthInformation')

It seems that the method getDepthInformation is returning null, causing the error.

I’m looking for guidance on how to properly use the depth-sensing API with Three.js version r168. Have there been any changes or deprecations in the API that I need to be aware of? How should I modify my code to make it work with the latest version?

Any help or pointers would be greatly appreciated!

Thank you in advance.

Hello, im new to responding on this forums, and the question was a long time ago, but as there is not a lot of help in this topic online i decided to post.
its because threejs only supports gpu-optimized depth sensing (I never tested if it works, but it should), and on that version their code for depth sensing assumes the device is gpu-optimized, so it throws that error.
If you want to keep using that version and you have a custom depth sensing approach (which i assumed you do since on r140 threejs didnt had depth sensing code) you should comment this part of WebXRManager.js

You can also use the latest threejs version as they added a check to see if the device is gpu-optimized, so you shouldnt have that error.

**
**

1 Like