40model.stl Module
40.1Overview
The model.stl
module provides measures to read/write files in STL format for 3D models.
Below is an example to read a STL file and to print information of faces it contains.
solid = model.stl.solid('example.stl')
println(solid.name || solid.header)
solid.faces.each {|face|
printf('normal: %g, %g, %g\n', face.normal.x, face.normal.y, face.normal.z)
printf('vertex1: %g, %g, %g\n', face.vertex1.x, face.vertex1.y, face.vertex1.z)
printf('vertex2: %g, %g, %g\n', face.vertex2.x, face.vertex2.y, face.vertex2.z)
printf('vertex3: %g, %g, %g\n', face.vertex3.x, face.vertex3.y, face.vertex3.z)
}
40.2model.stl.face Class
An instance of model.stl.face
class provides properties of face that consists of one normal vector and three vertices.
40.2.1Property
Property | Type | R/W | Explanation |
---|---|---|---|
normal |
vertex |
R | Normal vector. |
vertex1 |
vertex |
R | 1st vertex. |
vertex2 |
vertex |
R | 2nd vertex. |
vertex3 |
vertex |
R | 3rd vertex. |
40.3model.stl.solid Class
An instance of model.stl.solid
class represents a top-level data in STL format.
40.3.1Property
Property | Type | R/W | Explanation |
---|---|---|---|
header |
string |
R | This is only valid for binary format and is set to `nil` for ASCII. |
name |
string |
R | This is only valid for ASCII format and is set to `nil` for binary. |
faces |
iterator |
R |
An iterator that returns instances of model.stl.face . |
40.3.2Constructor
stl.solid(stream:stream) {block?}
Parses a file in STL format from stream
and creates an instance of model.stl.solid
that contains an iterator of model.stl.face
representing faces in the STL. It can read both binary and ASCII format of STL.
If block
is specified, it would be evaluated with a block parameter |solid:model.stl.solid|
, where solid
is the created instance. In this case, the block's result would become the function's returned value.