Skip to content

Commit

Permalink
GUI container refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Jul 9, 2023
1 parent 831f743 commit 9029769
Show file tree
Hide file tree
Showing 4,306 changed files with 43,082 additions and 857 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 2 additions & 2 deletions examples/03_gui_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
def main() -> None:
server = viser.ViserServer()

gui_reset_scene = server.add_gui_button("Reset Scene")

with server.gui_folder("Control"):
gui_show = server.add_gui_checkbox("Show Frame", initial_value=True)
gui_axis = server.add_gui_dropdown("Axis", ("x", "y", "z"))
Expand All @@ -35,8 +37,6 @@ def _(_) -> None:
"# Points", min=1000, max=200_000, step=1000, initial_value=10_000
)

gui_reset_scene = server.add_gui_button("Reset Scene")

def draw_frame() -> None:
axis = gui_axis.value
if axis == "x":
Expand Down
140 changes: 70 additions & 70 deletions examples/08_smplx_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,89 +126,89 @@ def make_gui_elements(
) -> GuiElements:
"""Make GUI elements for interacting with the model."""

# GUI elements: mesh settings + visibility.
with server.gui_folder("View"):
gui_rgb = server.add_gui_rgb("Color", initial_value=(90, 200, 255))
tab_group = server.add_gui_tab_group()

@gui_rgb.on_update
def _(_):
out.changed = True
tab_view = tab_group.add_tab("View", viser.Icon.VIEWFINDER)
tab_shape = tab_group.add_tab("Shape", viser.Icon.BOX)
tab_joints = tab_group.add_tab("Joints", viser.Icon.ANGLE)

gui_wireframe = server.add_gui_checkbox("Wireframe", initial_value=False)
# GUI elements: mesh settings + visibility.
gui_rgb = tab_view.add_gui_rgb("Color", initial_value=(90, 200, 255))
gui_wireframe = tab_view.add_gui_checkbox("Wireframe", initial_value=False)
gui_show_controls = tab_view.add_gui_checkbox("Handles", initial_value=False)

@gui_wireframe.on_update
def _(_):
out.changed = True
@gui_rgb.on_update
def _(_):
out.changed = True

gui_show_controls = server.add_gui_checkbox("Handles", initial_value=False)
@gui_wireframe.on_update
def _(_):
out.changed = True

@gui_show_controls.on_update
def _(_):
add_transform_controls(enabled=gui_show_controls.value)
@gui_show_controls.on_update
def _(_):
add_transform_controls(enabled=gui_show_controls.value)

# GUI elements: shape parameters.
with server.gui_folder("Shape"):
gui_reset_shape = server.add_gui_button("Reset Shape")
gui_random_shape = server.add_gui_button("Random Shape")

@gui_reset_shape.on_click
def _(_):
for beta in gui_betas:
beta.value = 0.0
gui_reset_shape = tab_shape.add_gui_button("Reset Shape")
gui_random_shape = tab_shape.add_gui_button("Random Shape")

@gui_reset_shape.on_click
def _(_):
for beta in gui_betas:
beta.value = 0.0

@gui_random_shape.on_click
def _(_):
for beta in gui_betas:
beta.value = onp.random.normal(loc=0.0, scale=1.0)

gui_betas = []
for i in range(num_betas):
beta = tab_shape.add_gui_slider(
f"beta{i}", min=-5.0, max=5.0, step=0.01, initial_value=0.0
)
gui_betas.append(beta)

@gui_random_shape.on_click
@beta.on_update
def _(_):
for beta in gui_betas:
beta.value = onp.random.normal(loc=0.0, scale=1.0)

gui_betas = []
for i in range(num_betas):
beta = server.add_gui_slider(
f"beta{i}", min=-5.0, max=5.0, step=0.01, initial_value=0.0
)
gui_betas.append(beta)

@beta.on_update
def _(_):
out.changed = True
out.changed = True

# GUI elements: joint angles.
with server.gui_folder("Joints"):
# Reset button.
gui_reset_joints = server.add_gui_button("Reset Joints")
gui_random_joints = server.add_gui_button("Random Joints")

@gui_reset_joints.on_click
def _(_):
for joint in gui_joints:
joint.value = (0.0, 0.0, 0.0)
sync_transform_controls()
gui_reset_joints = tab_joints.add_gui_button("Reset Joints")
gui_random_joints = tab_joints.add_gui_button("Random Joints")

@gui_reset_joints.on_click
def _(_):
for joint in gui_joints:
joint.value = (0.0, 0.0, 0.0)
sync_transform_controls()

@gui_random_joints.on_click
def _(_):
for joint in gui_joints:
# It's hard to uniformly sample orientations directly in so(3), so we
# first sample on S^3 and then convert.
quat = onp.random.normal(loc=0.0, scale=1.0, size=(4,))
quat /= onp.linalg.norm(quat)

# xyzw => wxyz => so(3)
joint.value = tf.SO3(wxyz=quat).log()
sync_transform_controls()

gui_joints: List[viser.GuiHandle[Tuple[float, float, float]]] = []
for i in range(num_body_joints + 1):
gui_joint = tab_joints.add_gui_vector3(
label=smplx.joint_names.JOINT_NAMES[i],
initial_value=(0.0, 0.0, 0.0),
step=0.05,
)
gui_joints.append(gui_joint)

@gui_random_joints.on_click
@gui_joint.on_update
def _(_):
for joint in gui_joints:
# It's hard to uniformly sample orientations directly in so(3), so we
# first sample on S^3 and then convert.
quat = onp.random.normal(loc=0.0, scale=1.0, size=(4,))
quat /= onp.linalg.norm(quat)

# xyzw => wxyz => so(3)
joint.value = tf.SO3(wxyz=quat).log()
sync_transform_controls()

gui_joints: List[viser.GuiHandle[Tuple[float, float, float]]] = []
for i in range(num_body_joints + 1):
gui_joint = server.add_gui_vector3(
label=smplx.joint_names.JOINT_NAMES[i],
initial_value=(0.0, 0.0, 0.0),
step=0.05,
)
gui_joints.append(gui_joint)

@gui_joint.on_update
def _(_):
sync_transform_controls()
out.changed = True
sync_transform_controls()
out.changed = True

# Transform control gizmos on joints.
transform_controls: List[viser.TransformControlsHandle] = []
Expand Down
26 changes: 14 additions & 12 deletions viser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from ._message_api import GuiButtonGroupHandle as GuiButtonGroupHandle
from ._message_api import GuiButtonHandle as GuiButtonHandle
from ._message_api import GuiDropdownHandle as GuiDropdownHandle
from ._message_api import GuiHandle as GuiHandle
from ._scene_handle import CameraFrustumHandle as CameraFrustumHandle
from ._scene_handle import FrameHandle as FrameHandle
from ._scene_handle import ImageHandle as ImageHandle
from ._scene_handle import LabelHandle as LabelHandle
from ._scene_handle import MeshHandle as MeshHandle
from ._scene_handle import PointCloudHandle as PointCloudHandle
from ._scene_handle import SceneNodeHandle as SceneNodeHandle
from ._scene_handle import TransformControlsHandle as TransformControlsHandle
from ._gui_api import GuiContainerHandle as GuiContainerHandle
from ._gui_handles import GuiButtonGroupHandle as GuiButtonGroupHandle
from ._gui_handles import GuiButtonHandle as GuiButtonHandle
from ._gui_handles import GuiDropdownHandle as GuiDropdownHandle
from ._gui_handles import GuiHandle as GuiHandle
from ._icons_enum import Icon as Icon
from ._scene_handles import CameraFrustumHandle as CameraFrustumHandle
from ._scene_handles import FrameHandle as FrameHandle
from ._scene_handles import ImageHandle as ImageHandle
from ._scene_handles import LabelHandle as LabelHandle
from ._scene_handles import MeshHandle as MeshHandle
from ._scene_handles import PointCloudHandle as PointCloudHandle
from ._scene_handles import SceneNodeHandle as SceneNodeHandle
from ._scene_handles import TransformControlsHandle as TransformControlsHandle
from ._viser import CameraHandle as CameraHandle
from ._viser import ClientHandle as ClientHandle
from ._viser import ViserServer as ViserServer
Loading

0 comments on commit 9029769

Please sign in to comment.