Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/LiDaR.py
Last active February 13, 2020 13:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/3c02a2920c1e8ba549b6 to your computer and use it in GitHub Desktop.
Save zeffii/3c02a2920c1e8ba549b6 to your computer and use it in GitHub Desktop.
import bpy
dfile = r"C:\Users\dealga\Desktop\Archive\SU8606_DSM_1M.asc"
getval = lambda i: next(i).split()[1]
with open(dfile) as ofile:
ncols = getval(ofile)
nrows = getval(ofile)
xllcorner = getval(ofile)
yllcorner = getval(ofile)
cellsize = getval(ofile)
NODATA_value = getval(ofile)
print(ncols, nrows, xllcorner, yllcorner, cellsize, NODATA_value)
# this will read the rest
verts = []
add_vert = verts.append
for i, row in enumerate(ofile):
for j, coord in enumerate(row.split()):
x = j * 0.01 # cell x width
y = i * 0.01 # cell y width
z = float(coord) / 20
add_vert((x,y,z))
print('done')
print('last vertex:', verts[-1])
# do your own error handling
mesh_data = bpy.data.meshes.new("LIDAR_mesh_data")
mesh_data.from_pydata(verts, [], [])
mesh_data.update()
LIDAR_object = bpy.data.objects.new("LIDAR_Object", mesh_data)
scene = bpy.context.scene
scene.objects.link(LIDAR_object)
LIDAR_object.select = True
@dirkteucher
Copy link

To get this to work in Blender 2.8+ replace

scene = bpy.context.scene
scene.objects.link(LIDAR_object)

with

bpy.context.collection.objects.link(LIDAR_object)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment