I figured that if I was going to nitpick every STL tool on the FEX, it's only fair that I at least put my own questionable work on the table.
So that's the core of this mini-toolbox. Both the encoder and decoder support binary and ASCII formats and they do basic mesh cleanup on both import/export. Both offer optional verbose console output for demonstration and troubleshooting purposes. Per-face color data is supported using standard unit-scale color tables. Both VisCAM and Magics attribute formatting are supported. Per-object color and reflectance parameters used by Magics, Fusion 360, and Inventor are supported to the extent that they are publicly documented.
stlread_legacy(): Read STL files. Outputs FV struct or F,V lists. Does face normal correction by default.
stlwrite_legacy(): Write STL files. Accepts multiple data formats. Output precision in ASCII mode can be optionally specified.
stlgetformat(): Determine the encoding type of an STL file.
split_multistl(): Split a nonstandard multiobject STLA file into separate proper ASCII STL files.
These first three tools were originally rooted in Pau Micó's stlTools (FEX #51200), though more detailed historical attributions, bugfixes, and changes are noted in the commentary.
There are other related tools. Many of these are used by the encoder/decoder, but others are just simply convenient tools to have. I've posted earlier, less competent versions of many of these tools on the forum already (which I guess I have to go fix now).
t2fv(): Succinctly convert between F,V lists and other mesh formats
tricat(): Combine multiple triangulated meshes into a single composite model.
quad2tri(): Convert a quad mesh to a triangular mesh by diagonal or cross subdivision.
getfacearea(): Get area for the triangles of a mesh.
getfaceperim(): Get the side lengths or total perimeter of the triangles of a mesh.
getfaceangles(): Get the interior angles of the triangles in a mesh.
getfacenormals(): Get the unit normals (and optionally normal magnitude) for all faces.
getfacecenters(): Get the face centers for a mesh. Supports many triangle center types.
getincidentfaces(): Find the faces incident on a selection of vertices or edges.
getedgetype(): Get a minimal list of unique edges for a mesh, and the number of faces they bound.
prunebadverts(): Remove optionally selected or non-finite vertices and the faces they bound.
pruneunusedverts(): Remove unused vertices and remap F to match.
prunedupeverts(): Remove duplicate vertices and remap F. Sorting is stable and consistent across versions.
prunedupefaces(): Remove duplicate or coincident faces. Sorting is stable and consistent across versions.
prunedegeneratefaces(): Remove degenerate faces, with control over which types are removed.
mono2fv()/fv2mono(): Convert between F,V lists and monolithic ordered coordinate arrays.
v2e()/e2v(): Convert between vertex index lists and edge lists.
fixboundaries(): Arrange an unsorted concatenated jumble of edge segments into a cell array of contiguous curves.
packattributes()/unpackattributes(): Convert between color tables and a list of uint16 packed fields as used by STL files.
splitconncomp(): Split a mesh into connected components based on either vertex-connectivity or edge-connectivity.
extrude(): Extrude or loft a 2D mesh or simple height map to create a closed 3D model.
offsetfaces(): Simple demonstration of face offsetting.
Unpack the archive, add the resulting folder (and its subfolders) to the path. Check the demo files:
stltool_demos.m: Demos for the encoder and decoder
assortedemos.m: Demos for everything else
Example STL files are included.
With a few exceptions, everything should run in any MATLAB version that you might be using. I tested these tools in R2009b, R2015b, and R2019b. The demo files illustrate usage of things across a wide range of versions, so pay attention to the comments. Not all parts of every demo will work in every version. The only other version dependency of note is splitconncomp() which relies on R2015b or newer. There may be issues in versions older than R2009b, but that's not something I can test or predict.
While MATLAB has had a built-in STL encoder/decoder since R2018b, and some of the other toolbox functionality is available via classes such as triangulation(), this toolbox should help if you want to create a more unified, version-agnostic workflow. Tools like packattributes()/unpackattributes() work with the canonical STL tools, while others support both modern triangulation classes (triangulation()/delaunayTriangulation()) and legacy triangulation classes (TriRep()/DelaunayTri()).
引用格式
DGM (2025). DGM's Legacy STL Tools (https://ww2.mathworks.cn/matlabcentral/fileexchange/182013-dgm-s-legacy-stl-tools), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2019b
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!legacy_stl_tools/TOOLBOX
legacy_stl_tools/TOOLBOX/demos
legacy_stl_tools/TOOLBOX/demos/private
版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.1.1 | fixed some minor dumb things i did
|
||
1.1 | Added support for other proprietary color data formats.
|
||
1.0.2 | edited description |
||
1.0.1 | description edit |
||
1.0.0 |