Skip to content

Commit 5ff0855

Browse files
authored
Merge pull request #1033 from nschloe/stl-improvement
Stl improvement
2 parents 51dece6 + 5912702 commit 5ff0855

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

meshio/stl/_stl.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,24 @@ def _binary(filename, points, cells):
221221
msg += (79 - len(msg)) * "X"
222222
msg += "\n"
223223
fh.write(msg.encode("utf-8"))
224+
225+
dtype = np.dtype(
226+
[
227+
("normal", ("<f4", 3)),
228+
("points", ("<f4", (3, 3))),
229+
("attr", "<u2"),
230+
]
231+
)
224232
for c in filter(lambda c: c.type == "triangle", cells):
225233
pts = points[c.data]
226234
normals = _compute_normals(pts)
227-
fh.write(np.uint32(len(c.data)))
228-
for pt, normal in zip(pts, normals):
229-
fh.write(normal.astype(np.float32))
230-
fh.write(pt.astype(np.float32))
231-
fh.write(np.uint16(0))
235+
fh.write(np.array(len(c.data)).astype("<u4"))
236+
237+
a = np.empty(len(c.data), dtype=dtype)
238+
a["normal"] = normals
239+
a["points"] = pts
240+
a["attr"] = 0
241+
a.tofile(fh)
232242

233243

234244
register("stl", [".stl"], read, {"stl": write})

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = meshio
3-
version = 4.3.9
3+
version = 4.3.10
44
author = Nico Schlömer et al.
55
author_email = [email protected]
66
description = I/O for many mesh formats

0 commit comments

Comments
 (0)