Example usage for javax.media.j3d Texture BASE_LEVEL

List of usage examples for javax.media.j3d Texture BASE_LEVEL

Introduction

In this page you can find the example usage for javax.media.j3d Texture BASE_LEVEL.

Prototype

int BASE_LEVEL

To view the source code for javax.media.j3d Texture BASE_LEVEL.

Click Source Link

Document

Indicates that Texture object only has one level.

Usage

From source file:MultiTextureTest.java

public Texture createLightMap() {

    int width = 128;
    int height = 128;
    BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    int[] rgbArray = new int[width * height];
    int index, index2;
    int rgbInc = 256 / (width / 2 - 20);
    int rgbValue = 0;
    int k = width / 2 - 5;
    int i, j, rgb;

    rgb = 0xff;/*from  w  w  w.j  a va  2  s .  com*/
    rgbValue = rgb | (rgb << 8) | (rgb << 16) | (rgb << 24);
    for (i = width / 2 - 1, j = 0; j < 10; j++, i--) {
        rgbArray[i] = rgbValue;
    }

    for (; i > 8; i--, rgb -= rgbInc) {
        rgbValue = rgb | (rgb << 8) | (rgb << 16) | (rgb << 24);
        rgbArray[i] = rgbValue;
    }

    for (; i >= 0; i--) {
        rgbArray[i] = rgbValue;
    }

    for (i = 0; i < width / 2; i++) {
        rgbValue = rgbArray[i];
        index = i;
        index2 = (width - i - 1);
        for (j = 0; j < height; j++) {
            rgbArray[index] = rgbArray[index2] = rgbValue;
            index += width;
            index2 += width;
        }
    }

    bimage.setRGB(0, 0, width, height, rgbArray, 0, width);

    ImageComponent2D grayImage = new ImageComponent2D(ImageComponent.FORMAT_RGB, bimage);

    lightTex = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, width, height);
    lightTex.setImage(0, grayImage);

    return lightTex;
}

From source file:ImageComponentByReferenceTest.java

public BranchGroup createSceneGraph() {
    objRoot = new BranchGroup();

    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(Group.ALLOW_CHILDREN_WRITE);

    objRoot.addChild(objTrans);//from www. j ava2 s  .  co m

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

    app.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    textureCube = new Box(0.4f, 0.4f, 0.4f, Box.GENERATE_TEXTURE_COORDS | Box.GENERATE_NORMALS, app);
    boxShape = textureCube.getShape(Box.FRONT);
    boxShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    objTrans.addChild(textureCube);

    checkBoard = new TiledImage();
    TextureLoader texLoader = new TextureLoader(texImage, this);
    ImageComponent2D oneImage = texLoader.getImage();
    bImage1 = oneImage.getImage();

    int index = 0;
    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, true);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, true);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, false);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, false);

    createRaster(objRoot);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, true);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, true);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, false);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, false);

    texOne = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[2].getWidth(), image[2].getHeight());

    texOne.setCapability(Texture.ALLOW_IMAGE_WRITE);
    texOne.setImage(0, image[2]);

    app.setTexture(texOne);

    texCheckBoard = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[4].getWidth(), image[4].getHeight());

    texCheckBoard.setCapability(Texture.ALLOW_IMAGE_WRITE);
    objRoot.compile();
    return objRoot;
}

From source file:TexBug.java

void setupAppearance() {
    appearance = new Appearance();

    // Texture2D/*from   w w w .  ja v a2 s  .c  om*/

    // set the values to the defaults
    texEnable = false;
    texMipMapMode = Texture.BASE_LEVEL;
    texBoundaryModeS = Texture.WRAP;
    texBoundaryModeT = Texture.WRAP;
    texMinFilter = Texture.BASE_LEVEL_POINT;
    texMagFilter = Texture.BASE_LEVEL_POINT;
    texBoundaryColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f);

    // set up the appearance to allow the texture to be changed
    appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    // set the texture
    setTexture();
}

From source file:BooksDemo.java

private Appearance createTexture(String fileName) {
    Image sourceImage = UIHelper.readImage(fileName);
    if (sourceImage == null)
        System.out.println("Image could not be loaded from " + fileName);

    TextureLoader loader = new TextureLoader(sourceImage, this);
    ImageComponent2D image = loader.getImage();

    if (image == null)
        System.out.println("Texture could not be loaded from " + fileName);

    Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image.getWidth(), image.getHeight());
    texture.setImage(0, image);//from   www  .ja v a2 s.c om
    texture.setEnable(true);
    texture.setMagFilter(Texture.BASE_LEVEL_LINEAR);
    texture.setMinFilter(Texture.BASE_LEVEL_LINEAR);

    Appearance appearance = new Appearance();
    PolygonAttributes polyAttributes = new PolygonAttributes(PolygonAttributes.POLYGON_FILL,
            PolygonAttributes.CULL_NONE, 0f);
    appearance.setPolygonAttributes(polyAttributes);
    appearance.setTexture(texture);

    TextureAttributes textureAttributes = new TextureAttributes();
    appearance.setTextureAttributes(textureAttributes);

    return appearance;
}

From source file:ExHenge.java

public Group buildScene() {
    // Turn off the example headlight
    setHeadlightEnable(false);/*from   w w  w .  j a  v a 2 s  . c  o m*/

    // Default to walk navigation
    setNavigationType(Walk);

    //
    // Preload the texture images
    //
    if (debug)
        System.err.println("  textures...");
    Texture groundTex = null;
    Texture spurTex = null;
    Texture domeTex = null;
    TextureLoader texLoader = null;
    ImageComponent image = null;

    texLoader = new TextureLoader("mud01.jpg", this);
    image = texLoader.getImage();
    if (image == null)
        System.err.println("Cannot load mud01.jpg texture");
    else {
        groundTex = texLoader.getTexture();
        groundTex.setBoundaryModeS(Texture.WRAP);
        groundTex.setBoundaryModeT(Texture.WRAP);
        groundTex.setMinFilter(Texture.NICEST);
        groundTex.setMagFilter(Texture.NICEST);
        groundTex.setMipMapMode(Texture.BASE_LEVEL);
        groundTex.setEnable(true);
    }

    texLoader = new TextureLoader("stonebrk2.jpg", this);
    image = texLoader.getImage();
    if (image == null)
        System.err.println("Cannot load stonebrk2.jpg texture");
    else {
        spurTex = texLoader.getTexture();
        spurTex.setBoundaryModeS(Texture.WRAP);
        spurTex.setBoundaryModeT(Texture.WRAP);
        spurTex.setMinFilter(Texture.NICEST);
        spurTex.setMagFilter(Texture.NICEST);
        spurTex.setMipMapMode(Texture.BASE_LEVEL);
        spurTex.setEnable(true);
    }

    texLoader = new TextureLoader("fire.jpg", this);
    image = texLoader.getImage();
    if (image == null)
        System.err.println("Cannot load fire.jpg texture");
    else {
        domeTex = texLoader.getTexture();
        domeTex.setBoundaryModeS(Texture.WRAP);
        domeTex.setBoundaryModeT(Texture.WRAP);
        domeTex.setMinFilter(Texture.NICEST);
        domeTex.setMagFilter(Texture.NICEST);
        domeTex.setMipMapMode(Texture.BASE_LEVEL);
        domeTex.setEnable(true);
    }

    //
    // Build some shapes we'll need
    //
    if (debug)
        System.err.println("  flying buttresses...");

    // Build three types of spurs (flying buttresses)
    Appearance spurApp = new Appearance();

    Material spurMat = new Material();
    spurMat.setAmbientColor(0.6f, 0.6f, 0.6f);
    spurMat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    spurMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    spurApp.setMaterial(spurMat);

    Transform3D tr = new Transform3D();
    tr.setIdentity();
    tr.setScale(new Vector3d(1.0, 4.0, 1.0));

    TextureAttributes spurTexAtt = new TextureAttributes();
    spurTexAtt.setTextureMode(TextureAttributes.MODULATE);
    spurTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    spurTexAtt.setTextureTransform(tr);
    spurApp.setTextureAttributes(spurTexAtt);

    if (spurTex != null)
        spurApp.setTexture(spurTex);

    Arch spur1 = new Arch(0.0, // start Phi
            1.571, // end Phi
            9, // nPhi
            -0.0982, // start Theta
            0.0982, // end Theta (11.25 degrees)
            2, // nTheta
            2.5, // start radius
            1.0, // end radius
            0.05, // start phi thickness
            0.025, // end phi thickness
            spurApp); // appearance

    Arch spur2 = new Arch(0.0, // start Phi
            1.571, // end Phi
            9, // nPhi
            -0.0982, // start Theta
            0.0982, // end Theta (11.25 degrees)
            2, // nTheta
            1.5, // start radius
            2.0, // end radius
            0.05, // start phi thickness
            0.025, // end phi thickness
            spurApp); // appearance

    Arch spur3 = new Arch(0.0, // start Phi
            1.571, // end Phi
            9, // nPhi
            -0.0982, // start Theta
            0.0982, // end Theta (11.25 degrees)
            2, // nTheta
            1.5, // start radius
            1.0, // end radius
            0.05, // start phi thickness
            0.025, // end phi thickness
            spurApp); // appearance

    Arch spur4 = new Arch(0.0, // start Phi
            1.178, // end Phi
            9, // nPhi
            -0.0982, // start Theta
            0.0982, // end Theta (11.25 degrees)
            2, // nTheta
            4.0, // start radius
            4.0, // end radius
            0.05, // start phi thickness
            0.025, // end phi thickness
            spurApp); // appearance

    // Put each spur into a shared group so we can instance
    // the spurs multiple times
    SharedGroup spur1Group = new SharedGroup();
    spur1Group.addChild(spur1);
    spur1Group.compile();

    SharedGroup spur2Group = new SharedGroup();
    spur2Group.addChild(spur2);
    spur2Group.compile();

    SharedGroup spur3Group = new SharedGroup();
    spur3Group.addChild(spur3);
    spur3Group.compile();

    SharedGroup spur4Group = new SharedGroup();
    spur4Group.addChild(spur4);
    spur4Group.compile();

    // Build a central dome
    if (debug)
        System.err.println("  central dome...");

    Appearance domeApp = new Appearance();
    // No material needed - we want the dome to glow,
    // so use a REPLACE mode texture only
    TextureAttributes domeTexAtt = new TextureAttributes();
    domeTexAtt.setTextureMode(TextureAttributes.REPLACE);
    domeTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    domeApp.setTextureAttributes(domeTexAtt);

    if (domeTex != null)
        domeApp.setTexture(domeTex);

    Arch dome = new Arch(0.0, // start Phi
            1.571, // end Phi
            5, // nPhi
            0.0, // start Theta
            2.0 * Math.PI, // end Theta (360 degrees)
            17, // nTheta
            1.0, // start radius
            1.0, // end radius
            0.0, // start phi thickness
            0.0, // end phi thickness
            domeApp); // appearance

    // Build the ground. Use a trick to get better lighting
    // effects by using an elevation grid. The idea is this:
    // for interactive graphics systems, such as those
    // controlled by Java3D, lighting effects are computed only
    // at triangle vertexes. Imagine a big rectangular ground
    // underneath a PointLight (added below). If the
    // PointLight is above the center of the square, in the real
    // world we'd expect a bright spot below it, fading to
    // darkness at the edges of the square. Not so in
    // interactive graphics. Since lighting is only computed
    // at vertexes, and the square's vertexes are each
    // equidistant from a centered PointLight, all four square
    // coordinates get the same brightness. That brightness
    // is interpolated across the square, giving a *constant*
    // brightness for the entire square! There is no bright
    // spot under the PointLight. So, here's the trick: use
    // more triangles. Pretty simple. Split the ground under
    // the PointLight into a grid of smaller squares. Each
    // smaller square is shaded using light brightness computed
    // at the square's vertexes. Squares directly under the
    // PointLight get brighter lighting at their vertexes, and
    // thus they are bright. This gives the desired bright
    // spot under the PointLight. The more squares we use
    // (a denser grid), the more accurate the bright spot and
    // the smoother the lighting gradation from bright directly
    // under the PointLight, to dark at the distant edges. Of
    // course, with more squares, we also get more polygons to
    // draw and a performance slow-down. So there is a
    // tradeoff between lighting quality and drawing speed.
    // For this example, we'll use a coarse mesh of triangles
    // created using an ElevationGrid shape.
    if (debug)
        System.err.println("  ground...");

    Appearance groundApp = new Appearance();

    Material groundMat = new Material();
    groundMat.setAmbientColor(0.3f, 0.3f, 0.3f);
    groundMat.setDiffuseColor(0.7f, 0.7f, 0.7f);
    groundMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    groundApp.setMaterial(groundMat);

    tr = new Transform3D();
    tr.setScale(new Vector3d(8.0, 8.0, 1.0));

    TextureAttributes groundTexAtt = new TextureAttributes();
    groundTexAtt.setTextureMode(TextureAttributes.MODULATE);
    groundTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    groundTexAtt.setTextureTransform(tr);
    groundApp.setTextureAttributes(groundTexAtt);

    if (groundTex != null)
        groundApp.setTexture(groundTex);

    ElevationGrid ground = new ElevationGrid(11, // X dimension
            11, // Z dimension
            2.0f, // X spacing
            2.0f, // Z spacing
            // Automatically use zero heights
            groundApp); // Appearance

    //
    // Build the scene using the shapes above. Place everything
    // withing a TransformGroup.
    //
    // Build the scene root
    TransformGroup scene = new TransformGroup();
    tr = new Transform3D();
    tr.setTranslation(new Vector3f(0.0f, -1.6f, 0.0f));
    scene.setTransform(tr);

    // Create influencing bounds
    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    // General Ambient light
    ambient = new AmbientLight();
    ambient.setEnable(ambientOnOff);
    ambient.setColor(new Color3f(0.3f, 0.3f, 0.3f));
    ambient.setCapability(AmbientLight.ALLOW_STATE_WRITE);
    ambient.setInfluencingBounds(worldBounds);
    scene.addChild(ambient);

    // Bright Ambient light
    brightAmbient = new AmbientLight();
    brightAmbient.setEnable(brightAmbientOnOff);
    brightAmbient.setColor(new Color3f(1.0f, 1.0f, 1.0f));
    brightAmbient.setCapability(AmbientLight.ALLOW_STATE_WRITE);
    brightAmbient.setInfluencingBounds(worldBounds);
    scene.addChild(brightAmbient);

    // Red directional light
    redDirectional = new DirectionalLight();
    redDirectional.setEnable(redDirectionalOnOff);
    redDirectional.setColor(new Color3f(1.0f, 0.0f, 0.0f));
    redDirectional.setDirection(new Vector3f(1.0f, -0.5f, -0.5f));
    redDirectional.setCapability(AmbientLight.ALLOW_STATE_WRITE);
    redDirectional.setInfluencingBounds(worldBounds);
    scene.addChild(redDirectional);

    // Yellow directional light
    yellowDirectional = new DirectionalLight();
    yellowDirectional.setEnable(yellowDirectionalOnOff);
    yellowDirectional.setColor(new Color3f(1.0f, 0.8f, 0.0f));
    yellowDirectional.setDirection(new Vector3f(-1.0f, 0.5f, 1.0f));
    yellowDirectional.setCapability(AmbientLight.ALLOW_STATE_WRITE);
    yellowDirectional.setInfluencingBounds(worldBounds);
    scene.addChild(yellowDirectional);

    // Orange point light
    orangePoint = new PointLight();
    orangePoint.setEnable(orangePointOnOff);
    orangePoint.setColor(new Color3f(1.0f, 0.5f, 0.0f));
    orangePoint.setPosition(new Point3f(0.0f, 0.5f, 0.0f));
    orangePoint.setCapability(AmbientLight.ALLOW_STATE_WRITE);
    orangePoint.setInfluencingBounds(worldBounds);
    scene.addChild(orangePoint);

    // Ground
    scene.addChild(ground);

    // Dome
    scene.addChild(dome);

    // Spur 1's
    Group g = buildRing(spur1Group);
    scene.addChild(g);

    // Spur 2's
    TransformGroup tg = new TransformGroup();
    tr = new Transform3D();
    tr.rotY(0.3927);
    tg.setTransform(tr);
    g = buildRing(spur2Group);
    tg.addChild(g);
    scene.addChild(tg);

    // Spur 3's
    g = buildRing(spur3Group);
    scene.addChild(g);

    // Spur 4's
    tg = new TransformGroup();
    tg.setTransform(tr);
    g = buildRing(spur4Group);
    tg.addChild(g);
    scene.addChild(tg);

    return scene;
}

From source file:TexBug.java

void setTexture() {
    // set up the image using the TextureLoader
    java.net.URL imageURL = null;
    try {//  ww w . ja  v  a2s .co  m
        imageURL = new java.net.URL(codeBaseString + "earth.jpg");
        //imageURL = new java.net.URL(codeBaseString +
        //   "decal_textures/fish1.gif");
    } catch (Exception e) {
        System.err.println("Exception: " + e);
        System.exit(1);
    }
    int flags;
    if (texMipMapMode == Texture.BASE_LEVEL) {
        flags = 0;
    } else {
        flags = TextureLoader.GENERATE_MIPMAP;
    }
    texLoader = new TextureLoader(imageURL, new String("RGBA"),
            //new String("LUMINANCE"),
            flags, this);

    // We could create texture from image
    //
    // Get the image from the loader. We need an image which
    // has power of two dimensions, so we'll get the unscaled image,
    // figure out what the scaled size should be and then get a scale
    // image
    //ImageComponent2D unscaledImage = texLoader.getImage();
    //int width = unscaledImage.getWidth();
    //int height = unscaledImage.getWidth();
    //
    // scaled values are next power of two greater than or equal to
    // value
    //texWidth = powerOfTwo(width);
    //texHeight = powerOfTwo(height);
    //
    // rescale the image if necessary
    //ImageComponent2D texImage;
    //if ((texWidth == width) && (texHeight == height)) {
    //    texImage = unscaledImage;
    //} else {
    //    texImage = texLoader.getScaledImage(texWidth, texHeight);
    //}
    //texFormat = Texture.RGB;
    //texture = new Texture2D(texMipMapMode, texFormat, texWidth,
    //   texHeight);
    //texture.setImage(0, texImage);

    // instead we'll just get get the texture from loader
    texture = (Texture2D) texLoader.getTexture();

    //texture.setBoundaryColor(texBoundaryColor);
    texture.setBoundaryColor(1.0f, 1.0f, 1.0f, 1.0f);
    texture.setBoundaryModeS(texBoundaryModeS);
    texture.setBoundaryModeT(texBoundaryModeT);
    texture.setEnable(texEnable);
    texture.setMinFilter(texMinFilter);
    texture.setMagFilter(texMagFilter);

    // Set the capabilities to enable the changable attrs
    texture.setCapability(Texture.ALLOW_ENABLE_WRITE);
    texture.setCapability(Texture.ALLOW_IMAGE_WRITE);

    // connect the new texture to the appearance
    System.out.println("Appearance.setTexture(" + texture + ")");
    appearance.setTexture(texture);
}

From source file:ExSwitch.java

public Group buildScene() {
    // Turn on the example headlight
    setHeadlightEnable(true);/*from   ww  w . j  a v a 2  s  . com*/

    // Default to walk navigation
    setNavigationType(Walk);

    // Build the scene group
    Group scene = new Group();

    if (debug)
        System.err.println("  switch shapes...");

    // BEGIN EXAMPLE TOPIC
    // Build the switch group and allow its switch
    // value to be changed via menu items
    swtch = new Switch();
    swtch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    //  Create several shapes to place in a switch group

    // Child 0: a red sphere
    Appearance app0 = new Appearance();
    Material mat0 = new Material();
    mat0.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat0.setDiffuseColor(1.0f, 0.0f, 0.2f);
    mat0.setSpecularColor(0.7f, 0.7f, 0.7f);
    app0.setMaterial(mat0);

    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3f(-2.0f, 1.5f, 0.0f));
    TransformGroup tg0 = new TransformGroup(t3d);
    Sphere sph0 = new Sphere(0.5f, // radius
            Primitive.GENERATE_NORMALS, // components
            16, // facets
            app0); // appearance
    tg0.addChild(sph0);
    swtch.addChild(tg0); // Child 0

    // Child 1: a green sphere
    Appearance app1 = new Appearance();
    Material mat1 = new Material();
    mat1.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat1.setDiffuseColor(0.0f, 1.0f, 0.0f);
    mat1.setSpecularColor(0.7f, 0.7f, 0.7f);
    app1.setMaterial(mat1);
    t3d.setTranslation(new Vector3f(0.0f, 1.5f, 0.0f));
    TransformGroup tg1 = new TransformGroup(t3d);
    Sphere sph1 = new Sphere(0.5f, // radius
            Primitive.GENERATE_NORMALS, // components
            16, // facets
            app1); // appearance
    tg1.addChild(sph1);
    swtch.addChild(tg1); // Child 1

    // Child 2: a blue sphere
    Appearance app2 = new Appearance();
    Material mat2 = new Material();
    mat2.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat2.setDiffuseColor(0.0f, 0.6f, 1.0f);
    mat2.setSpecularColor(0.7f, 0.7f, 0.7f);
    app2.setMaterial(mat2);
    t3d.setTranslation(new Vector3f(2.0f, 1.5f, 0.0f));
    TransformGroup tg2 = new TransformGroup(t3d);
    Sphere sph2 = new Sphere(0.5f, // radius
            Primitive.GENERATE_NORMALS, // components
            16, // facets
            app2); // appearance
    tg2.addChild(sph2);
    swtch.addChild(tg2);

    // Set the initial child choice
    swtch.setWhichChild(options[currentSwitch].child);
    scene.addChild(swtch);
    // END EXAMPLE TOPIC

    // Build foreground geometry including a floor and
    // columns on which the switchable shapes stand

    // Load textures
    TextureLoader texLoader = new TextureLoader("granite07rev.jpg", this);
    Texture columnTex = texLoader.getTexture();
    if (columnTex == null)
        System.err.println("Cannot load granite07rev.jpg texture");
    else {
        columnTex.setBoundaryModeS(Texture.WRAP);
        columnTex.setBoundaryModeT(Texture.WRAP);
        columnTex.setMinFilter(Texture.NICEST);
        columnTex.setMagFilter(Texture.NICEST);
        columnTex.setMipMapMode(Texture.BASE_LEVEL);
        columnTex.setEnable(true);
    }

    texLoader = new TextureLoader("flooring.jpg", this);
    Texture groundTex = texLoader.getTexture();
    if (groundTex == null)
        System.err.println("Cannot load flooring.jpg texture");
    else {
        groundTex.setBoundaryModeS(Texture.WRAP);
        groundTex.setBoundaryModeT(Texture.WRAP);
        groundTex.setMinFilter(Texture.NICEST);
        groundTex.setMagFilter(Texture.NICEST);
        groundTex.setMipMapMode(Texture.BASE_LEVEL);
        groundTex.setEnable(true);
    }

    //
    // Build several columns on the floor
    //
    if (debug)
        System.err.println("  columns...");
    SharedGroup column = new SharedGroup();
    Appearance columnApp = new Appearance();

    Material columnMat = new Material();
    columnMat.setAmbientColor(0.6f, 0.6f, 0.6f);
    columnMat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    columnMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    columnApp.setMaterial(columnMat);

    TextureAttributes columnTexAtt = new TextureAttributes();
    columnTexAtt.setTextureMode(TextureAttributes.MODULATE);
    columnTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    columnApp.setTextureAttributes(columnTexAtt);

    if (columnTex != null)
        columnApp.setTexture(columnTex);

    GothicColumn columnShape = new GothicColumn(1.8f, // height
            0.25f, // radius
            GothicColumn.BUILD_TOP, // flags
            columnApp); // appearance
    column.addChild(columnShape);

    Vector3f trans = new Vector3f();
    Transform3D tr = new Transform3D();
    TransformGroup tg;

    // Left
    trans.set(-2.0f, -1.0f, 0.0f);
    tr.set(trans);
    tg = new TransformGroup(tr);
    tg.addChild(new Link(column));
    scene.addChild(tg);

    // Middle
    trans.set(0.0f, -1.0f, 0.0f);
    tr.set(trans);
    tg = new TransformGroup(tr);
    tg.addChild(new Link(column));
    scene.addChild(tg);

    // Right
    trans.set(2.0f, -1.0f, 0.0f);
    tr.set(trans);
    tg = new TransformGroup(tr);
    tg.addChild(new Link(column));
    scene.addChild(tg);

    //
    //  Add the ground
    //
    if (debug)
        System.err.println("  ground...");

    Appearance groundApp = new Appearance();

    Material groundMat = new Material();
    groundMat.setAmbientColor(0.6f, 0.6f, 0.6f);
    groundMat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    groundMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    groundApp.setMaterial(groundMat);

    tr = new Transform3D();
    tr.setScale(new Vector3d(4.0, 4.0, 1.0));

    TextureAttributes groundTexAtt = new TextureAttributes();
    groundTexAtt.setTextureMode(TextureAttributes.MODULATE);
    groundTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    groundTexAtt.setTextureTransform(tr);
    groundApp.setTextureAttributes(groundTexAtt);

    if (groundTex != null)
        groundApp.setTexture(groundTex);

    ElevationGrid ground = new ElevationGrid(11, // X dimension
            11, // Z dimension
            2.0f, // X spacing
            2.0f, // Z spacing
            // Automatically use zero heights
            groundApp); // Appearance

    trans.set(0.0f, -1.0f, 0.0f);
    tr.set(trans);
    tg = new TransformGroup(tr);
    tg.addChild(ground);
    scene.addChild(tg);

    // Add a light
    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    DirectionalLight light = new DirectionalLight();
    light.setEnable(true);
    light.setColor(new Color3f(1.0f, 1.0f, 1.0f));
    light.setDirection(new Vector3f(0.5f, -1.0f, -0.5f));
    light.setInfluencingBounds(worldBounds);
    scene.addChild(light);

    return scene;
}

From source file:ExSound.java

private Group buildForeground() {
    ///*  w  ww .  j  a  va 2 s .c o m*/
    //  Create a group for the foreground, and move
    //  everything up a bit.
    //
    TransformGroup group = new TransformGroup();
    Transform3D tr = new Transform3D();
    tr.setTranslation(new Vector3f(0.0f, -1.6f, 0.0f));
    group.setTransform(tr);

    //
    //  Load textures
    //
    if (debug)
        System.err.println("  textures...");
    Texture groundTex = null;
    Texture spurTex = null;
    Texture domeTex = null;
    TextureLoader texLoader = null;
    ImageComponent image = null;

    texLoader = new TextureLoader("flooring.jpg", this);
    image = texLoader.getImage();
    if (image == null)
        System.err.println("Cannot load flooring.jpg texture");
    else {
        groundTex = texLoader.getTexture();
        groundTex.setBoundaryModeS(Texture.WRAP);
        groundTex.setBoundaryModeT(Texture.WRAP);
        groundTex.setMinFilter(Texture.NICEST);
        groundTex.setMagFilter(Texture.NICEST);
        groundTex.setMipMapMode(Texture.BASE_LEVEL);
        groundTex.setEnable(true);
    }

    texLoader = new TextureLoader("granite07rev.jpg", this);
    Texture columnTex = texLoader.getTexture();
    if (columnTex == null)
        System.err.println("Cannot load granite07rev.jpg texture");
    else {
        columnTex.setBoundaryModeS(Texture.WRAP);
        columnTex.setBoundaryModeT(Texture.WRAP);
        columnTex.setMinFilter(Texture.NICEST);
        columnTex.setMagFilter(Texture.NICEST);
        columnTex.setMipMapMode(Texture.BASE_LEVEL);
        columnTex.setEnable(true);
    }

    texLoader = new TextureLoader("brtsky.jpg", this);
    Texture boxTex = texLoader.getTexture();
    if (boxTex == null)
        System.err.println("Cannot load brtsky.jpg texture");
    else {
        boxTex.setBoundaryModeS(Texture.WRAP);
        boxTex.setBoundaryModeT(Texture.WRAP);
        boxTex.setMinFilter(Texture.NICEST);
        boxTex.setMagFilter(Texture.NICEST);
        boxTex.setMipMapMode(Texture.BASE_LEVEL);
        boxTex.setEnable(true);
    }

    //
    //  Build the ground
    //
    if (debug)
        System.err.println("  ground...");

    Appearance groundApp = new Appearance();

    Material groundMat = new Material();
    groundMat.setAmbientColor(0.3f, 0.3f, 0.3f);
    groundMat.setDiffuseColor(0.7f, 0.7f, 0.7f);
    groundMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    groundApp.setMaterial(groundMat);

    tr = new Transform3D();
    tr.setScale(new Vector3d(16.0, 4.0, 1.0));

    TextureAttributes groundTexAtt = new TextureAttributes();
    groundTexAtt.setTextureMode(TextureAttributes.MODULATE);
    groundTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    groundTexAtt.setTextureTransform(tr);
    groundApp.setTextureAttributes(groundTexAtt);

    if (groundTex != null)
        groundApp.setTexture(groundTex);

    ElevationGrid ground = new ElevationGrid(11, // X dimension
            11, // Z dimension
            2.0f, // X spacing
            2.0f, // Z spacing
            // Automatically use zero heights
            groundApp); // Appearance
    group.addChild(ground);

    //
    //  Create a column appearance used for both columns.
    //
    Appearance columnApp = new Appearance();

    Material columnMat = new Material();
    columnMat.setAmbientColor(0.6f, 0.6f, 0.6f);
    columnMat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    columnMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    columnApp.setMaterial(columnMat);

    TextureAttributes columnTexAtt = new TextureAttributes();
    columnTexAtt.setTextureMode(TextureAttributes.MODULATE);
    columnTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    columnApp.setTextureAttributes(columnTexAtt);

    if (columnTex != null)
        columnApp.setTexture(columnTex);

    //
    //  To give the point sound an apparent location,
    //  build a column and a set of three co-located
    //  tumbling boxes hovering above the column.
    //
    TransformGroup pointGroup = new TransformGroup();
    tr.setIdentity();
    tr.setTranslation(new Vector3f(pointX, 0.0f, 0.0f));
    pointGroup.setTransform(tr);

    GothicColumn column = new GothicColumn(1.0f, // height
            0.2f, // radius
            GothicColumn.BUILD_TOP, // flags
            columnApp); // appearance
    pointGroup.addChild(column);

    TransformGroup rotThing = new TransformGroup();
    tr.setIdentity();
    tr.setTranslation(new Vector3f(0.0f, soundHeight, 0.0f));
    rotThing.setTransform(tr);

    Appearance boxApp = new Appearance();
    // No material -- make it emissive
    TextureAttributes boxTexAtt = new TextureAttributes();
    boxTexAtt.setTextureMode(TextureAttributes.REPLACE);
    boxTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    boxApp.setTextureAttributes(boxTexAtt);

    if (boxTex != null)
        boxApp.setTexture(boxTex);

    rotThing.addChild(buildTumblingBox(0.4f, 0.4f, 0.4f, // width, height,
            // depth
            boxApp, // Appearance
            40000, 32000, 26000));// XYZ tumble durations
    rotThing.addChild(buildTumblingBox(0.4f, 0.4f, 0.4f, // width, height,
            // depth
            boxApp, // Appearance
            38000, 30000, 28000));// XYZ tumble durations
    rotThing.addChild(buildTumblingBox(0.4f, 0.4f, 0.4f, // width, height,
            // depth
            boxApp, // Appearance
            30000, 26000, 34000));// XYZ tumble durations

    pointGroup.addChild(rotThing);

    group.addChild(pointGroup);

    return group;
}

From source file:ExBackgroundImage.java

public TowerScene(Component observer) {
    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    // Add a few lights
    AmbientLight ambient = new AmbientLight();
    ambient.setEnable(true);/*from w  w  w .  j a  va2 s . c o m*/
    ambient.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    ambient.setInfluencingBounds(worldBounds);
    addChild(ambient);

    DirectionalLight dir1 = new DirectionalLight();
    dir1.setEnable(true);
    dir1.setColor(new Color3f(1.0f, 0.15f, 0.15f));
    dir1.setDirection(new Vector3f(0.8f, -0.35f, -0.5f));
    dir1.setInfluencingBounds(worldBounds);
    addChild(dir1);

    DirectionalLight dir2 = new DirectionalLight();
    dir2.setEnable(true);
    dir2.setColor(new Color3f(0.15f, 0.15f, 1.0f));
    dir2.setDirection(new Vector3f(-0.7f, -0.35f, 0.5f));
    dir2.setInfluencingBounds(worldBounds);
    addChild(dir2);

    // Load textures
    TextureLoader texLoader = new TextureLoader("moon5.jpg", observer);
    Texture moon = texLoader.getTexture();
    if (moon == null)
        System.err.println("Cannot load moon5.jpg texture");
    else {
        moon.setBoundaryModeS(Texture.WRAP);
        moon.setBoundaryModeT(Texture.WRAP);
        moon.setMinFilter(Texture.NICEST);
        moon.setMagFilter(Texture.NICEST);
        moon.setMipMapMode(Texture.BASE_LEVEL);
        moon.setEnable(true);
    }

    texLoader = new TextureLoader("stonebrk2.jpg", observer);
    Texture stone = texLoader.getTexture();
    if (stone == null)
        System.err.println("Cannot load stonebrk2.jpg texture");
    else {
        stone.setBoundaryModeS(Texture.WRAP);
        stone.setBoundaryModeT(Texture.WRAP);
        stone.setMinFilter(Texture.NICEST);
        stone.setMagFilter(Texture.NICEST);
        stone.setMipMapMode(Texture.BASE_LEVEL);
        stone.setEnable(true);
    }

    //
    //  Build a rough terrain
    //
    Appearance moonApp = new Appearance();

    Material moonMat = new Material();
    moonMat.setAmbientColor(0.5f, 0.5f, 0.5f);
    moonMat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    moonMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    moonApp.setMaterial(moonMat);

    TextureAttributes moonTexAtt = new TextureAttributes();
    moonTexAtt.setTextureMode(TextureAttributes.MODULATE);
    moonTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    moonApp.setTextureAttributes(moonTexAtt);

    if (moon != null)
        moonApp.setTexture(moon);

    CraterGrid grid = new CraterGrid(50, 50, // grid dimensions
            1.0, 1.0, // grid spacing
            4.0, // height exageration factor
            craters, // grid elevations
            moonApp); // grid appearance
    addChild(grid);

    //
    // Build several towers on the terrain
    //
    SharedGroup tower = new SharedGroup();
    Appearance towerApp = new Appearance();

    Material towerMat = new Material();
    towerMat.setAmbientColor(0.6f, 0.6f, 0.6f);
    towerMat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    towerMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    towerApp.setMaterial(towerMat);

    Transform3D tr = new Transform3D();
    tr.setScale(new Vector3d(4.0, 4.0, 1.0));

    TextureAttributes towerTexAtt = new TextureAttributes();
    towerTexAtt.setTextureMode(TextureAttributes.MODULATE);
    towerTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    towerTexAtt.setTextureTransform(tr);
    towerApp.setTextureAttributes(towerTexAtt);

    if (stone != null)
        towerApp.setTexture(stone);

    Arch towerShape = new Arch(0.0, // start Phi
            1.571, // end Phi
            2, // nPhi
            0.0, // start Theta
            Math.PI * 2.0, // end Theta
            5, // nTheta
            3.0, // start radius
            8.0, // end radius
            0.0, // start phi thickness
            0.0, // end phi thickness
            towerApp); // appearance
    tower.addChild(towerShape);

    // Place towers
    Matrix3f rot = new Matrix3f();
    rot.setIdentity();

    TransformGroup tg = new TransformGroup(new Transform3D(rot, new Vector3d(2.0, -3.0, -8.0), 1.0));
    tg.addChild(new Link(tower));
    addChild(tg);

    tg = new TransformGroup(new Transform3D(rot, new Vector3d(-1.0, -3.0, -6.0), 0.5));
    tg.addChild(new Link(tower));
    addChild(tg);

    tg = new TransformGroup(new Transform3D(rot, new Vector3d(5.0, -3.0, -6.0), 0.75));
    tg.addChild(new Link(tower));
    addChild(tg);

    tg = new TransformGroup(new Transform3D(rot, new Vector3d(1.0, -3.0, -3.0), 0.35));
    tg.addChild(new Link(tower));
    addChild(tg);
}

From source file:TexBug.java

public void actionPerformed(ActionEvent e) {
    String action = e.getActionCommand();
    Object source = e.getSource();
    if (action == texEnableString) {
        texEnable = texEnableCheckBox.isSelected();
        System.out.println("texture.setEnable(" + texEnable + ")");
        texture.setEnable(texEnable);/*from  ww  w . j av a2 s . c  o  m*/
    } else if (action == texBoundarySWrapString) {
        texBoundaryModeS = Texture.WRAP;
        setTexture();
    } else if (action == texBoundarySClampString) {
        texBoundaryModeS = Texture.CLAMP;
        setTexture();
    } else if (action == texBoundaryTWrapString) {
        texBoundaryModeT = Texture.WRAP;
        setTexture();
    } else if (action == texBoundaryTClampString) {
        texBoundaryModeT = Texture.CLAMP;
        setTexture();
    } else if (action == texMinFilterBasePointString) {
        texMinFilter = Texture.BASE_LEVEL_POINT;
        setTexture();
    } else if (action == texMinFilterBaseLinearString) {
        texMinFilter = Texture.BASE_LEVEL_LINEAR;
        setTexture();
    } else if (action == texMinFilterMultiPointString) {
        texMinFilter = Texture.MULTI_LEVEL_POINT;
        setTexture();
    } else if (action == texMinFilterMultiLinearString) {
        texMinFilter = Texture.MULTI_LEVEL_LINEAR;
        setTexture();
    } else if (action == texMinFilterFastestString) {
        texMinFilter = Texture.FASTEST;
        setTexture();
    } else if (action == texMinFilterNicestString) {
        texMinFilter = Texture.NICEST;
        setTexture();
    } else if (action == texMagFilterBasePointString) {
        texMagFilter = Texture.BASE_LEVEL_POINT;
        setTexture();
    } else if (action == texMagFilterBaseLinearString) {
        texMagFilter = Texture.BASE_LEVEL_LINEAR;
        setTexture();
    } else if (action == texMagFilterNicestString) {
        texMagFilter = Texture.NICEST;
        setTexture();
    } else if (action == texMagFilterFastestString) {
        texMagFilter = Texture.FASTEST;
        setTexture();
    } else if (action == texMipMapBaseString) {
        texMipMapMode = Texture.BASE_LEVEL;
        setTexture();
    } else if (action == texMipMapMultiString) {
        texMipMapMode = Texture.MULTI_LEVEL_MIPMAP;
        setTexture();
    }
}