Class ObjectGridPortrayal3D

All Implemented Interfaces:
Portrayal, Portrayal3D

public class ObjectGridPortrayal3D extends FieldPortrayal3D
Portrays ObjectGrid2D and ObjectGrid3D in 3D space. A (0,0) or (0,0,0) object is centered on the origin. 2D fields are spread through the XY plane and are presumed to have Z=0.

You should be aware that ObjectGrid3DPortrayal3D is slow, especially if objects change a lot at given locations. This is because it has to update all the objects on a per location basis rather than on a per object basis. This is a worst-case scenario for Java3D.

Note for Java3D users: We experimented with a number of approaches to dealing with this. One approach was to use shared groups and only portray an object once, then use links to draw it in many locations. This has two subapproaches: you can wrap the link in a BranchGroup and replace it and the BranchGroup when the object changes at that location; or you can just change the link directly. The first approach is very slow (building BranchGroups isn't efficient). The second approach has promise, but there are grievous bugs in Java3D's handling of links which generate all sorts of race conditions with array bounds exceptions and null pointer exceptions etc. internal to Java3D when you change the SharedGroup that a link is pointing to. Ultimately we just gave up and used BranchGroups wrapping whole new submodels, entire copies for each location. Memory inefficient, but it's the fastest method we have figured out which doesn't break with stupid Sun bugs. It's also fairly simple to grok. Sorry.

  • Constructor Details

    • ObjectGridPortrayal3D

      public ObjectGridPortrayal3D()
  • Method Details

    • createModel

      protected javax.media.j3d.TransformGroup createModel()
      Description copied from class: FieldPortrayal3D
      Returns a tree structure of the form InternalTransformGroup[model info].

      ...where InternalTransformGroup is an identity transformgroup whose transform will be modified elsewhere (create it but don't play with it).

      Specified by:
      createModel in class FieldPortrayal3D
    • updateModel

      protected void updateModel(javax.media.j3d.TransformGroup globalTG)
      Description copied from class: FieldPortrayal3D
      Returns a tree structure of the form InternalTransformGroup[model info].

      ...where InternalTransformGroup is an identity transformgroup whose transform will be modified elsewhere (don't play with it). By default, this function does nothing. Override it to update the model when it's called.

      Overrides:
      updateModel in class FieldPortrayal3D
    • setField

      public void setField(Object field)
      Description copied from class: FieldPortrayal
      Sets the field, and sets the dirtyField flag to true. May throw an exception if the field is inappropriate. The default version just sets the field and sets the dirtyField flag.
      Overrides:
      setField in class FieldPortrayal
    • completedWrapper

      public LocationWrapper completedWrapper(LocationWrapper w, com.sun.j3d.utils.picking.PickIntersection pi, com.sun.j3d.utils.picking.PickResult pr)
      Description copied from class: FieldPortrayal3D
      Given the provided PickIntersection and the PickResult it came from, fill in w the location of the picked object, and return it. Alternatively, return a new LocationWrapper with all information filled in. The PickResult is provided you in case the object is in a shared group and you need to identify what link had connected to it.
      Specified by:
      completedWrapper in class FieldPortrayal3D