Areas
  • J3D FAQ
  • Tutorials
  • Utilities
  • Books
  • News
  • Other Sites
  • FAQ Topics
  • Introduction to Java 3D
  • Documentation
  • Speed issues
  • Running Java 3D
  • Object manipulation
  • Scene appearance
  • Java 3D and Swing
  • Image capturing
  • Stereo viewing
  • Input Devices
  • Textures
  • Web browsers
  • Video Hardware
  • VRML
  •   

    Object manipulation

    1. Problems with "get" methods

    2. Detaching a BranchGroup or Behavior

    3. Breaking up polygons into triangles

    4. Generating normals

    5. Null pointer exceptions from GeomInfoConverter

    6. "IllegalArgumentException: Index lists must all be the same length" error from GeometryInfo.

    7. Sharing nodes across multiple universes

    8. Moving an object on the screen with a scrollbar

    9. Picking points and lines

    Return to the main FAQ page for more questions and answers.

      

    1. Problems with "get" methods

    Frequently, if you're having a problem (such as a null pointer exception) using one of Java 3D's "get" methods, you've forgotten to allocate the object needed to extract the data you're trying to retrieve. For example, calling the getCoordinates() in GeometryArray appears to allocate objects for you, and return the array elements that were allocated within the method. This is not the case.

    By requiring that the array elements already exist, objects that were subclassed from Point3d can be passed into the method, and the method will still work correctly. If they hadn't done it this way, you would have to allocate your own array, a Point3d array and then copy the Point3d info into your own objects after the method call completed.

    Back to top

    2. Detaching a BranchGroup or Behavior

    From Doug Gehringer:

    To add/remove a subgraph at runtime you need to put the stuff to be added/removed into a BranchGroup and set the capability bits on the parent and child to allow the runtime changes:
            Behavior yourBehavior; // this is what you want to remove
            Group    parent;       // this is where you want to add/remove
    
            BranchGroup removableBehavior = new BranchGroup();
            removeableBehavior.addChild(yourBehavior);
            removeableBehavior.setCapability(BranchGroup.ALLOW_DETACH);
    
            parent.setCapability(Group.ALLOW_CHILDREN_READ);
            parent.setCapability(Group.ALLOW_CHILDREN_WRITE);
            parent.setCapability(Group.ALLOW_CHILDREN_EXTEND);
            parent.addChild(removeableBehavior);
    
    
    With this, you can now add/remove after the scene graph is live. Call removableBehavior.detach() to remove the behavior from the scene and parent.addChild(removeableBehavior) to add it. Note: you may not need to add/remove the behavior from the graph. In many cases you can use the setEnable() method to turn the behavior on and off.

    If you're seeing an error that looks something like this:

    Exception occurred during event dispatching:
    javax.media.j3d.CapabilityNotSetException: Locale: no capability to 
    detach BranchGroup
    

    You might have noticed that locale doesn't have setCapability method. The error is a bit misleading. The BranchGroup needs the BranchGroup.ALLOW_DETACH capability set. That should fix the problem.

    Back to top

    3. Breaking up polygons into triangles

    You can break up polygons into triangles using some utility objects that Sun provides. Fill in the GeometryInfo object, and call the triangulate method of the Triangulator object.

    Back to top

    4. Generating normals

    Sun provides an object for generating normals. Fill in the GeometryInfo object, call the generateNormals method of the NormalGenerator object, and that should do it. You may want to use the setCreaseAngle before you generate the normals. Further information about that is available in the NormalGenerator javadoc.

    Back to top

    5. Null pointer exceptions from GeomInfoConverter

    If you get a null pointer excepting when trying to use Triangulator, this can be caused by a couple things. You may have forgotten to call the setStripCounts method of GeometryInfo. If you don't set this, the Triangulator has no way of telling how big each of the polygons are that you've given it. If you're doing this, and you still get this error, you may not be calling setCoordinateIndicies . If you have only coordinate data to set, and no coordinate indices to set, you must call the recomputeIndices method.

    Back to top

    6. "IllegalArgumentException: Index lists must all be the same length" error from GeometryInfo.

    This is a bug in Triangulator, and is listed as such in the README.

    Back to top

    7. Sharing nodes across multiple universes

    Sharing nodes across multiple universes is not permitted. See section 3.1 and appendix D.5 of the Java 3D specification.

    Back to top

    8. Moving an object on the screen with a scrollbar

    The example program, ScrollUniverse.java shows how to do this. Thanks to Doug Gehringer for providing this example.

    Back to top

    9. Picking points and lines

    Doug Gehringer posted some new picking utilities on the Java 3D mailing list that address this. The Java 3D FAQ has a copy of these posted on a seperate page for you to look at.

    Back to top

      

    [ Copyright Info ] [ FAQ Home ] [ J3D.org Home ] [ Tutorials ] [ Utilities ] [ Books ] [ Contact Us ]