forked from viser-project/viser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdummy_example.py
More file actions
73 lines (58 loc) · 2.19 KB
/
Copy pathdummy_example.py
File metadata and controls
73 lines (58 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import time
from typing import Tuple
import numpy as np
import tyro
from jaxtyping import UInt8
import gsplat_viewer
import viser
def main(port: int = 8080, rendering_latency: float = 0.0):
"""Rendering a dummy scene.
This example is the best starting point to understand the basic API.
You can inject an artificial rendering latency to simulate real-world
scenarios. The higher the latency, the lower the resolution of the rendered
output during camera movement.
Args:
port (int): The port number for the viewer server.
rendering_latency (float): The artificial rendering latency.
"""
def render_fn(
camera_state: gsplat_viewer.CameraState, img_wh: Tuple[int, int]
) -> UInt8[np.ndarray, "H W 3"]:
# Get camera parameters.
W, H = img_wh
c2w = camera_state.c2w
K = camera_state.get_K(img_wh)
# Render a dummy image as a function of camera direction.
camera_dirs = np.einsum(
"ij,hwj->hwi",
np.linalg.inv(K),
np.pad(
np.stack(np.meshgrid(np.arange(W), np.arange(H), indexing="xy"), -1)
+ 0.5,
((0, 0), (0, 0), (0, 1)),
constant_values=1.0,
),
)
dirs = np.einsum("ij,hwj->hwi", c2w[:3, :3], camera_dirs)
dirs /= np.linalg.norm(dirs, axis=-1, keepdims=True)
img = ((dirs + 1.0) / 2.0 * 255.0).astype(np.uint8)
return img
def delayed_render_fn(*args, **kwargs):
# Inject an artificial rendering latency to simulate the real-world
# scenario, e.g., rendering from a NGP model.
time.sleep(rendering_latency)
return render_fn(*args, **kwargs)
# Initialize the viser server and our viewer.
server = viser.ViserServer(port=port, verbose=False)
_ = gsplat_viewer.Viewer(
server=server,
render_fn=delayed_render_fn,
mode="rendering",
)
# Optionally make world axes visible for better visualization in this
# example. You don't need to do this in your own code.
server.scene.world_axes.visible = True
while True:
time.sleep(1.0)
if __name__ == "__main__":
tyro.cli(main)