106_ViewerMenu.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. # Add the igl library to the modules search path
  9. import sys, os
  10. sys.path.insert(0, os.getcwd() + "/../")
  11. import pyigl as igl
  12. import nanogui
  13. V1 = igl.eigen.MatrixXd()
  14. F1 = igl.eigen.MatrixXi()
  15. V2 = igl.eigen.MatrixXd()
  16. F2 = igl.eigen.MatrixXi()
  17. float_variable = 0.1
  18. bool_variable = True
  19. dir = 0
  20. def make_accessors(name):
  21. def setter(value):
  22. globals()[name] = value
  23. def getter():
  24. return globals()[name]
  25. return setter, getter
  26. def viewer_init(viewer):
  27. # add new group
  28. viewer.ngui.addGroup("New Group")
  29. # Expose the using general callback
  30. viewer.ngui.addDoubleVariable("double", *make_accessors("float_variable"))
  31. def setter(val):
  32. global bool_variable
  33. bool_variable = val
  34. def getter():
  35. global bool_variable
  36. return bool_variable
  37. # ... or using a custom callback
  38. viewer.ngui.addBoolVariable("bool", setter, getter)
  39. viewer.ngui.addEnumVariable("Direction", *make_accessors("dir")) \
  40. .setItems(["Up", "Down", "Left", "Right"])
  41. # Add a button
  42. def cb():
  43. print("Hello")
  44. viewer.ngui.addButton("Print Hello", cb)
  45. #Add an additional menu window
  46. viewer.ngui.addWindow((220, 10), "New Window")
  47. # add accessor
  48. viewer.ngui.addDoubleVariable("double", *make_accessors("float_variable"))
  49. #Generate menu
  50. viewer.screen.performLayout()
  51. return False
  52. def main():
  53. # Load a mesh in OFF format
  54. igl.readOFF("../../tutorial/shared/bunny.off", V1, F1)
  55. # Init the viewer
  56. viewer = igl.viewer.Viewer()
  57. # Extend viewer menu
  58. viewer.callback_init = viewer_init
  59. # Plot the mesh
  60. viewer.data.set_mesh(V1, F1)
  61. viewer.launch()
  62. if __name__ == "__main__":
  63. main()