diff options
author | Anthony LaTorre <telatorre@gmail.com> | 2011-05-09 16:55:44 -0400 |
---|---|---|
committer | Anthony LaTorre <telatorre@gmail.com> | 2011-05-09 16:55:44 -0400 |
commit | c69b090dc267bff5c985938e676798115830217f (patch) | |
tree | 5c84e908de7d8623061fcc64a013e1b4a9f6377c | |
parent | 34c57af59b8baac89b9fdc0b5ac964a4c67bd32d (diff) | |
download | chroma-c69b090dc267bff5c985938e676798115830217f.tar.gz chroma-c69b090dc267bff5c985938e676798115830217f.tar.bz2 chroma-c69b090dc267bff5c985938e676798115830217f.zip |
single read_stl function for both binary/ascii stl files
-rw-r--r-- | stl.py | 16 | ||||
-rw-r--r-- | test.py | 2 |
2 files changed, 15 insertions, 3 deletions
@@ -1,7 +1,19 @@ import numpy as np +import string import struct -def pull_vertices(filename): +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 = [] @@ -13,7 +25,7 @@ def pull_vertices(filename): f.close() return np.array(vertex) -def pull_vertices_binary(filename): +def read_binary_stl(filename): f = open(filename) f.read(80) @@ -27,7 +27,7 @@ intersect = mod.get_function('intersect_triangle_mesh') rotate = mod.get_function('rotate') translate = mod.get_function('translate') -mesh = array2float3(pull_vertices_binary('models/tie_interceptor6.stl')) +mesh = array2float3(read_stl('models/tie_interceptor6.stl')) import pygame size = width, height = 800, 600 |