maspack.geometry.io
Class WavefrontWriter
java.lang.Object
maspack.geometry.io.MeshWriterBase
maspack.geometry.io.WavefrontWriter
- All Implemented Interfaces:
- MeshWriter
public class WavefrontWriter
- extends MeshWriterBase
Writes meshes to an Alias Wavefront .obj file format
- Author:
- John Lloyd, Jan 2014
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
WavefrontWriter
public WavefrontWriter(java.io.OutputStream os)
throws java.io.IOException
- Throws:
java.io.IOException
WavefrontWriter
public WavefrontWriter(java.io.File file)
throws java.io.IOException
- Throws:
java.io.IOException
WavefrontWriter
public WavefrontWriter(java.lang.String fileName)
throws java.io.IOException
- Throws:
java.io.IOException
getFacesClockwise
public boolean getFacesClockwise()
setFacesClockwise
public void setFacesClockwise(boolean enable)
getZeroIndexed
public boolean getZeroIndexed()
setZeroIndexed
public void setZeroIndexed(boolean enable)
writeString
public void writeString(java.lang.String str)
throws java.io.IOException
- Throws:
java.io.IOException
writeMesh
public void writeMesh(MeshBase mesh)
throws java.io.IOException
- Specified by:
writeMesh
in interface MeshWriter
- Specified by:
writeMesh
in class MeshWriterBase
- Throws:
java.io.IOException
writeMesh
public void writeMesh(java.io.PrintWriter pw,
PolygonalMesh mesh)
throws java.io.IOException
- Writes a PolygonalMesh to a PrintWriter, using an Alias Wavefront "obj"
file format. Vertices are printed first, each starting with the letter
"v" and followed by x, y, and z coordinates. Faces are printed next,
starting with the letter "f" and followed by a list of integers which
gives the indices of that face's vertices. Unless
getZeroIndexed()
returns true
, these indices are
1-based, and unless getFacesClockwise()
returns
true
, they are printed in counter-clockwise order. For
example, a mesh consisting of a simple tetrahedron might be written like
this:
v 0.0 0.0 0.0
v 1.0 0.0 0.0
v 0.0 1.0 0.0
v 0.0 0.0 1.0
f 1 2 3
f 0 2 1
f 0 3 2
f 0 1 3
The format used to print the vertex, normal, and texture coordinates can be
controlled by
MeshWriterBase.setFormat(String)
or MeshWriterBase.setFormat(NumberFormat)
.
The default format has eight decimal places and is specified
by the string "%.8g"
.
- Parameters:
pw
- PrintWriter to write the mesh tomesh
- PolygonalMesh to be written.
- Throws:
java.io.IOException
writeMesh
public void writeMesh(java.io.PrintWriter pw,
PolylineMesh mesh)
throws java.io.IOException
- Writes a PolylineMesh to a PrintWriter, using an Alias Wavefront "obj"
file format. Vertices are printed first, each starting with the letter
"v" and followed by x, y, and z coordinates. Lines are printed next,
starting with the letter "f" and followed by a list of integers which
gives the indices of that line's vertices. Unless
getZeroIndexed()
returns true
, these indices are
1-based. An example of a simple three point line is:
v 1.0 0.0 0.0
v 0.0 1.0 0.0
v 0.0 0.0 1.0
l 0 1 2
The format used to print the vertex coordinates can be
controlled by
MeshWriterBase.setFormat(String)
or MeshWriterBase.setFormat(NumberFormat)
.
The default format has eight decimal places and is specified
by the string "%.8g"
.
- Parameters:
pw
- PrintWriter to write the mesh tomesh
- PolylineMesh to be written
- Throws:
java.io.IOException
writeMesh
public void writeMesh(java.io.PrintWriter pw,
PointMesh mesh)
throws java.io.IOException
- Writes a PointMesh to a PrintWriter, using an Alias Wavefront "obj" file
format. Vertices are printed first, each starting with the letter "v" and
followed by x, y, and z coordinates. Normals, if present, are printed
next, starting with the letter "vn" and followed by x, y, and z
coordinates.
The format used to print the vertex and normal coordinates can be
controlled by
MeshWriterBase.setFormat(String)
or MeshWriterBase.setFormat(NumberFormat)
.
The default format has eight decimal places and is specified
by the string "%.8g"
.
- Parameters:
pw
- PrintWriter to write this mesh tomesh
- PointMesh to be written
- Throws:
java.io.IOException
writeMesh
public static void writeMesh(java.lang.String fileName,
MeshBase mesh)
throws java.io.IOException
- Throws:
java.io.IOException
writeMesh
public static void writeMesh(java.io.File file,
MeshBase mesh)
throws java.io.IOException
- Throws:
java.io.IOException