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

Refactor scene pointer events + support rectangular selection #157

Merged
merged 47 commits into from
Mar 23, 2024

Conversation

chungmin99
Copy link
Collaborator

Currently, ScenePointerMessage supports only "click" events (single-click).

Here, we add support for mouse drag, by sending a list of ray origins/directions.

Similar to how a person may wave around their pointer finger!

Not sure what is more useful; a scribble, a lasso (similar to https://discourse.threejs.org/t/how-to-make-3d-lasso-tool/23207/2), or a box-style drag selection. Open to suggestions!

It would be trivial to add a similar logic for SceneNodeClickMessage (perhaps to move/push objects around).

Screen.Recording.2024-01-04.at.12.01.49.PM.mov

@simonbethke
Copy link
Contributor

As you asked if lasso- or box-style selections would be better, I think that depends much on the case where to use it. My experience is mostly grounded in photoshop that features all kind of selections. I personally never use the lasso-selection. Instead I use polygon selections as they only require precise clicks, but not a precise mouse-path.
What makes selections in photoshop especially powerful is, that by holding CTRL with a selection already existing, I can create a second selection that then is added to the existing one. With CTRL+Shift, the new selection is subtracted from the existing one.

However, in 3D-Space I assume that requirements differ in several ways: viewport-camera-projection should not affect the selection too much. Thus I think box-style selections can only help with selecting entire objects. For areas of objects the box doesn't make sense as long as the viewport doesn't feature an axis-aligned orthographic projection (as for example fusion 360 does).

With nerfstudio I usually have gsplats in mind. This makes selections tricky, as they preferably should not select hazey clouds in front of the objects. If I should come up with the best and sophisticated single selection tool it would work like this:

The selection would be created with a brush. By holding down a key, the brush becomes an eraser. The brush shape in space is a perfect sphere. To make a selection I have to enable selection mode and with that enabled, the sphere is always drawn as transparent sphere at the position of my mouse-cursor. Next to the button to enable the selection I have a slider that allows to control the size of the selection sphere. For better usability there might be a way to adjust the size with the mouse-wheel too.
However, the tricky part is the Z-position: For that a depthmap should be used. With gsplats, I would suggest to create a depthmap based on density 3D-space. The density-threshold should also be controllable in the UI with some kind of slider. If possible when adjusting the density threshold, it should be possible (by holding a key) to visualize it in the viewport. I am not sure if users additionally require a configurable Z-offset.

@chungmin99
Copy link
Collaborator Author

I think it might be good to first support box-selects for now, to get us started. This is probably enough to get us started on selecting gaussians (hopefully)!

This is the current version of the box-select; all the mesh vertices are projected onto the viewport camera's image plane, and the vertex colors are changed to red if they lie inside the 2D selection box.

Screen.Recording.2024-02-07.at.8.59.05.PM.mov

However, the tricky part is the Z-position: For that a depthmap should be used.

This is probably something to deal with in the python / nerfstudio end, but we could potentially make a heuristic for this using the discrepancy in the gaussian position and the rendered depth.

There is definitely a strong use case for polygon select / multi-click selects, and brush-selects, like you mentioned. The code should make this easy to do in the future, since now the code returns a list of 2D screen positions (for the box).

@chungmin99 chungmin99 marked this pull request as ready for review February 23, 2024 20:26
@chungmin99 chungmin99 requested a review from brentyi February 23, 2024 20:27
@chungmin99
Copy link
Collaborator Author

chungmin99 commented Feb 23, 2024

Actually, the drag-box visual feedback is currently buggy when the sidebar is set to "collapsible" or "fixed"...
-> Fixed in the following commit

@chungmin99
Copy link
Collaborator Author

chungmin99 commented Mar 15, 2024

  • Move origin to top-left corner
  • Check if the origin is in the center of pixel, or the corner of pixel (and document it).

Copy link
Collaborator

@brentyi brentyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some minor changes but looks good to me overall!!

@chungmin99 two questions:

  • Are we sure about naming the rectangular select event box? Is this descriptive enough?
  • Is the behavior when we attach two scene pointer events well-defined? When I clicked "Paint mesh" and then "Add sphere" consecutively it seemed like there was some unexpected behavior, like the cursor changing back to the standard pointer after I did a rectangular select even though it was still waiting for a click.

@chungmin99
Copy link
Collaborator Author

Ok!

  • let's rename box to rect-select.
  • Let's change to tracking only one scenepointer event at a time! If there is a new scenepointer event to be tracked, the one previously created should be removed / cleaned up.

@chungmin99
Copy link
Collaborator Author

Example of the single-scenepointerevent listening:

Screencast.from.03-22-2024.11.49.42.AM.webm

@brentyi brentyi changed the title Support dragging motion for ScenePointerEvents Refactor scene pointer events + support rectangular selection Mar 23, 2024
@brentyi brentyi enabled auto-merge (squash) March 23, 2024 01:51
@brentyi brentyi merged commit e532d67 into main Mar 23, 2024
12 checks passed
@brentyi brentyi deleted the cmk/scribble branch March 23, 2024 02:19
yzslab pushed a commit to yzslab/viser that referenced this pull request Oct 20, 2024
…udio-project#157)

* Initial commit for 3D scribble, WIP

* Add Viewer2DCanvas, use that to draw cursor feedback!

* Remove scribble support, smoothen out box select, add example

* Correctly update canvas size on resize

* Refactor ScenePointerMessage, send 2D coordinates for box

* Update example, walk through OpenCV/NDC coordinates

* Rename SceneClickEnableMessage->ScenePointerEnableMessage

* ruff, mypy

* Put camera in a reasonable initial location

* Add event type to on_scene_pointer

* Rename example file from scene_click->scene_pointer

* mypy, ruff

* Add backwards compatibility

* ruff, mypy

* ruff, mypy

* Rename click->pointer

* Use resizeobserver for element size tracking

* Use OpenCV image coords (normalized)

* mypy

* Remove irrelevant file

* mypy

* ruff, pyright

* mypy

* Nits

* Try to fix mypy

* Rename box to rect-select

* Listen to only one scenepointerevent at a given time.

* mypy, ruff

* ruff

* Track events for clients!

* Clear pre-existing callbacks for both server/clients, include warnings.

* ruff

* Code nit

* Nits

* oops

* Move pointer cleanup logic

---------

Co-authored-by: Brent Yi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants