In VTK+WASM, how do I make the camera zoom on right click?

Normally in VTK, if you wanted to modify what each mouse button does, you would create a subclass of vtkInteractorStyle with all your custom events described.

For example, in Python, if you wanted the camera to zoom every time you right-clicked:

class CustomInteractorStyle(vtkInteractorStyleTrackballCamera):
    def __init__(self, renderer: vtkRenderer): super().__init__()
        self.__Renderer = renderer

    def OnRightButtonDown(self):
        self.__Renderer.GetActiveCamera().Zoom(1.1)

However, I am working with VTK/WASM at the moment, and I do not know how to go about doing this in the VTK/WASM framework. Creating the custom interactor style like the example above does not do anything in VTK/WASM.

How would I implement this example above in VTK/WASM? I would like to make the camera zoom in a little bit every time I clicked the right mouse button.

Technically I could create a @trigger endpoint on the TrameApp server that receives a right-click event from the frontend, update the camera zoom on the server, and then forward the camera update back to the frontend. However this would be overkill and I know there has to be a better way.

Will I need to compile custom bindings into a VTK+WASM binary for access to the camera object?

Yes.

  1. The implementation needs to be in C++ for it to work in the browser.
  2. There is still one more missing link. The object manager should be capable of (de)serializing the custom class. We are working on infrastructure to allow classes from extension modules to (de)serialize over the network. We will need to flesh out how this all ties together. This work would also address ParaView serialization · Issue #2 · Kitware/trame-vtklocal · GitHub because ParaView has subclasses of VTK classes.

In the end, it would mean you implement custom overrides of the interactor style methods in C++, compile that project for desktop and wasm together.

@Sebastien_Jourdain