Skip to content

Commit

Permalink
Merge branch 'main' of github.com:brentyi/viser into brent/splatting
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Jun 6, 2024
2 parents 7cea4ee + 4b4e354 commit 80d6c45
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 136 deletions.
81 changes: 21 additions & 60 deletions docs/source/examples/09_urdf_visualizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,34 @@ and viser. It can also take a path to a local URDF file as input.
from __future__ import annotations
import time
from pathlib import Path
import numpy as onp
import tyro
import viser
from robot_descriptions.loaders.yourdfpy import load_robot_description
from viser.extras import ViserUrdf
# A subset of robots available in the robot_descriptions package.
ROBOT_MODEL_LIST = (
"panda_description",
"ur10_description",
"ur3_description",
"ur5_description",
"cassie_description",
"skydio_x2_description",
"allegro_hand_description",
"barrett_hand_description",
"robotiq_2f85_description",
"atlas_drc_description",
"atlas_v4_description",
"draco3_description",
"g1_description",
"h1_description",
"anymal_c_description",
"go2_description",
"mini_cheetah_description",
)
def main() -> None:
# Start viser server.
Expand Down Expand Up @@ -97,64 +117,5 @@ and viser. It can also take a path to a local URDF file as input.
time.sleep(10.0)
ROBOT_MODEL_LIST = (
"edo_description",
"fanuc_m710ic_description",
"gen2_description",
"gen3_description",
"iiwa14_description",
"iiwa7_description",
"panda_description",
"poppy_ergo_jr_description",
"ur10_description",
"ur3_description",
"ur5_description",
"z1_description",
"bolt_description",
"cassie_description",
"rhea_description",
"spryped_description",
"upkie_description",
"baxter_description",
"nextage_description",
"poppy_torso_description",
"yumi_description",
"cf2_description",
"skydio_x2_description",
"double_pendulum_description",
"finger_edu_description",
"simple_humanoid_description",
"trifinger_edu_description",
"allegro_hand_description",
"barrett_hand_description",
"robotiq_2f85_description",
"atlas_drc_description",
"atlas_v4_description",
"draco3_description",
"ergocub_description",
"g1_description",
"h1_description",
"icub_description",
"jaxon_description",
"jvrc_description",
"r2_description",
"romeo_description",
"sigmaban_description",
"talos_description",
"valkyrie_description",
"a1_description",
"aliengo_description",
"anymal_b_description",
"anymal_c_description",
"b1_description",
"go1_description",
"go2_description",
"hyq_description",
"laikago_description",
"mini_cheetah_description",
"minitaur_description",
"solo_description",
)
if __name__ == "__main__":
tyro.cli(main)
81 changes: 21 additions & 60 deletions examples/09_urdf_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,34 @@
from __future__ import annotations

import time
from pathlib import Path

import numpy as onp
import tyro
import viser
from robot_descriptions.loaders.yourdfpy import load_robot_description
from viser.extras import ViserUrdf

# A subset of robots available in the robot_descriptions package.
ROBOT_MODEL_LIST = (
"panda_description",
"ur10_description",
"ur3_description",
"ur5_description",
"cassie_description",
"skydio_x2_description",
"allegro_hand_description",
"barrett_hand_description",
"robotiq_2f85_description",
"atlas_drc_description",
"atlas_v4_description",
"draco3_description",
"g1_description",
"h1_description",
"anymal_c_description",
"go2_description",
"mini_cheetah_description",
)


def main() -> None:
# Start viser server.
Expand Down Expand Up @@ -85,64 +105,5 @@ def _(_):
time.sleep(10.0)


ROBOT_MODEL_LIST = (
"edo_description",
"fanuc_m710ic_description",
"gen2_description",
"gen3_description",
"iiwa14_description",
"iiwa7_description",
"panda_description",
"poppy_ergo_jr_description",
"ur10_description",
"ur3_description",
"ur5_description",
"z1_description",
"bolt_description",
"cassie_description",
"rhea_description",
"spryped_description",
"upkie_description",
"baxter_description",
"nextage_description",
"poppy_torso_description",
"yumi_description",
"cf2_description",
"skydio_x2_description",
"double_pendulum_description",
"finger_edu_description",
"simple_humanoid_description",
"trifinger_edu_description",
"allegro_hand_description",
"barrett_hand_description",
"robotiq_2f85_description",
"atlas_drc_description",
"atlas_v4_description",
"draco3_description",
"ergocub_description",
"g1_description",
"h1_description",
"icub_description",
"jaxon_description",
"jvrc_description",
"r2_description",
"romeo_description",
"sigmaban_description",
"talos_description",
"valkyrie_description",
"a1_description",
"aliengo_description",
"anymal_b_description",
"anymal_c_description",
"b1_description",
"go1_description",
"go2_description",
"hyq_description",
"laikago_description",
"mini_cheetah_description",
"minitaur_description",
"solo_description",
)

if __name__ == "__main__":
tyro.cli(main)
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "viser"
version = "0.1.31"
version = "0.2.0"
description = "3D visualization + Python"
readme = "README.md"
license = { text="MIT" }
Expand Down Expand Up @@ -40,7 +40,7 @@ dependencies = [
[project.optional-dependencies]
dev = [
"pyright>=1.1.308",
"ruff==0.4.3",
"ruff==0.4.6",
"pre-commit==3.3.2",
]
examples = [
Expand Down
8 changes: 6 additions & 2 deletions src/viser/_client_autobuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ def ensure_client_is_built() -> None:
elif not (build_dir / "index.html").exists():
rich.print("[bold](viser)[/bold] No client build found. Building now...")
build = True
elif _modified_time_recursive(client_dir / "src") > _modified_time_recursive(
build_dir
elif (
# We should be at least 10 seconds newer than the last build.
# This buffer is important when we install from pip, and the src/ +
# build/ directories have very similar timestamps.
_modified_time_recursive(client_dir / "src")
> _modified_time_recursive(build_dir) + 10.0
):
rich.print(
"[bold](viser)[/bold] Client build looks out of date. Building now..."
Expand Down
23 changes: 18 additions & 5 deletions src/viser/_gui_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import time
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from typing import TYPE_CHECKING, Any, Sequence, TypeVar, Union, overload
from typing import TYPE_CHECKING, Any, Sequence, Tuple, TypeVar, Union, cast, overload

import numpy as onp
from typing_extensions import (
Literal,
LiteralString,
TypeAlias,
TypedDict,
get_args,
get_origin,
Expand Down Expand Up @@ -57,6 +58,17 @@
TString = TypeVar("TString", bound=str)
TLiteralString = TypeVar("TLiteralString", bound=LiteralString)
T = TypeVar("T")
LengthTenStrTuple: TypeAlias = Tuple[str, str, str, str, str, str, str, str, str, str]


def _hex_from_hls(h: float, l: float, s: float) -> str:
"""Converts HLS values in [0.0, 1.0] to a hex-formatted string, eg 0xffffff."""
return "#" + "".join(
[
int(min(255, max(0, channel * 255.0)) + 0.5).to_bytes(1, "little").hex()
for channel in colorsys.hls_to_rgb(h, l, s)
]
)


def _compute_step(x: float | None) -> float: # type: ignore
Expand Down Expand Up @@ -382,9 +394,7 @@ def configure_theme(
brand_color: An optional tuple of integers (RGB) representing the brand color.
"""

colors_cast: tuple[
str, str, str, str, str, str, str, str, str, str
] | None = None
colors_cast: LengthTenStrTuple | None = None

if brand_color is not None:
assert len(brand_color) in (3, 10)
Expand Down Expand Up @@ -413,7 +423,10 @@ def configure_theme(
fp=onp.array([max_l, l, min_l]),
)
)
colors_cast = tuple(_hex_from_hls(h, ls[i], s) for i in range(10)) # type: ignore
colors_cast = cast(
LengthTenStrTuple,
tuple(_hex_from_hls(h, ls[i], s) for i in range(10)),
)

assert colors_cast is None or all(
[isinstance(val, str) and val.startswith("#") for val in colors_cast]
Expand Down
4 changes: 2 additions & 2 deletions src/viser/_viser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class _BackwardsCompatibilityShim:

def __getattr__(self, name: str) -> Any:
fixed_name = {
# Map from old method names (viser v0.1.30) to new methods names.
# Map from old method names (viser v0.1.*) to new methods names.
"reset_scene": "reset",
"set_global_scene_node_visibility": "set_global_visibility",
"on_scene_pointer": "on_pointer_event",
Expand All @@ -41,7 +41,7 @@ def __getattr__(self, name: str) -> Any:
}.get(name, name)
if hasattr(self.scene, fixed_name):
warnings.warn(
f"{type(self).__name__}.{name} has been deprecated, use {type(self).__name__}.scene.{fixed_name} instead. Alternatively, pin to `viser<=0.1.30`.",
f"{type(self).__name__}.{name} has been deprecated, use {type(self).__name__}.scene.{fixed_name} instead. Alternatively, pin to `viser<0.2.0`.",
stacklevel=2,
)
return object.__getattribute__(self.scene, fixed_name)
Expand Down
2 changes: 1 addition & 1 deletion src/viser/client/src/ControlPanel/Generated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function GeneratedGuiContainer({
const updateGuiProps = viewer.useGui((state) => state.updateGuiProps);
const messageSender = makeThrottledMessageSender(viewer.websocketRef, 50);

function setValue(id: string, value: any) {
function setValue(id: string, value: NonNullable<unknown>) {
updateGuiProps(id, { value: value });
messageSender({
type: "GuiUpdateMessage",
Expand Down
2 changes: 1 addition & 1 deletion src/viser/client/src/ControlPanel/GuiComponentContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Messages from "../WebsocketMessages";

interface GuiComponentContext {
folderDepth: number;
setValue: (id: string, value: any) => void;
setValue: (id: string, value: NonNullable<unknown>) => void;
messageSender: (message: Messages.Message) => void;
GuiContainer: React.FC<{ containerId: string }>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/viser/client/src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function DropdownComponent({
radius="xs"
value={value}
data={options}
onChange={(value) => setValue(id, value)}
onChange={(value) => value !== null && setValue(id, value)}
disabled={disabled}
searchable
maxDropdownHeight={400}
Expand Down
5 changes: 3 additions & 2 deletions src/viser/extras/_urdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

from functools import partial
from pathlib import Path
from typing import Dict, List, Tuple
from typing import List, Tuple

import numpy as onp
import trimesh
import viser
import yourdfpy

import viser

from .. import transforms as tf


Expand Down

0 comments on commit 80d6c45

Please sign in to comment.