Example usage for javax.media.j3d Appearance setTexture

List of usage examples for javax.media.j3d Appearance setTexture

Introduction

In this page you can find the example usage for javax.media.j3d Appearance setTexture.

Prototype

public void setTexture(Texture texture) 

Source Link

Document

Sets the texture object to the specified object.

Usage

From source file:PlatformTest.java

public BranchGroup createSceneGraph() {
    final int LAND_WIDTH = 12;
    final float LAND_HEIGHT = -1.0f;
    final int LAND_LENGTH = 12;
    final int nTileSize = 2;

    // calculate how many vertices we need to store all the "tiles"
    // that compose the QuadArray.
    final int nNumTiles = ((LAND_LENGTH / nTileSize) * 2) * ((LAND_WIDTH / nTileSize) * 2);
    final int nVertexCount = 4 * nNumTiles;
    Point3f[] coordArray = new Point3f[nVertexCount];
    Point2f[] texCoordArray = new Point2f[nVertexCount];

    // create an Appearance and load a texture
    Appearance app = new Appearance();
    Texture tex = new TextureLoader("land.jpg", this).getTexture();
    app.setTexture(tex);

    // create the parent BranchGroup
    BranchGroup bg = new BranchGroup();

    int nItem = 0;

    // loop over all the tiles in the environment
    for (int x = -LAND_WIDTH; x <= LAND_WIDTH; x += nTileSize) {
        for (int z = -LAND_LENGTH; z <= LAND_LENGTH; z += nTileSize) {
            // if we are on the border of the environment create a
            // TransformGroup to position a ColorCube to create a "wall"
            if (x == -LAND_WIDTH || x == LAND_WIDTH || z == -LAND_LENGTH || z == LAND_LENGTH) {
                TransformGroup tg = new TransformGroup();
                Transform3D t3d = new Transform3D();
                t3d.setTranslation(new Vector3d(x, 0, z));
                tg.setTransform(t3d);//from  w  w  w .j a  v a  2  s.com
                tg.addChild(new ColorCube(nTileSize / 2));
                bg.addChild(tg);
            }

            // if we are not on the last row or column create a "tile"
            // and add to the QuadArray. Use CCW winding and assign texture
            // coordinates.
            if (z < LAND_LENGTH && x < LAND_WIDTH) {
                coordArray[nItem] = new Point3f(x, LAND_HEIGHT, z);
                texCoordArray[nItem++] = new Point2f(0, 0);
                coordArray[nItem] = new Point3f(x, LAND_HEIGHT, z + nTileSize);
                texCoordArray[nItem++] = new Point2f(1, 0);
                coordArray[nItem] = new Point3f(x + nTileSize, LAND_HEIGHT, z + nTileSize);
                texCoordArray[nItem++] = new Point2f(1, 1);
                coordArray[nItem] = new Point3f(x + nTileSize, LAND_HEIGHT, z);
                texCoordArray[nItem++] = new Point2f(0, 1);
            }
        }
    }

    // create a GeometryInfo and generate Normal vectors
    // for the QuadArray that was populated.
    GeometryInfo gi = new GeometryInfo(GeometryInfo.QUAD_ARRAY);

    gi.setCoordinates(coordArray);
    gi.setTextureCoordinates(texCoordArray);

    NormalGenerator normalGenerator = new NormalGenerator();
    normalGenerator.generateNormals(gi);

    // wrap the GeometryArray in a Shape3D
    Shape3D shape = new Shape3D(gi.getGeometryArray(), app);

    // add the Shape3D to the parent BranchGroup
    bg.addChild(shape);

    // create some lights for the scene
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(m_Bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(m_Bounds);

    // add the lights to the parent BranchGroup
    bg.addChild(aLgt);
    bg.addChild(lgt1);

    // create a light gray background
    Background back = new Background(new Color3f(0.9f, 0.9f, 0.9f));
    back.setApplicationBounds(m_Bounds);
    bg.addChild(back);

    // compile the whole scene
    //bg.compile();

    return bg;
}

From source file:HiResCoordTest.java

private TransformGroup createPlanet(String szName, Color3f color, Transform3D t3d, String szTexture) {
    TransformGroup objTrans = new TransformGroup(t3d);

    Appearance app = new Appearance();

    if (szTexture != null) {
        TextureLoader tex = new TextureLoader(szTexture, this);
        app.setTexture(tex.getTexture());
    } else {/*from w  w  w. j  av  a  2s .  c  o  m*/
        ColoringAttributes ca = new ColoringAttributes();
        ca.setColor(color);
        app.setColoringAttributes(ca);
    }

    objTrans.addChild(createLabel(szName, 1.2f, 1.2f, 0));
    objTrans.addChild(new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, app));

    return objTrans;
}

From source file:AvatarTest.java

public void createBackground(Group bg) {
    // add the sky backdrop
    Background back = new Background();
    back.setApplicationBounds(getBoundingSphere());
    bg.addChild(back);//from ww  w . j  a va 2 s  . co  m

    BranchGroup bgGeometry = new BranchGroup();

    // create an appearance and assign the texture image
    Appearance app = new Appearance();
    Texture tex = new TextureLoader("back.jpg", this).getTexture();
    app.setTexture(tex);

    Sphere sphere = new Sphere(1.0f, Primitive.GENERATE_TEXTURE_COORDS | Primitive.GENERATE_NORMALS_INWARD,
            app);

    bgGeometry.addChild(sphere);
    back.setGeometry(bgGeometry);
}

From source file:PickWorld.java

private Appearance createAppearance(int idx) {
    Appearance app = new Appearance();

    // Globally used colors
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f gray = new Color3f(0.4f, 0.4f, 0.4f);
    idx = idx % 5;//  w w  w  .  j  a v a  2 s .  com

    switch (idx) {
    // Lit solid
    case 0: {
        // Set up the material properties
        Color3f objColor = new Color3f(0.0f, 0.8f, 0.0f);
        app.setMaterial(new Material(objColor, black, objColor, white, 80.0f));
        break;
    }
    // Lit solid, specular only
    case 1: {

        // Set up the material properties
        Color3f objColor = new Color3f(0.0f, 0.4f, 0.2f);
        app.setMaterial(new Material(black, black, objColor, white, 80.0f));
        break;
    }

    case 2: {
        // Set up the texture map
        TextureLoader tex = new TextureLoader("apimage.jpg", this);
        app.setTexture(tex.getTexture());

        // Set up the material properties
        app.setMaterial(new Material(gray, black, gray, white, 1.0f));
        break;
    }

    // Texture mapped, lit solid
    case 3: {
        // Set up the texture map
        TextureLoader tex = new TextureLoader("earth.jpg", this);
        app.setTexture(tex.getTexture());

        // Set up the material properties
        app.setMaterial(new Material(gray, black, gray, white, 1.0f));
        break;
    }

    // Another lit solid with a different color
    case 4: {
        // Set up the material properties
        Color3f objColor = new Color3f(1.0f, 1.0f, 0.0f);
        app.setMaterial(new Material(objColor, black, objColor, white, 80.0f));
        break;
    }

    default: {
        ColoringAttributes ca = new ColoringAttributes();
        ca.setColor(new Color3f(0.0f, 1.0f, 0.0f));
        app.setColoringAttributes(ca);
    }
    }

    return app;
}

From source file:BehaviorTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    // create a TransformGroup to rotate the hand
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // create a RotationInterpolator behavior to rotate the hand
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    m_RotationInterpolator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    m_RotationInterpolator.setSchedulingBounds(createApplicationBounds());
    objTrans.addChild(m_RotationInterpolator);

    // create an Appearance and Material
    Appearance app = new Appearance();

    TextureLoader tex = new TextureLoader("earth.jpg", this);
    app.setTexture(tex.getTexture());

    Sphere sphere = new Sphere(3, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, 32, app);

    // connect the scenegraph
    objTrans.addChild(sphere);/*  w  w w  . j a  v a  2s  .  c  o  m*/
    objRoot.addChild(objTrans);

    m_FpsBehavior = new FpsBehavior();
    m_FpsBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_FpsBehavior);

    m_BoundsBehavior = new BoundsBehavior(sphere);
    m_BoundsBehavior.setSchedulingBounds(getApplicationBounds());
    m_BoundsBehavior.addBehaviorToParentGroup(objTrans);

    m_StretchBehavior = new StretchBehavior((GeometryArray) sphere.getShape().getGeometry());
    m_StretchBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_StretchBehavior);
    m_StretchBehavior.setEnable(false);

    m_SizeBehavior = new ObjectSizeBehavior((GeometryArray) sphere.getShape().getGeometry());
    m_SizeBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_SizeBehavior);
    m_SizeBehavior.setEnable(false);

    m_ExplodeBehavior = new ExplodeBehavior(sphere.getShape(), 10000, 20, this);
    m_ExplodeBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_ExplodeBehavior);

    return objRoot;
}

From source file:TextureTest.java

protected Shape3D createTextureGeometry(String szFile, boolean bWireframe) {
    // load all the texture data from the file and create the geometry
    // coordinates
    TextureGeometryInfo texInfo = createTextureCoordinates(szFile);

    if (texInfo == null) {
        System.err.println("Could not load texture info for file:" + szFile);
        return null;
    }//from  ww w  . j  a va 2  s  .  c  o  m

    // print some stats on the loaded file
    System.out.println("Loaded File: " + szFile);
    System.out.println("   Texture image: " + texInfo.m_szImage);
    System.out.println("   Texture coordinates: " + texInfo.m_TexCoordArray.length);

    // create an Appearance and assign a Material
    Appearance app = new Appearance();

    PolygonAttributes polyAttribs = null;

    // create the PolygonAttributes and attach to the Appearance,
    // note that we use CULL_NONE so that the "rear" side of the geometry
    // is visible with the applied texture image
    if (bWireframe == false)
        polyAttribs = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0);
    else
        polyAttribs = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0);

    app.setPolygonAttributes(polyAttribs);

    // load the texture image and assign to the appearance
    TextureLoader texLoader = new TextureLoader(texInfo.m_szImage, Texture.RGB, this);
    Texture tex = texLoader.getTexture();
    app.setTexture(tex);

    // create a GeometryInfo for the QuadArray that was populated.
    GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
    gi.setCoordinates(texInfo.m_CoordArray);
    gi.setTextureCoordinates(texInfo.m_TexCoordArray);

    // use the triangulator utility to triangulate the polygon
    int[] stripCountArray = { texInfo.m_CoordArray.length };
    int[] countourCountArray = { stripCountArray.length };

    gi.setContourCounts(countourCountArray);
    gi.setStripCounts(stripCountArray);

    Triangulator triangulator = new Triangulator();
    triangulator.triangulate(gi);

    // generate normal vectors for the triangles, not
    // strictly necessary as we are not lighting the scene
    // but generally useful
    NormalGenerator normalGenerator = new NormalGenerator();
    normalGenerator.generateNormals(gi);

    // wrap the GeometryArray in a Shape3D and assign appearance
    return new Shape3D(gi.getGeometryArray(), app);
}

From source file:OrientedTest.java

public BranchGroup createSceneGraph() {

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    TransformGroup objScale = new TransformGroup();
    Transform3D textMat = new Transform3D();
    // Assuming uniform size chars, set scale to fit string in view
    textMat.setScale(1.2 / sl);// ww w .j  a  v  a 2s.com
    objScale.setTransform(textMat);

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRoot.addChild(objTrans);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    Appearance apText = new Appearance();
    Material m = new Material();
    m.setLightingEnable(true);
    apText.setMaterial(m);

    Appearance apEarth = new Appearance();
    Material mm = new Material();
    mm.setLightingEnable(true);
    apEarth.setMaterial(mm);

    Appearance apStone = new Appearance();
    apStone.setMaterial(mm);

    // create 3D text
    Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
    Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, 3.0f, 0.0f));
    OrientedShape3D textShape = new OrientedShape3D();
    textShape.setGeometry(txt);
    textShape.setAppearance(apText);
    textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f);
    objScale.addChild(textShape);

    // Create a simple shape leaf node, add it to the scene graph.

    Transform3D cubeMat = new Transform3D();
    TransformGroup cubeTrans = new TransformGroup(cubeMat);
    cubeMat.set(new Vector3d(0.9, 0.0, -1.0));
    cubeTrans.setTransform(cubeMat);
    cubeTrans.addChild(new ColorCube(0.3));
    objTrans.addChild(cubeTrans);

    TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this);
    if (stoneTex != null)
        apStone.setTexture(stoneTex.getTexture());

    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    apStone.setTextureAttributes(texAttr);

    Transform3D coneMat = new Transform3D();
    TransformGroup coneTrans = new TransformGroup(coneMat);
    coneMat.set(new Vector3d(0.0, 0.0, 0.0));
    coneTrans.setTransform(coneMat);
    coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone));
    objTrans.addChild(coneTrans);

    TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this);
    if (earthTex != null)
        apEarth.setTexture(earthTex.getTexture());

    apEarth.setTextureAttributes(texAttr);

    Transform3D cylinderMat = new Transform3D();
    TransformGroup cylinderTrans = new TransformGroup(cylinderMat);
    cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0));
    cylinderTrans.setTransform(cylinderMat);
    cylinderTrans.addChild(
            new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth));
    objTrans.addChild(cylinderTrans);

    objTrans.addChild(objScale);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    apText.setMaterial(mm);

    // Have Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:ConicWorld.java

private Appearance createAppearance(int idx) {
    Appearance app = new Appearance();

    // Globally used colors
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);

    idx = idx % 5;/*  w  w w  . ja v  a2  s . c o m*/

    switch (idx) {
    // Lit solid
    case 0: {
        // Set up the material properties
        Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f);
        app.setMaterial(new Material(objColor, black, objColor, white, 80.0f));
        break;
    }
    // Lit solid, no specular
    case 1: {
        // Set up the material properties
        Color3f objColor = new Color3f(0.0f, 0.8f, 0.0f);
        app.setMaterial(new Material(objColor, black, objColor, white, 80.0f));
        break;
    }

    // Lit solid, specular only
    case 2: {
        // Set up the material properties
        Color3f objColor = new Color3f(0.0f, 0.8f, 0.8f);
        app.setMaterial(new Material(black, black, objColor, white, 80.0f));
        break;
    }

    // Texture mapped, lit solid
    case 3: {
        // Set up the texture map
        TextureLoader tex = new TextureLoader(texImage, this);
        app.setTexture(tex.getTexture());

        // Set up the material properties
        app.setMaterial(new Material(white, black, white, black, 1.0f));
        TextureAttributes texAttr = new TextureAttributes();
        texAttr.setTextureMode(TextureAttributes.MODULATE);
        app.setTextureAttributes(texAttr);

        break;
    }

    // Another lit solid with a different color
    case 4: {
        // Set up the material properties
        Color3f objColor = new Color3f(1.0f, 1.0f, 0.0f);
        app.setMaterial(new Material(objColor, black, objColor, white, 80.0f));
        break;
    }

    default: {
        ColoringAttributes ca = new ColoringAttributes();
        ca.setColor(new Color3f(0.0f, 1.0f, 0.0f));
        app.setColoringAttributes(ca);
    }
    }

    return app;
}

From source file:KeyNavigateTest.java

protected void setTexture(Appearance app, String szFile) {
    Texture tex = new TextureLoader(szFile, m_Component).getTexture();
    app.setTexture(tex);
}

From source file:OrientedPtTest.java

public BranchGroup createSceneGraph() {

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    TransformGroup objScale = new TransformGroup();
    Transform3D textMat = new Transform3D();
    // Assuming uniform size chars, set scale to fit string in view
    textMat.setScale(1.2 / sl);/*from   www.j a v  a2 s.  com*/
    objScale.setTransform(textMat);

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRoot.addChild(objTrans);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    Appearance apText = new Appearance();
    Material m = new Material();
    m.setLightingEnable(true);
    apText.setMaterial(m);

    Appearance apEarth = new Appearance();
    Material mm = new Material();
    mm.setLightingEnable(true);
    apEarth.setMaterial(mm);

    Appearance apStone = new Appearance();
    apStone.setMaterial(mm);

    // create 3D text
    Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
    Point3f textPt = new Point3f(-sl / 2.0f, 3.0f, 0.0f);
    Text3D txt = new Text3D(f3d, textString, textPt);
    OrientedShape3D textShape = new OrientedShape3D();
    textShape.setGeometry(txt);
    textShape.setAppearance(apText);

    textShape.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_POINT);
    // text is centered around 0, 3, 0. Make it rotate around 0,5,0
    Point3f rotationPt = new Point3f(0.0f, 5.0f, 0.0f);
    textShape.setRotationPoint(rotationPt);
    objScale.addChild(textShape);

    // also add a small Sphere at the rotation point to
    // show that we are rotating around the right point
    Sphere sphere = new Sphere(0.2f);
    TransformGroup sphereGroup = new TransformGroup();
    Transform3D sphereXform = new Transform3D();
    sphereXform.set(new Vector3f(rotationPt));
    sphereGroup.setTransform(sphereXform);
    sphereGroup.addChild(sphere);
    objScale.addChild(sphereGroup);

    // Create a simple shape leaf node, add it to the scene graph.

    Transform3D cubeMat = new Transform3D();
    TransformGroup cubeTrans = new TransformGroup(cubeMat);
    cubeMat.set(new Vector3d(0.9, 0.0, -1.0));
    cubeTrans.setTransform(cubeMat);
    cubeTrans.addChild(new ColorCube(0.3));
    objTrans.addChild(cubeTrans);

    TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this);
    if (stoneTex != null)
        apStone.setTexture(stoneTex.getTexture());

    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.REPLACE);
    apStone.setTextureAttributes(texAttr);

    Transform3D coneMat = new Transform3D();
    TransformGroup coneTrans = new TransformGroup(coneMat);
    coneMat.set(new Vector3d(0.0, 0.0, 0.0));
    coneTrans.setTransform(coneMat);
    coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone));
    objTrans.addChild(coneTrans);

    TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this);
    if (earthTex != null)
        apEarth.setTexture(earthTex.getTexture());
    apEarth.setTextureAttributes(texAttr);

    Transform3D cylinderMat = new Transform3D();
    TransformGroup cylinderTrans = new TransformGroup(cylinderMat);
    cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0));
    cylinderTrans.setTransform(cylinderMat);
    cylinderTrans.addChild(
            new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth));
    objTrans.addChild(cylinderTrans);

    objTrans.addChild(objScale);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    apText.setMaterial(mm);

    // Have Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}