The following steps are taken by the example program to create the scene graph elements and link them together. Java 3D will then render the scene graph and display the graphics in a window on the screen:
Most Java 3D programs build an identical set of superstructure
and view branch objects, so the Java 3D utility packages provide a universe
package for constructing and manipulating the objects in a view branch. The
classes in the universe package provide a quick means for building a single
view (single window) application. Listing 2-3 shows a code fragment for using
the SimpleUniverse class. Note that the SimpleUniverse constructor takes a Canvas3D
as an argument, in this case referred to by the variable myCanvas.
------------------------------------------------------------------------ import com.sun.j3d.utils.universe.*; Shape3D myShape1 = new Shape3D(myGeometry1, myAppearance1); Shape3D myShape2 = new Shape3D(myGeometry2, myAppearance2); BranchGroup myBranch = new BranchGroup(); myBranch.addChild(myShape1); myBranch.addChild(myShape2); myBranch.compile(); SimpleUniverse myUniv = new SimpleUniverse(myCanvas); myUniv.addBranchGraph(myBranch);