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

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

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // 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);/*  w  w w .  j  a  v  a 2  s .  c o m*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // This Transformgroup is used by the mouse manipulators to
    // move the CYlinder.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(objTrans);

    //Create Model Clip
    ModelClip mc = new ModelClip();
    boolean enables[] = { false, false, false, false, false, false };
    Vector4d eqn1 = new Vector4d(0.0, 1.0, 0.0, 0.0);
    Vector4d eqn2 = new Vector4d(1.0, 1.0, 0.0, 0.0);
    mc.setEnables(enables);
    mc.setPlane(1, eqn1);
    mc.setPlane(2, eqn2);
    mc.setEnable(1, true);
    mc.setEnable(2, true);
    mc.setInfluencingBounds(bounds);
    objTrans.addChild(mc);

    //Create a cylinder
    PolygonAttributes attr = new PolygonAttributes();
    attr.setCullFace(PolygonAttributes.CULL_NONE);
    Appearance ap = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    ap.setPolygonAttributes(attr);

    Cylinder CylinderObj = new Cylinder(1.0f, 2.0f, ap);
    objTrans.addChild(CylinderObj);

    // Create the rotate behavior node
    MouseRotate behavior = new MouseRotate(objTrans);
    objTrans.addChild(behavior);
    behavior.setSchedulingBounds(bounds);

    // Create the zoom behavior node
    MouseZoom behavior2 = new MouseZoom(objTrans);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    //Shine it with two colored lights.
    Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f);
    Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

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

    return objRoot;
}

From source file:SimpleTest.java

public SimpleTest() {
    // create the SimpleUniverse class that will
    // encapsulate the scene that we are building.
    // SimpleUniverse is a helper class (utility)
    // from SUN that is included with the core Java 3D
    // distribution.
    SimpleUniverse u = new SimpleUniverse();

    // create a BranchGroup. A BranchGroup is a node in
    // a Tree data structure that can have child nodes
    BranchGroup bgRoot = new BranchGroup();

    // create the Background node and add it to the SimpleUniverse
    u.addBranchGraph(createBackground());

    // create the behaviors to move the geometry along the X-axis.
    // The behavior is added as a child of the bgRoot node.
    // Anything add as a child of the tg node will be effected by the
    // behvior (will be moved along the X-axis).
    TransformGroup tg = createBehaviors(bgRoot);

    // add the Sphere geometry as a child of the tg
    // so that it will be moved along the X-axis.
    tg.addChild(createSceneGraph());/*ww  w  . j  a va 2 s .  c  om*/

    // because the sphere was added at the 0,0,0 coordinate
    // and by default the viewer is also located at 0,0,0
    // we have to move the viewer back a little so that
    // she can see the scene.
    u.getViewingPlatform().setNominalViewingTransform();

    // add a light to the root BranchGroup to illuminate the scene
    addLights(bgRoot);

    // finally wire everything together by adding the root
    // BranchGroup to the SimpleUniverse
    u.addBranchGraph(bgRoot);
}

From source file:LitSphereApp.java

BranchGroup createScene() {
    BranchGroup scene = new BranchGroup();

    scene.addChild(new Sphere(0.9f, Sphere.GENERATE_NORMALS, createAppearance()));

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);/*  w w  w.j a  va 2 s  .co  m*/

    DirectionalLight lightD1 = new DirectionalLight();
    lightD1.setInfluencingBounds(new BoundingSphere());
    Vector3f direction1 = new Vector3f(-1.0f, -1.0f, -0.5f);
    direction1.normalize();
    lightD1.setDirection(direction1);
    lightD1.setColor(new Color3f(0.0f, 0.0f, 1.0f));
    scene.addChild(lightD1);

    DirectionalLight lightD2 = new DirectionalLight();
    lightD2.setInfluencingBounds(new BoundingSphere());
    Vector3f direction2 = new Vector3f(1.0f, -1.0f, -0.5f);
    direction2.normalize();
    lightD2.setDirection(direction2);
    lightD2.setColor(new Color3f(1.0f, 0.0f, 0.0f));
    scene.addChild(lightD2);

    Background bg = new Background();
    bg.setColor(1.0f, 1.0f, 1.0f);
    bg.setApplicationBounds(new BoundingSphere());
    scene.addChild(bg);

    return scene;
}

From source file:Pyramid2Cube.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 ww . j  a va 2 s .c  o  m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create a bounds for the background and behavior
    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);

    //
    // 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 rotY15 = new Transform3D();
    rotY15.rotY(15.0 * Math.PI / 180.0);

    objTrans[0].getTransform(tr);
    tr.setTranslation(new Vector3d(-3.0, 1.5, -6.5));
    tr.mul(rotY15);
    objTrans[0].setTransform(tr);

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

    objTrans[2].getTransform(tr);
    tr.setTranslation(new Vector3d(3.0, 1.5, -6.5));
    tr.mul(rotY15);
    objTrans[2].setTransform(tr);

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

    // Now create simple geometries.

    QuadArray g[] = new QuadArray[3];
    Shape3D shape[] = new Shape3D[3];
    for (int i = 0; i < 3; i++) {
        g[i] = null;
        shape[i] = null;
    }

    g[0] = new ColorPyramidUp();
    g[1] = new ColorCube();
    g[2] = new ColorPyramidDown();

    Appearance a = new Appearance();

    for (int i = 0; i < 3; i++) {
        shape[i] = new Shape3D(g[i], a);
        objTrans[i].addChild(shape[i]);
    }

    //
    // 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.
    //
    Morph morph = new Morph((GeometryArray[]) g, a);
    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, 4000, 1000, 500,
            4000, 1000, 500);

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

    return objRoot;
}

From source file:BackgroundGeometry.java

public 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);//  www.  j a va 2  s .c  o m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // 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.
    TransformGroup objTrans = new TransformGroup();
    objScale.addChild(objTrans);

    Background bg = new Background();
    bg.setApplicationBounds(bounds);
    BranchGroup backGeoBranch = new BranchGroup();
    Sphere sphereObj = new Sphere(1.0f,
            Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 45);
    Appearance backgroundApp = sphereObj.getAppearance();
    backGeoBranch.addChild(sphereObj);
    bg.setGeometry(backGeoBranch);
    objTrans.addChild(bg);

    TextureLoader tex = new TextureLoader(bgImage, new String("RGB"), this);
    if (tex != null)
        backgroundApp.setTexture(tex.getTexture());

    Vector3f tranlation = new Vector3f(2.0f, 0.0f, 0.0f);
    Transform3D modelTransform = new Transform3D();
    Transform3D tmpTransform = new Transform3D();
    double angleInc = Math.PI / 8.0;
    double angle = 0.0;
    int numBoxes = 16;

    float scaleX[] = { 0.1f, 0.2f, 0.2f, 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f,
            0.3f };

    float scaleY[] = { 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f,
            0.4f };

    float scaleZ[] = { 0.3f, 0.2f, 0.1f, 0.1f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f,
            0.2f };

    Appearance a1 = new Appearance();
    Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor = new Color3f(0.5f, 0.5f, 1.0f);
    Color3f oColor = new Color3f(0.5f, 0.5f, 0.3f);

    Material m = new Material(oColor, eColor, oColor, sColor, 100.0f);
    m.setLightingEnable(true);
    a1.setMaterial(m);

    for (int i = 0; i < numBoxes; i++, angle += angleInc) {
        modelTransform.rotY(angle);
        tmpTransform.set(tranlation);
        modelTransform.mul(tmpTransform);

        TransformGroup tgroup = new TransformGroup(modelTransform);
        objTrans.addChild(tgroup);

        tgroup.addChild(new Box(scaleX[i], scaleY[i], scaleZ[i], Box.GENERATE_NORMALS, a1));
    }

    // Shine it with two lights.
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f lColor2 = new Color3f(0.2f, 0.2f, 0.1f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

    return objRoot;
}

From source file:TickTockCollision.java

public 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 ww  w . j a  va2 s. c om
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create a bounds for the background and behaviors
    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);

    // Create a pair of transform group nodes and initialize them to
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behaviors can modify them at runtime. Add them to the
    // root of the subgraph.
    TransformGroup objTrans1 = new TransformGroup();
    objTrans1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objScale.addChild(objTrans1);

    TransformGroup objTrans2 = new TransformGroup();
    objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans1.addChild(objTrans2);

    // Create the positioning and scaling transform group node.
    Transform3D t = new Transform3D();
    t.set(0.3, new Vector3d(0.0, -1.5, 0.0));
    TransformGroup objTrans3 = new TransformGroup(t);
    objTrans2.addChild(objTrans3);

    // Create a simple shape leaf node, add it to the scene graph.
    objTrans3.addChild(new ColorCube());

    // Create a new Behavior object that will perform the desired
    // rotation on the specified transform object and add it into
    // the scene graph.
    Transform3D yAxis1 = new Transform3D();
    yAxis1.rotX(Math.PI / 2.0);
    Alpha tickTockAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 2500,
            200, 5000, 2500, 200);

    RotationInterpolator tickTock = new RotationInterpolator(tickTockAlpha, objTrans1, yAxis1,
            -(float) Math.PI / 2.0f, (float) Math.PI / 2.0f);
    tickTock.setSchedulingBounds(bounds);
    objTrans2.addChild(tickTock);

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

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans2, yAxis2, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans2.addChild(rotator);

    // Now create a pair of rectangular boxes, each with a collision
    // detection behavior attached. The behavior will highlight the
    // object when it is in a state of collision.

    Group box1 = createBox(0.3, new Vector3d(-1.3, 0.0, 0.0));
    Group box2 = createBox(0.3, new Vector3d(1.3, 0.0, 0.0));

    objScale.addChild(box1);
    objScale.addChild(box2);

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

    return objRoot;
}

From source file:Text2DTest.java

public 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 .  j ava2s  . c  o m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // 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 objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    TransformGroup textTranslationGroup;
    Transform3D textTranslation;
    float yPos = -.5f;
    Shape3D textObject = new Text2D("Rotating Yellow Text", new Color3f(1f, 1f, 0f), "Serif", 60, Font.BOLD);
    Appearance app = textObject.getAppearance();

    PolygonAttributes pa = app.getPolygonAttributes();
    if (pa == null)
        pa = new PolygonAttributes();
    pa.setCullFace(PolygonAttributes.CULL_NONE);
    if (app.getPolygonAttributes() == null)
        app.setPolygonAttributes(pa);
    objTrans.addChild(textObject);

    textTranslation = new Transform3D();
    textTranslation.setTranslation(new Vector3f(0f, yPos, 0f));
    textTranslationGroup = new TransformGroup(textTranslation);
    textTranslationGroup.addChild(objTrans);
    objScale.addChild(textTranslationGroup);
    yPos += .5f;

    /* Blue 40point text */
    textObject = new Text2D("Blue 40point Text", new Color3f(0f, 0f, 1f), "Serif", 40, Font.BOLD);
    textTranslation = new Transform3D();
    textTranslation.setTranslation(new Vector3f(0f, yPos, 0f));
    textTranslationGroup = new TransformGroup(textTranslation);
    textTranslationGroup.addChild(textObject);
    objScale.addChild(textTranslationGroup);
    yPos += .5f;

    /* Green italic text */
    textObject = new Text2D("Green Italic Text", new Color3f(0f, 1f, 0f), "Serif", 70, Font.ITALIC);
    textTranslation = new Transform3D();
    textTranslation.setTranslation(new Vector3f(0f, yPos, 0f));
    textTranslationGroup = new TransformGroup(textTranslation);
    textTranslationGroup.addChild(textObject);
    objScale.addChild(textTranslationGroup);
    yPos += .5f;

    // 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, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);

    return objRoot;
}

From source file:Drag.java

/**
 *  Create the scenegraph for this program.
 *///from   w  ww  .j a  v a2  s . co m
public BranchGroup createSceneGraph() {

    // Define colors
    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.80f, 0.20f, 0.2f);
    Color3f ambientRed = new Color3f(0.2f, 0.05f, 0.0f);
    Color3f ambient = new Color3f(0.2f, 0.2f, 0.2f);
    Color3f diffuse = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f specular = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);

    // Create the branch group
    BranchGroup branchGroup = 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);
    objScale.setTransform(t3d);
    branchGroup.addChild(objScale);

    // Create the bounding leaf node
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    BoundingLeaf boundingLeaf = new BoundingLeaf(bounds);
    objScale.addChild(boundingLeaf);

    // Set up the background
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

    // Create the ambient light
    AmbientLight ambLight = new AmbientLight(white);
    ambLight.setInfluencingBounds(bounds);
    objScale.addChild(ambLight);

    // Create the directional light
    Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f);
    DirectionalLight dirLight = new DirectionalLight(white, dir);
    dirLight.setInfluencingBounds(bounds);
    objScale.addChild(dirLight);

    // Create the red appearance node
    Material redMaterial = new Material(ambientRed, black, red, specular, 75.0f);
    redMaterial.setLightingEnable(true);
    Appearance redAppearance = new Appearance();
    redAppearance.setMaterial(redMaterial);

    // Create the white appearance node
    Material whiteMaterial = new Material(ambient, black, diffuse, specular, 75.0f);
    whiteMaterial.setLightingEnable(true);
    Appearance whiteAppearance = new Appearance();
    whiteAppearance.setMaterial(whiteMaterial);

    // Create the transform node
    TransformGroup transformGroup = new TransformGroup();
    transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    transformGroup.addChild(new Cube(redAppearance).getChild());
    //   transformGroup.addChild(new Corners(whiteAppearance).getChild());
    objScale.addChild(transformGroup);

    // Create the drag behavior node
    MouseRotate behavior = new MouseRotate();
    behavior.setTransformGroup(transformGroup);
    transformGroup.addChild(behavior);
    behavior.setSchedulingBounds(bounds);

    // Create the zoom behavior node
    MouseZoom behavior2 = new MouseZoom();
    behavior2.setTransformGroup(transformGroup);
    transformGroup.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    // Create the zoom behavior node
    MouseTranslate behavior3 = new MouseTranslate();
    behavior3.setTransformGroup(transformGroup);
    transformGroup.addChild(behavior3);
    behavior3.setSchedulingBounds(bounds);

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

    return branchGroup;
}

From source file:ModelClipTest2.java

public 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);/*ww w  . j  a v a 2 s  . com*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    //Shine it with two colored lights.
    Color3f lColor0 = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f);
    Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);

    AmbientLight lgt0 = new AmbientLight(true, lColor2);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt0.setInfluencingBounds(bounds);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt0);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

    // Create a Transformgroup for the geometry
    TransformGroup objRot = new TransformGroup();
    Transform3D t3d1 = new Transform3D();
    AxisAngle4f rot1 = new AxisAngle4f(0.0f, 1.0f, 0.0f, 45.0f);
    t3d1.setRotation(rot1);
    objRot.setTransform(t3d1);
    objScale.addChild(objRot);

    //Create a cylinder
    PolygonAttributes attr = new PolygonAttributes();
    attr.setCullFace(PolygonAttributes.CULL_NONE);
    Appearance ap = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    ap.setPolygonAttributes(attr);

    Cylinder CylinderObj = new Cylinder(0.5f, 2.2f, ap);
    objRot.addChild(CylinderObj);

    //Create a box
    Box BoxObj = new Box(0.8f, 0.8f, 0.8f, ap);
    objRot.addChild(BoxObj);

    // This Transformgroup is used by the mouse manipulators to
    // move the model clip planes.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRot.addChild(objTrans);

    // Create the rotate behavior node
    MouseRotate behavior = new MouseRotate(objTrans);
    objTrans.addChild(behavior);
    behavior.setSchedulingBounds(bounds);

    // Create the zoom behavior node
    MouseZoom behavior2 = new MouseZoom(objTrans);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    //Create Model Clip
    ModelClip mc = new ModelClip();
    boolean enables[] = { false, false, false, false, false, false };
    Vector4d eqn = new Vector4d(0.0, 1.0, 1.0, 0.0);
    mc.setEnables(enables);
    mc.setPlane(1, eqn);
    mc.setEnable(1, true);
    mc.setInfluencingBounds(bounds);
    objTrans.addChild(mc);

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

    return objRoot;
}

From source file:PickWorld.java

public BranchGroup createSceneGraph(Canvas3D c) {
    // 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(1.0);/* ww w.  j  a va2  s  .  co  m*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

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

    // Attach picking behavior utlities to the scene root.
    // They will wake up when user manipulates a scene node.
    PickRotateBehavior behavior = new PickRotateBehavior(objRoot, c, bounds);
    objRoot.addChild(behavior);

    PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, c, bounds);
    objRoot.addChild(behavior2);

    PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, c, bounds);
    objRoot.addChild(behavior3);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.4f);
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objRoot.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);
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    // Create a bunch of objects with a behavior and add them
    // into the scene graph.

    int row, col;
    int numRows = 3, numCols = 5;
    Appearance[][] app = new Appearance[numRows][numCols];

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

    for (int i = 0; i < numRows; i++) {
        double ypos = (double) (i - numRows / 2) * 0.6;
        for (int j = 0; j < numCols; j++) {
            double xpos = (double) (j - numCols / 2) * 0.4;
            objScale.addChild(createObject(i, j, app[i][j], 0.1, xpos, ypos));
        }
    }

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

    return objRoot;
}