Main Content

writeSurfaceMesh

Write surface mesh to standard mesh file formats

Since R2022b

    Description

    writeSurfaceMesh(mesh,fileName) writes the surface mesh mesh to a supported mesh file format with the specified filename.

    example

    writeSurfaceMesh(mesh,fileName,Encoding=enc) additionally specifies the encoding type as "ascii" or "binary".

    Examples

    collapse all

    Define mesh vertices and faces for a surface mesh.

    vertices = [0 0 0; 0 0 1; 0 1 1; 0 0 2; 1 0.5 1];
    faces = [1 2 3; 2 3 4; 2 3 5];

    Create and display the surface mesh.

    mesh = surfaceMesh(vertices,faces);
    surfaceMeshShow(mesh)

    Write the surface mesh data into an STL file.

    writeSurfaceMesh(mesh,"ManifoldMesh.stl")

    Write the surface mesh data into a PLY file.

    writeSurfaceMesh(mesh,"ManifoldMesh.ply")

    Input Arguments

    collapse all

    Surface mesh to write, specified as a surfaceMesh object.

    Filename to write surface mesh data to, specified as a character vector or string scalar. You must specify the file extension along with the filename. If a file of specified name already exists, it must have write permissions. The function supports these standard mesh file formats:

    • STL — Stereolithography file format

    • PLY — Polygon file format

    • FBX® — Autodesk® Filmbox

    • OBJ — Wavefront® OBJ

    • GLTF — GL Transmission Format, glTF™

    • GLB — GL Transmission Format Binary File

    • OFF — Object File Format

    • DAE — COLLADA™ Digital Asset Exchange

    Encoding type in which to write surface mesh data to the file, specified as "ascii" or "binary".

    Data Types: char | string

    Limitations

    • You cannot write these attributes into an STL file.

      • Vertex normals

      • Vertex colors

      • Face colors

    • You cannot write face normals and face colors into a PLY file.

    • You can write only mesh vertices, vertex colors, and mesh triangular faces to the FBX file format.

    • You can write only mesh vertices and mesh triangular faces to the OBJ, GLTF, GLB, OFF, DAE, STEP, STP, IGES, or IGS file formats.

    • The function supports only "ascii" encoding for the OBJ, GLTF, GLB, OFF, and DAE file formats, and only "binary" encoding for the FBX file format.

    Version History

    Introduced in R2022b

    expand all