def body(): vertices = np.array([ [0, 0, 0], [24, 0, 0], [24, 24, 0], [0, 24, 0], [0, 0, 10], [24, 0, 10], [24, 24, 10], [0, 24, 10] ]) faces = np.array([ [0, 1, 2], [0, 2, 3], [4, 5, 6], [4, 6, 7], [0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7] ]) return mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype), remove_empty_areas=False), vertices, faces def button(): vertices = np.array([ [6, 0, 10], [18, 0, 10], [18, 4, 10], [6, 4, 10], [6, 0, 12], [18, 0, 12], [18, 4, 12], [6, 4, 12] ]) faces = np.array([ [0, 1, 2], [0, 2, 3], [4, 5, 6], [4, 6, 7], [0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7] ]) return mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype), remove_empty_areas=False), vertices, faces def speaker(): resolution = 20 height = 2 radius = 6 circle_points = np.linspace(0, 2 * np.pi, resolution) vertices = np.zeros((resolution + 2, 3)) vertices[1:-1, 0] = np.cos(circle_points) * radius vertices[1:-1, 1] = np.sin(circle_points) * radius vertices[0, 2] = 0 vertices[1:-1, 2] = height / 2 vertices[-1, 2] = height faces = np.zeros((resolution * 2, 3), dtype=np.int32) for i in range(resolution): idx = i * 2 faces[idx] = [0, i + 1, (i + 1) % resolution + 1] faces[idx + 1] = [resolution + 1, i + 1, (i + 1) % resolution + 1] return mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype), remove_empty_areas=False), vertices, faces # M5StickCのメッシュを作成する m5stickc = mesh.Mesh(np.zeros(0, dtype=mesh.Mesh.dtype)) parts = [body, button, speaker] for part in parts: mesh_part, vertices, faces = part() mesh_part.vectors = vertices[faces] m5stickc = mesh.Mesh(np.concatenate([m5stickc.data, mesh_part.data])) # M5StickCの形状をSTLファイルに出力する m5stickc.save('m5stickc.stl') Numpy-stlを用いたPythonコードと生成されたM5StickC形状