MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / export_to_obj

Function export_to_obj

src/diffusers/utils/export_utils.py:98–115  ·  view source on GitHub ↗
(mesh, output_obj_path: str = None)

Source from the content-addressed store, hash-verified

96
97
98def export_to_obj(mesh, output_obj_path: str = None):
99 if output_obj_path is None:
100 output_obj_path = tempfile.NamedTemporaryFile(suffix=".obj").name
101
102 verts = mesh.verts.detach().cpu().numpy()
103 faces = mesh.faces.cpu().numpy()
104
105 vertex_colors = np.stack([mesh.vertex_channels[x].detach().cpu().numpy() for x in "RGB"], axis=1)
106 vertices = [
107 "{} {} {} {} {} {}".format(*coord, *color) for coord, color in zip(verts.tolist(), vertex_colors.tolist())
108 ]
109
110 faces = ["f {} {} {}".format(str(tri[0] + 1), str(tri[1] + 1), str(tri[2] + 1)) for tri in faces.tolist()]
111
112 combined_data = ["v " + vertex for vertex in vertices] + faces
113
114 with open(output_obj_path, "w") as f:
115 f.writelines("\n".join(combined_data))
116
117
118def export_to_video(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected