Skip to content

Commit

Permalink
fix(wasm): properly handle camera sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Nov 27, 2024
1 parent 95f8862 commit 272cb77
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions pan3d/ui/vtk_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,27 @@ def __init__(
# 3D view
if local_rendering is not None:
if local_rendering == "wasm":
with wasm.LocalView(self.render_window, throttle_rate=10) as view:
with wasm.LocalView(
self.render_window,
throttle_rate=10,
listeners=("wasm_listeners", {}),
) as view:
self.ctrl.view_update_force = view.update
self.ctrl.view_update = view.update_throttle
self.ctrl.view_reset_camera = view.reset_camera
camera_id = view.get_wasm_id(self.camera)
self.state.setdefault("wasm_camera", None)
self.state.wasm_listeners = {
camera_id: {
"ModifiedEvent": {
"wasm_camera": {
"position": [camera_id, "Position"],
"view_up": [camera_id, "ViewUp"],
"focal_point": [camera_id, "FocalPoint"],
}
}
}
}
for w in widgets or []:
view.register_widget(w)
else:
Expand Down Expand Up @@ -158,7 +175,8 @@ def reset_camera_to_axis(self, axis):
camera.focal_point = (0, 0, 0)
camera.position = axis
camera.view_up = VIEW_UPS.get(tuple(axis))
self.ctrl.view_reset_camera()
self.renderer.ResetCamera()
self.ctrl.view_update(push_camera=True)

def rotate_camera(self, direction):
camera = self.renderer.active_camera
Expand All @@ -171,7 +189,15 @@ def rotate_camera(self, direction):
]
camera.view_up = view_up

self.ctrl.view_update()
self.ctrl.view_update(push_camera=True)

@change("wasm_camera")
def _on_camera(self, wasm_camera, **_):
if wasm_camera is None:
return

for k, v in wasm_camera.items():
setattr(self.camera, k, v)

@change("view_3d")
def _on_view_type_change(self, view_3d, **_):
Expand Down

0 comments on commit 272cb77

Please sign in to comment.