Example usage for javax.media.j3d BranchGroup BranchGroup

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

Introduction

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

Prototype

public BranchGroup() 

Source Link

Document

Constructs and initializes a new BranchGroup node object.

Usage

From source file:TwistStripApp.java

public BranchGroup createSceneGraph() {

    BranchGroup contentRoot = new BranchGroup();

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    contentRoot.addChild(objSpin);//from  ww w.j a v a  2 s. c  om

    Shape3D twist = new Twist();
    objSpin.addChild(twist);

    // Duplicate the twist strip geometry and set the
    // appearance of the new Shape3D object to line mode
    // without culling.
    // Add the POLYGON_FILLED and POLYGON_LINE strips
    // in the scene graph at the same point.
    // This will show the triangles of the original Mobius strip that
    // are clipped. The PolygonOffset is set to prevent stitching.
    PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
    polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrib.setPolygonOffset(0.001f);
    Appearance polyAppear = new Appearance();
    polyAppear.setPolygonAttributes(polyAttrib);
    objSpin.addChild(new Shape3D(twist.getGeometry(), polyAppear));

    Alpha rotationAlpha = new Alpha(-1, 16000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 1
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    // make background white
    Background background = new Background(1.0f, 1.0f, 1.0f);
    background.setApplicationBounds(bounds);
    contentRoot.addChild(background);

    // Let Java 3D perform optimizations on this scene graph.
    contentRoot.compile();

    return contentRoot;
}

From source file:AlternateAppearanceScopeTest.java

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

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

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.1f, 0.0f));
    // Shrink the object
    t.setScale(0.8);/* w ww . j  a v a  2s  .  co m*/

    TransformGroup trans = new TransformGroup(t);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    otherApp = new Appearance();
    altMat = new Material();
    altMat.setCapability(Material.ALLOW_COMPONENT_WRITE);
    altMat.setDiffuseColor(new Color3f(0.0f, 1.0f, 0.0f));
    otherApp.setMaterial(altMat);

    altApp = new AlternateAppearance();
    altApp.setAppearance(otherApp);
    altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_WRITE);
    altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_READ);
    altApp.setInfluencingBounds(worldBounds);
    objRoot.addChild(altApp);

    // Build foreground geometry into two groups. We'll
    // create three directional lights below, one each with
    // scope to cover the first geometry group only, the
    // second geometry group only, or both geometry groups.
    Appearance app1 = new Appearance();
    mat1 = new Material();
    mat1.setCapability(Material.ALLOW_COMPONENT_WRITE);
    mat1.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f));
    app1.setMaterial(mat1);
    content1 = new SphereGroup(0.05f, // radius of spheres
            0.4f, // x spacing
            0.2f, // y spacing
            3, // number of spheres in X
            5, // number of spheres in Y
            app1, // appearance
            true); // alt app override = true
    trans.addChild(content1);
    shapes1 = ((SphereGroup) content1).getShapes();

    content2 = new SphereGroup(0.05f, // radius of spheres
            .4f, // x spacing
            0.2f, // y spacing
            2, // number of spheres in X
            5, // number of spheres in Y
            app1, // appearance
            true); // alt app override = true
    trans.addChild(content2);
    shapes2 = ((SphereGroup) content2).getShapes();

    // Add lights
    DirectionalLight light1 = null;
    light1 = new DirectionalLight();
    light1.setEnable(true);
    light1.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light1.setInfluencingBounds(worldBounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight();
    light2.setEnable(true);
    light2.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    light2.setDirection(new Vector3f(-1.0f, 0.0f, 1.0f));
    light2.setInfluencingBounds(worldBounds);
    objRoot.addChild(light2);

    // Add an ambient light to dimly illuminate the rest of
    // the shapes in the scene to help illustrate that the
    // directional lights are being scoped... otherwise it looks
    // like we're just removing shapes from the scene
    AmbientLight ambient = new AmbientLight();
    ambient.setEnable(true);
    ambient.setColor(new Color3f(1.0f, 1.0f, 1.0f));
    ambient.setInfluencingBounds(worldBounds);
    objRoot.addChild(ambient);

    objRoot.addChild(trans);

    return objRoot;
}

From source file:YoyoPointApp.java

public BranchGroup createSceneGraph() {

    BranchGroup objRoot = new BranchGroup();

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    objRoot.addChild(objSpin);/*www .  j a va 2  s.  c o  m*/

    objSpin.addChild(new Yoyo());

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, 4000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:SimpleLOD.java

/**
 * Build the content branch for the scene graph This creates three
 * cylinders, each with a different resolution. These are then used with a
 * LOD node to implement a crude level of detail.
 * /*  www.  j a  v a  2s .  c o m*/
 * @return BranchGroup that is the root of the content
 */
protected BranchGroup buildContentBranch() {
    //Create the appearance
    Appearance app = new Appearance();
    Color3f ambientColour = new Color3f(1.0f, 1.0f, 0.0f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f diffuseColour = new Color3f(1.0f, 1.0f, 0.0f);
    float shininess = 20.0f;
    app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
    //Make the switch node that is to used with the LOD
    //and make it writable
    Switch LODswitch = new Switch();
    LODswitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    //Add the three cylinders
    LODswitch.addChild(new Cylinder(1.0f, 1.0f, Cylinder.GENERATE_NORMALS, 10, 10, app));
    LODswitch.addChild(new Cylinder(1.0f, 1.0f, Cylinder.GENERATE_NORMALS, 5, 5, app));
    LODswitch.addChild(new Cylinder(1.0f, 1.0f, Cylinder.GENERATE_NORMALS, 3, 3, app));
    //Define the distances for the LOD
    float[] LODdistances = { 5.0f, 10.0f, 15.0f };
    DistanceLOD myLOD = new DistanceLOD(LODdistances, new Point3f(0.0f, 0.0f, 0.0f));
    myLOD.setSchedulingBounds(bounds);
    //Add the switch to the LOD
    myLOD.addSwitch(LODswitch);
    BranchGroup contentBranch = new BranchGroup();
    contentBranch.addChild(myLOD);
    addLights(contentBranch);

    contentBranch.addChild(LODswitch);
    return contentBranch;

}

From source file:SimpleBillboard.java

/**
 * Build the content branch for the scene graph. This creates two cubes and
 * uses a billboard node to keep one face of one of the cubes facing the
 * viewer.//  ww w  . ja v  a 2s. co m
 * 
 * @return BranchGroup that is the root of the content
 */
protected BranchGroup buildContentBranch() {
    //Create the appearance
    Appearance app = new Appearance();
    Color3f ambientColour = new Color3f(1.0f, 1.0f, 0.0f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f diffuseColour = new Color3f(1.0f, 1.0f, 0.0f);
    float shininess = 20.0f;
    app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
    //Make the cubes
    Box leftCube = new Box(1.0f, 1.0f, 1.0f, app);
    ColorCube rightCube = new ColorCube();
    //Create the transformgroup used for the billboard
    TransformGroup billBoardGroup = new TransformGroup();
    //Set the access rights to the group
    billBoardGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    //Add the cube to the group
    billBoardGroup.addChild(rightCube);
    //Create and activate the billboard
    Billboard myBillboard = new Billboard(billBoardGroup, Billboard.ROTATE_ABOUT_AXIS,
            new Vector3f(0.0f, 1.0f, 0.0f));
    myBillboard.setSchedulingBounds(bounds);
    BranchGroup contentBranch = new BranchGroup();
    contentBranch.addChild(myBillboard);
    addLights(contentBranch);
    //Position the cubes
    TransformGroup bothGroup = new TransformGroup();
    Transform3D leftGroupXfm = new Transform3D();
    leftGroupXfm.set(new Vector3d(-1.5, 0.0, 0.0));
    TransformGroup leftGroup = new TransformGroup(leftGroupXfm);
    Transform3D rightGroupXfm = new Transform3D();
    rightGroupXfm.set(new Vector3d(1.5, 0.0, 0.0));
    TransformGroup rightGroup = new TransformGroup(rightGroupXfm);
    //Put it all together
    bothGroup.addChild(leftGroup);
    leftGroup.addChild(leftCube);
    bothGroup.addChild(rightGroup);
    rightGroup.addChild(billBoardGroup);
    contentBranch.addChild(bothGroup);
    return contentBranch;

}

From source file:AlternateAppearanceBoundsTest.java

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

    // Create an alternate appearance
    otherApp = new Appearance();
    altMat = new Material();
    altMat.setCapability(Material.ALLOW_COMPONENT_WRITE);
    altMat.setDiffuseColor(new Color3f(0.0f, 1.0f, 0.0f));
    otherApp.setMaterial(altMat);//  ww w  . j  a  va2  s.co m

    altApp = new AlternateAppearance();
    altApp.setAppearance(otherApp);
    altApp.setCapability(AlternateAppearance.ALLOW_BOUNDS_WRITE);
    altApp.setCapability(AlternateAppearance.ALLOW_INFLUENCING_BOUNDS_WRITE);
    altApp.setInfluencingBounds(worldBounds);
    objRoot.addChild(altApp);

    // Build foreground geometry
    Appearance app1 = new Appearance();
    mat1 = new Material();
    mat1.setCapability(Material.ALLOW_COMPONENT_WRITE);
    mat1.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f));
    app1.setMaterial(mat1);
    content1 = new SphereGroup(0.05f, // radius of spheres
            0.15f, // x spacing
            0.15f, // y spacing
            5, // number of spheres in X
            5, // number of spheres in Y
            app1, // appearance
            true); // alt app override = true
    objRoot.addChild(content1);
    shapes1 = ((SphereGroup) content1).getShapes();

    // Add lights
    light1 = new DirectionalLight();
    light1.setEnable(true);
    light1.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light1.setInfluencingBounds(worldBounds);
    light1.setCapability(DirectionalLight.ALLOW_INFLUENCING_BOUNDS_WRITE);
    light1.setCapability(DirectionalLight.ALLOW_BOUNDS_WRITE);
    objRoot.addChild(light1);

    // Add an ambient light to dimly illuminate the rest of
    // the shapes in the scene to help illustrate that the
    // directional lights are being scoped... otherwise it looks
    // like we're just removing shapes from the scene
    AmbientLight ambient = new AmbientLight();
    ambient.setEnable(true);
    ambient.setColor(new Color3f(1.0f, 1.0f, 1.0f));
    ambient.setInfluencingBounds(worldBounds);
    objRoot.addChild(ambient);

    // Define a bounding leaf
    leafBounds = new BoundingLeaf(allBounds[currentBounds]);
    leafBounds.setCapability(BoundingLeaf.ALLOW_REGION_WRITE);
    objRoot.addChild(leafBounds);
    if (boundingLeafOn) {
        altApp.setInfluencingBoundingLeaf(leafBounds);
    } else {
        altApp.setInfluencingBounds(allBounds[currentBounds]);
    }

    return objRoot;
}

From source file:BackgroundApp.java

public BranchGroup createBackGraph() {

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    PointArray starGeom1 = new PointArray(7, PointArray.COORDINATES);
    Appearance starAppear1 = new Appearance();
    starGeom1.setCoordinate(0, new Point3f(0.79483311f, -0.58810995f, 0.14955615f));
    starGeom1.setCoordinate(1, new Point3f(0.44430932f, -0.55736839f, -0.70137505f));
    starGeom1.setCoordinate(2, new Point3f(0.94901367f, -0.30404968f, 0.08322775f));
    starGeom1.setCoordinate(3, new Point3f(0.68060123f, -0.43044807f, 0.59287173f));
    starGeom1.setCoordinate(4, new Point3f(-0.11641672f, 0.47273532f, 0.87348049f));
    starGeom1.setCoordinate(5, new Point3f(-0.10399289f, -0.98059412f, 0.16619437f));
    starGeom1.setCoordinate(6, new Point3f(0.08024400f, -0.96944100f, -0.23182900f));
    PointAttributes point1 = new PointAttributes(4.0f, false);
    starAppear1.setPointAttributes(point1);
    objRoot.addChild(new Shape3D(starGeom1, starAppear1));

    PointArray starGeom2 = new PointArray(18, PointArray.COORDINATES);
    starGeom2.setCoordinate(0, new Point3f(0.050844f, -0.992329f, 0.112678f));
    starGeom2.setCoordinate(1, new Point3f(-0.063091f, -0.997672f, 0.025869f));
    starGeom2.setCoordinate(2, new Point3f(0.096706f, -0.980384f, 0.171736f));
    starGeom2.setCoordinate(3, new Point3f(-0.562384f, 0.073568f, 0.823595f));
    starGeom2.setCoordinate(4, new Point3f(-0.863904f, 0.059045f, 0.500180f));
    starGeom2.setCoordinate(5, new Point3f(-0.727033f, 0.304149f, 0.615559f));
    starGeom2.setCoordinate(6, new Point3f(-0.724850f, 0.535590f, 0.433281f));
    starGeom2.setCoordinate(7, new Point3f(0.185904f, -0.976907f, -0.105311f));
    starGeom2.setCoordinate(8, new Point3f(0.738028f, -0.531886f, -0.415221f));
    starGeom2.setCoordinate(9, new Point3f(-0.402152f, 0.392690f, -0.827085f));
    starGeom2.setCoordinate(10, new Point3f(-0.020020f, -0.999468f, -0.025724f));
    starGeom2.setCoordinate(11, new Point3f(-0.384103f, -0.887075f, 0.256050f));
    starGeom2.setCoordinate(12, new Point3f(-0.224464f, -0.968946f, -0.103720f));
    starGeom2.setCoordinate(13, new Point3f(-0.828880f, -0.397932f, -0.393203f));
    starGeom2.setCoordinate(14, new Point3f(-0.010557f, -0.998653f, 0.050797f));
    starGeom2.setCoordinate(15, new Point3f(-0.282122f, 0.258380f, -0.923930f));
    starGeom2.setCoordinate(16, new Point3f(-0.941342f, -0.030364f, 0.336082f));
    starGeom2.setCoordinate(17, new Point3f(0.00057f, -0.99651f, -0.08344f));
    Appearance starAppear2 = new Appearance();
    PointAttributes point2 = new PointAttributes(2.0f, false);
    starAppear2.setPointAttributes(point2);
    objRoot.addChild(new Shape3D(starGeom2, starAppear2));

    PointArray starGeom3 = new PointArray(20, PointArray.COORDINATES);
    starGeom3.setCoordinate(0, new Point3f(0.07292f, -0.98862f, -0.13153f));
    starGeom3.setCoordinate(1, new Point3f(0.23133f, -0.87605f, -0.42309f));
    starGeom3.setCoordinate(2, new Point3f(-0.08215f, -0.64657f, 0.75840f));
    starGeom3.setCoordinate(3, new Point3f(-0.84545f, 0.53398f, 0.00691f));
    starGeom3.setCoordinate(4, new Point3f(-0.49365f, -0.83645f, -0.23795f));
    starGeom3.setCoordinate(5, new Point3f(0.06883f, -0.99319f, -0.09396f));
    starGeom3.setCoordinate(6, new Point3f(0.87582f, -0.40662f, 0.25997f));
    starGeom3.setCoordinate(7, new Point3f(-0.09095f, -0.99555f, 0.02467f));
    starGeom3.setCoordinate(8, new Point3f(0.45306f, -0.81575f, -0.35955f));
    starGeom3.setCoordinate(9, new Point3f(0.17669f, -0.97939f, 0.09776f));
    starGeom3.setCoordinate(10, new Point3f(0.27421f, -0.83963f, 0.46884f));
    starGeom3.setCoordinate(11, new Point3f(0.32703f, -0.94013f, -0.09584f));
    starGeom3.setCoordinate(12, new Point3f(-0.01615f, -0.99798f, -0.06132f));
    starGeom3.setCoordinate(13, new Point3f(-0.76665f, 0.45998f, -0.44791f));
    starGeom3.setCoordinate(14, new Point3f(-0.91025f, -0.07102f, 0.40791f));
    starGeom3.setCoordinate(15, new Point3f(-0.00240f, -0.97104f, -0.23887f));
    starGeom3.setCoordinate(16, new Point3f(0.91936f, -0.39244f, 0.02740f));
    starGeom3.setCoordinate(17, new Point3f(0.18290f, -0.97993f, 0.07920f));
    starGeom3.setCoordinate(18, new Point3f(-0.48755f, 0.61592f, 0.61884f));
    starGeom3.setCoordinate(19, new Point3f(-0.89375f, 0.36087f, -0.26626f));
    objRoot.addChild(new Shape3D(starGeom3));

    int[] stripCount = { 10 };
    LineStripArray orion = new LineStripArray(10, LineStripArray.COORDINATES, stripCount);
    orion.setCoordinate(0, new Point3f(0.978330f, -0.033900f, 0.204426f));
    orion.setCoordinate(1, new Point3f(0.968007f, -0.167860f, 0.186506f));
    orion.setCoordinate(2, new Point3f(0.981477f, -0.142660f, 0.127873f));
    orion.setCoordinate(3, new Point3f(0.983764f, -0.005220f, 0.179391f));
    orion.setCoordinate(4, new Point3f(0.981112f, 0.110597f, 0.158705f));
    orion.setCoordinate(5, new Point3f(0.967377f, 0.172516f, 0.185523f));
    orion.setCoordinate(6, new Point3f(0.961385f, 0.128845f, 0.243183f));
    orion.setCoordinate(7, new Point3f(0.978330f, -0.033900f, 0.204426f));
    orion.setCoordinate(8, new Point3f(0.981293f, -0.020980f, 0.191375f));
    orion.setCoordinate(9, new Point3f(0.983764f, -0.005220f, 0.179391f));
    objRoot.addChild(new Shape3D(orion));

    objRoot.compile();//from   w  ww.  j a  va2  s .  com
    return objRoot;
}

From source file:LitTwistApp.java

public BranchGroup createSceneGraph() {

    BranchGroup contentRoot = new BranchGroup();

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    contentRoot.addChild(objSpin);/* w  w w . j  av a  2  s. com*/

    Shape3D twist = new Twist();
    objSpin.addChild(twist);

    Alpha rotationAlpha = new Alpha(-1, 16000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 1.5
    BoundingSphere bounds = new BoundingSphere();
    bounds.setRadius(1.5);
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    DirectionalLight lightD = new DirectionalLight();
    lightD.setInfluencingBounds(bounds);
    contentRoot.addChild(lightD);

    Background background = new Background();
    background.setColor(1.0f, 1.0f, 1.0f);
    background.setApplicationBounds(bounds);
    contentRoot.addChild(background);

    // Let Java 3D perform optimizations on this scene graph.
    // contentRoot.compile();

    return contentRoot;
}

From source file:Morphing.java

private BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);/*from   w  w w.  ja  v  a  2  s.c o m*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create a bounds for the background and lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

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

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

    //
    // Create the transform group nodes for the 3 original objects
    // and the morphed object. Add them to the root of the
    // branch graph.
    //
    TransformGroup objTrans[] = new TransformGroup[4];

    for (int i = 0; i < 4; i++) {
        objTrans[i] = new TransformGroup();
        objScale.addChild(objTrans[i]);
    }

    Transform3D tr = new Transform3D();
    Transform3D rotX90 = new Transform3D();
    rotX90.rotX(90.0 * Math.PI / 180.0);

    objTrans[0].getTransform(tr);
    tr.setTranslation(new Vector3d(-2.0, 1.5, -2.0));
    tr.mul(rotX90);
    objTrans[0].setTransform(tr);

    objTrans[1].getTransform(tr);
    tr.setTranslation(new Vector3d(0.0, 1.5, -2.0));
    tr.mul(rotX90);
    objTrans[1].setTransform(tr);

    objTrans[2].getTransform(tr);
    tr.setTranslation(new Vector3d(2.0, 1.5, -2.0));
    tr.mul(rotX90);
    objTrans[2].setTransform(tr);

    objTrans[3].getTransform(tr);
    tr.setTranslation(new Vector3d(0.0, -2.0, -2.0));
    tr.mul(rotX90);
    objTrans[3].setTransform(tr);

    // Now load the object files
    Scene s[] = new Scene[3];
    GeometryArray g[] = new GeometryArray[3];
    Shape3D shape[] = new Shape3D[3];
    ObjectFile loader = new ObjectFile(ObjectFile.RESIZE);
    for (int i = 0; i < 3; i++) {
        s[i] = null;
        g[i] = null;
        shape[i] = null;
    }

    for (int i = 0; i < 3; i++) {
        try {
            s[i] = loader.load(objFiles[i]);
        } catch (FileNotFoundException e) {
            System.err.println(e);
            System.exit(1);
        } catch (ParsingErrorException e) {
            System.err.println(e);
            System.exit(1);
        } catch (IncorrectFormatException e) {
            System.err.println(e);
            System.exit(1);
        }

        BranchGroup b = s[i].getSceneGroup();
        shape[i] = (Shape3D) b.getChild(0);
        g[i] = (GeometryArray) shape[i].getGeometry();

        shape[i].setGeometry(g[i]);
        objTrans[i].addChild(b);
    }

    //
    // Create a Morph node, and set the appearance and input geometry
    // arrays. Set the Morph node's capability bits to allow the weights
    // to be modified at runtime.
    //
    Appearance app = new Appearance();
    Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    app.setMaterial(new Material(objColor, black, objColor, black, 80.0f));
    Morph morph = new Morph(g, app);
    morph.setCapability(Morph.ALLOW_WEIGHTS_READ);
    morph.setCapability(Morph.ALLOW_WEIGHTS_WRITE);

    objTrans[3].addChild(morph);

    // Now create the Alpha object that controls the speed of the
    // morphing operation.
    Alpha morphAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 2000, 1000, 200,
            2000, 1000, 200);

    // Finally, create the morphing behavior
    MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph);
    mBeh.setSchedulingBounds(bounds);
    objScale.addChild(mBeh);

    return objRoot;
}

From source file:AvatarTest.java

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

    for (int n = (int) Road.ROAD_LENGTH; n < 0; n = n + 10) {
        Building building = new Building(this, bg,
                ComplexObject.GEOMETRY | ComplexObject.TEXTURE | ComplexObject.COLLISION);

        building.createObject(new Appearance(), new Vector3d(getRandomNumber(-4.0f, 0.25f),
                getRandomNumber(1.0f, 0.5f), getRandomNumber(n, 0.5f)), new Vector3d(1, 1, 1), "house.jpg",
                null, null);/*w w  w.j a va2  s  .c  o  m*/

        building = new Building(this, bg,
                ComplexObject.GEOMETRY | ComplexObject.TEXTURE | ComplexObject.COLLISION);

        building.createObject(new Appearance(), new Vector3d(getRandomNumber(4.0f, 0.25f),
                getRandomNumber(1.0f, 0.5f), getRandomNumber(n, 0.5f)), new Vector3d(1, 1, 1), "house.jpg",
                null, null);

    }

    g.addChild(bg);

    return bg;
}