Class ObjWriter
java.lang.Object
org.apache.commons.geometry.io.core.utils.AbstractTextFormatWriter
org.apache.commons.geometry.io.euclidean.threed.obj.ObjWriter
- All Implemented Interfaces:
Closeable, AutoCloseable
Class for writing OBJ files containing 3D polygon geometries.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classClass used to produce OBJ mesh content from sequences of facets. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintGet the number of vertices written to the output.intGet the number of vertex normals written to the output.Create a newObjWriter.MeshBufferinstance with an unlimited batch size, meaning that no vertex definitions are duplicated in the mesh output.meshBuffer(int batchSize) Create a newObjWriter.MeshBufferinstance with the given batch size.voidWrite the boundaries present in the given boundary source using aObjWriter.MeshBufferwith an unlimited size.voidwriteBoundaries(BoundarySource3D src, int batchSize) Write the boundaries present in the given boundary source using aObjWriter.MeshBufferwith the givenbatchSize.voidwriteComment(String comment) Write an OBJ comment with the given value.voidwriteFace(int... vertexIndices) Write a face with the given 0-based vertex indices.voidwriteFace(int[] vertexIndices, int normalIndex) Write a face with the given 0-based vertex indices and 0-based normal index.voidwriteFace(int[] vertexIndices, int[] normalIndices) Write a face with the given vertex and normal indices.voidwriteGroupName(String groupName) Write a group name to the output.voidWrite a mesh to the output.voidwriteObjectName(String objectName) Write an object name to the output.intwriteVertex(Vector3D vertex) Write a vertex and return the 0-based index of the vertex in the output.intwriteVertexNormal(Vector3D normal) Write a vertex normal and return the 0-based index of the normal in the output.Methods inherited from class AbstractTextFormatWriter
close, getDoubleFormat, getLineSeparator, getWriter, setDoubleFormat, setLineSeparator, write, write, write, write, writeNewLine
-
Constructor Details
-
ObjWriter
-
-
Method Details
-
getVertexCount
Get the number of vertices written to the output.- Returns:
- the number of vertices written to the output.
-
getVertexNormalCount
Get the number of vertex normals written to the output.- Returns:
- the number of vertex normals written to the output.
-
writeComment
Write an OBJ comment with the given value.- Parameters:
comment- comment to write- Throws:
UncheckedIOException- if an I/O error occurs
-
writeObjectName
Write an object name to the output. This is metadata for the file and does not affect the geometry, although it may affect how the file content is read by other programs.- Parameters:
objectName- the name to write- Throws:
UncheckedIOException- if an I/O error occurs
-
writeGroupName
Write a group name to the output. This is metadata for the file and does not affect the geometry, although it may affect how the file content is read by other programs.- Parameters:
groupName- the name to write- Throws:
UncheckedIOException- if an I/O error occurs
-
writeVertex
Write a vertex and return the 0-based index of the vertex in the output.- Parameters:
vertex- vertex to write- Returns:
- 0-based index of the written vertex
- Throws:
UncheckedIOException- if an I/O error occurs
-
writeVertexNormal
Write a vertex normal and return the 0-based index of the normal in the output.- Parameters:
normal- normal to write- Returns:
- 0-based index of the written normal
- Throws:
UncheckedIOException- if an I/O error occurs
-
writeFace
Write a face with the given 0-based vertex indices.- Parameters:
vertexIndices- 0-based vertex indices for the face- Throws:
IllegalArgumentException- if fewer than 3 vertex indices are givenIndexOutOfBoundsException- if any vertex index is computed to be outside of the bounds of the elements written so farUncheckedIOException- if an I/O error occurs
-
writeFace
Write a face with the given 0-based vertex indices and 0-based normal index. The normal index is applied to all face vertices.- Parameters:
vertexIndices- 0-based vertex indicesnormalIndex- 0-based normal index- Throws:
IndexOutOfBoundsException- if any vertex or normal index is computed to be outside of the bounds of the elements written so farUncheckedIOException- if an I/O error occurs
-
writeFace
Write a face with the given vertex and normal indices. Indices are 0-based. ThenormalIndicesargument may be null, but if present, must contain the same number of indices asvertexIndices.- Parameters:
vertexIndices- 0-based vertex indices; may not be nullnormalIndices- 0-based normal indices; may be null but if present must contain the same number of indices asvertexIndices- Throws:
IllegalArgumentException- if fewer than 3 vertex indices are given ornormalIndicesis not null but has a different length thanvertexIndicesIndexOutOfBoundsException- if any vertex or normal index is computed to be outside of the bounds of the elements written so farUncheckedIOException- if an I/O error occurs
-
writeBoundaries
Write the boundaries present in the given boundary source using aObjWriter.MeshBufferwith an unlimited size.- Parameters:
src- boundary source containing the boundaries to write to the output- Throws:
IllegalArgumentException- if any boundary in the argument is infiniteUncheckedIOException- if an I/O error occurs- See Also:
-
writeBoundaries
Write the boundaries present in the given boundary source using aObjWriter.MeshBufferwith the givenbatchSize.- Parameters:
src- boundary source containing the boundaries to write to the outputbatchSize- batch size to use for the mesh buffer; pass-1to use a buffer of unlimited size- Throws:
IllegalArgumentException- if any boundary in the argument is infiniteUncheckedIOException- if an I/O error occurs- See Also:
-
writeMesh
Write a mesh to the output. All vertices and faces are written exactly as found. For example, if a vertex is duplicated in the argument, it will also be duplicated in the output.- Parameters:
mesh- the mesh to write- Throws:
UncheckedIOException- if an I/O error occurs
-
meshBuffer
Create a newObjWriter.MeshBufferinstance with an unlimited batch size, meaning that no vertex definitions are duplicated in the mesh output. This produces the most compact mesh but at the most of higher memory usage during writing.- Returns:
- new mesh buffer instance
-
meshBuffer
Create a newObjWriter.MeshBufferinstance with the given batch size. The batch size determines how many faces will be stored in the buffer before being flushed. Faces stored in the buffer share duplicate vertices, reducing the number of vertices required in the file. ThebatchSizeis therefore a trade-off between higher memory usage (high batch size) and a higher probability of duplicate vertices present in the output (low batch size). A batch size of-1indicates an unlimited batch size.- Parameters:
batchSize- number of faces to store in the buffer before automatically flushing to the output- Returns:
- new mesh buffer instance
-