103_Events.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python
  2. #
  3. # This file is part of libigl, a simple c++ geometry processing library.
  4. #
  5. # Copyright (C) 2017 Sebastian Koch <s.koch@tu-berlin.de> and Daniele Panozzo <daniele.panozzo@gmail.com>
  6. #
  7. # This Source Code Form is subject to the terms of the Mozilla Public License
  8. # v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. # obtain one at http://mozilla.org/MPL/2.0/.
  10. import sys, os
  11. # Add the igl library to the modules search path
  12. sys.path.insert(0, os.getcwd() + "/../")
  13. import pyigl as igl
  14. from shared import TUTORIAL_SHARED_PATH, check_dependencies
  15. dependencies = ["glfw"]
  16. check_dependencies(dependencies)
  17. V1 = igl.eigen.MatrixXd()
  18. F1 = igl.eigen.MatrixXi()
  19. V2 = igl.eigen.MatrixXd()
  20. F2 = igl.eigen.MatrixXi()
  21. def key_pressed(viewer, key, modifier):
  22. print("Key: ", chr(key))
  23. if key == ord('1'):
  24. # # Clear should be called before drawing the mesh
  25. viewer.data().clear()
  26. # # Draw_mesh creates or updates the vertices and faces of the displayed mesh.
  27. # # If a mesh is already displayed, draw_mesh returns an error if the given V and
  28. # # F have size different than the current ones
  29. viewer.data().set_mesh(V1, F1)
  30. viewer.core.align_camera_center(V1,F1)
  31. elif key == ord('2'):
  32. viewer.data().clear()
  33. viewer.data().set_mesh(V2, F2)
  34. viewer.core.align_camera_center(V2,F2)
  35. return False
  36. # Load two meshes
  37. igl.readOFF(TUTORIAL_SHARED_PATH + "bumpy.off", V1, F1)
  38. igl.readOFF(TUTORIAL_SHARED_PATH + "fertility.off", V2, F2)
  39. print("1 Switch to bump mesh")
  40. print("2 Switch to fertility mesh")
  41. viewer = igl.glfw.Viewer()
  42. # Register a keyboard callback that allows to switch between
  43. # the two loaded meshes
  44. viewer.callback_key_pressed = key_pressed
  45. viewer.data().set_mesh(V1, F1)
  46. viewer.launch()