in commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/stl/StlBoundaryWriteHandler3D.java [136:169]
public void writeFacets(final Stream<? extends FacetDefinition> facets, final GeometryOutput out) {
// write the triangle data to a buffer and track how many we write
int triangleCount = 0;
final ByteArrayOutputStream triangleBuffer = new ByteArrayOutputStream(initialBufferSize);
try (BinaryStlWriter dataWriter = new BinaryStlWriter(triangleBuffer)) {
final Iterator<? extends FacetDefinition> it = facets.iterator();
FacetDefinition facet;
int attributeValue;
while (it.hasNext()) {
facet = it.next();
attributeValue = getFacetAttributeValue(facet);
for (final List<Vector3D> tri :
EuclideanUtils.convexPolygonToTriangleFan(facet.getVertices(), t -> t)) {
dataWriter.writeTriangle(
tri.get(0),
tri.get(1),
tri.get(2),
facet.getNormal(),
attributeValue);
++triangleCount;
}
}
}
// write the header and copy the data
writeWithHeader(triangleBuffer, triangleCount, out);
}