Get renders¶
Example for getting renders from a client’s viewport to the Python API.
1import time
2
3import imageio.v3 as iio
4import numpy as np
5
6import viser
7
8
9def main():
10 server = viser.ViserServer()
11
12 button = server.gui.add_button("Render a GIF")
13
14 @button.on_click
15 def _(event: viser.GuiEvent) -> None:
16 client = event.client
17 assert client is not None
18
19 client.scene.reset()
20
21 images = []
22
23 for i in range(20):
24 positions = np.random.normal(size=(30, 3))
25 client.scene.add_spline_catmull_rom(
26 f"/catmull_{i}",
27 positions,
28 tension=0.5,
29 line_width=3.0,
30 color=np.random.uniform(size=3),
31 )
32 images.append(client.get_render(height=720, width=1280))
33 print("Got image with shape", images[-1].shape)
34
35 print("Generating and sending GIF...")
36 client.send_file_download(
37 "image.gif", iio.imwrite("<bytes>", images, extension=".gif", loop=0)
38 )
39 print("Done!")
40
41 while True:
42 time.sleep(10.0)
43
44
45if __name__ == "__main__":
46 main()