Main Content

stlwrite

Create STL file from triangulation

Description

stlwrite(TR,filename) writes a triangulation TR to a binary STL file filename. The triangulation can be either a triangulation object or a 2-D delaunayTriangulation object.

stlwrite(TR,filename,fileformat) also specifies a file format for the written file. fileformat can be either 'binary' (default) or 'text'.

example

stlwrite(___,Name,Value) specifies additional options for writing to the STL file using one or more Name,Value pair arguments for either of the previous syntaxes. For example, stlwrite(TR,'stlbinary','Attribute',attributes) also writes a uint16 vector of attributes for each triangle in TR.

Examples

collapse all

Create and plot a 2-D triangulation object.

P = [2.5 8.0; 6.5 8.0; 2.5 5.0; 6.5 5.0; 1.0 6.5; 8.0 6.5];
T = [5 3 1; 3 2 1; 3 4 2; 4 6 2];
TR = triangulation(T,P);
triplot(TR)

Write the triangulation to a text file named tritext.stl.

stlwrite(TR,'tritext.stl','text')

Input Arguments

collapse all

Triangulation, specified as a triangulation object or a 2-D delaunayTriangulation object.

STL file name, specified as a character vector or scalar string. The file name must end with the .stl or .STL extension.

Example: 'stltextfile.stl'

File format, specified as either 'binary' or 'text'.

Name-Value Arguments

Example: stlwrite(TR,'stltext','SolidIndex',solidIDs)

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify the name and value pair arguments in any order as Name1,Value1,Name2,Value2.

Binary attributes, specified as a uint16 vector. When the input file is a binary file, attributes can contain coded information about the triangles. Its length must be equal to the number of triangles in the triangulation. This parameter is not supported when the input file is a text file.

Solid grouping index, specified as a vector of identification numbers. When the input file is a text file, the identification numbers must assign each triangle to a grouping of triangles in the triangulation. The length of the vector must be equal to the number of triangles in the triangulation. This parameter is not supported when the input file is binary.

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2018b