XelToFab
API Reference

save_mesh

Export an extracted 3D mesh to file

Import

from xeltofab import save_mesh
# or
from xeltofab.io import save_mesh

Signature

def save_mesh(state: PipelineState, path: str | Path) -> None

Parameters

ParameterTypeDescription
statePipelineStateA processed state containing mesh data
pathstr | PathOutput file path. The format is determined by the file extension.

Supported output formats

Any format supported by trimesh, including:

FormatExtension
STL.stl
OBJ.obj
PLY.ply

Behavior

save_mesh uses the best_vertices property on the state, which returns smoothed vertices if Taubin smoothing has been applied, or raw vertices otherwise. This ensures exported meshes always use the highest-quality geometry available.

2D limitation

save_mesh only supports 3D meshes. For 2D fields, the pipeline produces contours rather than triangle meshes. Attempting to save a 2D result raises a ValueError:

ValueError: 2D contour export to .stl not supported — use viz for 2D output

For 2D results, use the visualization functions to render contours or save them as images.

Example

from xeltofab import load_field, process, save_mesh

state = process(load_field("field_3d.npy"))

# Export as STL
save_mesh(state, "output.stl")

# Export as OBJ
save_mesh(state, "output.obj")

Errors

  • ValueError — no mesh data (extraction has not been run), or the state contains 2D contours instead of a 3D mesh

Outline