napari1.py 746 B

1234567891011121314151617181920212223242526
  1. import numpy as np
  2. import napari
  3. import vedo
  4. print("\nSEE ALSO https://github.com/jo-mueller/napari-vedo-bridge")
  5. # Load the surface, triangulate just in case, and compute vertex normals
  6. surf = vedo.Mesh(vedo.dataurl+"beethoven.ply").triangulate().compute_normals()
  7. surf.rotate_x(180).rotate_y(60)
  8. vertices = surf.vertices
  9. faces = np.array(surf.cells)
  10. normals = surf.vertex_normals
  11. # generate vertex values by projecting normals on a "lighting vector"
  12. values = np.dot(normals, [-1, 1, 1])
  13. # create an empty viewer
  14. viewer = napari.Viewer()
  15. # add the surface
  16. viewer.add_surface((vertices, faces, values), opacity=0.8)
  17. viewer.add_points(vertices, size=0.05, face_color='pink')
  18. # turn on 3D rendering
  19. viewer.dims.ndisplay = 3
  20. napari.run()