Class ObjWriter.MeshBuffer

java.lang.Object
org.apache.commons.geometry.io.euclidean.threed.obj.ObjWriter.MeshBuffer
Enclosing class:
ObjWriter

public final class ObjWriter.MeshBuffer extends Object
Class used to produce OBJ mesh content from sequences of facets. As facets are added to the buffer their vertices and normals are converted to OBJ vertex and normal definition strings. Vertices and normals that produce equal definition strings are shared among all of the facets in the buffer. This process converts the facet sequence into a compact mesh suitable for writing as OBJ file content.

Ideally, no vertices or normals would be duplicated in an OBJ file. However, when working with very large geometries it may not be desirable to store values in memory before writing to the output. This is where the batchSize property comes into play. The batchSize represents the maximum number of faces that the buffer will store before automatically flushing its contents to the output and resetting its state. This reduces the amount of memory used by the buffer at the cost of increasing the likelihood of duplicate vertices and/or normals in the output.

  • Method Details

    • add

      public void add(FacetDefinition facet)
      Add a facet to this buffer. If batchSize is greater than -1 and the number of currently stored faces is greater than or equal to batchSize, then the buffer content is written to the output and the buffer state is reset.
      Parameters:
      facet - facet to add
      Throws:
      UncheckedIOException - if an I/O error occurs
    • add

      public void add(PlaneConvexSubset boundary)
      Add a boundary to this buffer. If batchSize is greater than -1 and the number of currently stored faces is greater than or equal to batchSize, then the buffer content is written to the output and the buffer state is reset.
      Parameters:
      boundary - boundary to add
      Throws:
      IllegalArgumentException - if the boundary is infinite
      UncheckedIOException - if an I/O error occurs
    • addVertex

      public int addVertex(Vector3D vertex)
      Add a vertex to the buffer.
      Parameters:
      vertex - vertex to add
      Returns:
      the index of the vertex in the buffer
    • addNormal

      public int addNormal(Vector3D normal)
      Add a normal to the buffer.
      Parameters:
      normal - normal to add
      Returns:
      the index of the normal in the buffer
    • flush

      public void flush()
      Flush the buffer content to the output and reset its state.
      Throws:
      UncheckedIOException - if an I/O error occurs