Class PrimitivePortrayal3D
- All Implemented Interfaces:
Portrayal
,Portrayal3D
- Direct Known Subclasses:
BranchGroupPortrayal3D
,ConePortrayal3D
,CylinderPortrayal3D
,Shape3DPortrayal3D
,SpherePortrayal3D
The objects are pickable by default, though you can change this by calling setPickable(). This must be called prior to the first call to getModel(...) (or if you override getModel(...), prior to your calling of super.getModel(...)).
The objects are can also have an optional internal Transform3D through which they may be rotated or scaled etc. Note that adding this Transform3D also adds additonal overhead, slowing down the model by perhaps 25%. To add this Transform3D, call setTransform() or setScale() at prior to the first call to getModel(...) (or if you override getModel(...), prior to your calling of super.getModel(...)). Once you have done this, you may change the scaling or transform again with these methods at any time, preferably during getModel(...).
The objects also have an appearance. To set the appearance, call setAppearance().
-
Field Summary
Modifier and TypeFieldDescriptionprotected javax.media.j3d.Node
This is cloned to create the model.Fields inherited from class sim.portrayal3d.SimplePortrayal3D
DEFAULT_APPEARANCE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected javax.media.j3d.Appearance
getAppearance
(javax.media.j3d.TransformGroup j3dModel) Returns an appearance object suitable to set in setAppearance(...).javax.media.j3d.TransformGroup
We suggest that if you wish to override this to change the appearance or scale or transform of the underlying model, do the changes first and THEN call super.getModel(obj, j3dModel).protected javax.media.j3d.Shape3D
getShape
(javax.media.j3d.TransformGroup j3dModel, int shapeIndex) Returns the shape by the given index.protected abstract int
Returns the number of shapes handled by this primitive or Shape3D.protected void
setAppearance
(javax.media.j3d.TransformGroup j3dModel, javax.media.j3d.Appearance app) Sets the Appearance of the portrayal.void
setPickable
(boolean val) Sets objects as pickable or not.boolean
setScale
(javax.media.j3d.TransformGroup j3dModel, double val) Sets the Transform3D of the portrayal to a given scaling value, if there *is* a transform (in some cases, such as ValuePortrayal3D, there won't be any).static void
setShape3DFlags
(javax.media.j3d.Shape3D shape) Sets common Shape3D flags to make its appearance and geometry easy to modify.boolean
setTransform
(javax.media.j3d.TransformGroup j3dModel, javax.media.j3d.Transform3D transform) Sets the Transform3D of the portrayal, if there is one (in some cases, such as ValuePortrayal3D, there won't be any).Methods inherited from class sim.portrayal3d.SimplePortrayal3D
appearanceForColor, appearanceForColors, appearanceForImage, clearPickableFlags, getCurrentDisplay, getCurrentFieldPortrayal, getCurrentGUIState, getInspector, getName, getStatus, isSelected, polygonAttributes, setAppearanceFlags, setCurrentDisplay, setCurrentFieldPortrayal, setPickableFlags, setPickableFlags, setSelected
-
Field Details
-
group
protected javax.media.j3d.Node groupThis is cloned to create the model. Typically this group holds a single element, either a Shape3D object or a Primitive of some sort. The model, which is also a TransformGroup, will then hold onto this object (or more properly, a clone). Note that the outer model TransformGroup (called j3dModel throughout this code) is not owned by us once we create it. So if we want to rotate or scale the Shape3D or Primitive, we do it by transforming 'group' instead upon creation.
-
-
Constructor Details
-
PrimitivePortrayal3D
public PrimitivePortrayal3D()
-
-
Method Details
-
setShape3DFlags
public static void setShape3DFlags(javax.media.j3d.Shape3D shape) Sets common Shape3D flags to make its appearance and geometry easy to modify. -
getShape
protected javax.media.j3d.Shape3D getShape(javax.media.j3d.TransformGroup j3dModel, int shapeIndex) Returns the shape by the given index. Cylinder has three shapes (BODY=0, TOP=1, BOTTOM=2), while Cone has two shapes (BODY=0, CAP=1) and Sphere has a single shape (BODY=0). Useful for use in for-loops in combination with numShapes(). -
setAppearance
protected void setAppearance(javax.media.j3d.TransformGroup j3dModel, javax.media.j3d.Appearance app) Sets the Appearance of the portrayal. If the j3DModel isn't null, its transform is set directly. If the j3DModel is null (probably because the model hasn't been built yet), an underlying appearance will be set and then used when the model is built. Only call this method within getModel(). -
getAppearance
protected javax.media.j3d.Appearance getAppearance(javax.media.j3d.TransformGroup j3dModel) Returns an appearance object suitable to set in setAppearance(...). If the j3DModel is null, a brand new Appearance will be created and returned; otherwise the Appearance (not a copy) will be extracted from the j3DModel and provided to you. It's good practice to call setAppearance(...) anyway afterwards. Only call this method within getModel(). -
setTransform
public boolean setTransform(javax.media.j3d.TransformGroup j3dModel, javax.media.j3d.Transform3D transform) Sets the Transform3D of the portrayal, if there is one (in some cases, such as ValuePortrayal3D, there won't be any). Returns TRUE if the transform was set. If the j3DModel isn't null, its transform is set directly. If the j3DModel is null (probably because the model hasn't been built yet), an underlying transform will be set and then used when the model is built. Only call this method within getModel(). -
setScale
public boolean setScale(javax.media.j3d.TransformGroup j3dModel, double val) Sets the Transform3D of the portrayal to a given scaling value, if there *is* a transform (in some cases, such as ValuePortrayal3D, there won't be any). Returns TRUE if the transform was set. If the j3DModel isn't null, its transform is set directly. If the j3DModel is null (probably because the model hasn't been built yet), an underlying transform will be set and then used when the model is built. Only call this method within getModel(). -
numShapes
protected abstract int numShapes()Returns the number of shapes handled by this primitive or Shape3D. Shape3D objects only have a single shape. Cylinder has three shapes (BODY=0, TOP=1, BOTTOM=2), while Cone has two shapes (BODY=0, CAP=1) and Sphere has a single shape (BODY=0). -
setPickable
public void setPickable(boolean val) Sets objects as pickable or not. If you call setPickable prior to the model being built in getModel(), then the model will be pickable or not as you specify. -
getModel
We suggest that if you wish to override this to change the appearance or scale or transform of the underlying model, do the changes first and THEN call super.getModel(obj, j3dModel). Be sure to also set the appearance/scale/transform of the model the first time (that is, when j3dModel is null) as well as when something interesting changes necessitating an update.- Specified by:
getModel
in interfacePortrayal3D
- Overrides:
getModel
in classSimplePortrayal3D
-