From c69b090dc267bff5c985938e676798115830217f Mon Sep 17 00:00:00 2001 From: Anthony LaTorre Date: Mon, 9 May 2011 16:55:44 -0400 Subject: single read_stl function for both binary/ascii stl files --- stl.py | 16 ++++++++++++++-- test.py | 2 +- 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 -- cgit