103_Events.py 1.3 KB

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