MeshesΒΆ

Visualize a mesh. To get the demo data, see ./assets/download_dragon_mesh.sh.

 1import time
 2from pathlib import Path
 3
 4import numpy as np
 5import trimesh
 6
 7import viser
 8import viser.transforms as tf
 9
10mesh = trimesh.load_mesh(str(Path(__file__).parent / "assets/dragon.obj"))
11assert isinstance(mesh, trimesh.Trimesh)
12mesh.apply_scale(0.05)
13
14vertices = mesh.vertices
15faces = mesh.faces
16print(f"Loaded mesh with {vertices.shape} vertices, {faces.shape} faces")
17
18server = viser.ViserServer()
19server.scene.add_mesh_simple(
20    name="/simple",
21    vertices=vertices,
22    faces=faces,
23    wxyz=tf.SO3.from_x_radians(np.pi / 2).wxyz,
24    position=(0.0, 0.0, 0.0),
25)
26server.scene.add_mesh_trimesh(
27    name="/trimesh",
28    mesh=mesh.smoothed(),
29    wxyz=tf.SO3.from_x_radians(np.pi / 2).wxyz,
30    position=(0.0, 5.0, 0.0),
31)
32
33while True:
34    time.sleep(10.0)