Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import bpy
  2. import math
  3. import bmesh
  4.  
  5. file_path = "D:\terrain.xyz"
  6.  
  7. def read_verts(file_path):
  8. verts = []
  9. with open(file_path) as myfile:
  10. for line in myfile:
  11. verts.append([float(x) / 500 for x in line.split()])
  12. return verts
  13.  
  14. def create_faces(num_wid, num_heigh):
  15. faces = []
  16. j = 0
  17. for i in range(0, num_heigh * (num_wid - 1)):
  18. if j < num_heigh - 1:
  19. face = (i, i + 1, i + num_heigh + 1, i + num_heigh)
  20. faces.append(face)
  21. j = j + 1
  22. else:
  23. j = 0
  24. return faces
  25.  
  26.  
  27.  
  28. verts = read_verts(file_path)
  29. num_width = int(math.sqrt(len(verts)))
  30. faces = create_faces(num_width, num_width)
  31.  
  32.  
  33. # mesh
  34. mesh = bpy.data.meshes.new("terrain")
  35. mesh.from_pydata(verts,[],faces)
  36. mesh.update(calc_edges=True)
  37.  
  38. # object
  39. object = bpy.data.objects.new("terrain",mesh)
  40. object.location = (-10, 10, 0)
  41. bpy.context.scene.objects.link(object)
  42. bpy.context.scene.objects.active = object
  43. object.select = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement