GPU multi picking

A function called multiPickAsync has been added. It’s similar to the pickAsync function but accepts an array of IVector2Like coordinates as an input not just a single one.

DOCS:
https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/picking_collisions#gpu-picking

10 Likes

You rock @roland

1 Like

Can’t agree more :slight_smile:

2 Likes

@sebavan @Deltakosh you guys flatter me too much…

Don’t stop :joy::joy::joy::joy:

2 Likes

Since there are multi picking by point list, will there be picking by rect region?

Do you want to pick all meshes in a given region? If so, GPU picking is not the right tool to use. You can use bounds checking to get all meshes in the selected region. For example you can create a box (width: regionWidth, height: regionHeight, deprh: cameraMaxZ - cameraMinZ) a use the intersects function. Or I think you could use mesh.isInFrustum(planes) where you limit the frustum with planes positioned at the boundaries of the region.

2 Likes

Hmm, but bbox-based frustum checking is not as accurate as gpu picking, many meshes are not in a cube shape and there are many cases that mesh having a bounding box in rect with no triangle in it.

You’re right.

I just woke up and a solution has popped out of my mind. It seems that my brain is more rested because I could think of it right away :slight_smile:

Basically you can ask for a multiPick with two coordinates. Left upper corner and right bottom corner - a region. All you have do then is read the gpuPicker._readBuffer’s data. It’s an Uint8Array with Color4 data. Each color represents a meshId - index + 1 in the pickingList.

Move the meshes into the magenta region.

The example reads only one color byte, so you’re limited to 255 meshes.

@Deltakosh maybe we could expose the _readBuffer or it would be more elegant to make the private _getColorIdFromReadBuffer(offset: number):IColor3Like function public.

EDIT:
Drag to create region and pick meshes in the region. Picks only visible meshes but can be easily updated to pick ocluded meshes as well.

The same but also picks the meshes onmousemove:

Code is not optimized yet.

2 Likes

That’s pretty awesome!

1 Like

Man! this is excellent! please add it to the code!

1 Like

Sir, yes sir! :saluting_face: I’ll create a PR.

1 Like