Skip to content

Commit

Permalink
fix(example): sync client camera on server
Browse files Browse the repository at this point in the history
  • Loading branch information
jspanchu committed Aug 13, 2024
1 parent 104ad30 commit f6011c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions examples/vtk/glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import vtkmodules.vtkRenderingOpenGL2 # noqa
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleSwitch # noqa

import json


def setup_vtk():
colors = vtkNamedColors()
Expand Down Expand Up @@ -122,6 +124,8 @@ def __init__(self, server=None):
self.view_remote = None
self.ui = self._build_ui()

self.server.state.update(dict(camera=None))

@property
def ctrl(self):
return self.server.controller
Expand All @@ -133,6 +137,13 @@ def on_resolution_change(self, resolution, **kwargs):
self.view_remote.update()
self.view_local.update()

@change("camera")
def on_camera_change(self, camera, **kwargs):
if camera is not None:
self.view_local.object_manager.RegisterState(json.dumps(camera))
self.view_local.object_manager.UpdateObjectsFromStates()
self.view_remote.update()

def reset_camera(self):
self.renderer.ResetCamera()
self.view_local.update()
Expand Down Expand Up @@ -164,6 +175,7 @@ def _build_ui(self):
self.view_local = vtklocal.LocalView(
self.render_window,
eager_sync=True,
camera="camera = $event",
)
self.ctrl.view_update = self.view_local.update
with vuetify.VContainer(
Expand Down
2 changes: 1 addition & 1 deletion trame_vtklocal/widgets/vtklocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, render_window, **kwargs):
"updated",
("memory_vtk", "memory-vtk"),
("memory_arrays", "memory-arrays"),
"camera",
("camera", "camera"),
]

@property
Expand Down

0 comments on commit f6011c0

Please sign in to comment.