-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Click callbacks for scene node handles (#46)
* initial work on adding click callbacks * WIP outline on hover * Improve performance * Aesthetic cleanup * Fix bug, add clicks for add_mesh_trimesh * WIP example * Automate `.clickable`, nits * Example nits * Fix mypy error, add matplotlib * Docs sync * Cleanup * Dependencies tweak * Remove foobar * Fix clicking for frustums, update examples * More specific handle types * Docs * Run ruff * Docs nit --------- Co-authored-by: Chung Min Kim <[email protected]>
- Loading branch information
1 parent
f84db3a
commit 35011ea
Showing
35 changed files
with
1,104 additions
and
615 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
img.sidebar-logo { | ||
width: 3em; | ||
margin: 1em 0 0 0; | ||
width: 3em; | ||
margin: 1em 0 0 0; | ||
} | ||
.sidebar-brand-text { | ||
display: none; | ||
display: none; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
.. Comment: this file is automatically generated by `update_example_docs.py`. | ||
It should not be modified manually. | ||
Click callback demonstration. | ||
========================================== | ||
|
||
|
||
Click on meshes to select them. The index of the last clicked mesh is displayed in the GUI. | ||
|
||
|
||
|
||
.. code-block:: python | ||
:linenos: | ||
import time | ||
import matplotlib | ||
import numpy as onp | ||
import trimesh.creation | ||
import viser | ||
def main() -> None: | ||
grid_shape = (4, 5) | ||
server = viser.ViserServer() | ||
with server.gui_folder("Last clicked"): | ||
x_value = server.add_gui_number( | ||
name="x", | ||
initial_value=0, | ||
disabled=True, | ||
hint="x coordinate of the last clicked mesh", | ||
) | ||
y_value = server.add_gui_number( | ||
name="y", | ||
initial_value=0, | ||
disabled=True, | ||
hint="y coordinate of the last clicked mesh", | ||
) | ||
def add_swappable_mesh(i: int, j: int) -> None: | ||
"""Simple callback that swaps between: | ||
- a gray box | ||
- a colored box | ||
- a colored sphere | ||
Color is chosen based on the position (i, j) of the mesh in the grid. | ||
""" | ||
colormap = matplotlib.colormaps["tab20"] | ||
def create_mesh(counter: int) -> None: | ||
if counter == 0: | ||
mesh = trimesh.creation.box((0.5, 0.5, 0.5)) | ||
elif counter == 1: | ||
mesh = trimesh.creation.box((0.5, 0.5, 0.5)) | ||
else: | ||
mesh = trimesh.creation.icosphere(subdivisions=2, radius=0.4) | ||
colors = colormap( | ||
(i * grid_shape[1] + j + onp.random.rand(mesh.vertices.shape[0])) | ||
/ (grid_shape[0] * grid_shape[1]) | ||
) | ||
if counter != 0: | ||
assert mesh.visual is not None | ||
mesh.visual.vertex_colors = colors | ||
handle = server.add_mesh_trimesh( | ||
name=f"/sphere_{i}_{j}", | ||
mesh=mesh, | ||
position=(i, j, 0.0), | ||
) | ||
@handle.on_click | ||
def _(_) -> None: | ||
x_value.value = i | ||
y_value.value = j | ||
# The new mesh will replace the old one because the names (/sphere_{i}_{j}) are | ||
# the same. | ||
create_mesh((counter + 1) % 3) | ||
create_mesh(0) | ||
for i in range(grid_shape[0]): | ||
for j in range(grid_shape[1]): | ||
add_swappable_mesh(i, j) | ||
while True: | ||
time.sleep(10.0) | ||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Infrastructure | ||
# Communication | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.