Example usage for javax.media.j3d Group addChild

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

Introduction

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

Prototype

public void addChild(Node child) 

Source Link

Document

Appends the specified child node to this group node's list of children.

Usage

From source file:BoundsTest.java

Group createColorCubes() {
    Group group = new Group();

    // defaults//from  w w w . j a v  a2 s  . c o m
    ColorCube cube1 = new ColorCube(1.0);
    group.addChild(cube1);

    // explicitly set the bounds (box)
    ColorCube cube2 = new ColorCube(2.0);
    cube2.setBoundsAutoCompute(false);
    Bounds bounds = new BoundingBox(new Point3d(-2, -2, -2), new Point3d(2, 2, 2));
    cube2.setBounds(bounds);
    cube2.setCollisionBounds(bounds);
    group.addChild(cube2);

    // (sphere)
    ColorCube cube3 = new ColorCube(4.0);
    cube3.setBoundsAutoCompute(false);
    bounds = new BoundingSphere(new Point3d(0, 0, 0), 4);
    cube3.setBounds(bounds);
    cube3.setCollisionBounds(bounds);
    group.addChild(cube3);

    // auto compute, manual collision
    ColorCube cube4 = new ColorCube(6.0);
    cube4.setBoundsAutoCompute(true);
    bounds = new BoundingBox(new Point3d(-10, -10, -10), new Point3d(10, 10, 10));
    cube4.setCollisionBounds(bounds);
    group.addChild(cube4);

    // auto compute both
    ColorCube cube5 = new ColorCube(6.0);
    cube5.setBoundsAutoCompute(true);
    group.addChild(cube5);

    return group;
}

From source file:MixedTest.java

protected BranchGroup createViewBranchGroup(TransformGroup[] tgArray, ViewPlatform vp) {
    BranchGroup vpBranchGroup = new BranchGroup();

    if (tgArray != null && tgArray.length > 0) {
        Group parentGroup = vpBranchGroup;
        TransformGroup curTg = null;//from  www.j a  va2  s . co m

        for (int n = 0; n < tgArray.length; n++) {
            curTg = tgArray[n];
            parentGroup.addChild(curTg);
            parentGroup = curTg;
        }

        tgArray[tgArray.length - 1].addChild(vp);
    } else
        vpBranchGroup.addChild(vp);

    return vpBranchGroup;
}

From source file:SwingTest.java

/**
 * Creates the View side BranchGroup. The ViewPlatform is wired in beneath
 * the TransformGroups.//from   w w  w.ja  v a2 s.co m
 */
protected BranchGroup createViewBranchGroup(TransformGroup[] tgArray, ViewPlatform vp) {
    BranchGroup vpBranchGroup = new BranchGroup();

    if (tgArray != null && tgArray.length > 0) {
        Group parentGroup = vpBranchGroup;
        TransformGroup curTg = null;

        for (int n = 0; n < tgArray.length; n++) {
            curTg = tgArray[n];
            parentGroup.addChild(curTg);
            parentGroup = curTg;
        }

        tgArray[tgArray.length - 1].addChild(vp);
    } else
        vpBranchGroup.addChild(vp);

    return vpBranchGroup;
}

From source file:LineTypes.java

Group createLineTypes() {

    Group lineGroup = new Group();

    Appearance app = new Appearance();
    ColoringAttributes ca = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT);
    app.setColoringAttributes(ca);//from   w w w  . j a  v  a 2 s  .  co m

    // Plain line
    Point3f[] plaPts = new Point3f[2];
    plaPts[0] = new Point3f(-0.9f, -0.7f, 0.0f);
    plaPts[1] = new Point3f(-0.5f, 0.7f, 0.0f);
    LineArray pla = new LineArray(2, LineArray.COORDINATES);
    pla.setCoordinates(0, plaPts);
    Shape3D plShape = new Shape3D(pla, app);
    lineGroup.addChild(plShape);

    // line pattern dot
    Point3f[] dotPts = new Point3f[2];
    dotPts[0] = new Point3f(-0.4f, -0.7f, 0.0f);
    dotPts[1] = new Point3f(-0.0f, 0.7f, 0.0f);
    LineArray dot = new LineArray(2, LineArray.COORDINATES);
    dot.setCoordinates(0, dotPts);
    LineAttributes dotLa = new LineAttributes();
    dotLa.setLineWidth(2.0f);
    dotLa.setLinePattern(LineAttributes.PATTERN_DOT);
    Appearance dotApp = new Appearance();
    dotApp.setLineAttributes(dotLa);
    dotApp.setColoringAttributes(ca);
    Shape3D dotShape = new Shape3D(dot, dotApp);
    lineGroup.addChild(dotShape);

    // line pattern dash
    Point3f[] dashPts = new Point3f[2];
    dashPts[0] = new Point3f(-0.0f, -0.7f, 0.0f);
    dashPts[1] = new Point3f(0.4f, 0.7f, 0.0f);
    LineArray dash = new LineArray(2, LineArray.COORDINATES);
    dash.setCoordinates(0, dashPts);
    LineAttributes dashLa = new LineAttributes();
    dashLa.setLineWidth(4.0f);
    dashLa.setLinePattern(LineAttributes.PATTERN_DASH);
    Appearance dashApp = new Appearance();
    dashApp.setLineAttributes(dashLa);
    dashApp.setColoringAttributes(ca);
    Shape3D dashShape = new Shape3D(dash, dashApp);
    lineGroup.addChild(dashShape);

    // line pattern dot-dash
    Point3f[] dotDashPts = new Point3f[2];
    dotDashPts[0] = new Point3f(0.5f, -0.7f, 0.0f);
    dotDashPts[1] = new Point3f(0.9f, 0.7f, 0.0f);
    LineArray dotDash = new LineArray(2, LineArray.COORDINATES);
    dotDash.setCoordinates(0, dotDashPts);
    LineAttributes dotDashLa = new LineAttributes();
    dotDashLa.setLineWidth(4.0f);
    dotDashLa.setLinePattern(LineAttributes.PATTERN_DASH_DOT);
    Appearance dotDashApp = new Appearance();
    dotDashApp.setLineAttributes(dotDashLa);
    dotDashApp.setColoringAttributes(ca);
    Shape3D dotDashShape = new Shape3D(dotDash, dotDashApp);
    lineGroup.addChild(dotDashShape);

    return lineGroup;

}

From source file:AvatarTest.java

public void createBackground(Group bg) {
    // add the sky backdrop
    Background back = new Background();
    back.setApplicationBounds(getBoundingSphere());
    bg.addChild(back);

    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);//ww w.  j av a2s  .co  m

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

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

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);/*from  w  w  w  .jav a2  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:BoundsTest.java

protected Group createPoints() {
    Group group = new Group();

    final int kNumPoints = 200;
    final double kRadius = 10.0;
    Point3d points[] = new Point3d[kNumPoints];

    for (int n = 0; n < kNumPoints; n++) {
        double randX = (java.lang.Math.random() * kRadius) - kRadius / 2;
        double randY = (java.lang.Math.random() * kRadius) - kRadius / 2;
        double randZ = (java.lang.Math.random() * kRadius) - kRadius / 2;

        points[n] = new Point3d(randX, randY, randZ);
    }/*from w w w. jav  a2  s .  com*/

    PointArray pointArray = new PointArray(points.length, GeometryArray.COLOR_4 | GeometryArray.COORDINATES);
    pointArray.setCoordinates(0, points);
    Shape3D shapePoints = new Shape3D(pointArray, new Appearance());

    group.addChild(shapePoints);
    return group;
}

From source file:LightTest.java

public Group createGeometry() {
    m_DirectionTransformGroup = new TransformGroup();
    m_DirectionTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    m_DirectionTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // create appearance and material for the Cone
    Appearance app = new Appearance();

    // create the Primitive and add to the parent BranchGroup
    m_Cone = new Cone(0.5f, 2, Primitive.ENABLE_APPEARANCE_MODIFY | Primitive.GENERATE_NORMALS, app);
    m_DirectionTransformGroup.addChild(m_Cone);

    Group superGroup = super.createGeometry();
    superGroup.addChild(m_DirectionTransformGroup);
    return superGroup;
}

From source file:LightTest.java

public Group createGeometry() {
    m_TransformGroup = new TransformGroup();
    m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // create appearance and material for the Cone
    Appearance app = new Appearance();

    // create the Primitive and add to the parent BranchGroup
    m_Cone = new Cone(1, 10, Primitive.ENABLE_APPEARANCE_MODIFY | Primitive.GENERATE_NORMALS, app);
    m_TransformGroup.addChild(m_Cone);/*from   www  . j  a v  a 2 s  . c  om*/

    Group superGroup = super.createGeometry();
    superGroup.addChild(m_TransformGroup);

    return superGroup;
}

From source file:AvatarTest.java

public Group createCars(Group g) {
    BranchGroup bg = new BranchGroup();

    for (int n = (int) Road.ROAD_LENGTH; n < 0; n = n + 10) {
        Car car = new Car(this, bg, ComplexObject.GEOMETRY | ComplexObject.TEXTURE | ComplexObject.SOUND);

        car.createObject(new Appearance(),
                new Vector3d(getRandomNumber(0.0f, 2.0f), Car.CAR_HEIGHT / 2.0f, getRandomNumber(n, 5.0f)),
                new Vector3d(1, 1, 1), "car0.jpg", "car.wav", "collide.wav");
    }/*from w  ww  .java 2  s.  com*/

    g.addChild(bg);
    return bg;
}