summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony LaTorre <telatorre@gmail.com>2011-05-09 16:55:44 -0400
committerAnthony LaTorre <telatorre@gmail.com>2011-05-09 16:55:44 -0400
commitc69b090dc267bff5c985938e676798115830217f (patch)
tree5c84e908de7d8623061fcc64a013e1b4a9f6377c
parent34c57af59b8baac89b9fdc0b5ac964a4c67bd32d (diff)
downloadchroma-c69b090dc267bff5c985938e676798115830217f.tar.gz
chroma-c69b090dc267bff5c985938e676798115830217f.tar.bz2
chroma-c69b090dc267bff5c985938e676798115830217f.zip
single read_stl function for both binary/ascii stl files
-rw-r--r--stl.py16
-rw-r--r--test.py2
2 files changed, 15 insertions, 3 deletions
diff --git a/stl.py b/stl.py
index 076c739..7989d43 100644
--- a/stl.py
+++ b/stl.py
@@ -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)
diff --git a/test.py b/test.py
index 0261e6d..267b266 100644
--- a/test.py
+++ b/test.py
@@ -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