103_Events.py 1.8 KB

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