cadquery
cadquery copied to clipboard
Allow STL export in binary format in addition to ASCII
Currently the CadQuery export STL feature makes use of OCP.StlAPI_Writer
This writes an ASCII STL file but it would be helpful (to preserve high precision) to be able to write a binary STL file.
Perhaps an option to the CadQuery export could be added that allows STL files to be saved in binary format, it looks like OCCT supports binary STL files
Links to OCCT documentation: Convert and write shape to STL format. file is written in binary if aAsciiMode is False otherwise it is written in Ascii (by default) https://dev.opencascade.org/doc/occt-7.0.0/refman/html/class_stl_a_p_i.html
I tested exporting binary STL.
exporters.export - added "ascii" to the opt dict.
https://github.com/lorenzncode/cadquery/blob/e53bdc0951e67da23cccf31f5b334022b23af654/cadquery/occ_impl/exporters/init.py#L105-L109
example usage:
exporters.export(result, "test_binary.stl", "STL",0.05, 0.1, opt={"ascii": False})
The change to Shape.exportStl signature was to add a bool parameter to control ASCII or binary output.
def exportStl(
self,
fileName: str,
tolerance: float = 1e-3,
angularTolerance: float = 0.1,
ascii: bool = True,
) -> bool:
example usage:
result.val().exportStl("test_binary2.stl", 0.05, 0.1, False)
Any feedback for/against adding this feature?
@lorenzncode I would be for adding it.
+1