Combining enable_trackball_style and enable_trackball_actor_style to create a small 3D editor #5964
HLFILIOZAT
started this conversation in
Show and tell
Replies: 2 comments 2 replies
-
First try with key events 'a' and 'c'. import pyvista
pyvista.set_plot_theme( 'dark' )
plotter = pyvista.Plotter( notebook=False )
# gen the scene: 2 3D texts
txt1, txt2 = ("YES", "NO")
mesh = pyvista.Text3D( txt1, normal=(1,0,0), center=(5,0,0) )
plotter.add_mesh( mesh, name=txt1 )
mesh = pyvista.Text3D( txt2, normal=(0,1,0), center=(0,5,0) )
plotter.add_mesh( mesh, name=txt2 )
# horizontal floor
plotter.add_floor( face='-z', show_edges=True, offset=0.1, pickable=False )
#
plotter.show_axes( )
#
def set_mode_camera_cb( ):
plotter.enable_trackball_style()
def set_mode_actor_cb( ):
plotter.enable_trackball_actor_style()
plotter.iren.add_key_event( 'a', set_mode_actor_cb )
plotter.iren.add_key_event( 'c', set_mode_camera_cb )
#
plotter.show( title='3D editor', full_screen=True ) |
Beta Was this translation helpful? Give feedback.
2 replies
-
Finally, I have succeeded in implementing hovering, thanks to #4781 ADD the following code to the previous one (that initializes the plotter, creates the scene...) ! from vtkmodules.vtkCommonCore import vtkCommand
from vtkmodules.vtkInteractionWidgets import vtkHoverWidget
from vtkmodules.vtkRenderingCore import vtkPointPicker
picker = vtkPointPicker()
hovered_actor = None
def release_hovered_actor():
global hovered_actor
if hovered_actor is None:
pass
else:
hovered_actor.prop.show_edges = False;
hovered_actor = None
return
def hovering_cb(_widget, event_name):
x, y = plotter.iren.interactor.GetEventPosition()
renderer = plotter.iren.get_poked_renderer(x, y)
picker.Pick(x, y, 0, renderer)
actors = list(picker.GetActors()) # /!\ generator !
n_actors = len(actors)
global hovered_actor
if n_actors == 1:
if hovered_actor == actors[0]: return # no change
release_hovered_actor() # release previously hovered actor
hovered_actor = actors[0]
hovered_actor.prop.show_edges = True
text = hovered_actor.name
set_mode_actor_cb()
elif n_actors == 0:
text = ''
if hovered_actor != None: release_hovered_actor()
set_mode_camera_cb()
else:
text = f"{n_actors} actors / abort"
set_mode_camera_cb()
plotter.add_text( text=text, name='hovering', position='upper_left' )
hw = vtkHoverWidget()
hw.SetInteractor(plotter.iren.interactor)
hw.SetTimerDuration(10)
hw.AddObserver(vtkCommand.TimerEvent, hovering_cb )
#hw.AddObserver(vtkCommand.EndInteractionEvent, hovering_cb)
hw.EnabledOn() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe something you've made
I would like to create a small 3D editor, which means:
. to observe it (as usual)
. AND also to transform it, by moving or resizing any of the included actors.
To my knowledge, this is not possible with a single interaction style of the current pyvista API.
For now, we have to “cumulate” 2 interaction styles, one to control the camera and the other one to control actors.
I have chosen:
Links to Documentation, Examples, or Class Definitions.
https://docs.pyvista.org/version/stable/api/plotting/_autosummary/pyvista.Plotter.enable_trackball_style.html#pyvista-plotter-enable-trackball-style
https://docs.pyvista.org/version/stable/api/plotting/_autosummary/pyvista.Plotter.enable_trackball_actor_style.html#pyvista-plotter-enable-trackball-actor-style
Pseudocode or Screenshots
No response
Beta Was this translation helpful? Give feedback.
All reactions