-
-
Save zeffii/3c02a2920c1e8ba549b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)