103_Events.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import sys, os
  2. # Add the igl library to the modules search path
  3. sys.path.insert(0, os.getcwd() + "/../")
  4. import pyigl as igl
  5. from shared import TUTORIAL_SHARED_PATH, check_dependencies
  6. dependencies = ["viewer"]
  7. check_dependencies(dependencies)
  8. V1 = igl.eigen.MatrixXd()
  9. F1 = igl.eigen.MatrixXi()
  10. V2 = igl.eigen.MatrixXd()
  11. F2 = igl.eigen.MatrixXi()
  12. def key_pressed(viewer, key, modifier):
  13. print("Key: ", chr(key))
  14. if key == ord('1'):
  15. # # Clear should be called before drawing the mesh
  16. viewer.data.clear()
  17. # # Draw_mesh creates or updates the vertices and faces of the displayed mesh.
  18. # # If a mesh is already displayed, draw_mesh returns an error if the given V and
  19. # # F have size different than the current ones
  20. viewer.data.set_mesh(V1, F1)
  21. viewer.core.align_camera_center(V1,F1)
  22. elif key == ord('2'):
  23. viewer.data.clear()
  24. viewer.data.set_mesh(V2, F2)
  25. viewer.core.align_camera_center(V2,F2)
  26. return False
  27. # Load two meshes
  28. igl.readOFF(TUTORIAL_SHARED_PATH + "bumpy.off", V1, F1)
  29. igl.readOFF(TUTORIAL_SHARED_PATH + "fertility.off", V2, F2)
  30. print("1 Switch to bump mesh")
  31. print("2 Switch to fertility mesh")
  32. viewer = igl.viewer.Viewer()
  33. # Register a keyboard callback that allows to switch between
  34. # the two loaded meshes
  35. viewer.callback_key_pressed = key_pressed
  36. viewer.data.set_mesh(V1, F1)
  37. viewer.launch()