MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / export_to_obj

Function export_to_obj

diffusers/src/diffusers/utils/testing_utils.py:582–599  ·  view source on GitHub ↗
(mesh, output_obj_path: str = None)

Source from the content-addressed store, hash-verified

580
581
582def export_to_obj(mesh, output_obj_path: str = None):
583 if output_obj_path is None:
584 output_obj_path = tempfile.NamedTemporaryFile(suffix=".obj").name
585
586 verts = mesh.verts.detach().cpu().numpy()
587 faces = mesh.faces.cpu().numpy()
588
589 vertex_colors = np.stack([mesh.vertex_channels[x].detach().cpu().numpy() for x in "RGB"], axis=1)
590 vertices = [
591 "{} {} {} {} {} {}".format(*coord, *color) for coord, color in zip(verts.tolist(), vertex_colors.tolist())
592 ]
593
594 faces = ["f {} {} {}".format(str(tri[0] + 1), str(tri[1] + 1), str(tri[2] + 1)) for tri in faces.tolist()]
595
596 combined_data = ["v " + vertex for vertex in vertices] + faces
597
598 with open(output_obj_path, "w") as f:
599 f.writelines("\n".join(combined_data))
600
601
602def export_to_video(video_frames: List[np.ndarray], output_video_path: str = None) -> str:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected