Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions __init___.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def execute(self, context):
point['Y'] * infile.header.y_scale + infile.header.y_offset,
point['Z'] * infile.header.z_scale + infile.header.z_offset)
for point in all_points])

colors = (np.vstack((all_points['red'], all_points['green'], all_points['blue'])).T)/65536

# Prepare LiDAR info
lidar_info = {
Expand All @@ -73,11 +75,11 @@ def execute(self, context):
}

# Import LAS points as a mesh
self.import_points_as_mesh(context, points, lidar_info)
self.import_points_as_mesh(context, points, colors, lidar_info)

return {'FINISHED'}

def import_points_as_mesh(self, context, points, lidar_info):
def import_points_as_mesh(self, context, points, colors, lidar_info):
# Create a new mesh object
mesh = bpy.data.meshes.new("LAS Data")
obj = bpy.data.objects.new("LAS Data", mesh)
Expand All @@ -99,7 +101,19 @@ def import_points_as_mesh(self, context, points, lidar_info):
obj['lidar_point_count_by_return'] = get_attribute(lidar_info['header'], 'point_count_by_return')

# Create mesh vertices from points
mesh.from_pydata(points, [], [])
num_vertices = len(points)
faces = [(i, i, i) for i in range(num_vertices)]

mesh.from_pydata(points, [], faces)
mesh.update() # Update mesh data


vertex_colors = mesh.vertex_colors.new(name="Col") if "Col" not in mesh.vertex_colors else mesh.vertex_colors["Col"]

# Assign colors through loops
for loop in mesh.loops:
loop_color = colors[loop.vertex_index]
vertex_colors.data[loop.index].color = (*loop_color, 1.0) # Ensure RGBA (A=1.0)

# Set mesh object's origin to the center of its bounding box and location to (0, 0, 0)
min_coords = [min(points, key=lambda coord: coord[i])[i] for i in range(3)]
Expand Down