STL (Stereolithography) format is a simple, openly documented format for describing the surface of an object as a triangular mesh. Every triangle is represented by the unit normal and vertices (ordered by the right-hand rule) using a three-dimensional Cartesian coordinate system.
Use the STL import module to perform the import procedure:
STLImport_xx.yy_zz.tx
where:
To import an .stl file using the STLImport module:
OdStlImport
object.OdStlImportRes import(const OdString &strFilePath);
OdStlImportRes import(const OdStreamBufPtr& pStreamBuf);
The difference between the functions is that the first function imports from a file while the second one imports from a stream.
When STL data is imported, you can get a shell as an array of vertices, facets (triangles), and facet normals using the following function:
OdStlImportRes getShell(OdGePoint3dArray &vertices,
OdUInt32Array &faces,
OdGeVector3dArray &normals,
OdUInt8 flags = 0) const
where flags
can take the following values:
kFixNormals
— Check the normals and correct them in
the following cases:
kUnifyDuplicatedVertices
— Unify duplicating vertices.
If this flag is set, the array of vertices contains only non-repeating
vertices.
kCalcNormalsAtVertices
— Perform a primitive
calculation of the normals at vertices. Normals at vertices can be used in
smooth-shaded rendering modes.
kUnifyDuplicatedVertices
flag is not set, the
normals at a vertex are simply equal to the normals of faces that
contain the vertex.
kUnifyDuplicatedVertices
flag is set, the normal
at a vertex is calculated by averaging the normals at faces that
contain the vertex.
Note: This method of calculation is very rough and works well only for smooth shells. For example, for cubes, this method gives poor results. In such cases, more complex algorithms on the user side are required.
For more information about how to create
a body (FacetModeler::Body
) or a solid
(OdDb3dSolidPtr
) using the obtained arrays of facets and
vertices, see the following:
This example illustrates importing from an .stl file and getting the shell
using the getShell()
function.
STLFileImport::OdStlImportModulePtr stlModule = odrxDynamicLinker()->loadModule(OdStlImportModuleName);
STLFileImport::OdStlImportPtr stlImport = stlModule->create();
stlImport->import(fileName);
OdGePoint3dArray vertices;
OdUInt32Array faces;
OdGeVector3dArray normals;
OdUInt8 flags = 0;
SETBIT(flags, STLFileImport::OdStlImport::kUnifyDuplicatedVertices, true);
stlImport->getShell(vertices, faces, normals, flags);
Creating Bodies using the Facet Modeler
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|