summaryrefslogtreecommitdiff
path: root/stl.py
diff options
context:
space:
mode:
Diffstat (limited to 'stl.py')
-rw-r--r--stl.py43
1 files changed, 0 insertions, 43 deletions
diff --git a/stl.py b/stl.py
deleted file mode 100644
index a458708..0000000
--- a/stl.py
+++ /dev/null
@@ -1,43 +0,0 @@
-import numpy as np
-import string
-import struct
-
-def read_stl(filename):
- """Return a triangle mesh from `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('<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).reshape(len(vertex)//3,3,3)