maspack.geometry.io
Class WavefrontWriter

java.lang.Object
  extended by maspack.geometry.io.MeshWriterBase
      extended by 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

Nested Class Summary
 
Nested classes/interfaces inherited from interface maspack.geometry.io.MeshWriter
MeshWriter.DataFormat, MeshWriter.FloatType
 
Field Summary
 
Fields inherited from class maspack.geometry.io.MeshWriterBase
DEFAULT_FORMAT
 
Constructor Summary
WavefrontWriter(java.io.File file)
           
WavefrontWriter(java.io.OutputStream os)
           
WavefrontWriter(java.lang.String fileName)
           
 
Method Summary
 boolean getFacesClockwise()
           
 boolean getZeroIndexed()
           
 void setFacesClockwise(boolean enable)
           
 void setZeroIndexed(boolean enable)
           
static void writeMesh(java.io.File file, MeshBase mesh)
           
 void writeMesh(MeshBase mesh)
           
 void writeMesh(java.io.PrintWriter pw, PointMesh mesh)
          Writes a PointMesh to a PrintWriter, using an Alias Wavefront "obj" file format.
 void writeMesh(java.io.PrintWriter pw, PolygonalMesh mesh)
          Writes a PolygonalMesh to a PrintWriter, using an Alias Wavefront "obj" file format.
 void writeMesh(java.io.PrintWriter pw, PolylineMesh mesh)
          Writes a PolylineMesh to a PrintWriter, using an Alias Wavefront "obj" file format.
static void writeMesh(java.lang.String fileName, MeshBase mesh)
           
 void writeString(java.lang.String str)
           
 
Methods inherited from class maspack.geometry.io.MeshWriterBase
close, getFormat, setFormat, setFormat
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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
Method Detail

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 to
mesh - 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 to
mesh - 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 to
mesh - 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