diff options
author | Anthony LaTorre <telatorre@gmail.com> | 2011-05-07 20:32:35 -0400 |
---|---|---|
committer | Anthony LaTorre <telatorre@gmail.com> | 2011-05-07 20:32:35 -0400 |
commit | 16736eeae08d9627ad751c65919900ae9191a08f (patch) | |
tree | 602af6b7fdfd32c9cdc7fc3b85e6c8e247209197 /stl.py | |
parent | 76a6dd33cdaf4b583b7e8353f198925ddb4a4685 (diff) | |
download | chroma-16736eeae08d9627ad751c65919900ae9191a08f.tar.gz chroma-16736eeae08d9627ad751c65919900ae9191a08f.tar.bz2 chroma-16736eeae08d9627ad751c65919900ae9191a08f.zip |
tie fighter
Diffstat (limited to 'stl.py')
-rw-r--r-- | stl.py | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -1,15 +1,30 @@ import numpy as np +import struct def pull_vertices(filename): f = open(filename) - vertices = [] + vertex = [] for line in f: if not line.strip().startswith('vertex'): continue - vertices.append([float(s) for s in line.strip().split()[1:]]) + vertex.append([float(s) for s in line.strip().split()[1:]]) - return np.array(vertices) + f.close() + return np.array(vertex) -if __name__ == '__main__': - print pull_vertices('models/MiniFig.STL') +def pull_vertices_binary(filename): + f = open(filename) + + f.read(80) + triangles = struct.unpack('<I', f.read(4))[0] + + vertex = [] + for i in range(triangles): + f.read(12) + for j in range(3): + vertex.append(struct.unpack('<fff', f.read(12))) + f.read(2) + + f.close() + return np.array(vertex) |