// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
// Create the transform group node and initialize it to the
// identity. Add it to the root of the subgraph.
TransformGroup objSpin = new TransformGroup();
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objSpin);
// Create a simple Text2D leaf node, add it to the scene graph.
Text2D text2d = new Text2D("2D text in Java 3D",
new Color3f(0.9f, 1.0f, 1.0f),
"Helvetica", 24, Font.ITALIC);
objSpin.addChild(text2d);
Appearance textAppear = text2d.getAppearance();
// The following 4 lines of code (commented out) make the Text2D object
// 2-sided.
// This code depends on the line of code above that sets TextAppear.
// PolygonAttributes polyAttrib = new PolygonAttributes();
// polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
// polyAttrib.setBackFaceNormalFlip(true);
// textAppear.setPolygonAttributes(polyAttrib);
// The following 12 lines of code (commented out) use the texture from
// the previous Text2D object on another object.
// This code depends on the line of code above that sets TextAppear.
// QuadArray qa = new QuadArray(4, QuadArray.COORDINATES |
// QuadArray.TEXTURE_COORDINATE_2);
// qa.setCoordinate(0, new Point3f(-10.0f, 1.0f, -5.0f));
// qa.setCoordinate(1, new Point3f(-10.0f, -1.0f, -5.0f));
// qa.setCoordinate(2, new Point3f(10.0f, -1.0f, -5.0f));
// qa.setCoordinate(3, new Point3f(10.0f, 1.0f, -5.0f));
// qa.setTextureCoordinate(0, new Point2f(0.0f, 1.0f));
// qa.setTextureCoordinate(1, new Point2f(0.0f, 0.0f));
// qa.setTextureCoordinate(2, new Point2f(1.0f, 0.0f));
// qa.setTextureCoordinate(3, new Point2f(1.0f, 1.0f));
//
// objRoot.addChild(new Shape3D(qa, textAppear));
// Create a new Behavior object that will perform the desired
// operation on the specified transform object and add it into
// the scene graph.
Alpha rotationAlpha = new Alpha(-1, 8000);
RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha, objSpin);
// a bounding sphere specifies a region a behavior is active
// create a sphere centered at the origin with radius of 100
BoundingSphere bounds = new BoundingSphere();
rotator.setSchedulingBounds(bounds);
objSpin.addChild(rotator);
Background backg = new Background();
backg.setColor(0.4f, 0.4f, 1.0f);
backg.setApplicationBounds(new BoundingSphere());
objRoot.addChild(backg);
return objRoot;