Main Content

writeSurfaceMesh

Write 3-D surface mesh into STL or PLY file

Since R2022b

    Description

    example

    writeSurfaceMesh(mesh,fileName) writes the surface mesh mesh into an STL or PLY file with the specified filename.

    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)

    Figure contains an object of type images.ui.graphics3d.viewer3d.

    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 .stl or .ply extension along with the filename. If a file of specified name already exists, it must have write permissions.

    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.

    Version History

    Introduced in R2022b