visualdynamics.io.stl¶
stl
¶
STL triangle meshes, read and written with the standard library.
An STL file is already tessellated — the CAD program did the hard work
at export — so importing one is reading triangles and handing them to
the geometry as face elements. The format carries no units (the
object imports unit-less and the units pane asks, like any other
undeclared source) and, in its binary form, no part names: a
binary file arrives as one block named for the file. ASCII STL can
hold several solid <name> sections, and each becomes its own
named block — but CAD tools rarely write it, and 3MF (threemf) is
the format that actually preserves an assembly's parts. This importer
exists because everything exports STL.
Vertices repeat per triangle in the file; identical coordinates are merged on import so shared edges share nodes.
Functions:
| Name | Description |
|---|---|
mesh_geometry |
A Geometry from [(name, (n, 3, 3) corner arrays)] — one named |
load |
Read an STL file as a geometry of triangle face elements. |
faces_as_triangles |
[(block id, (n, 3, 3) corners)] from the face elements — quads |
save |
Write the geometry's face elements as binary STL. |
Classes¶
Functions:¶
mesh_geometry
¶
mesh_geometry(
parts: list[tuple[str, ndarray]],
length_unit: str | None = None,
) -> Geometry
A Geometry from [(name, (n, 3, 3) corner arrays)] — one named block per part, vertices merged where coordinates are identical.
Source code in src/visualdynamics/io/stl.py
load
¶
load(
path: str | PathLike, length_unit: str | None = None
) -> Geometry
Read an STL file as a geometry of triangle face elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or path - like
|
The |
required |
length_unit
|
str
|
What the file's numbers are in — STL cannot say. Undeclared, the geometry imports unit-less and units are defined later. |
None
|
Returns:
| Type | Description |
|---|---|
Geometry
|
Triangles as face elements; one block per ASCII |
Source code in src/visualdynamics/io/stl.py
faces_as_triangles
¶
faces_as_triangles(
geometry: Geometry,
) -> list[tuple[int, ndarray]]
[(block id, (n, 3, 3) corners)] from the face elements — quads split along a diagonal, higher-order faces read by their corner nodes, lines and volumes left out.
Source code in src/visualdynamics/io/stl.py
save
¶
save(
obj: Geometry,
path: str | PathLike,
unit_system: Any = None,
) -> None
Write the geometry's face elements as binary STL.
STL cannot name parts or declare units: the blocks flatten into
one solid, and the numbers are metres (the stored SI) unless a
unit_system says to write its own length unit instead. A
geometry with no face elements is refused — there is nothing an
STL can hold of it.