-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SetInteractorStyle fails to do anything #413
Comments
|
Hi @jourdain , is there any update on this issue? I can see that it has a WASM tag, so I tried a simple example with that repo, but it doesn't show the expected behavior. Switching to VtkRemoteView kind of works, but the view becomes very unresponsive and laggy. from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame_vtklocal.widgets import vtklocal
from vtkmodules.vtkFiltersSources import vtkLineSource
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleTrackballCamera
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderer,
vtkRenderWindow,
vtkRenderWindowInteractor,
)
from trame.widgets import vtk as vtk_widgets
# Required for vtk factory
import vtkmodules.vtkRenderingOpenGL2 # noqa
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleSwitch # noqa
# VTK line
line_source = vtkLineSource()
line_source.SetPoint1(0, 0, 0)
line_source.SetPoint2(1, 0, 0)
line_source.Update()
# mappers and actors
line_mapper = vtkPolyDataMapper()
line_mapper.SetInputConnection(line_source.GetOutputPort())
line_actor = vtkActor()
line_actor.SetMapper(line_mapper)
# Create a renderer, render window, and interactor
renderer = vtkRenderer()
render_window = vtkRenderWindow()
render_window.AddRenderer(renderer)
interactor = vtkRenderWindowInteractor()
interactor.SetRenderWindow(render_window)
# Add actors to the renderer
renderer.AddActor(line_actor)
# Custom interactor style class
class MouseInteractorStyle(vtkInteractorStyleTrackballCamera):
def __init__(self):
self.AddObserver("LeftButtonPressEvent", self.left_button_press_event)
self.AddObserver("MouseMoveEvent", self.mouse_move_event)
def left_button_press_event(self, obj, event):
print("left_button_press_event")
def mouse_move_event(self, obj, event):
print("mouse_move_event")
# Set the custom interactor style
style = MouseInteractorStyle()
style.SetDefaultRenderer(renderer)
interactor.SetInteractorStyle(style)
# Create a Trame server
server = get_server()
server.client_type="vue2"
# Define the layout
with SinglePageLayout(server) as layout:
layout.root.style = "width: 100vw; height: 100vh; margin: 0; padding: 0;"
layout.title.set_text("VTK Line")
with layout.content:
vtklocal.LocalView(render_window)
# vtk_widgets.VtkRemoteView(render_window)
# Start the server
if __name__ == "__main__":
server.start() |
The issue with your code is that you have server side logic (MouseInteractorStyle) which won't work on the WASM side. I guess the other question would be why is the remote rendering very unresponsive and laggy. |
I see. Thank you for clarifying. And yes, it’s surprisingly slow in the remote view. |
Are you using OSMesa and therefore no GPU on the server side? |
Sorry for the delayed response. I'm running the code on a laptop with an RTX A1000. I created a new environment and reinstalled everything from scratch, but I see the same behavior. |
Remote rendering should feel fairly responsive like 25-30 fps. |
Hi @jourdain , may I ask how to listen for click events in LocalView? |
You might be able to attache listener on the interactor. You can see examples of listeners inside the widgets examples. You will have to figure out which vtk object you want to listen to and which event type. So far I don't have any example doing that. |
Thank you for your reply!
Should I replace
I apologize for bothering you with this question again and thank you in advance. |
To really provide a solution to you, I will need to spend time investigating and solving that specific use case. To really put the time needed, I will need some support. |
Describe the bug
Trying to use
SetInteractorStyle
always seems to fail, I always getvtkInteractorStyleTrackballCamera
. Specifically I can't use a custom subclass.To Reproduce
The script below was taken from https://examples.vtk.org/site/Python/Picking/HighlightWithSilhouette/ with minimal adaptation for trame.
When running, the custom code in
MouseInteractorHighLightActor.onLeftButtonDown
never executes, so the functionality does not work and there are no debug prints.Code
Expected behavior
The
MouseInteractorHighLightActor
sublcass should work like it does in the VTK example linked.Platform:
I've checked only the following, but I imagine the bug is on all platforms.
Device:
OS:
Browsers Affected:
The text was updated successfully, but these errors were encountered: