Class BinaryStlWriter
java.lang.Object
org.apache.commons.geometry.io.euclidean.threed.stl.BinaryStlWriter
- All Implemented Interfaces:
Closeable, AutoCloseable
Low-level class for writing binary STL content.
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance for writing to the given output. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidwriteHeader(byte[] headerContent, int triangleCount) Write binary STL header content.voidwriteTriangle(Vector3D p1, Vector3D p2, Vector3D p3, Vector3D normal) Write a triangle to the output using a default attribute value of 0.voidwriteTriangle(Vector3D p1, Vector3D p2, Vector3D p3, Vector3D normal, int attributeValue) Write a triangle to the output.
-
Constructor Details
-
BinaryStlWriter
Construct a new instance for writing to the given output.- Parameters:
out- output stream to write to
-
-
Method Details
-
writeHeader
Write binary STL header content. IfheaderContentis null, the written header will consist entirely of zeros. Otherwise, up to 80 bytes fromheaderContentare written to the header, with any remaining bytes of the header filled with zeros.- Parameters:
headerContent- bytes to include in the header; may be nulltriangleCount- number of triangles to be included in the content- Throws:
UncheckedIOException- if an I/O error occurs
-
writeTriangle
Write a triangle to the output using a default attribute value of 0. Callers are responsible for ensuring that the number of triangles written matches the number given in the header.If a normal is given, the vertices are ordered using the right-hand rule, meaning that they will be in a counter-clockwise orientation when looking down the normal. Thus, the given point ordering may not be the ordering used in the written content.
- Parameters:
p1- first pointp2- second pointp3- third pointnormal- triangle normal; may be null- Throws:
UncheckedIOException- if an I/O error occurs
-
writeTriangle
public void writeTriangle(Vector3D p1, Vector3D p2, Vector3D p3, Vector3D normal, int attributeValue) Write a triangle to the output. Callers are responsible for ensuring that the number of triangles written matches the number given in the header.If a non-zero normal is given, the vertices are ordered using the right-hand rule, meaning that they will be in a counter-clockwise orientation when looking down the normal. If no normal is given, or the given value cannot be normalized, a normal is computed from the triangle vertices, also using the right-hand rule. If this also fails (for example, if the triangle vertices do not define a plane), then the zero vector is used.
- Parameters:
p1- first pointp2- second pointp3- third pointnormal- triangle normal; may be nullattributeValue- 2-byte STL triangle attribute value- Throws:
UncheckedIOException- if an I/O error occurs
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-