WebXR (AR): Is this possible to get detected planes on floor?

Hi,

Using the AR mode from WebXR, I’m trying to get the detected planes on the floor to apply a textures on it. This can be usefull to see the detected area and to preview a new floor in my room.

Is this possible to do that with the WebXR implemented in Playcanvas.

The immersive-web have some documentation about planes detection and how to get them: https://github.com/immersive-web/real-world-geometry/blob/master/plane-detection-explainer.md

// Function that's passed in to XRSession.requestAnimationFrame().
function onXRFrame(timestamp, frame) {
 let detectedPlanes = frame.worldInformation.detectedPlanes;
 detectedPlanes.forEach(plane => {
   let planePose = frame.getPose(plane.planeSpace, xrReferenceSpace);
   let planeVertices = plane.polygon; // plane.polygon is an array of objects
                                      // containing x,y,z coordinates
   
   // ...draw plane_vertices relative to plane_pose...
 });
 

The frame isn’t exposed in the engine currently.

I’m thinking that maybe this event should also pass the frame so developers can subscribe to it? https://github.com/playcanvas/engine/blob/master/src/xr/xr-manager.js#L460

For the moment, you should be able to monkey patch the update function in the XR Manager to do so.

Edit: Created an issue to track this: https://github.com/playcanvas/engine/issues/2421

1 Like

Thank you for your response. :slight_smile:

Exposing the frame will be useful indeed.

Are you able to write a monkey patch for this or do you need support?

Max has implemented that change :slight_smile: https://github.com/playcanvas/engine/pull/2422