Performance lag on enabling quest controllers with pointer

import {
  Nullable,
  Scene,
  Vector3,
  WebXRControllerPointerSelection,
  WebXRDefaultExperience,
  WebXRExperienceHelper,
  WebXRFeatureName,
  WebXRInput,
} from '@babylonjs/core';

let xrHelper: WebXRExperienceHelper;

let xr: WebXRDefaultExperience;

const attachControllers = (xrHelper: WebXRExperienceHelper) => {
  const controllers = new WebXRInput(xrHelper.sessionManager, xrHelper.camera);
  const xrayPointer = new WebXRControllerPointerSelection(
    xrHelper.sessionManager,
    {
      disablePointerUpOnTouchOut: false,
      disableScenePointerVectorUpdate: false,
      forceGazeMode: false,
      xrInput: controllers,
    }
  );
  xrayPointer.displayLaserPointer = true;
  xrayPointer.attach();
  return controllers;
};

export const enterXR = async (scene: Nullable<Scene>) => {
  if (scene !== null) {
    xrHelper = await WebXRExperienceHelper.CreateAsync(scene);
    attachControllers(xrHelper);
    await xrHelper.enterXRAsync('immersive-vr', 'local-floor', undefined, {});
  }
};

export const exitXR = async (scene: Nullable<Scene>) => {
  if (scene !== null && xrHelper !== undefined) {
    await xrHelper.exitXRAsync();
  }
};

using the above code to enter xr and enable controllers, but as soon as i enable controllers that is call the ‘attachControllers(xrHelper);’ function my fps drops to 20, other wise they are between 40 to 50.

attaching the profiling image and profile data

Profile-20220818T132955.zip (465.5 KB)

cc @RaananW

I assume you have a large scene with complex meshes. This happens because the pointer-move event is triggered on every frame, and it checks the mesh under the pointer so you can interact with the scene. Is that the case here?

You can set complex meshes to be not-pickable (mesh.isPickable = false and mesh.isNearPickable = false) and see if it helps the performance

1 Like

Thanks @RaananW It really improved the performance, yes we do have a complex mesh with around 100K vertices and 50K faces. though its just a single mesh.

1 Like