Images

Display background images and 3D image textures in the scene.

Display background images and 3D image textures positioned in world space.

Features:

Note

This example requires external assets. To download them, run:

cd /path/to/viser/examples/assets
./download_assets.sh

Source: examples/01_scene/04_images.py

Images

Code

 1import time
 2from pathlib import Path
 3
 4import imageio.v3 as iio
 5import numpy as np
 6import viser
 7
 8
 9def main() -> None:
10    server = viser.ViserServer()
11
12    # Add a background image.
13    server.scene.set_background_image(
14        iio.imread(Path(__file__).parent / "../assets/Cal_logo.png"),
15        format="png",
16    )
17
18    # Add main image.
19    server.scene.add_image(
20        "/img",
21        iio.imread(Path(__file__).parent / "../assets/Cal_logo.png"),
22        4.0,
23        4.0,
24        format="png",
25        wxyz=(1.0, 0.0, 0.0, 0.0),
26        position=(2.0, 2.0, 0.0),
27    )
28    while True:
29        server.scene.add_image(
30            "/noise",
31            np.random.randint(0, 256, size=(400, 400, 3), dtype=np.uint8),
32            4.0,
33            4.0,
34            format="jpeg",
35            wxyz=(1.0, 0.0, 0.0, 0.0),
36            position=(2.0, 2.0, -1e-2),
37        )
38        time.sleep(0.2)
39
40
41if __name__ == "__main__":
42    main()