Depth compositingΒΆ

In this example, we show how to use a background image with depth compositing. This can be useful when we want a 2D image to occlude 3D geometry, such as for NeRF rendering.

 1import time
 2
 3import numpy as np
 4import trimesh
 5import trimesh.creation
 6
 7import viser
 8
 9server = viser.ViserServer()
10
11
12img = np.random.randint(0, 255, size=(1000, 1000, 3), dtype=np.uint8)
13depth = np.ones((1000, 1000, 1), dtype=np.float32)
14
15# Make a square middle portal.
16depth[250:750, 250:750, :] = 10.0
17img[250:750, 250:750, :] = 255
18
19mesh = trimesh.creation.box((0.5, 0.5, 0.5))
20server.scene.add_mesh_trimesh(
21    name="/cube",
22    mesh=mesh,
23    position=(0, 0, 0.0),
24)
25server.scene.set_background_image(img, depth=depth)
26
27
28while True:
29    time.sleep(1.0)