AWT Shape Extruder

com.interactivemesh.j3d.community.utils.geometry
Class AWTShapeExtruder

java.lang.Object
  extended by com.interactivemesh.j3d.community.utils.geometry.AWTShapeExtruder

public class AWTShapeExtruder
extends java.lang.Object

AWTShapeExtruder converts a Java 2D Shape, called here AWT Shape, to a 3D geometry in a factory manner.

Each AWTShapeExtruder object has the following parameters:

According to the current state of these parameters a AWTShapeExtruder object creates for a given AWT Shape or for given characters a javax.media.j3d.GeometryArray


AWTShapeExtruder is a generalized version of javax.media.j3d.Font3D.

Version:
1.7
See Also:
AWTShapeExtrusion, String3D

Constructor Summary
AWTShapeExtruder()
          Constructs an AWTShapeExtruder object using the default values for the extrusion path, the tessellation tolerance, the crease angle, and the geometry transform.
AWTShapeExtruder(AWTShapeExtrusion extrudePath)
          Constructs an AWTShapeExtruder object from the specified AWTShapeExtrusion object, using the default values for the tessellation tolerance, the crease angle, and the geometry transform.
AWTShapeExtruder(double tessellationTolerance, AWTShapeExtrusion extrudePath)
          Constructs an AWTShapeExtruder object from the specified AWTShapeExtrusion object, using the specified tessellation tolerance and the default values for the crease angle and the geometry transform.
AWTShapeExtruder(double tessellationTolerance, AWTShapeExtrusion extrudePath, double creaseAngle)
          Constructs an AWTShapeExtruder object from the specified AWTShapeExtrusion object, using the specified tessellation tolerance and crease angle and the default value for the geometry transform.
 
Method Summary
static java.awt.Shape createAWTShape(char[] chars, java.awt.Font font, boolean flip)
          Returns an AWT Shape of the specified characters according to the specified Font object which describes the font name (Helvetica, Courier, etc.), the font style (bold, italic, etc.), and point size.
 double getCreaseAngle()
          Returns the crease angle.
 javax.media.j3d.GeometryArray getGeometry(char[] chars, java.awt.Font font, boolean flip)
          Returns a GeometryArray for the given characters according to the specified extrusion path, tessellation tolerance, crease angle, and geometry transform of this AWTShapeExtruder object and according to the specified Font object which describes the font name (Helvetica, Courier, etc.), the font style (bold, italic, etc.), and point size.
 javax.media.j3d.GeometryArray getGeometry(java.awt.Shape shape, java.awt.geom.AffineTransform trans)
          Returns a GeometryArray for the given AWT Shape object according to the specified extrusion path, tessellation tolerance, crease angle, and geometry transform of this AWTShapeExtruder object.
 void getGeometryTransform(javax.media.j3d.Transform3D transform)
          Copies the transform component of this AWTShapeExtruder object into the passed Transform3D object.
 javax.media.j3d.GeometryArray getOutlineGeometry(java.awt.Shape shape, java.awt.geom.AffineTransform trans)
          Returns a GeometryArray representing the outline of the given AWT Shape object according to the specified tessellation tolerance and geometry transform of this AWTShapeExtruder object.
 AWTShapeExtrusion getShapeExtrusion()
          Returns the AWTShapeExtrusion object used to describe how the edge of the AWT Shape varies along the Z axis.
 double getTessellationTolerance()
          Returns the tessellation tolerance with which the geometry of the AWT Shape will be created.
 void setCreaseAngle(double creaseAngle)
          Sets the crease angle in radians.
 void setGeometryTransform(javax.media.j3d.Transform3D transform)
          Sets the transform component of this AWTShapeExtruder object to the value of the passed transform.
 void setShapeExtrusion(AWTShapeExtrusion extrudePath)
          Sets the AWTShapeExtrusion object used to describe how the edge of the AWT Shape varies along the Z axis.
 void setTessellationTolerance(double tessellationTolerance)
          Sets the tessellation tolerance with which the geometry of the AWT Shape will be created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AWTShapeExtruder

public AWTShapeExtruder()
Constructs an AWTShapeExtruder object using the default values for the extrusion path, the tessellation tolerance, the crease angle, and the geometry transform.

The default values are as follows:


AWTShapeExtruder

public AWTShapeExtruder(AWTShapeExtrusion extrudePath)
Constructs an AWTShapeExtruder object from the specified AWTShapeExtrusion object, using the default values for the tessellation tolerance, the crease angle, and the geometry transform.

The default values are as follows:

The AWTShapeExtrusion object contains the extrusion path to use on the AWT Shape object. Passing null for the AWTShapeExtrusion parameter results in no extrusion being done.

Parameters:
extrudePath - the extrusion path used to describe how the edge of the AWT Shape varies along the Z axis

AWTShapeExtruder

public AWTShapeExtruder(double tessellationTolerance,
                        AWTShapeExtrusion extrudePath)
Constructs an AWTShapeExtruder object from the specified AWTShapeExtrusion object, using the specified tessellation tolerance and the default values for the crease angle and the geometry transform.

The default values are as follows:

The AWTShapeExtrusion object contains the extrusion path to use on the AWT Shape. Passing null for the AWTShapeExtrusion parameter results in no extrusion being done.

Parameters:
tessellationTolerance - the tessellation tolerance value used in tessellating the AWT Shape. This corresponds to the flatness parameter in the java.awt.Shape.getPathIterator method.
extrudePath - the extrusion path used to describe how the edge of the AWT Shape varies along the Z axis.

AWTShapeExtruder

public AWTShapeExtruder(double tessellationTolerance,
                        AWTShapeExtrusion extrudePath,
                        double creaseAngle)
Constructs an AWTShapeExtruder object from the specified AWTShapeExtrusion object, using the specified tessellation tolerance and crease angle and the default value for the geometry transform.

The default value is as follows:

The AWTShapeExtrusion object contains the extrusion path to use on the AWT Shape. Passing null for the AWTShapeExtrusion parameter results in no extrusion being done.

Parameters:
tessellationTolerance - the tessellation tolerance value used in tessellating the AWT Shape. This corresponds to the flatness parameter in the java.awt.Shape.getPathIterator method.
extrudePath - the extrusion path used to describe how the edge of the AWT Shape varies along the Z axis.
creaseAngle - an angle between surface normals in radians to determin if adjacent triangles are shaded smoothly across the edge, clamped to [0, Math.PI]
Method Detail

getShapeExtrusion

public AWTShapeExtrusion getShapeExtrusion()
Returns the AWTShapeExtrusion object used to describe how the edge of the AWT Shape varies along the Z axis.

The default extrusion path is null.

Returns:
the extrusion path of this AWTShapeExtruder object

setShapeExtrusion

public void setShapeExtrusion(AWTShapeExtrusion extrudePath)
Sets the AWTShapeExtrusion object used to describe how the edge of the AWT Shape varies along the Z axis. Passing null results in no extrusion being done.

The default extrusion path is null.

Parameters:
extrudePath - the extrusion path used to describe how the edge of the AWT Shape varies along the Z axis.

getTessellationTolerance

public double getTessellationTolerance()
Returns the tessellation tolerance with which the geometry of the AWT Shape will be created.

The default tolerance value is 0.01.

Returns:
the tessellation tolerance used by this AWTShapeExtruder

setTessellationTolerance

public void setTessellationTolerance(double tessellationTolerance)
Sets the tessellation tolerance with which the geometry of the AWT Shape will be created.

The default tolerance value is 0.01.

Parameters:
tessellationTolerance - the tessellation tolerance value used in tessellating the AWT Shape

getCreaseAngle

public double getCreaseAngle()
Returns the crease angle.

The default value is 0.767944871 radians (44 degrees)

Returns:
the crease angle in radians

setCreaseAngle

public void setCreaseAngle(double creaseAngle)
Sets the crease angle in radians. The specified value will be clamped to [0, Math.PI].

The default value is 0.767944871 radians (44 degrees)

Parameters:
creaseAngle - an angle between surface normals to determin if adjacent triangles are shaded smoothly across the edge

getGeometryTransform

public void getGeometryTransform(javax.media.j3d.Transform3D transform)
Copies the transform component of this AWTShapeExtruder object into the passed Transform3D object.

The default transform is the identity matrix.

Parameters:
transform - the Transform3D object to be copied into
Throws:
java.lang.NullPointerException - if transform is null

setGeometryTransform

public void setGeometryTransform(javax.media.j3d.Transform3D transform)
Sets the transform component of this AWTShapeExtruder object to the value of the passed transform.

The specified transform will be applied to the generated coordinates and normals in addition to a shape's affine transformation resp. a string's position value.

The font size of a text string and the tesselation tolerance determine the precision and resolution of the tesselated geometry. These values should be set according to the desired quality. Finally, this transform allows to scale the geometry to achieve a scene conform character size. Of course, rotation and translation components can be set as well.

See also the sample code on this javadoc's overview page.

The default transform is the identity matrix, so that the generated geometry remains unchanged.

Parameters:
transform - the Transform3D object to be copied
Throws:
java.lang.NullPointerException - if transform is null
java.lang.IllegalArgumentException - if transform is not invertable

getGeometry

public javax.media.j3d.GeometryArray getGeometry(java.awt.Shape shape,
                                                 java.awt.geom.AffineTransform trans)
Returns a GeometryArray for the given AWT Shape object according to the specified extrusion path, tessellation tolerance, crease angle, and geometry transform of this AWTShapeExtruder object. If an optional AffineTransform is specified, the coordinates returned by the shape's path iterator are transformed accordingly.

The returned GeometryArray includes triangle primitives and normals which are determined by the current crease angle.

Parameters:
shape - AWT Shape from which to generate a tessellated extruded geometry
trans - an optional AffineTransform to be applied to the coordinates of the shape's path iterater, or null if untransformed coordinates are desired
Returns:
a GeometryArray or null if no GeometryArray could be created

getOutlineGeometry

public javax.media.j3d.GeometryArray getOutlineGeometry(java.awt.Shape shape,
                                                        java.awt.geom.AffineTransform trans)
Returns a GeometryArray representing the outline of the given AWT Shape object according to the specified tessellation tolerance and geometry transform of this AWTShapeExtruder object. Neither the extrusion path nor the crease angle attributes are applied. If an optional AffineTransform is specified, the coordinates returned by the shape's path iterator are transformed accordingly.

The returned GeometryArray includes line primitives and normals which are directed along the positive Z axis (0, 0, 1).

Parameters:
shape - AWT Shape from which to generate an outline geometry
trans - an optional AffineTransform to be applied to the coordinates of the shape's path iterater, or null if untransformed coordinates are desired
Returns:
a GeometryArray or null if no GeometryArray could be created

getGeometry

public javax.media.j3d.GeometryArray getGeometry(char[] chars,
                                                 java.awt.Font font,
                                                 boolean flip)
Returns a GeometryArray for the given characters according to the specified extrusion path, tessellation tolerance, crease angle, and geometry transform of this AWTShapeExtruder object and according to the specified Font object which describes the font name (Helvetica, Courier, etc.), the font style (bold, italic, etc.), and point size. The flip value allows to reverse the Font's Y-axis downwards orientation.

The returned GeometryArray includes triangle primitives and normals which are determined by the current crease angle.

Sample characters:

 char[] chars0 = {'A'};
 
 char[] chars1 = {'Y', 'e', 's', ' ', '?'};
 
 char[] chars2 = new String("Text").toCharArray();
 
 // Unicode code point
 int codePoint = 64; 
 char[] chars3 = Character.toChars(codePoint);
 

Parameters:
chars - characters from which to generate tessellated glyphs
font - the Java 2D Font used to create the glyphs
flip - if true the Font's Y-axis downwards orientaton is reversed
Returns:
a GeometryArray or null if no GeometryArray could be created
See Also:
String3D

createAWTShape

public static java.awt.Shape createAWTShape(char[] chars,
                                            java.awt.Font font,
                                            boolean flip)
Returns an AWT Shape of the specified characters according to the specified Font object which describes the font name (Helvetica, Courier, etc.), the font style (bold, italic, etc.), and point size. The flip value allows to reverse the Font's Y-axis downwards orientation.

Sample characters:

 char[] chars0 = {'A'};
 
 char[] chars1 = {'Y', 'e', 's', ' ', '?'};
 
 char[] chars2 = new String("Text").toCharArray();
 
 // Unicode code point
 int codePoint = 64; 
 char[] chars3 = Character.toChars(codePoint);
 

Parameters:
chars - characters from which to generate an AWT Shape
font - the Java 2D Font used to create the glyphs
flip - if true the Font's Y-axis downwards orientation is reversed
Returns:
an AWT Shape

AWT Shape Extruder