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