Skip to content

Commit

Permalink
Merge pull request #1033 from nschloe/stl-improvement
Browse files Browse the repository at this point in the history
Stl improvement
  • Loading branch information
nschloe authored Feb 22, 2021
2 parents 51dece6 + 5912702 commit 5ff0855
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions meshio/stl/_stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,24 @@ def _binary(filename, points, cells):
msg += (79 - len(msg)) * "X"
msg += "\n"
fh.write(msg.encode("utf-8"))

dtype = np.dtype(
[
("normal", ("<f4", 3)),
("points", ("<f4", (3, 3))),
("attr", "<u2"),
]
)
for c in filter(lambda c: c.type == "triangle", cells):
pts = points[c.data]
normals = _compute_normals(pts)
fh.write(np.uint32(len(c.data)))
for pt, normal in zip(pts, normals):
fh.write(normal.astype(np.float32))
fh.write(pt.astype(np.float32))
fh.write(np.uint16(0))
fh.write(np.array(len(c.data)).astype("<u4"))

a = np.empty(len(c.data), dtype=dtype)
a["normal"] = normals
a["points"] = pts
a["attr"] = 0
a.tofile(fh)


register("stl", [".stl"], read, {"stl": write})
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = meshio
version = 4.3.9
version = 4.3.10
author = Nico Schlömer et al.
author_email = [email protected]
description = I/O for many mesh formats
Expand Down

0 comments on commit 5ff0855

Please sign in to comment.