question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SelectionBox: Add support for pixel-perfect selection.

See original GitHub issue

P.S. it is not question, it is feature request for frustum.intersectsGeometry(mesh.geometry)

I mean not bounding box and bounding sphere, but exactly pixel perfect, I mean.

Maybe shader or special renderer? Give different colors to different meshes, and by rendered colors detect what objects were selected?

After three days of googling, I haven’t found a single answer on the Internet.

For example, this Box should not be selected:

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

10reactions
gkjohnsoncommented, Apr 21, 2021

In terms of alternatives in other projects something similar (lasso selection of individual triangles) was requested a bit ago in three-mesh-bvh and I’ve created an example for it here. It uses the bounds tree to accelerate selection but you can disable it to see the difference in performance (ms displayed in bottom left). The core the approach involves projecting the triangles to screen space and performing the line-crossing algorithm to determine triangle intersection so you don’t need an acceleration structure to implement it. If you’re limiting selection to a box you can use the projected frustum shape and check every triangle, instead, which might be a bit faster / simpler.

Anyway it might be at least a start for someone looking to implement this in a project. Other relevant discussions in three-mesh-bvh issues 109 and 166.

image

4reactions
gkjohnsoncommented, Oct 19, 2020

Maybe we can paint objects in the scene in different colors, and render the scene, and then use the pixel colors to understand what colors are visible? And so we exploit the parallel nature of the graphics card? Its like raycasting, but by every selection pixel.

This would make selection asynchronous which might not be desirable. Copying render target data from the GPU to to the CPU can also be a slow operation and will scale based on canvas size / pixel density. GPU picking for raycasting is a bit more consistent because you only need to render / copy a single pixel.

How does Blender do it? If I select many objects, he clearly understands what I have selected. Do you have any ideas about their algorithm?

Blender may have extra underlying acceleration data structures to facilitate performant interactions like this that three.js doesn’t provide out of the box. With simple geometry performance may not be all that bad though. For all the meshes you want to check selection for you could perform a triangle / selectionbox frustum intersection for every triangle in the mesh to see if it is selected. If the bounding box / sphere of a mesh is completely contained in the frustum you could skip the triangle check and just mark it as selected. Supporting all the corner cases of instanced, skinned, etc meshes may get complicated, though.

If performance turns out to be an issue you could only run the selection check when the user releases the mouse rather than on every frame. For particularly complex meshes you could use some kind of spatially indexed data structure like a quad tree or bvh which there are some libraries for.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to use the Raycaster with a selection box?
Pixel-perfect selection support for SelectionBox was discussed GitHub some time ago. The conclusion was to not add support to it considering the related ......
Read more >
Pixel Perfect Selections in Affinity Photo - YouTube
Enroll in the course here: https://affinity.sale/ pixelperfect * ... This course is designed to help you become a selection master.
Read more >
Tweak selection bounding box - PDFTron Community
I'm building a tool which relies on the user selecting text, and having that text extracted and piped into other features. Some PDFs...
Read more >
Selecting 3D surfaces with a selection box (in two different ways)
You set up the selection rectangle as the scissor rectangle, and render all ... buffer) and add any new selected object to selected...
Read more >
Intermediate Tutorial 4 - Ogre Wiki - Ogre3D
This is so it doesn't get covered up by the objects we are trying to select. Add the following to the body of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found