Export¶
Write a mesh to a file (SPEC S-53, S-54, S-55)
Write a mesh to a file (SPEC S-53, S-54, S-55).
The way out of the library. pybosl2.vnf.VNF.export() and
export() are the calls a user makes; this module holds the format
writers behind them.
Every format here is pure data, so it is written by pybosl2 itself with no native runtime involved (S-54, A-2): a mesh built with nothing but numpy can be saved with nothing but numpy. Formats that are a CAD kernel’s own (3MF, AMF) are the kernel’s job and are refused by name rather than half-written.
Winding follows the rest of the library: faces counter-clockwise seen from outside, so
volume() is positive for a solid. Normals are computed per face on the way
out where the format wants them.
-
pybosl2.export.FORMATS : dict[str, str] =
{'.obj': 'obj', '.off': 'off', '.ply': 'ply', '.stl': 'stl'}¶ The mesh formats pybosl2 writes itself, mapped from the file suffixes that select them.
"stl"is binary;"stla"is the ASCII form, chosen with an explicitformat=.
-
pybosl2.export.format_for(path, explicit=
None)[source]¶ Return the writer name for path, or the explicit override.
- Parameters:¶
- Returns:¶
The writer name.
- Raises:¶
Bosl2ValueError – If the format is unknown, or belongs to a CAD kernel this library does not carry.
- Return type:¶
str
Examples
>>> format_for("bracket.stl") 'stl' >>> format_for("bracket.stl", explicit="stla") 'stla'
-
pybosl2.export.write_mesh(mesh, path, *, file_format=
None, check=True)[source]¶ Write mesh to path (SPEC S-53).
- Parameters:¶
- mesh : VNF¶
the mesh to write.
- path : Path¶
the destination; its suffix picks the format unless format says otherwise.
- file_format : str | None¶
explicit format name, overriding the suffix. Spelled with the
file_prefix becauseformatis a Python builtin.- check : bool¶
validate watertightness and winding first (SPEC S-55).
Falsefor a surface that is open on purpose.
- Returns:¶
The path written, so the call can be chained or logged.
- Raises:¶
Bosl2ValueError – If the format is unknown, or check is on and the mesh is not a solid.
- Return type:¶