Performance hit with scene pick and mousemove

Hi everyone!

I have a short question about how Babylon handles pointermove and scene picking / raycast. Take a look at the image below:

It seems that there is some background logic going on, since when I keep wiggling my mouse I can lower my performance quite a lot. I do have a lot of meshes in my scene, but I also do set them as not pickable in the scene when they are further away from the camera/player.

So what is the deal here? This can be produced easily when going into any playground, for example: https://playground.babylonjs.com/#S7E00P#52
and using the chrome performance tool… Can someone clarify why the mousemove is being processed continuously and with the scene.pick?

1 Like

This is done by the system to see if some meshes are pickable and need to trigger their actions (onPointerMove).

This is the predicate used to select if a mesh needs an action:
Babylon.js/scene.inputManager.ts at master · BabylonJS/Babylon.js (github.com)

So if you have a lot of meshes in your scene the system will go through all of them on every pointer move.

I will introduce an option on the scene to skip that feature entirely if you do not need it

4 Likes

Address perf issue with picking on move by deltakosh · Pull Request #11556 · BabylonJS/Babylon.js (github.com)

You will be able to set scene.skipPointerMovePicking = true to skip all that phase

6 Likes

Wow that was fast! Thank you Deltakosh! :heart_eyes::pray:

Just a clarification, will I be able to use DeviceSourceManager normally? How about if I manually add an ActionManager to the mesh, will I be able to add, for example, ActionManager.OnPointerOverTrigger ExecuteCodeActions if I have scene.skipPointerMovePicking = true?

Nope cause in this case you will need to run the pointer move function

1 Like

For the action manager you mean? Or for also DeviceSourceManager?

For the actionManager, the rest should be fine as it is done before.

1 Like

Nice nice :sunglasses:

1 Like

Hello!

I decided not to create a new topic on the forum. I’m sorry if this is wrong. I can’t access the scene.skipPointerMovePicking property.

I use TypeScript + ESLint.

"@babylonjs/core": "^4.2.0",
import {
  Scene, Engine,
  SceneLoader, CubeTexture, Matrix,
  Tools, SceneOptimizerOptions,
  SceneOptimizer, DirectionalLight,
  RenderTargetTexture, ShadowGenerator
} from '@babylonjs/core'
this.scene = new Scene(engine)
this.scene.skipPointerMovePicking = true

TS2339: Property ‘skipPointerMovePicking’ does not exist on type ‘Scene’.

Other properties and methods work fine.

Is there a workaround? I will be glad of any help.

this method would be on the beta 5.0 not 4.2

3 Likes