Guest User

Untitled

a guest
Jun 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. # Run this script to generate a UV map and Image with 1 pixel per face so each face has a single colour.
  2.  
  3. import bpy
  4. import bmesh
  5. import math
  6.  
  7. # Get selected/active object
  8. obj = bpy.context.object
  9. obj.update_from_editmode()
  10. bpy.ops.object.mode_set(mode='EDIT')
  11. bm = bmesh.from_edit_mesh(obj.data)
  12.  
  13. # Get count of faces
  14. num_faces = len(bm.faces)
  15.  
  16. # Create UV map
  17. obj.data.uv_textures.new("facepixels_"+str(num_faces))
  18. uv_layer = bm.loops.layers.uv[0]
  19. bm.faces.layers.tex.verify()
  20.  
  21. # Process each face and position each loop vertex around the centre point
  22. faceidx = -1
  23. for f in bm.faces:
  24. faceidx = faceidx + 1
  25. loopidx = -1
  26. numverts = len(f.loops)
  27. for l in f.loops:
  28. loopidx = loopidx + 1
  29. luv = l[uv_layer]
  30. luv.uv[0] = float(faceidx)
  31. luv.uv[1] = 0.5
Add Comment
Please, Sign In to add comment