clicking on cameras in the viewer

This commit is contained in:
Justin committed 2023-06-16 06:05:38 +00:00
1 parent 9db97773b9
commit efd18266f7
1 file changed
+14 -7
+14 -7
View File
@@ -95,8 +95,7 @@ class Viewer:
self.train_btn_state: Literal["training", "paused", "completed"] = "training"
self._prev_train_state: Literal["training", "paused", "completed"] = "training"
self.camera_message = None
self.client = None
self.viser_server = viser.ViserServer(host=config.websocket_host, port=websocket_port)
self.viser_server.on_client_connect(self.handle_new_client)
@@ -114,14 +113,16 @@ class Viewer:
self.render_statemachine.start()
def handle_new_client(self, client: viser.ClientHandle) -> None:
self.client = client
@client.camera.on_update
def _(_: viser.CameraHandle) -> None:
R = vtf.SO3(wxyz=client.camera.wxyz)
R = vtf.SO3(wxyz=self.client.camera.wxyz)
R = R @ vtf.SO3.from_x_radians(np.pi)
R = torch.tensor(R.as_matrix())
pos = torch.tensor(client.camera.position, dtype=torch.float64) / VISER_NERFSTUDIO_SCALE_RATIO
pos = torch.tensor(self.client.camera.position, dtype=torch.float64) / VISER_NERFSTUDIO_SCALE_RATIO
c2w = torch.concatenate([R, pos[:, None]], dim=1)
self.camera_state = CameraState(fov=client.camera.fov, aspect=client.camera.aspect, c2w=c2w)
self.camera_state = CameraState(fov=self.client.camera.fov, aspect=self.client.camera.aspect, c2w=c2w)
self.render_statemachine.action(RenderAction("move", self.camera_state))
def _interrupt_render(self, _) -> None:
@@ -190,8 +191,8 @@ class Viewer:
c2w = camera.camera_to_worlds.cpu().numpy()
R = vtf.SO3.from_matrix(c2w[:3, :3])
R = R @ vtf.SO3.from_x_radians(np.pi)
self.viser_server.add_camera_frustum(
name=f"Camera {idx}",
camera_handle = self.viser_server.add_camera_frustum(
name=f"/camera_{idx:05d}",
fov=float(camera.fx[0]),
scale=0.2,
aspect=float(camera.cx[0] / camera.cy[0]),
@@ -200,6 +201,12 @@ class Viewer:
position=c2w[:3, 3] * VISER_NERFSTUDIO_SCALE_RATIO,
)
@camera_handle.on_click
def _(cam: viser.CameraHandle) -> None:
with self.client.atomic():
self.client.camera.position = cam.position
self.client.camera.wxyz = cam.wxyz
self.train_state = train_state
self.train_util = 0.9