sim.portrayal3d
Class SimplePortrayal3D

java.lang.Object
  extended by sim.portrayal3d.SimplePortrayal3D
All Implemented Interfaces:
java.io.Serializable, Portrayal, Portrayal3D
Direct Known Subclasses:
Axes, CircledPortrayal3D, ConePortrayal3D, CubePortrayal3D, CylinderPortrayal3D, ImagePortrayal3D, LabelledPortrayal3D, LightPortrayal3D, Shape3DPortrayal3D, SharedGroupPortrayal3D, SpherePortrayal3D, TransformedPortrayal3D, ValuePortrayal3D, WireFrameBoxPortrayal3D

public class SimplePortrayal3D
extends java.lang.Object
implements Portrayal3D

The superclass of all 3D Simple Portrayals which by default adds nothing to the 3D scene. Since nothing is added to the scene, nothing is shown and you cannot select anything. Subclasses add items to the scene, so they can then be selected if they so choose. By default SimplePortrayal3Ds respond to requests for inspectors by providing a basic LabelledList which shows all the portrayed object's object properties (see sim.util.SimpleProperties). They also respond to inspector update requests by updating this same LabelledList. No polygonAttributes are provided by default, and setSelected always returns false.

SimplePortrayal3Ds have a parentPortrayal, which is the FieldPortrayal3D which houses them. This value can be null if the SimplePortrayal3D was added directly into the Display3D's collection of portrayals rather than being used inside a field portrayal. The contract SimplePortrayal3Ds may assume is that the parentPortrayal, if it exists, will have been set prior to getModel(...) being called.

Various utility functions are provided. setPickableFlags makes a Java3D object pickable (necessary for inspectability and selection). clearPickableFlags does the opposite. appearanceForColor creates a Java3D appearance that's a flat version of the color which requires no lighting -- a very basic default appearance function. If the color has a degree of transparency, the appearance will as well.

A default appearance is provided for subclasses which wish to draw themselves using a default: flat white opaque.

See Also:
Serialized Form

Field Summary
static javax.media.j3d.Appearance DEFAULT_APPEARANCE
          Flat white opaque.
protected  FieldPortrayal3D parentPortrayal
          Used by the SimplePortrayal3D to add its parent to its pickInfo object when the user picks the SimplePortrayal3D.
 
Constructor Summary
SimplePortrayal3D()
           
 
Method Summary
static javax.media.j3d.Appearance appearanceForColor(java.awt.Color color)
          Creates an Appearance equivalent to a flat opaque surface of the provided color, needing no lighting.
static javax.media.j3d.Appearance appearanceForImage(java.awt.Image image, boolean opaque)
          Creates an Appearance using the provided image.
static void clearPickableFlags(javax.media.j3d.Node n)
          Utility method which makes the given Node unpickable.
 Inspector getInspector(LocationWrapper wrapper, GUIState state)
          Provide an inspector for an object.
 javax.media.j3d.TransformGroup getModel(java.lang.Object object, javax.media.j3d.TransformGroup prev)
          Provides a TransformGroup which defines the node(s) to place in the scenegraph.
 java.lang.String getName(LocationWrapper wrapper)
          Returns a static, one-line name for the given object that is useful for a human to distinguish it from other objects.
 java.lang.String getStatus(LocationWrapper wrapper)
          Returns a simple, informative one-line description of the current status of the object, which may change at any time to reflect how the object is changing.
 javax.media.j3d.PolygonAttributes polygonAttributes()
          Provides a PolygonAttributes which can be modified to change the underlying model's attributes (culling, vertex versus point versus fill).
 void setParentPortrayal(FieldPortrayal3D p)
          Sets the parent portrayal (a FieldPortrayal3D).
static void setPickableFlags(javax.media.j3d.Geometry geom)
          Utility method which prepares the given Geometry to be pickable (for selection and inspection).
static void setPickableFlags(javax.media.j3d.Shape3D s3d)
          Utility method which prepares the given Shape3D to be pickable (for selection and inspection).
 boolean setSelected(LocationWrapper wrapper, boolean selected)
          Change the portrayal state to reflect the fact that you've been selected or not selected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_APPEARANCE

public static final javax.media.j3d.Appearance DEFAULT_APPEARANCE
Flat white opaque.


parentPortrayal

protected FieldPortrayal3D parentPortrayal
Used by the SimplePortrayal3D to add its parent to its pickInfo object when the user picks the SimplePortrayal3D.

Constructor Detail

SimplePortrayal3D

public SimplePortrayal3D()
Method Detail

appearanceForColor

public static javax.media.j3d.Appearance appearanceForColor(java.awt.Color color)
Creates an Appearance equivalent to a flat opaque surface of the provided color, needing no lighting.


appearanceForImage

public static javax.media.j3d.Appearance appearanceForImage(java.awt.Image image,
                                                            boolean opaque)
Creates an Appearance using the provided image. If the image should be entirely opaque, you should definitely set opaque to true. If you want to use the image's built-in transparency information, you should set opaque to false. Beware that there are bugs in Java3D's handling of transparent textures: multiple such objects often will not draw in the correct order; thus objects in the back may appear to be in the front.


polygonAttributes

public javax.media.j3d.PolygonAttributes polygonAttributes()
Description copied from interface: Portrayal3D
Provides a PolygonAttributes which can be modified to change the underlying model's attributes (culling, vertex versus point versus fill). This is an optional function: you are free to return null

Specified by:
polygonAttributes in interface Portrayal3D

getModel

public javax.media.j3d.TransformGroup getModel(java.lang.Object object,
                                               javax.media.j3d.TransformGroup prev)
Description copied from interface: Portrayal3D
Provides a TransformGroup which defines the node(s) to place in the scenegraph. This is the Portrayal3D equivalent of Portrayal2D's draw(object, graphics, drawinfo) method.

You should hang your model off of the TransformGroup provided. You should not transform that TransformGroup in any way -- it is used elsewhere. Instead if you wish to transform your model (rotate it etc.) you should add your own additional TransformGroup as necessary.

The provided TransformGroup can be null; in this case you need to create and return the outer TransformGroup for the object. If the provided TransformGroup is non-null, you should modify it and return the same.

SimplePortrayals should assume the following contract: at the point that getModel(...) is called, the parentPortrayal will have already been set if it exists, else it will be null.

Specified by:
getModel in interface Portrayal3D

getInspector

public Inspector getInspector(LocationWrapper wrapper,
                              GUIState state)
Description copied from interface: Portrayal
Provide an inspector for an object.

Specified by:
getInspector in interface Portrayal

getStatus

public java.lang.String getStatus(LocationWrapper wrapper)
Description copied from interface: Portrayal
Returns a simple, informative one-line description of the current status of the object, which may change at any time to reflect how the object is changing. A simple default would be just to return getName(wrapper).

Specified by:
getStatus in interface Portrayal

getName

public java.lang.String getName(LocationWrapper wrapper)
Description copied from interface: Portrayal
Returns a static, one-line name for the given object that is useful for a human to distinguish it from other objects. A simple default would be just to return "" + object.

Specified by:
getName in interface Portrayal

setParentPortrayal

public void setParentPortrayal(FieldPortrayal3D p)
Sets the parent portrayal (a FieldPortrayal3D).


setSelected

public boolean setSelected(LocationWrapper wrapper,
                           boolean selected)
Description copied from interface: Portrayal
Change the portrayal state to reflect the fact that you've been selected or not selected. Always return true, except if you've received a setSelected(true) and in fact do not wish to be selectable, in which case return false in that sole situation.

Specified by:
setSelected in interface Portrayal

setPickableFlags

public static void setPickableFlags(javax.media.j3d.Shape3D s3d)
Utility method which prepares the given Shape3D to be pickable (for selection and inspection).


setPickableFlags

public static void setPickableFlags(javax.media.j3d.Geometry geom)
Utility method which prepares the given Geometry to be pickable (for selection and inspection).


clearPickableFlags

public static void clearPickableFlags(javax.media.j3d.Node n)
Utility method which makes the given Node unpickable.