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:BehaviorTest.java

public void addBehaviorToParentGroup(Group nodeParentGroup) {
    nodeParentGroup.addChild(this);

    m_TransformGroup = new TransformGroup();
    m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    m_BoundsSwitch = new Switch();
    m_BoundsSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    Appearance app = new Appearance();

    PolygonAttributes polyAttrbutes = new PolygonAttributes();
    polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
    app.setPolygonAttributes(polyAttrbutes);

    m_BoundsSwitch.addChild(new Sphere(1, app));

    ColorCube cube = new ColorCube();
    cube.setAppearance(app);/*www  .  j  a va  2  s .c o m*/

    Group g = new Group();
    g.addChild(cube);
    m_BoundsSwitch.addChild(g);

    m_BoundsSwitch.setWhichChild(Switch.CHILD_NONE);

    m_TransformGroup.addChild(m_BoundsSwitch);
    nodeParentGroup.addChild(m_TransformGroup);
}

From source file:KeyNavigateTest.java

public Group createMap(Group g) {
    System.out.println("Creating map items");

    Group mapGroup = new Group();
    g.addChild(mapGroup);/*  ww w.j  av  a 2 s  . c o  m*/

    Texture tex = new TextureLoader(m_szMapName, this).getTexture();
    m_MapImage = ((ImageComponent2D) tex.getImage(0)).getImage();

    float imageWidth = m_MapImage.getWidth();
    float imageHeight = m_MapImage.getHeight();

    FLOOR_WIDTH = imageWidth * 8;
    FLOOR_LENGTH = imageHeight * 8;

    for (int nPixelX = 1; nPixelX < imageWidth - 1; nPixelX++) {
        for (int nPixelY = 1; nPixelY < imageWidth - 1; nPixelY++)
            createMapItem(mapGroup, nPixelX, nPixelY);

        float percentDone = 100 * (float) nPixelX / (float) (imageWidth - 2);
        System.out.println("   " + (int) (percentDone) + "%");
    }

    createExternalWall(mapGroup);

    return mapGroup;
}

From source file:ExLinearFog.java

private Group buildColumns(SharedGroup column) {
    Group group = new Group();

    // Place columns
    float x = -ColumnSideOffset;
    float y = -1.6f;
    float z = ColumnDepthSpacing;
    float xSpacing = 2.0f * ColumnSideOffset;
    float zSpacing = -ColumnDepthSpacing;

    // BEGIN EXAMPLE TOPIC
    Vector3f trans = new Vector3f();
    Transform3D tr = new Transform3D();
    TransformGroup tg;//w ww. java  2s . c o m

    for (int i = 0; i < NumberOfColumns; i++) {
        // Left link
        trans.set(x, y, z);
        tr.set(trans);
        tg = new TransformGroup(tr);
        tg.addChild(new Link(column));
        group.addChild(tg);

        // Right link
        trans.set(x + xSpacing, y, z);
        tr.set(trans);
        tg = new TransformGroup(tr);
        tg.addChild(new Link(column));
        group.addChild(tg);

        z += zSpacing;
    }
    // END EXAMPLE TOPIC

    return group;
}

From source file:ExHenge.java

public Group buildRing(SharedGroup sg) {
    Group g = new Group();

    g.addChild(new Link(sg)); // 0 degrees

    TransformGroup tg = new TransformGroup();
    Transform3D tr = new Transform3D();
    tr.rotY(0.785); // 45 degrees
    tg.setTransform(tr);/*from  ww w . ja v  a2 s  . c o  m*/
    tg.addChild(new Link(sg));
    g.addChild(tg);

    tg = new TransformGroup();
    tr = new Transform3D();
    tr.rotY(-0.785); // -45 degrees
    tg.setTransform(tr);
    tg.addChild(new Link(sg));
    g.addChild(tg);

    tg = new TransformGroup();
    tr = new Transform3D();
    tr.rotY(1.571); // 90 degrees
    tg.setTransform(tr);
    tg.addChild(new Link(sg));
    g.addChild(tg);

    tg = new TransformGroup();
    tr = new Transform3D();
    tr.rotY(-1.571); // -90 degrees
    tg.setTransform(tr);
    tg.addChild(new Link(sg));
    g.addChild(tg);

    tg = new TransformGroup();
    tr = new Transform3D();
    tr.rotY(2.356); // 135 degrees
    tg.setTransform(tr);
    tg.addChild(new Link(sg));
    g.addChild(tg);

    tg = new TransformGroup();
    tr = new Transform3D();
    tr.rotY(-2.356); // -135 degrees
    tg.setTransform(tr);
    tg.addChild(new Link(sg));
    g.addChild(tg);

    tg = new TransformGroup();
    tr = new Transform3D();
    tr.rotY(Math.PI); // 180 degrees
    tg.setTransform(tr);
    tg.addChild(new Link(sg));
    g.addChild(tg);

    return g;
}

From source file:ExText.java

/**
 * Builds the scene. Example application subclasses should replace this
 * method with their own method to build 3D content.
 * /*from w w  w.j a  v a 2  s  . c o m*/
 * @return a Group containing 3D content to display
 */
public Group buildScene() {
    // Build the scene group containing nothing
    Group scene = new Group();
    return scene;
}

From source file:KeyNavigateTest.java

protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile,
        String szSoundFile) {/*from  w w w  .j av  a  2s.  c om*/
    Group g = new Group();

    app.setPolygonAttributes(
            new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false));
    app.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f));

    m_TextureAttributes = new TextureAttributes(TextureAttributes.REPLACE, new Transform3D(),
            new Color4f(0, 0, 0, 1), TextureAttributes.FASTEST);
    app.setTextureAttributes(m_TextureAttributes);

    if ((m_nFlags & ComplexObject.TEXTURE) == ComplexObject.TEXTURE)
        setTexture(app, szTextureFile);

    Cone cone = new Cone(1, 1, Primitive.GENERATE_TEXTURE_COORDS, app);

    g.addChild(cone);

    attachBehavior(new TextureAnimationBehavior(m_TextureAttributes));

    return g;
}

From source file:AppearanceExplorer.java

Group setupLights() {

    Group group = new Group();

    // set up the BoundingSphere for all the lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0);

    // Set up the ambient light
    AmbientLight lightAmbient = new AmbientLight(medGrey);
    lightAmbient.setInfluencingBounds(bounds);
    lightAmbient.setCapability(Light.ALLOW_STATE_WRITE);
    group.addChild(lightAmbient);//w w w. j ava  2  s  .  co m

    lightSwitch = new Switch();
    lightSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    group.addChild(lightSwitch);

    // Set up the directional light
    Vector3f lightDirection1 = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight lightDirectional1 = new DirectionalLight(white, lightDirection1);
    lightDirectional1.setInfluencingBounds(bounds);
    lightDirectional1.setCapability(Light.ALLOW_STATE_WRITE);
    lightSwitch.addChild(lightDirectional1);

    Point3f lightPos1 = new Point3f(-4.0f, 8.0f, 16.0f);
    Point3f lightAttenuation1 = new Point3f(1.0f, 0.0f, 0.0f);
    PointLight pointLight1 = new PointLight(brightWhite, lightPos1, lightAttenuation1);
    pointLight1.setInfluencingBounds(bounds);
    lightSwitch.addChild(pointLight1);

    Point3f lightPos2 = new Point3f(-16.0f, 8.0f, 4.0f);
    //Point3f lightPos = new Point3f(-4.0f, 2.0f, 1.0f);
    Point3f lightAttenuation2 = new Point3f(1.0f, 0.0f, 0.0f);
    PointLight pointLight2 = new PointLight(white, lightPos2, lightAttenuation2);
    pointLight2.setInfluencingBounds(bounds);
    lightSwitch.addChild(pointLight2);

    return group;
}

From source file:FourByFour.java

public Poles(Appearance appearance) {
    float x = -30.0f;
    float z = -30.0f;
    group = new Group();
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            Cylinder c = new Cylinder(x, z, 1.0f, 60.0f, 10, appearance);
            group.addChild(c.getShape());
            x += 20.0f;/*from w ww  .j a  v a  2 s.  c  o m*/
        }
        x = -30.0f;
        z += 20.0f;
    }
}

From source file:FourByFour.java

public Positions() {

    // Define colors for lighting
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f red = new Color3f(0.9f, 0.1f, 0.2f);
    Color3f blue = new Color3f(0.3f, 0.3f, 0.8f);
    Color3f yellow = new Color3f(1.0f, 1.0f, 0.0f);
    Color3f ambRed = new Color3f(0.3f, 0.03f, 0.03f);
    Color3f ambBlue = new Color3f(0.03f, 0.03f, 0.3f);
    Color3f ambYellow = new Color3f(0.3f, 0.3f, 0.03f);
    Color3f ambWhite = new Color3f(0.3f, 0.3f, 0.3f);
    Color3f specular = new Color3f(1.0f, 1.0f, 1.0f);

    // Create the red appearance node
    redMat = new Material(ambRed, black, red, specular, 100.f);
    redMat.setLightingEnable(true);//ww w.  j  a v  a2 s  . co m
    redApp = new Appearance();
    redApp.setMaterial(redMat);

    // Create the blue appearance node
    blueMat = new Material(ambBlue, black, blue, specular, 100.f);
    blueMat.setLightingEnable(true);
    blueApp = new Appearance();
    blueApp.setMaterial(blueMat);

    // Create the yellow appearance node
    yellowMat = new Material(ambYellow, black, yellow, specular, 100.f);
    yellowMat.setLightingEnable(true);
    yellowApp = new Appearance();
    yellowApp.setMaterial(yellowMat);

    // Create the white appearance node
    whiteMat = new Material(ambWhite, black, white, specular, 100.f);
    whiteMat.setLightingEnable(true);
    whiteApp = new Appearance();
    whiteApp.setMaterial(whiteMat);

    // Load the point array with the offset (coordinates) for each of
    // the 64 positions.
    point = new Vector3f[64];
    int count = 0;
    for (int i = -30; i < 40; i += 20) {
        for (int j = -30; j < 40; j += 20) {
            for (int k = -30; k < 40; k += 20) {
                point[count] = new Vector3f((float) k, (float) j, (float) i);
                count++;
            }
        }
    }

    // Create the switch nodes
    posSwitch = new Switch(Switch.CHILD_MASK);
    humanSwitch = new Switch(Switch.CHILD_MASK);
    machineSwitch = new Switch(Switch.CHILD_MASK);

    // Set the capability bits
    posSwitch.setCapability(Switch.ALLOW_SWITCH_READ);
    posSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    humanSwitch.setCapability(Switch.ALLOW_SWITCH_READ);
    humanSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    machineSwitch.setCapability(Switch.ALLOW_SWITCH_READ);
    machineSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // Create the bit masks
    posMask = new BitSet();
    humanMask = new BitSet();
    machineMask = new BitSet();

    // Create the small white spheres that mark unoccupied
    // positions.
    posSphere = new Sphere[64];
    for (int i = 0; i < 64; i++) {
        Transform3D transform3D = new Transform3D();
        transform3D.set(point[i]);
        TransformGroup transformGroup = new TransformGroup(transform3D);
        posSphere[i] = new Sphere(2.0f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_APPEARANCE_MODIFY, 12,
                whiteApp);
        Shape3D shape = posSphere[i].getShape();
        ID id = new ID(i);
        shape.setUserData(id);
        transformGroup.addChild(posSphere[i]);
        posSwitch.addChild(transformGroup);
        posMask.set(i);
    }

    // Create the red spheres that mark the user's positions.
    for (int i = 0; i < 64; i++) {
        Transform3D transform3D = new Transform3D();
        transform3D.set(point[i]);
        TransformGroup transformGroup = new TransformGroup(transform3D);
        transformGroup.addChild(new Sphere(7.0f, redApp));
        humanSwitch.addChild(transformGroup);
        humanMask.clear(i);
    }

    // Create the blue cubes that mark the computer's positions.
    for (int i = 0; i < 64; i++) {
        Transform3D transform3D = new Transform3D();
        transform3D.set(point[i]);
        TransformGroup transformGroup = new TransformGroup(transform3D);
        BigCube cube = new BigCube(blueApp);
        transformGroup.addChild(cube.getChild());
        machineSwitch.addChild(transformGroup);
        machineMask.clear(i);
    }

    // Set the positions mask
    posSwitch.setChildMask(posMask);
    humanSwitch.setChildMask(humanMask);
    machineSwitch.setChildMask(machineMask);

    // Throw everything into a single group
    group = new Group();
    group.addChild(posSwitch);
    group.addChild(humanSwitch);
    group.addChild(machineSwitch);
}