Example usage for javax.media.j3d Group Group

List of usage examples for javax.media.j3d Group Group

Introduction

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

Prototype

public Group() 

Source Link

Document

Constructs a Group node with default parameters.

Usage

From source file:ExPointLight.java

public Group buildScene() {
    // Get the current color, position, and attenuation
    Color3f color = (Color3f) colors[currentColor].value;
    Point3f pos = (Point3f) positions[currentPosition].value;
    Point3f atten = (Point3f) attenuations[currentAttenuation].value;

    // Turn off the example headlight
    setHeadlightEnable(false);/*from   w w  w  .  j ava  2s.c  om*/

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

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

    // Set the light color and its influencing bounds
    light = new PointLight();
    light.setEnable(lightOnOff);
    light.setColor(color);
    light.setPosition(pos);
    light.setAttenuation(atten);
    light.setCapability(PointLight.ALLOW_STATE_WRITE);
    light.setCapability(PointLight.ALLOW_COLOR_WRITE);
    light.setCapability(PointLight.ALLOW_POSITION_WRITE);
    light.setCapability(PointLight.ALLOW_ATTENUATION_WRITE);
    light.setInfluencingBounds(worldBounds);
    scene.addChild(light);
    // END EXAMPLE TOPIC

    // Build foreground geometry
    scene.addChild(new SphereGroup());

    // Add arrows in a fan to show light ray directions
    scene.addChild(buildArrows());

    return scene;
}

From source file:ExSwitch.java

public Group buildScene() {
    // Turn on the example headlight
    setHeadlightEnable(true);//w  w  w.ja v  a2 s . c o m

    // 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:ExBackgroundColor.java

public Group buildScene() {
    // Get the current color
    Color3f color = (Color3f) colors[currentColor].value;

    // Turn off the example headlight
    setHeadlightEnable(false);/*from  w  w  w .  j  a va 2  s  . c  o m*/

    // Default to walk navigation
    setNavigationType(Walk);

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

    // BEGIN EXAMPLE TOPIC
    // Create application bounds
    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    // Set the background color and its application bounds
    background = new Background();
    background.setColor(color);
    background.setCapability(Background.ALLOW_COLOR_WRITE);
    background.setApplicationBounds(worldBounds);
    scene.addChild(background);
    // END EXAMPLE TOPIC

    // Build foreground geometry
    scene.addChild(new TowerScene(this));

    return scene;
}

From source file:ExTexture.java

public Group buildScene() {
    // Get the current menu choices for appearance attributes
    int textureMode = ((Integer) modes[currentMode].value).intValue();
    Color3f color = (Color3f) colors[currentColor].value;
    Color3f blendColor = (Color3f) colors[currentBlendColor].value;

    // Turn on the example headlight
    setHeadlightEnable(true);//from   w  w  w  .j  a va 2 s. co  m

    // Default to examine navigation
    setNavigationType(Examine);

    // Disable scene graph compilation for this example
    setCompilable(false);

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

    // BEGIN EXAMPLE TOPIC
    // Set up a basic material
    Material mat = new Material();
    mat.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    mat.setSpecularColor(0.0f, 0.0f, 0.0f);
    mat.setLightingEnable(true);

    // Set up the texturing attributes with an initial
    // texture mode, texture transform, and blend color
    texatt = new TextureAttributes();
    texatt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    texatt.setTextureMode(textureMode);
    texatt.setTextureTransform(new Transform3D()); // Identity
    texatt.setTextureBlendColor(blendColor.x, blendColor.y, blendColor.z, 0.5f);

    // Enable changing these while the node component is live
    texatt.setCapability(TextureAttributes.ALLOW_MODE_WRITE);
    texatt.setCapability(TextureAttributes.ALLOW_BLEND_COLOR_WRITE);
    texatt.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE);

    // Create an appearance using these attributes
    app = new Appearance();
    app.setMaterial(mat);
    app.setTextureAttributes(texatt);
    app.setTexture(tex);

    // And enable changing these while the node component is live
    app.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
    app.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_WRITE);

    // Build a shape and enable changing its appearance
    shape = new Shape3D(buildGeometry(), app);
    shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    // END EXAMPLE TOPIC

    // Create some dummy appearance and tex attribute node components
    // In response to menu choices, we quickly switch the shape to
    // use one of these, then diddle with the main appearance or
    // tex attribute, then switch the shape back. This effectively
    // makes the appearance or tex attributes we want to change
    // become un-live during a change. We have to do this approach
    // because some texture features have no capability bits to set
    // to allow changes while live.
    dummyApp = new Appearance();
    dummyAtt = new TextureAttributes();

    scene.addChild(shape);

    return scene;
}

From source file:ExBackgroundImage.java

public Group buildScene() {
    // Get the current image
    ImageComponent2D image = imageComponents[currentImage];

    // Turn off the example headlight
    setHeadlightEnable(false);//ww  w .  jav  a 2  s.  c o m

    // Default to walk navigation
    setNavigationType(Walk);

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

    // BEGIN EXAMPLE TOPIC
    // Create application bounds
    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    // Set the background color and its application bounds
    background = new Background();
    background.setImage(image);
    background.setCapability(Background.ALLOW_IMAGE_WRITE);
    background.setApplicationBounds(worldBounds);
    scene.addChild(background);
    // END EXAMPLE TOPIC

    // Build foreground geometry
    scene.addChild(new TowerScene(this));

    return scene;
}

From source file:ExSpotLight.java

public Group buildScene() {
    // Get the current color, position, attenuation,
    // spread angle, and concentration
    Color3f color = (Color3f) colors[currentColor].value;
    Point3f pos = (Point3f) positions[currentPosition].value;
    Vector3f dir = (Vector3f) directions[currentDirection].value;
    Point3f atten = (Point3f) attenuations[currentAttenuation].value;
    float spread = ((Double) spreads[currentSpread].value).floatValue();
    float concen = ((Double) concentrations[currentConcentration].value).floatValue();

    // Turn off the example headlight
    setHeadlightEnable(false);/* ww  w .j a  v  a  2  s  . com*/

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

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

    // Set the light color and its influencing bounds
    light = new SpotLight();
    light.setEnable(lightOnOff);
    light.setColor(color);
    light.setPosition(pos);
    light.setAttenuation(atten);
    light.setDirection(dir);
    light.setSpreadAngle(spread);
    light.setConcentration(concen);
    light.setCapability(SpotLight.ALLOW_STATE_WRITE);
    light.setCapability(SpotLight.ALLOW_COLOR_WRITE);
    light.setCapability(SpotLight.ALLOW_POSITION_WRITE);
    light.setCapability(SpotLight.ALLOW_ATTENUATION_WRITE);
    light.setCapability(SpotLight.ALLOW_DIRECTION_WRITE);
    light.setCapability(SpotLight.ALLOW_SPREAD_ANGLE_WRITE);
    light.setCapability(SpotLight.ALLOW_CONCENTRATION_WRITE);
    light.setInfluencingBounds(worldBounds);
    scene.addChild(light);
    // END EXAMPLE TOPIC

    // Build foreground geometry
    scene.addChild(new SphereGroup());

    // Add annotation arrows in a fan to show light ray directions,
    // positions, and the spread angle
    scene.addChild(buildArrows());

    return scene;
}

From source file:ExExponentialFog.java

public Group buildScene() {
    // Get the current color
    Color3f color = (Color3f) colors[currentColor].value;
    float density = ((Float) densities[currentDensity].value).floatValue();

    // Turn off the example headlight
    setHeadlightEnable(false);/*from  www.  j  a  v a2s  .  com*/

    // Default to walk navigation
    setNavigationType(Walk);

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

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

    // Set the fog color, density, and its influencing bounds
    fog = new ExponentialFog();
    fog.setColor(color);
    fog.setDensity(density);
    fog.setCapability(Fog.ALLOW_COLOR_WRITE);
    fog.setCapability(ExponentialFog.ALLOW_DENSITY_WRITE);
    fog.setInfluencingBounds(worldBounds);
    scene.addChild(fog);
    // END EXAMPLE TOPIC

    // Set the background color and its application bounds
    //   Usually, the background color should match the fog color
    //   or the results look odd.
    background = new Background();
    background.setColor(color);
    background.setApplicationBounds(worldBounds);
    background.setCapability(Background.ALLOW_COLOR_WRITE);
    scene.addChild(background);

    // Build foreground geometry
    scene.addChild(new ColumnScene(this));

    return scene;
}

From source file:ExBluePrint.java

public Group buildScene() {
    // Get the current image
    ImageComponent2D image = imageComponents[currentImage];

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

    // BEGIN EXAMPLE TOPIC
    // Create application bounds
    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    // Set the background color and its application bounds
    background = new Background();
    background.setColor(White);/*from   w ww .jav a2s  .c o  m*/
    background.setImage(image);
    background.setCapability(Background.ALLOW_IMAGE_WRITE);
    background.setApplicationBounds(worldBounds);
    scene.addChild(background);
    // END EXAMPLE TOPIC

    // Build foreground geometry
    scene.addChild(buildGadget());

    return scene;
}

From source file:ExLinearFog.java

public Group buildScene() {
    // Get the current color
    Color3f color = (Color3f) colors[currentColor].value;
    float front = ((Float) fronts[currentFront].value).floatValue();
    float back = ((Float) backs[currentBack].value).floatValue();

    // Turn off the example headlight
    setHeadlightEnable(false);//  ww  w .  ja  v  a 2  s. c om

    // Default to walk navigation
    setNavigationType(Walk);

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

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

    // Set the fog color, front & back distances, and
    // its influencing bounds
    fog = new LinearFog();
    fog.setColor(color);
    fog.setFrontDistance(front);
    fog.setBackDistance(back);
    fog.setCapability(Fog.ALLOW_COLOR_WRITE);
    fog.setCapability(LinearFog.ALLOW_DISTANCE_WRITE);
    fog.setInfluencingBounds(worldBounds);
    scene.addChild(fog);
    // END EXAMPLE TOPIC

    // Set the background color and its application bounds
    //   Usually, the background color should match the fog color
    //   or the results look odd.
    background = new Background();
    background.setColor(color);
    background.setApplicationBounds(worldBounds);
    background.setCapability(Background.ALLOW_COLOR_WRITE);
    scene.addChild(background);

    // Build foreground geometry
    scene.addChild(new ColumnScene(this));

    return scene;
}

From source file:ExAppearance.java

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

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

    // Set up the global lights
    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);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    // Add a background
    Background background = new Background();
    background.setColor(new Color3f(0.0f, 0.5f, 1.0f));
    background.setApplicationBounds(bounds);
    objRoot.addChild(background);

    // Create a bunch of objects with a behavior and add them
    // into the scene graph.
    int row, col;
    Appearance[][] app = new Appearance[3][3];

    for (row = 0; row < 3; row++)
        for (col = 0; col < 3; col++)
            app[row][col] = createAppearance(row * 3 + col);

    for (int i = 0; i < 3; i++) {
        double ypos = (double) (i - 1) * 1.9;
        for (int j = 0; j < 3; j++) {
            double xpos = (double) (j - 1) * 2.1;
            objRoot.addChild(createObject(app[i][j], 1.0, xpos, ypos));
        }
    }

    return objRoot;
}