Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import bpy
  2.  
  3. #super simple export of vert positions, colors and indices
  4. #note: you probably need to run blender as admin to store files
  5.  
  6. current = bpy.context.object.data
  7.  
  8. file = open("your path!", "w")
  9.  
  10. #VERTEX POSITIONS
  11. for vert in current.vertices:
  12. #get coords
  13. x = vert.co[0]
  14. y = vert.co[1]
  15. z = vert.co[2]
  16. #formate coords to specific count of decimal places
  17. xs = str("%.6f" % x)
  18. ys = str("%.6f" % y)
  19. zs = str("%.6f" % z)
  20. #align plus with minus values (beautify output)
  21. if x >= 0: xs = " " + xs
  22. if y >= 0: ys = " " + ys
  23. if z >= 0: zs = " " + zs
  24. #write
  25. file.write("p " + xs + " " + ys + " " + zs + "\n")
  26.  
  27. #VERTEX COLORS
  28. for col in current.vertex_colors:
  29. print(col.data)
  30. for c in col.data:
  31. #get colors and formate colors to specific count of decimal places
  32. r = str("%.6f" % c.color[0])
  33. g = str("%.6f" % c.color[1])
  34. b = str("%.6f" % c.color[2])
  35. a = str("%.6f" % c.color[3])
  36. #write
  37. file.write("c " + r + " " + g + " " + b + " " + a + "\n")
  38.  
  39. #TRIANGLES
  40. #triangulate faces before!
  41. for poly in current.polygons:
  42. #get indices
  43. i1 = str(poly.vertices[0])
  44. i2 = str(poly.vertices[1])
  45. i3 = str(poly.vertices[2])
  46. #write
  47. file.write("i " + i1 + " " + i2 + " " + i3 + "\n")
  48.  
  49. file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement