STL¶
STL reader & writer.
https://en.wikipedia.org/wiki/STL_(file_format)
- class design3d.stl.Stl(triangles: List[Triangle3D], name: str = '')[source]¶
Bases:
object
STL files are used to represent simple 3D models, defined using triangular 3D faces.
Initially it was introduced as native format for 3D Systems Stereo-lithography CAD system, but due to its extreme simplicity, it was adopted by a wide range of 3D modeling, CAD, rapid prototyping and 3D printing applications as the simplest 3D model exchange format.
STL is extremely bare-bones format: there are no complex headers, no texture / color support, no units specifications, no distinct vertex arrays. Whole model is specified as a collection of triangular faces.
There are two versions of the format (text and binary), this spec describes binary version.
- clean_flat_triangles(threshold: float = 1e-12) Stl [source]¶
Clean the STL object by removing flat triangles with an area below a threshold.
- Returns:
A new instance of the Stl class with the flat triangles removed.
- Return type:
- extract_points()[source]¶
Extract the unique points from the STL object.
- Returns:
A list of unique Point3D objects.
- Return type:
List[d3d.Point3D]
- extract_points_bis(min_distance: float = 0.001)[source]¶
Extract the unique points from the STL object.
- Returns:
A list of unique Point3D objects.
- Return type:
List[d3d.Point3D]
- classmethod from_binary_stream(stream, distance_multiplier: float = 0.001)[source]¶
Create an STL object from a binary stream.
- Parameters:
stream (BinaryFile) – The binary stream containing the STL data.
distance_multiplier (float) – (optional) The distance multiplier. Defaults to 0.001.
- Returns:
An instance of the Stl class.
- Return type:
- classmethod from_display_mesh(mesh: Mesh3D)[source]¶
Create an STL object from a display mesh.
- Parameters:
mesh (d3d.display.DisplayMesh3D) – The display mesh to convert to an STL object.
- Returns:
An instance of the Stl class.
- Return type:
- classmethod from_file(filename: str = None, distance_multiplier: float = 0.001)[source]¶
Import stl from file.
- classmethod from_text_stream(stream, distance_multiplier: float = 0.001)[source]¶
Create an STL object from a text stream.
- Parameters:
stream (StringFile) – The text stream containing the STL data.
distance_multiplier (float) – (optional) The distance multiplier. Defaults to 0.001.
- Returns:
An instance of the Stl class.
- Return type:
- classmethod load_from_file(filepath: str, distance_multiplier: float = 0.001)[source]¶
Load an STL object from a file.
- Parameters:
filepath (str) – The path to the STL file.
distance_multiplier (float) – (optional) The distance multiplier. Defaults to 0.001.
- Returns:
An instance of the Stl class.
- Return type:
- classmethod points_from_file(filename: str, distance_multiplier=0.001)[source]¶
Read points from an STL file and return a list of points.
- Parameters:
filename (str) – The path to the STL file.
distance_multiplier (float) – (optional) The distance multiplier. Defaults to 0.001.
- Returns:
A list of Point3D objects.
- Return type:
List[d3d.Point3D]
- save_to_binary_file(filepath, distance_multiplier=1000)[source]¶
Save the STL object into a binary file.
- Parameters:
filepath (str) – The path to the STL file.
distance_multiplier (float) – (optional) The distance multiplier. Defaults to 1000.
- Returns:
An instance of the Stl class.
- Return type:
- save_to_stream(stream, distance_multiplier=1000)[source]¶
Save the STL object into a binary file.
- Parameters:
stream – The binary stream containing the STL data.
distance_multiplier (float) – (optional) The distance multiplier. Defaults to 1000.
- Returns:
An instance of the Stl class.
- Return type:
- to_closed_shell()[source]¶
Convert the STL object to a closed triangle shell.
- Returns:
A closed triangle shell representation of the STL object.
- Return type: