def rotate_bin_stl(self, rotation_matrix, content):
"""Rotate the object and save as binary STL. This module is currently replaced
by the ascii version. If you want to use binary STL, please do the
following changes in Tweaker.py: Replace "rotatebinSTL" by "rotateSTL"
and set in the write sequence the open outfile option from "w" to "wb".
However, the ascii version is much faster in Python 3."""
mesh = np.array(content, dtype=np.float64)
# prefix area vector, if not already done (e.g. in STL format)
if len(mesh[0]) == 3:
row_number = int(len(content) / 3)
mesh = mesh.reshape(row_number, 3, 3)
# upgrade numpy with: "pip install numpy --upgrade"
rotated_content = np.matmul(mesh, rotation_matrix)
v0 = rotated_content[:, 0, :]
v1 = rotated_content[:, 1, :]
v2 = rotated_content[:, 2, :]
normals = np.cross(np.subtract(v1, v0), np.subtract(v2, v0)
).reshape(int(len(rotated_content)), 1, 3)
rotated_content = np.hstack((normals, rotated_content))
# header = "Tweaked on {}".format(time.strftime("%a %d %b %Y %H:%M:%S")
# ).encode().ljust(79, b" ") + b"\n"
# header = struct.pack("<I", int(len(content) / 3)) # list("solid %s" % filename)
tweaked_array = list(map(self.write_bin_facett, rotated_content))
# return header + b"".join(tweaked_array)
# return b"".join(tweaked_array)
return tweaked_array
评论列表
文章目录