Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement picking rather than custom maths for mouse collision #1382

Closed
6 tasks done
jacomyal opened this issue Sep 21, 2023 · 2 comments
Closed
6 tasks done

Implement picking rather than custom maths for mouse collision #1382

jacomyal opened this issue Sep 21, 2023 · 2 comments

Comments

@jacomyal
Copy link
Owner

jacomyal commented Sep 21, 2023

Using picking for mouse collision would bring a lot of good things in sigma:

  • Nodes / edges clicking would work for every nodes and edges programs, including curved edges, rectangle nodes...
  • Checking what's below the mouse would be O(1), whatever the size of the graph

The cost would be:

  • It will take some time to implement
  • It will make writing program shaders a bit worse
  • It will have a RAM cost:
    • We need to store an image the size of the container, where pixel colors represent top item index
    • We need to add to every programs the index of the item in addition to the color (but this will cost way less than PR Instanced rendering #1377 will make us win)

Here is one plan to implement this feature:

  • Shaders have macros to be built either for RENDERING_MODE or PICKING_MODE. Rendering mode is as it is today, picking mode will feed every pixel with either transparent or the index of the item (node or edge) to display as the color.
  • Each program takes a new argument, pickingMode. When true, the program will compile the shaders with PICKING_MODE.
  • The rendering loop has a new canvas and WebGL context, not visible on screen, where it draws every edge then every node, using the "picking" programs.
  • Both normal programs and picking programs use the same ByteArrays.
  • The methods getNodeAtPosition and getEdgeAtPosition look at the color of the pixel at the position, translates it to the related item index if any, and returns the related ID.
  • Migrate all programs

Any opinion on that @Yomguithereal?

@jacomyal
Copy link
Owner Author

Oh, and it might allow us to completely remove the quad tree.

@jacomyal
Copy link
Owner Author

jacomyal commented Dec 7, 2023

We just merged a working version of the picking into the v3 branch.

@jacomyal jacomyal closed this as completed Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant