public class SimplePortrayal3D extends java.lang.Object implements Portrayal3D
SimplePortrayal3Ds have a getFieldPortrayal(), 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 getFieldPortrayal(), 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.
Modifier and Type | Field and Description |
---|---|
static javax.media.j3d.Appearance |
DEFAULT_APPEARANCE
Flat white opaque.
|
Constructor and Description |
---|
SimplePortrayal3D() |
Modifier and Type | Method and Description |
---|---|
static javax.media.j3d.Appearance |
appearanceForColor(java.awt.Color unlitColor)
Creates an Appearance equivalent to a flat opaque surface of the provided color, needing no lighting.
|
static javax.media.j3d.Appearance |
appearanceForColors(java.awt.Color ambientColor,
java.awt.Color emissiveColor,
java.awt.Color diffuseColor,
java.awt.Color specularColor,
double shininess,
double opacity)
Creates an Appearance with the provided lit colors.
|
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.
|
Display3D |
getCurrentDisplay()
If the current display has been set, returns it.
|
FieldPortrayal3D |
getCurrentFieldPortrayal() |
GUIState |
getCurrentGUIState()
Returns the current GUIState, or null if no GUIState has been set yet.
|
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.
|
boolean |
isSelected(java.lang.Object obj) |
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).
|
static void |
setAppearanceFlags(javax.media.j3d.Appearance a)
Sets a variety of flags on an Appearance so that its features can be modified
when the scene is live.
|
void |
setCurrentDisplay(Display3D display)
Sets the current Display3D.
|
void |
setCurrentFieldPortrayal(FieldPortrayal3D p) |
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)
If the object is selected, adds it to a hash table of selected objects for which
this SimplePortrayal3D's isSelected() method will return TRUE.
|
public static final javax.media.j3d.Appearance DEFAULT_APPEARANCE
public static javax.media.j3d.Appearance appearanceForColor(java.awt.Color unlitColor)
public static javax.media.j3d.Appearance appearanceForColors(java.awt.Color ambientColor, java.awt.Color emissiveColor, java.awt.Color diffuseColor, java.awt.Color specularColor, double shininess, double opacity)
public static javax.media.j3d.Appearance appearanceForImage(java.awt.Image image, boolean opaque)
public javax.media.j3d.PolygonAttributes polygonAttributes()
Portrayal3D
polygonAttributes
in interface Portrayal3D
public javax.media.j3d.TransformGroup getModel(java.lang.Object object, javax.media.j3d.TransformGroup prev)
Portrayal3D
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 field portrayal and display will have already been set if it exists, else it will be null.
getModel
in interface Portrayal3D
public Inspector getInspector(LocationWrapper wrapper, GUIState state)
Portrayal
getInspector
in interface Portrayal
public java.lang.String getStatus(LocationWrapper wrapper)
Portrayal
public java.lang.String getName(LocationWrapper wrapper)
Portrayal
public void setCurrentFieldPortrayal(FieldPortrayal3D p)
public FieldPortrayal3D getCurrentFieldPortrayal()
public void setCurrentDisplay(Display3D display)
Portrayal3D
setCurrentDisplay
in interface Portrayal3D
public Display3D getCurrentDisplay()
getCurrentDisplay
in interface Portrayal3D
public GUIState getCurrentGUIState()
Portrayal3D
getCurrentGUIState
in interface Portrayal3D
public boolean isSelected(java.lang.Object obj)
public boolean setSelected(LocationWrapper wrapper, boolean selected)
There are two implications to this approach. First, it means that after you've selected an object, there's a hash table attached to its portrayal. If you're using the same portrayal for lots of stuff, that's no big deal. But if you've got per-object portrayals and a lot of objects (or if the objects are themselves SimplePortrayal3D subclasses) then that's a fair number of hash tables. This is a minor memory issue but if you don't care about testing for whether you've been selected or not, you could just override this method to always return TRUE (and don't call super.selected(...) ) and the hash table will never be created. Note that isSelected will always return FALSE for your portrayal in this situation.
Second, though you can test for selection with the isSelected() method, if you want to, say, change the look of your portrayal based on whether or not it's selected, you will need to test isSelected() each time getModel() is called and modify the model accordingly. This could be a bit expensive. We're working on an approach for you to be able to test if the object was RECENTLY selected or deselected so you could only test then, but it's nontrivial to do without using up a lot of memory.
setSelected
in interface Portrayal
public static void setAppearanceFlags(javax.media.j3d.Appearance a)
public static void setPickableFlags(javax.media.j3d.Shape3D s3d)
public static void setPickableFlags(javax.media.j3d.Geometry geom)
public static void clearPickableFlags(javax.media.j3d.Node n)