Add gpu picking as picking option at scene level

We’ve only known ray picking since there was babylonJS. And a lot of work was put in to ensure it was usuable (still recall the days where the perf tanked while trying to pick triangles on the skull, heh).

Now that gpu picking is here, I’d like to add gpu picking as a pick option, implemented at scene level. Observables, action managers etc should all benefit from it. Off the top of my head, I think pointerConfiguration, inputManager etc will need rework, scene.pick() becomes await scene.gpu_pick(), _pickMove() becomes async _gpu_pickMove() blah blah blah. You get the point.

Pseudocode

scene.useGPUPicking = true;    // turns off ray picking
scene.setGPUPIckingList();    // defaults to all pickable meshes in scene

// crappy napkin idea for interfacing
BABYLON.Scene.prototype.setGPUPIckingList = function(arr){
    if (this.useGPUPicking){
        this.gpu_picker = new BABYLON.GPUPicker();
        const list = arr? arr:this.meshes.filter(mesh=>mesh.isPickable);
        this.gpu_picker.setPickingList(list);
    } else {
        // warn user
    }
}

The larger problem here is that all ray pick codes were not async. Which means there is a need to async some of the major functions (attachControl, processPointerMove/Pick/Up etc). Do we want to do this now? Can we do this now? Will it break back-compat anywhere?

If we want to do it we must do it in a way that protect backward compat :frowning:

I don’t want to bloat the repo if there’s no interest, its not terribly difficult to extend the scene class and integrate the gpu picker in userland. Suggest to kiv, thanks.

1 Like

Quick test: Babylon.js Playground

Seems like a fair bit of work is needed for a full integration, but I love the perf! :heart: Its really smooth even for pointermove!

2 Likes

Yeah I agree it is a bit heavy on the changes :slight_smile: