I/O Functions

OpenMesh provides functions that read and write meshes from and to files: read_trimesh(), read_polymesh() and write_mesh()

import openmesh as om

trimesh = om.read_trimesh("bunny.ply")
polymesh = om.read_polymesh("bunny.ply")
# modify mesh ...
om.write_mesh(trimesh, "bunny.ply")

OpenMesh currently supports five file types: .obj, .off, .ply, .stl and .om

For writing .obj files there is also support for textures. You can pass the path of a texture image and optionally the suffix for the material file, default is “.mat”, but some programs, e.g. Blender expect “.mtl” as suffix

om.write_mesh(
    "out.obj",
    trimesh,
    texture_file="moon.png",
    material_file_extension=".mtl"  # default is ".mat", blender needs ".mtl"
)