502_LSCMParam.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. V = igl.eigen.MatrixXd()
  9. F = igl.eigen.MatrixXi()
  10. V_uv = igl.eigen.MatrixXd()
  11. def key_down(viewer, key, modifier):
  12. if key == ord('1'):
  13. # Plot the 3D mesh
  14. viewer.data.set_mesh(V, F)
  15. viewer.core.align_camera_center(V, F)
  16. elif key == ord('2'):
  17. # Plot the mesh in 2D using the UV coordinates as vertex coordinates
  18. viewer.data.set_mesh(V_uv, F)
  19. viewer.core.align_camera_center(V_uv, F)
  20. viewer.data.compute_normals()
  21. return False
  22. # Load a mesh in OFF format
  23. igl.readOFF(TUTORIAL_SHARED_PATH + "camelhead.off", V, F)
  24. # Fix two points on the boundary
  25. bnd = igl.eigen.MatrixXi()
  26. b = igl.eigen.MatrixXi(2, 1)
  27. igl.boundary_loop(F, bnd)
  28. b[0] = bnd[0]
  29. b[1] = bnd[int(bnd.size() / 2)]
  30. bc = igl.eigen.MatrixXd([[0, 0], [1, 0]])
  31. # LSCM parametrization
  32. igl.lscm(V, F, b, bc, V_uv)
  33. # Scale the uv
  34. V_uv *= 5
  35. # Plot the mesh
  36. viewer = igl.viewer.Viewer()
  37. viewer.data.set_mesh(V, F)
  38. viewer.data.set_uv(V_uv)
  39. viewer.callback_key_down = key_down
  40. # Disable wireframe
  41. viewer.core.show_lines = False
  42. # Draw checkerboard texture
  43. viewer.core.show_texture = True
  44. # Launch the viewer
  45. viewer.launch()