add explicit fast mode to STL exporters
@@ -236,11 +236,14 @@ def obj_loads(content: str) -> List[MeshTransformer]:
return meshes
-def stl_dumps(mesh: MeshBuilder) -> str:
+def stl_dumps(mesh: MeshBuilder, *, fast=True) -> str:
"""Returns the `STL`_ data as string for the given `mesh`.
This function triangulates the meshes automatically because the `STL`_
format supports only triangles as faces.
+ The `fast` mode uses a shortcut for faces with less than 6 vertices
+ which may not work for concave faces!
+
This function does not check if the mesh obey the
`STL`_ format `rules <http://www.fabbers.com/tech/STL_Format>`_:
@@ -253,7 +256,7 @@ def stl_dumps(mesh: MeshBuilder) -> str:
"""
lines: List[str] = [f"solid STL generated by ezdxf {__version__}"]
- for face in mesh.tessellation(max_vertex_count=3):
+ for face in mesh.tessellation(max_vertex_count=3, fast=fast):
if len(face) < 3:
continue
try:
@@ -274,14 +277,17 @@ def stl_dumps(mesh: MeshBuilder) -> str:
STL_SIGNATURE = (b"STL generated ezdxf" + b" " * 80)[:80]
-def stl_dumpb(mesh: MeshBuilder) -> bytes:
+def stl_dumpb(mesh: MeshBuilder, *, fast=True) -> bytes:
"""Returns the `STL`_ binary data as bytes for the given `mesh`.
+ The `fast` mode uses a shortcut for faces with less than 6 vertices
+ which may not work for concave faces!
+
For more information see function: :func:`stl_dumps`
"""
data: List[bytes] = [STL_SIGNATURE, b"0000"]
count = 0
- for face in mesh.tessellation(max_vertex_count=3):
+ for face in mesh.tessellation(max_vertex_count=3, fast=fast):
try:
n = normal_vector_3p(face[0], face[1], face[2])
except ZeroDivisionError:
