The 'stlTools' toolbox is a collection of functions, samples and demos to illustrate how to deal with STL files. Some of them are contributions published in Matlab Central and properly referenced here. This toolbox contains the following files:
(*) stlGetFormat: identifies the format of the STL file and returns 'binary' or 'ascii'. This file is inspired in the 'READ-stl' file written and published by Adam H. Aitkenhead
(*) stlReadAscii: reads an STL file written in ascii format. This file is inspired in the 'READ-stl' file written and published by Adam H. Aitkenhead
(*) stlReadBinary: reads an STL file written in binary format. This file is inspired in the 'READ-stl' file written and published by Adam H. Aitkenhead
(*) stlRead: uses 'stlGetFormat', 'stlReadAscii' and 'stlReadBinary' to make STL reading independent of the format of the file
(*) stlWrite: writes an STL file in 'ascii' or 'binary' formats. This is written and published by Sven Holcombe (*) stlSlimVerts: finds and removes duplicated vertices. This function is written and published by Francis Esmonde-White as PATCHSLIM
(*) stlGetVerts: returns a list of vertices that are 'opened' or 'closed' depending on the 'mode' input parameter. An 'open' vertice is the one that defines an open side. An open side is the one that only takes part of one triangle
(*) stlDelVerts: removes a list of vertices from STL files
(*) stlAddVerts: adds the new vertices from a list (and consequently, new faces) to a STL object
(*) stlPlot: is an easy way to plot an STL object
(*) stlDemo: is a collection of examples about how to use stlTools
(*) femur_binary: is an ascii STL sample used in 'stlDemo'. It is published by Eric Johnson
(*) sphere_ascii: is a binary STL sample
Pau Micó (2020). stlTools (https://www.mathworks.com/matlabcentral/fileexchange/51200-stltools), MATLAB Central File Exchange. Retrieved .
Works like a charm.
I downloaded the files today (7/01/2019) and got an error. I think the demo file currently loads a non-excisting stl. If I change the name everything works as expected.
Hello, I have a ASCII STL fie and i want to display it in matlab. but I dont know how to open it and to use all theses functions because I am beginner in Matlab. could you just tell me how to open it or where should i make changes. Thank in advance
I found that I can improve the performace of stlReadAscii.m from around 81seconds to around 12seconds on one of my larger .stl files (R2017a).
normals = char(content(logical(strncmp(content,'facet normal',12))));
normals = str2num(normals_char(:,13:end));
normals_char = char(content(logical(strncmp(content,'facet normal',12))));
normals = zeros(size(normals_char,1),3);
for normal_id = 1:size(normals,1)
normals(normal_id,:) = sscanf(normals_char(normal_id,13:end),'%f',[1 3]);
Same for the vertices. Seems odd that the 'for loop' is faster, but I guess that matlabs interpreter has gotten a little more clever over time. It seems that the str2num() function is actually quite slow (Matlab even throws a warning on that). But of course the code above doesn't read as nice as your version. You can choose if you want to change it.
Apart from that I love the code! Well organized and clearly written. Just does its job well.
Sunny regards from Munich ;)
When I read in my stl, the faces list has floating point numbers, does anyone know why this is?
Is there anyway to offset STL File in 3D direction. I know surf2solid turns thin surface to a solid part. But what I'm looking for is to offset STL body. for example positive offset factor makes the body bigger and return new vertices, and negative offset factor make the body smaller and also return the new vertices.
The function (transformSTL.m) in the IGES Toolbox by Per Bergström does only transform STL. But what I'm looking for is something like( offsetIGES.m ) in the same toolbox except for STL instead of IGES file format.
Is there any function that does that?
Thank you so much
Line 54 in stlReadAscii should be 'nvert = size(vertices,1);' instead of 'length(vertices)' to avoid problems with small .stl files
works for both ascii and binary formats though ascii files tend to read slower. Not sure if this is just the nature of loading an uncompressed format or if more optimization is need but it works really well overall.
for stlAddVerts you say it adds the new vertices from a list (and consequently, new faces) to a STL object.
can you put an example and include a list ?
Really good! Compute fast!
It's really really very helpful,thanks!!!
Fantastic! I have found a problem with stlDelVerts, though. If vdel contains any zeros, it throws a "Subscript indices must either be real positive integers or logicals" error.
It always returns my an error saying either "Undefined function or variable" of the file im trying to read or "Not enough input arguments.". Is someone familiar with such problem with the stl toolbox? Thanks in advance!
very usefull. Thx.
Great, thank you!
Demo creates an error when it runs. It was looking for 'sphere300faces.stl' but the included sphere is 'sphere_ascii.stl'. Changing the name of the still file or the code fixes it.
stlReadAscii.m function is reviewed with the suggestion made by Philipp Ertl
new tags added