Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import bpy
  2. import csv
  3. from operator import itemgetter
  4.  
  5. csvfile = open('G:\Telechargements\Heatmap_ES_output_01.csv')
  6.  
  7. inFile = csv.reader(csvfile, delimiter=',', quotechar='"')
  8. # skip header
  9. inFile.__next__()
  10.  
  11. #Read and sort the vertices coordinates (sort by x and y)
  12. vertices = sorted( [(float(r[0]), float(r[1]), float(r[2])) for r in inFile], key = itemgetter(0,1) )
  13.  
  14. #********* Assuming we have a rectangular grid *************
  15. xSize = next( i for i in range( len(vertices) ) if vertices[i][0] != vertices[i+1][0] ) + 1 #Find the first change in X
  16. ySize = len(vertices) // xSize
  17.  
  18. #Generate the polygons (four vertices linked in a face)
  19. polygons = [(i, i - 1, i - 1 + xSize, i + xSize) for i in range( 1, len(vertices) - xSize ) if i % xSize != 0]
  20.  
  21. name = "grid"
  22. mesh = bpy.data.meshes.new( name ) #Create the mesh (inner data)
  23. obj = bpy.data.objects.new( name, mesh ) #Create an object
  24.  
  25. obj.data.from_pydata( vertices, [], polygons ) #Associate vertices and polygons
  26.  
  27. obj.scale = (1, 5, 0.2) #Scale it (if needed)
  28. for p in obj.data.polygons: #Set smooth shading (if needed)
  29. p.use_smooth = True
  30.  
  31. bpy.context.scene.objects.link( obj ) #Link the object to the scene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement