import numpy as np import string import struct def read_stl(filename): f = open(filename) buf = f.read(200) f.close() for char in buf: if char not in string.printable: return read_binary_stl(filename) return read_ascii_stl(filename) def read_ascii_stl(filename): f = open(filename) vertex = [] for line in f: if not line.strip().startswith('vertex'): continue vertex.append([float(s) for s in line.strip().split()[1:]]) f.close() return np.array(vertex).reshape(len(vertex)//3,3,3) def read_binary_stl(filename): f = open(filename) f.read(80) triangles = struct.unpack('