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:ExClip.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);/*from  w  w w. j  a  v  a  2  s .  co  m*/

    // 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);

    // Add a clip node with it's clip distance (back
    // distance) set to the fog's back distance. This
    // insures that shapes are clipped off, and not drawn,
    // from the fog back (maximum density) onwards into
    // the distance.
    clip = new Clip();
    clip.setBackDistance(back);
    clip.setCapability(Clip.ALLOW_BACK_DISTANCE_WRITE);
    clip.setApplicationBounds(worldBounds);
    scene.addChild(clip);
    // 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:ExSound.java

public Group buildScene() {
    // Get the initial sound volume
    float vol = ((Float) volumes[currentVolume].value).floatValue();

    // Turn off the example headlight
    setHeadlightEnable(false);//w w  w.ja v a2  s .c o  m

    // Default to walk navigation
    setNavigationType(Walk);

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

    //
    // Preload the sounds
    //
    if (debug)
        System.err.println("  sounds...");
    String path = getCurrentDirectory();
    MediaContainer backgroundMedia = new MediaContainer(path + "canon.wav");
    backgroundMedia.setCacheEnable(true);

    MediaContainer pointMedia = new MediaContainer(path + "willow1.wav");
    pointMedia.setCacheEnable(true);

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

    // Background sound
    backgroundSound = new BackgroundSound();
    backgroundSound.setEnable(backgroundSoundOnOff);
    backgroundSound.setLoop(Sound.INFINITE_LOOPS);
    backgroundSound.setSoundData(backgroundMedia);
    backgroundSound.setInitialGain(vol);
    backgroundSound.setSchedulingBounds(worldBounds);
    backgroundSound.setCapability(Sound.ALLOW_ENABLE_WRITE);
    backgroundSound.setCapability(Sound.ALLOW_INITIAL_GAIN_WRITE);
    scene.addChild(backgroundSound);

    // Create a distance gain array for the point sound
    Point2f[] distanceGain = { new Point2f(9.0f, 1.0f), // Full volume
            new Point2f(10.0f, 0.5f), // Half volume
            new Point2f(20.0f, 0.25f), // Quarter volume
            new Point2f(30.0f, 0.0f), // Zero volume
    };

    // Point sound
    pointSound = new PointSound();
    pointSound.setEnable(pointSoundOnOff);
    pointSound.setPosition(new Point3f(pointX, soundHeight, 0.0f));
    pointSound.setLoop(Sound.INFINITE_LOOPS);
    pointSound.setSoundData(pointMedia);
    pointSound.setInitialGain(vol);
    pointSound.setDistanceGain(distanceGain);
    pointSound.setSchedulingBounds(worldBounds);
    pointSound.setCapability(Sound.ALLOW_ENABLE_WRITE);
    pointSound.setCapability(Sound.ALLOW_INITIAL_GAIN_WRITE);
    scene.addChild(pointSound);
    // END EXAMPLE TOPIC

    // Build a few lights, one per sound. We'll turn them
    // on when the associated sound is on.
    ambientLight = new AmbientLight();
    ambientLight.setEnable(backgroundSoundOnOff);
    ambientLight.setColor(Gray);
    ambientLight.setInfluencingBounds(worldBounds);
    ambientLight.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(ambientLight);

    pointLight = new PointLight();
    pointLight.setEnable(pointSoundOnOff);
    pointLight.setColor(White);
    pointLight.setPosition(0.0f, soundHeight, 0.0f);
    pointLight.setInfluencingBounds(worldBounds);
    pointLight.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(pointLight);

    // Add a basic ambient light for when all sounds (and
    // their lights) are off so that the world isn't dark
    AmbientLight amb = new AmbientLight();
    amb.setEnable(true);
    amb.setColor(Gray);
    amb.setInfluencingBounds(worldBounds);
    amb.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(amb);

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

    return scene;
}

From source file:EnvironmentExplorer.java

void setupLights() {

    lightGroup = new Group();

    // Set up the ambient light
    lightAmbient = new AmbientLight(darkGrey);
    lightAmbient.setInfluencingBounds(infiniteBounds);
    lightAmbient.setCapability(Light.ALLOW_STATE_WRITE);
    lightAmbient.setEnable(true);/*from w w  w.j ava  2 s.  c om*/
    lightGroup.addChild(lightAmbient);

    // Set up the directional light
    Vector3f lightDirection = new Vector3f(0.65f, -0.65f, -0.40f);
    lightDirectional = new DirectionalLight(white, lightDirection);
    lightDirectional.setInfluencingBounds(infiniteBounds);
    lightDirectional.setEnable(true);
    lightDirectional.setCapability(Light.ALLOW_STATE_WRITE);
    lightGroup.addChild(lightDirectional);

    // Set up the point light
    Point3f lightPosition = new Point3f(-1.0f, 1.0f, 0.6f);
    lightPoint = new PointLight(white, lightPosition, attenuation);
    lightPoint.setInfluencingBounds(infiniteBounds);
    lightPoint.setEnable(false);
    lightPoint.setCapability(Light.ALLOW_STATE_WRITE);
    lightPoint.setCapability(PointLight.ALLOW_ATTENUATION_WRITE);
    lightGroup.addChild(lightPoint);

    // Set up the spot light
    // Point the light back at the origin
    lightSpot = new SpotLight(white, lightPosition, attenuation, lightDirection,
            (float) Math.toRadians(spotSpreadAngle), spotConcentration);
    lightSpot.setInfluencingBounds(infiniteBounds);
    lightSpot.setEnable(false);
    lightSpot.setCapability(Light.ALLOW_STATE_WRITE);
    lightSpot.setCapability(PointLight.ALLOW_ATTENUATION_WRITE);
    lightSpot.setCapability(SpotLight.ALLOW_CONCENTRATION_WRITE);
    lightSpot.setCapability(SpotLight.ALLOW_SPREAD_ANGLE_WRITE);
    lightGroup.addChild(lightSpot);
}

From source file:J3dSwingFrame.java

public Camera() {
    hud_group = new Group();
    hud_group.setCapability(Group.ALLOW_CHILDREN_EXTEND);

    platform = new ViewPlatform();
    location = new Transform3D();

    root_tx_grp = new TransformGroup();
    root_tx_grp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    root_tx_grp.setTransform(location);//from   w ww.  java  2  s  .co m
    root_tx_grp.addChild(platform);
    root_tx_grp.addChild(hud_group);

    // now create the headlight
    headlight = new DirectionalLight();
    headlight.setCapability(Light.ALLOW_STATE_WRITE);
    headlight.setColor(White);
    headlight.setInfluencingBounds(LIGHT_BOUNDS);
    root_tx_grp.addChild(headlight);

    body = new PhysicalBody();
    env = new PhysicalEnvironment();

    view = new View();
    view.setBackClipDistance(BACK_CLIP_DISTANCE);
    view.setPhysicalBody(body);
    view.setPhysicalEnvironment(env);
    view.attachViewPlatform(platform);
}

From source file:ExDepthCue.java

public Group buildIsoline() {
    Group group = new Group();

    //                           alpha theta radius r g b
    group.addChild(buildSurface(3.0, 5.0, 2.194, 1.0f, 0.0f, 0.0f));
    group.addChild(buildSurface(2.0, 4.0, 1.181, 1.0f, 0.5f, 0.0f));
    group.addChild(buildSurface(1.0, 3.0, 0.506, 1.0f, 1.0f, 0.0f));

    return group;
}

From source file:KeyNavigateTest.java

public Group createFloor(Group g) {
    System.out.println("Creating floor");

    Group floorGroup = new Group();
    Land floorTile = null;// w ww.ja va2 s  .com

    // use a shared Appearance so we only store 1 copy of the texture
    Appearance app = new Appearance();
    g.addChild(floorGroup);

    final double kNumTiles = 6;

    for (double x = -FLOOR_WIDTH + FLOOR_WIDTH / (2 * kNumTiles); x < FLOOR_WIDTH; x = x
            + FLOOR_WIDTH / kNumTiles) {
        for (double z = -FLOOR_LENGTH + FLOOR_LENGTH / (2 * kNumTiles); z < FLOOR_LENGTH; z = z
                + FLOOR_LENGTH / kNumTiles) {
            floorTile = new Land(this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE);
            floorTile.createObject(app, new Vector3d(x, m_kFloorLevel, z),
                    new Vector3d(FLOOR_WIDTH / (2 * kNumTiles), 1, FLOOR_LENGTH / (2 * kNumTiles)), "floor.gif",
                    null, null);
        }
    }

    return floorGroup;
}

From source file:ExBluePrint.java

private Group buildGadget() {
    if (debug)/* ww  w. jav  a 2  s  .  co m*/
        System.err.println("  gadget...");
    //
    //  Create two appearances:
    //    wireframeApp: draw as blue wireframe
    //    shadedApp: draw as metalic shaded polygons
    //

    //  Wireframe:
    //    no Material - defaults to coloring attributes color
    //    polygons as lines, with backfaces
    //    thick lines
    Appearance wireframeApp = new Appearance();

    ColoringAttributes wireframeCatt = new ColoringAttributes();
    wireframeCatt.setColor(0.0f, 0.2559f, 0.4213f);
    wireframeCatt.setShadeModel(ColoringAttributes.SHADE_FLAT);
    wireframeApp.setColoringAttributes(wireframeCatt);

    PolygonAttributes wireframePatt = new PolygonAttributes();
    wireframePatt.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    wireframePatt.setCullFace(PolygonAttributes.CULL_NONE);
    wireframeApp.setPolygonAttributes(wireframePatt);

    LineAttributes wireframeLatt = new LineAttributes();
    wireframeLatt.setLineWidth(2.0f);
    wireframeApp.setLineAttributes(wireframeLatt);

    //  Shaded:
    //    silver material
    Appearance shadedApp = new Appearance();

    Material shadedMat = new Material();
    shadedMat.setAmbientColor(0.30f, 0.30f, 0.30f);
    shadedMat.setDiffuseColor(0.30f, 0.30f, 0.50f);
    shadedMat.setSpecularColor(0.60f, 0.60f, 0.80f);
    shadedMat.setShininess(0.10f);
    shadedApp.setMaterial(shadedMat);

    ColoringAttributes shadedCatt = new ColoringAttributes();
    shadedCatt.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
    shadedApp.setColoringAttributes(shadedCatt);

    //
    //  Create a switch group to hold two versions of the
    //  shape: one wireframe, and one shaded
    //
    Transform3D tr = new Transform3D();
    tr.set(new Vector3f(-1.0f, 0.2f, 0.0f));
    TransformGroup gadget = new TransformGroup(tr);
    shadingSwitch = new Switch();
    shadingSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    Group wireframe = new Group();
    Group shaded = new Group();
    shadingSwitch.addChild(wireframe);
    shadingSwitch.addChild(shaded);
    shadingSwitch.setWhichChild(1); // shaded
    gadget.addChild(shadingSwitch);

    //
    //  Build a gear (wireframe and shaded)
    //
    tr = new Transform3D();
    tr.rotY(Math.PI / 2.0);
    TransformGroup tg = new TransformGroup(tr);
    SpurGear gear = new SpurGearThinBody(24, // tooth count
            1.6f, // pitch circle radius
            0.3f, // shaft radius
            0.08f, // addendum
            0.05f, // dedendum
            0.3f, // gear thickness
            0.28f, // tooth tip thickness
            wireframeApp);// appearance
    tg.addChild(gear);
    wireframe.addChild(tg);

    tg = new TransformGroup(tr);
    gear = new SpurGearThinBody(24, // tooth count
            1.6f, // pitch circle radius
            0.3f, // shaft radius
            0.08f, // addendum
            0.05f, // dedendum
            0.3f, // gear thickness
            0.28f, // tooth tip thickness
            shadedApp); // appearance
    tg.addChild(gear);
    shaded.addChild(tg);

    //
    //  Build another gear (wireframe and shaded)
    //
    tr.rotY(Math.PI / 2.0);
    Vector3f trans = new Vector3f(-0.5f, 0.0f, 0.0f);
    tr.setTranslation(trans);
    tg = new TransformGroup(tr);
    gear = new SpurGearThinBody(30, // tooth count
            2.0f, // pitch circle radius
            0.3f, // shaft radius
            0.08f, // addendum
            0.05f, // dedendum
            0.3f, // gear thickness
            0.28f, // tooth tip thickness
            wireframeApp);// appearance
    tg.addChild(gear);
    wireframe.addChild(tg);

    tg = new TransformGroup(tr);
    gear = new SpurGearThinBody(30, // tooth count
            2.0f, // pitch circle radius
            0.3f, // shaft radius
            0.08f, // addendum
            0.05f, // dedendum
            0.3f, // gear thickness
            0.28f, // tooth tip thickness
            shadedApp); // appearance
    tg.addChild(gear);
    shaded.addChild(tg);

    //
    //  Build a cylindrical shaft (wireframe and shaded)
    //
    tr.rotZ(-Math.PI / 2.0);
    trans = new Vector3f(1.0f, 0.0f, 0.0f);
    tr.setTranslation(trans);
    tg = new TransformGroup(tr);
    Cylinder cyl = new Cylinder(0.3f, // radius
            4.0f, // length
            Primitive.GENERATE_NORMALS, // format
            16, // radial resolution
            1, // length-wise resolution
            wireframeApp);// appearance
    tg.addChild(cyl);
    wireframe.addChild(tg);

    tg = new TransformGroup(tr);
    cyl = new Cylinder(0.3f, // radius
            4.0f, // length
            Primitive.GENERATE_NORMALS, // format
            16, // radial resolution
            1, // length-wise resolution
            shadedApp); // appearance
    tg.addChild(cyl);
    shaded.addChild(tg);

    //
    //  Build shaft teeth (wireframe and shaded)
    //
    tr.rotY(Math.PI / 2.0);
    trans = new Vector3f(2.05f, 0.0f, 0.0f);
    tr.setTranslation(trans);
    tg = new TransformGroup(tr);
    gear = new SpurGear(12, // tooth count
            0.5f, // pitch circle radius
            0.3f, // shaft radius
            0.05f, // addendum
            0.05f, // dedendum
            1.5f, // gear thickness
            0.8f, // tooth tip thickness
            wireframeApp);// appearance
    tg.addChild(gear);
    wireframe.addChild(tg);

    tg = new TransformGroup(tr);
    gear = new SpurGear(12, // tooth count
            0.5f, // pitch circle radius
            0.3f, // shaft radius
            0.05f, // addendum
            0.05f, // dedendum
            1.5f, // gear thickness
            0.8f, // tooth tip thickness
            shadedApp); // appearance
    tg.addChild(gear);
    shaded.addChild(tg);

    return gadget;
}

From source file:KeyNavigateTest.java

public Group createCeiling(Group g) {
    System.out.println("Creating ceiling");

    Group ceilingGroup = new Group();
    Land ceilingTile = null;/*from   ww  w .  j a  v  a 2 s.  c om*/

    // because we are technically viewing the ceiling from below
    // we want to switch the normals using a PolygonAttributes.
    Appearance app = new Appearance();
    app.setPolygonAttributes(
            new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false));

    g.addChild(ceilingGroup);

    final double kNumTiles = 6;

    for (double x = -FLOOR_WIDTH + FLOOR_WIDTH / (2 * kNumTiles); x < FLOOR_WIDTH; x = x
            + FLOOR_WIDTH / kNumTiles) {
        for (double z = -FLOOR_LENGTH + FLOOR_LENGTH / (2 * kNumTiles); z < FLOOR_LENGTH; z = z
                + FLOOR_LENGTH / kNumTiles) {
            ceilingTile = new Land(this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE);
            ceilingTile.createObject(app, new Vector3d(x, m_kCeilingLevel, z),
                    new Vector3d(FLOOR_WIDTH / (2 * kNumTiles), 1, FLOOR_LENGTH / (2 * kNumTiles)),
                    "ceiling.gif", null, null);
        }
    }

    return ceilingGroup;
}

From source file:TexBug.java

void setupScene() {

    scene = new Group();

    // create a sphere with the shared appearance
    Sphere sphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, appearance);
    scene.addChild(sphere);/* w ww.  j  a va2  s.  com*/

}

From source file:LightTest.java

public Group createGeometry() {
    Group g = new Group();
    m_Light.setUserData(this);

    return g;
}