Scilab Home Page | Wiki | Bug Tracker | Forge | Mailing List Archives | Scilab Online Help | ATOMS
File : Details
Please login or create an account

STL Files

Read and write STL files (ascii and binary formats)
(164 downloads for this version - 730 downloads for all versions)
Details
Version
1.0
A more recent valid version with binaries for Scilab exists: 2.1
Author
Jerome Briot
Maintainer
Jerome Briot
Categories
License
Supported Scilab Version
5.5
Creation Date
August 26, 2016
Description
            Toolbox to read and write STL files (ascii and binary formats)

* Installation:
1. Download and extract the Zip file
2. Run builder.sce script in the sources folder 
3. Run loader.sce script in the sources folder 
4. Run demos in the *demos* folder 

* To read data from a STL file:
t = stlread(filename, fmt)

* To write data to a STL file:
stlwrite(t, filename, fmt)

Arguments:
- filename: a character string containing the path of the STL file
- fmt: a character string specifying the format of the STL file (e.g.
"ascii" or "binary")
- t: a tlist of type stldata

* Data storage:
Data are stored in a tlist of type stldata

The list fields are:
- header: the string at the begining of the STL file
- x: a [3xn] matrix wich represent the X coordinates of the model (one colum per
facet)
- y: a [3xn] matrix wich represent the Y coordinates of the model (one colum per
facet)
- z: a [3xn] matrix wich represent the Z coordinates of the model (one colum per
facet)
- normals: a [3xn] matrix wich represent the normals of the model (one colum per
facet)

* Data display in the Scilab console:

The display of the data is overloaded. Example:

-->t
 t  =
 
 Summary
   Header:    >3D Systems - View: ship.stl                                   
                
   #faces:    828 triangles
   #vertices: 2484 (non unique)

 Vertices coordinates [x y z] (first 5 only)
   2.02900 1.62800 0.91100
   2.22900 1.62800 0.91100
   2.22900 1.67200 0.91100
   2.22900 1.67200 0.91100
   2.02900 1.67200 0.91100
   ...

 Normals coordinates [x y z] (first 5 only)
   0.00000 0.00000 0.00000
   0.00000 0.00000 0.00000
   1.00000 1.00000 1.00000
   0.00000 0.00000 0.00000
   0.00000 0.00000 0.00000
   ...


* 3D model display:
The 3D model is displayed using the plot3d function:

figure

tcolor = 2*ones(1, size(t.x,"c"))

plot3d(t.x, t.y, list(t.z,tcolor));

a = gca()
a.isoview = "on"            
Files (1)
[20.35 kB]
Source code archive

News (0)
Comments (4)     Leave a comment 
Comment from Remo De Donno -- March 17, 2017, 11:49:17 AM    
To whom it may concern,

could you please share an example (demo) for writing an STL from a given surface?
The demos available are only for reading STL.

I have a surface (X,Y,Z) coordinates and I would like to export it in STL format.

Thank you and best regards,
Remo
Answer from Jerome Briot -- March 17, 2017, 02:21:01 PM    
Try this:

[X,Y] = meshgrid(-1:.1:1,-1:.1:1);
Z = X.^2-Y.^2;

[m, n] = size(X)

X = X.'
Y = Y.'
Z = Z.'

idx = []
subidx = [1:n-1 2:n ; 2:n n+2:2*n ; n+1:2*n-1 n+1:2*n-1]
for k = 1:m-1
    idx = [idx subidx+n*(k-1)]    
end

t = tlist(["stldata", "header", "x", "y",
"z", "normals"], "", [], [], [], [])
t.header = ''
t.x = matrix(X(idx), 3, -1)
t.y = matrix(Y(idx), 3, -1)
t.z = matrix(Z(idx), 3, -1)
t.normals = zeros(t.x)

stlwrite(t, "test.stl", "binary")
Answer from Jerome Briot -- March 17, 2017, 03:32:26 PM    
This answer has been deleted.
Comment from Remo De Donno -- March 24, 2017, 04:16:42 PM    
Hi, 

when I try the example I get:

 !--error 999 
mprintf: Wrong number of input arguments: data do not fit with format.
at line       7 of function %stldata_p called by :  
t = tlist(["stldata", "header", "x",
"y","z", "normals"], "", [], [], [], [])


thank you
Answer from Jerome Briot -- March 24, 2017, 08:42:52 PM    
Sorry, there is a faulty line break in the example. 

You should add .. at the end of the line :

t = tlist(["stldata", "header", "x", "y", ..
"z", "normals"], "", [], [], [], [])
Comment from Remo De Donno -- March 27, 2017, 09:30:34 AM    
Hi,

even trying .. I get the same error.

Also trying 

t = tlist(["stldata", "header",
"x","y","z", "normals"], "", [], [], [],
[]) 

(everything on the same line) the error message is the same.

The Scilab version I use is the 5.5.2.

Thank you
Comment from Remo De Donno -- March 27, 2017, 12:33:24 PM    
Hi, 

I solved using the version 2.0 of this utility.

Since the "loader" is not available for this version (and the one of the previous
version
returns an error") the files "stlwrite.sci" and "stlread.sci" are
executed explicitely.
 
Answer from Jerome Briot -- August 11, 2018, 02:23:58 PM    
Hi,

better late than never, but you have to execute builder.sce to generate loader.sce
Leave a comment
You must register and log in before leaving a comment.
Email notifications
Send me email when this toolbox has changes, new files or a new release.
You must register and log in before setting up notifications.