texture_coords.py 776 B

12345678910111213141516171819202122232425262728293031
  1. """Assign texture coordinates to a polygon"""
  2. from vedo import *
  3. settings.default_font = 'Bongas'
  4. # define a polygon of 4 vertices:
  5. polygon = [
  6. [(82, 92, 47), (87, 88, 47), # x,y,z of vertices
  7. (93, 95, 47), (88, 99, 47)],
  8. [[0, 1, 2, 3]], # vertex connectivity
  9. ]
  10. # texture coordinates, one (u,v) pair for each vertex:
  11. tc = [(0,0), (1,0), (1,1), (0,1)]
  12. #tc = [(0,0), (2,0), (2,2), (0,2)]
  13. # create the Mesh object (a rectangle)
  14. m = Mesh(polygon)
  15. # apply texture to m
  16. fpath = download('https://vedo.embl.es/examples/data/images/dog.jpg')
  17. m.texture(
  18. fpath,
  19. tcoords=tc,
  20. interpolate=True,
  21. repeat=True, # when tcoords extend beyond [0,1]
  22. edge_clamp=False, # only used when repeat is False
  23. )
  24. show(m, __doc__, axes=1).close()