open3d.t.io.write_triangle_mesh#
- open3d.t.io.write_triangle_mesh(filename: os.PathLike, mesh: open3d.t.geometry.TriangleMesh, write_ascii: bool = False, compressed: bool = False, write_vertex_normals: bool = True, write_vertex_colors: bool = True, write_triangle_uvs: bool = True, print_progress: bool = False) bool#
Write a TriangleMesh to a file.
The format is inferred from the file extension.
Supported formats and material/texture export:
npz– full round-trip (geometry + material + all texture maps).glb– via ASSIMP; full PBR single material with embedded textures.gltf– via ASSIMP; full PBR single material with external textures.obj– via ASSIMP; single material exported; texture maps written as external PNG sidecars (<stem>_albedo.png,<stem>_normal.png,<stem>_roughness.png,<stem>_metallic.png,<stem>_ambient_occlusion.png,<stem>_ao_rough_metal.png).fbx– via ASSIMP; best-effort geometry export; texture maps may not be reliably written by the ASSIMP FBX exporter.stl– via ASSIMP; geometry only (positions, faces, normals); materials, UV coordinates, and vertex colors are not supported by STL.ply,off– via legacy Open3D writer; geometry + colors/normals only; materials and UV coordinates are not exported.
Only a single material per mesh is supported. Multiple materials,
triangle_material_ids, per-triangle normals, and animation are not supported.Example: write an OBJ with a textured material:
import open3d as o3d import numpy as np mesh = o3d.t.geometry.TriangleMesh.create_box() mesh.material.set_default_properties() albedo = o3d.t.geometry.Image( np.random.randint(0, 256, (256, 256, 3), dtype=np.uint8)) mesh.material.texture_maps['albedo'] = albedo o3d.t.io.write_triangle_mesh('/tmp/box.obj', mesh)
- Parameters:
filename (os.PathLike) – Path to the output file.
mesh (open3d.t.geometry.TriangleMesh) – The mesh to write.
write_ascii (bool, optional, default=False) – If True, write in ASCII format where supported. Not supported for glb or gltf.
compressed (bool, optional, default=False) – Reserved; not used by current writers.
write_vertex_normals (bool, optional, default=True) – If True, write vertex normals when present.
write_vertex_colors (bool, optional, default=True) – If True, write vertex colors when present (not supported by STL).
write_triangle_uvs (bool, optional, default=True) – If True, write UV coordinates and associated texture maps (not supported by STL or ply/off).
print_progress (bool, optional, default=False) – If True print the writing progress to the terminal.
filename – Path to file.
mesh – The
TriangleMeshobject for I/O.write_ascii – Set to
Trueto output in ascii format, otherwise binary format will be used.compressed – Set to
Trueto write in compressed format.write_vertex_normals – Set to
Falseto not write any vertex normals, even if present on the mesh.write_vertex_colors – Set to
Falseto not write any vertex colors, even if present on the mesh.write_triangle_uvs – Set to
Falseto not write any triangle uvs, even if present on the mesh. Forobjformat, mtl file is saved only whenTrueis set.print_progress – If set to true a progress bar is visualized in the console.
- Returns:
True on success, False on failure.
- Returns:
bool