Example usage for javax.media.j3d BranchGroup addChild

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

Introduction

In this page you can find the example usage for javax.media.j3d BranchGroup 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:PickCollisionTest.java

protected void addSphere(BranchGroup bg, double x, double y, double z, Vector3d incVector, String name) {
    Appearance app = new Appearance();

    TransformGroup sphereTg = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(x, y, z));
    sphereTg.setTransform(t3d);/*from  www  . ja  v a 2s . co m*/

    sphereTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    sphereTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    sphereTg.addChild(new Sphere(1, app));
    bg.addChild(sphereTg);
    recursiveSetUserData(sphereTg, name);

    // create the collision behaviour
    CollisionBehavior collisionBehavior = new CollisionBehavior(bg, sphereTg, app, new Vector3d(x, y, z),
            incVector);
    collisionBehavior.setSchedulingBounds(getApplicationBounds());
    bg.addChild(collisionBehavior);
}

From source file:SimpleTest.java

public BranchGroup createBackground() {
    // create a parent BranchGroup for the Background
    BranchGroup backgroundGroup = new BranchGroup();

    // create a new Background node
    Background back = new Background();

    // set the range of influence of the background
    back.setApplicationBounds(getBoundingSphere());

    // create a BranchGroup that will hold
    // our Sphere geometry
    BranchGroup bgGeometry = new BranchGroup();

    // create an appearance for the Sphere
    Appearance app = new Appearance();

    // load a texture image using the Java 3D texture loader
    Texture tex = new TextureLoader("back.jpg", this).getTexture();

    // apply the texture to the Appearance
    app.setTexture(tex);//from  www . j a v a 2s .  c o m

    // create the Sphere geometry with radius 1.0
    // we tell the Sphere to generate texture coordinates
    // to enable the texture image to be rendered
    // and because we are *inside* the Sphere we have to generate
    // Normal coordinates inwards or the Sphere will not be visible.
    Sphere sphere = new Sphere(1.0f, Primitive.GENERATE_TEXTURE_COORDS | Primitive.GENERATE_NORMALS_INWARD,
            app);

    // start wiring everything together
    // add the Sphere to its parent BranchGroup
    bgGeometry.addChild(sphere);

    // assign the BranchGroup to the Background as geometry.
    back.setGeometry(bgGeometry);

    // add the Background node to its parent BranchGroup
    backgroundGroup.addChild(back);

    return backgroundGroup;
}

From source file:SimpleMouse.java

/**
 * Build the content branch for the scene graph
 * //from  w  w w . j  av a2  s . com
 * @return BranchGroup that is the root of the content
 */
protected BranchGroup buildContentBranch() {
    Appearance app = new Appearance();
    Color3f ambientColour = new Color3f(1.0f, 0.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, 0.0f, 0.0f);
    float shininess = 20.0f;
    app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));

    Box cube = new Box(2.0f, 2.0f, 2.0f, app);

    BranchGroup contentBranch = new BranchGroup();
    addLights(contentBranch);
    //Create the transform groups that will be
    //affected by the mouse utiltities
    TransformGroup spinGroup = new TransformGroup();
    TransformGroup zoomGroup = new TransformGroup();
    TransformGroup moveGroup = new TransformGroup();
    //Set the capabilities of the groups so that we can
    //manipulate them
    spinGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spinGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    zoomGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    zoomGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    //Create and use the rotation utility
    MouseRotate mouseSpin = new MouseRotate();
    mouseSpin.setTransformGroup(spinGroup);
    contentBranch.addChild(mouseSpin);
    mouseSpin.setSchedulingBounds(bounds);
    //Create and use the zoom utility
    MouseZoom mouseSize = new MouseZoom();
    mouseSize.setTransformGroup(zoomGroup);
    contentBranch.addChild(mouseSize);
    mouseSize.setSchedulingBounds(bounds);
    //Create and use the translation utility
    MouseTranslate mouseMove = new MouseTranslate();
    mouseMove.setTransformGroup(moveGroup);
    contentBranch.addChild(mouseMove);
    mouseMove.setSchedulingBounds(bounds);
    //Put it all together
    spinGroup.addChild(cube);
    moveGroup.addChild(spinGroup);
    zoomGroup.addChild(moveGroup);
    contentBranch.addChild(zoomGroup);
    return contentBranch;

}

From source file:CompileTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    // do NOT auto compute bounds for this node
    objRoot.setBoundsAutoCompute(false);

    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    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(createApplicationBounds());
    objTrans.addChild(rotator);/*from ww  w . j  a v a2 s .  c o  m*/

    objTrans.addChild(createColorCubes());

    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:PolygonOffset.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    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 objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);

    // Create a Sphere. We will display this as both wireframe and
    // solid to make a hidden line display
    // wireframe//from   www. j av  a2  s  .c om
    Appearance wireApp = new Appearance();

    ColoringAttributes wireCa = new ColoringAttributes();
    wireCa.setColor(black);
    wireApp.setColoringAttributes(wireCa);
    wirePa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0.0f);
    wireApp.setPolygonAttributes(wirePa);
    Sphere outWireSphere = new Sphere(sphereRadius, 0, 15, wireApp);
    objTrans.addChild(outWireSphere);

    // solid
    ColoringAttributes outCa = new ColoringAttributes(red, ColoringAttributes.SHADE_FLAT);
    Appearance outSolid = new Appearance();
    outSolid.setColoringAttributes(outCa);
    solidPa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_BACK, 0.0f);
    solidPa.setPolygonOffsetFactor(dynamicOffset);
    solidPa.setPolygonOffset(staticOffset);
    solidPa.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE);
    outSolid.setPolygonAttributes(solidPa);
    Sphere outSolidSphere = new Sphere(sphereRadius, 0, 15, outSolid);
    objTrans.addChild(outSolidSphere);

    innerTG = new TransformGroup();
    innerTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    scale = new Transform3D();
    updateInnerScale();
    objTrans.addChild(innerTG);

    // Create a smaller sphere to go inside. This sphere has a different
    // tesselation and color
    Sphere inWireSphere = new Sphere(sphereRadius, 0, 10, wireApp);
    innerTG.addChild(inWireSphere);

    // inside solid
    ColoringAttributes inCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT);
    Appearance inSolid = new Appearance();
    inSolid.setColoringAttributes(inCa);
    inSolid.setPolygonAttributes(solidPa);
    Sphere inSolidSphere = new Sphere(sphereRadius, 0, 10, inSolid);
    innerTG.addChild(inSolidSphere);

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    AxisAngle4f axisAngle = new AxisAngle4f(0.0f, 0.0f, 1.0f, -(float) Math.PI / 2.0f);
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 80000, 0, 0, 0, 0, 0);

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

    // set up a white background
    Background bgWhite = new Background(new Color3f(1.0f, 1.0f, 1.0f));
    bgWhite.setApplicationBounds(bounds);
    objTrans.addChild(bgWhite);

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

    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  w w  . j  a  v a  2 s. com
    return objRoot;
}

From source file:StereoCube.java

public BranchGroup createSceneGraph(int i) {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D t = new Transform3D();
    TransformGroup tg = new TransformGroup(t);
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.addChild(tg);/*  w  w  w. j  a  va  2 s. com*/
    tg.addChild(new ColorCube(0.4));
    MouseRotate behavior = new MouseRotate();
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    behavior.setTransformGroup(tg);
    objTrans.addChild(behavior);
    // Create the translate behavior node
    MouseTranslate behavior3 = new MouseTranslate();
    behavior3.setTransformGroup(tg);
    objTrans.addChild(behavior3);
    behavior3.setSchedulingBounds(bounds);

    KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(tg);
    keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0));
    objTrans.addChild(keyNavBeh);

    behavior.setSchedulingBounds(bounds);
    objRoot.addChild(objTrans);
    return objRoot;
}

From source file:OrientedTest.java

public BranchGroup createSceneGraph() {

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

    TransformGroup objScale = new TransformGroup();
    Transform3D textMat = new Transform3D();
    // Assuming uniform size chars, set scale to fit string in view
    textMat.setScale(1.2 / sl);/*w w w.  ja  va  2 s . c o m*/
    objScale.setTransform(textMat);

    // 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);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRoot.addChild(objTrans);

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

    Appearance apText = new Appearance();
    Material m = new Material();
    m.setLightingEnable(true);
    apText.setMaterial(m);

    Appearance apEarth = new Appearance();
    Material mm = new Material();
    mm.setLightingEnable(true);
    apEarth.setMaterial(mm);

    Appearance apStone = new Appearance();
    apStone.setMaterial(mm);

    // create 3D text
    Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
    Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, 3.0f, 0.0f));
    OrientedShape3D textShape = new OrientedShape3D();
    textShape.setGeometry(txt);
    textShape.setAppearance(apText);
    textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f);
    objScale.addChild(textShape);

    // Create a simple shape leaf node, add it to the scene graph.

    Transform3D cubeMat = new Transform3D();
    TransformGroup cubeTrans = new TransformGroup(cubeMat);
    cubeMat.set(new Vector3d(0.9, 0.0, -1.0));
    cubeTrans.setTransform(cubeMat);
    cubeTrans.addChild(new ColorCube(0.3));
    objTrans.addChild(cubeTrans);

    TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this);
    if (stoneTex != null)
        apStone.setTexture(stoneTex.getTexture());

    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    apStone.setTextureAttributes(texAttr);

    Transform3D coneMat = new Transform3D();
    TransformGroup coneTrans = new TransformGroup(coneMat);
    coneMat.set(new Vector3d(0.0, 0.0, 0.0));
    coneTrans.setTransform(coneMat);
    coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone));
    objTrans.addChild(coneTrans);

    TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this);
    if (earthTex != null)
        apEarth.setTexture(earthTex.getTexture());

    apEarth.setTextureAttributes(texAttr);

    Transform3D cylinderMat = new Transform3D();
    TransformGroup cylinderTrans = new TransformGroup(cylinderMat);
    cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0));
    cylinderTrans.setTransform(cylinderMat);
    cylinderTrans.addChild(
            new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth));
    objTrans.addChild(cylinderTrans);

    objTrans.addChild(objScale);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    apText.setMaterial(mm);

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

    return objRoot;
}

From source file:SplineAnim.java

public BranchGroup createSceneGraph() {

    // Colors for lights and objects
    Color3f aColor = new Color3f(0.2f, 0.2f, 0.2f);
    Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f coneColor = new Color3f(0.9f, 0.1f, 0.1f);
    Color3f sphereColor = new Color3f(0.1f, 0.7f, 0.9f);
    Color3f bgColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f lightColor = new Color3f(1.0f, 1.0f, 1.0f);

    // Root of the branch grsph
    BranchGroup root = new BranchGroup();

    // Create transforms such that all objects appears in the scene
    sceneTransform = new Transform3D();
    sceneTransform.setScale(0.14f);//from w  w w . jav a 2  s  .  c  om
    Transform3D yrot = new Transform3D();
    yrot.rotY(-Math.PI / 5.0d);
    sceneTransform.mul(yrot);
    sceneTransformGroup = new TransformGroup(sceneTransform);
    sceneTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    sceneTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    root.addChild(sceneTransformGroup);

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

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

    // Create the transform group node for the lights
    lightTransform1 = new Transform3D();
    lightTransform2 = new Transform3D();
    Vector3d lightPos1 = new Vector3d(0.0, 0.0, 2.0);
    Vector3d lightPos2 = new Vector3d(1.0, 0.0, -2.0);
    lightTransform1.set(lightPos1);
    lightTransform2.set(lightPos2);
    light1TransformGroup = new TransformGroup(lightTransform1);
    light2TransformGroup = new TransformGroup(lightTransform2);
    sceneTransformGroup.addChild(light1TransformGroup);
    sceneTransformGroup.addChild(light2TransformGroup);

    // Create lights
    AmbientLight ambLight = new AmbientLight(aColor);
    Light dirLight1;
    Light dirLight2;

    Vector3f lightDir1 = new Vector3f(lightPos1);
    Vector3f lightDir2 = new Vector3f(lightPos2);
    lightDir1.negate();
    lightDir2.negate();
    dirLight1 = new DirectionalLight(lightColor, lightDir1);
    dirLight2 = new DirectionalLight(lightColor, lightDir2);

    // Set the influencing bounds
    ambLight.setInfluencingBounds(bounds);
    dirLight1.setInfluencingBounds(bounds);
    dirLight2.setInfluencingBounds(bounds);

    // Add the lights into the scene graph
    sceneTransformGroup.addChild(ambLight);
    sceneTransformGroup.addChild(dirLight1);
    sceneTransformGroup.addChild(dirLight2);

    // Create a cone and add it to the scene graph.
    objTransform = new Transform3D();
    objTransformGroup = new TransformGroup(objTransform);
    objTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    sceneTransformGroup.addChild(objTransformGroup);

    Material m = new Material(coneColor, eColor, coneColor, sColor, 100.0f);
    Appearance a = new Appearance();
    m.setLightingEnable(true);
    a.setMaterial(m);
    Cone cone = new Cone(0.4f, 1.0f);
    cone.setAppearance(a);
    objTransformGroup.addChild(cone);

    // Create transform groups for each knot point
    // knot point 0
    Transform3D t3dKnot = new Transform3D();
    t3dKnot.set(pos0);
    TransformGroup k0TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k0TransformGroup);

    // knot point 1
    t3dKnot = new Transform3D();
    t3dKnot.set(pos1);
    TransformGroup k1TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k1TransformGroup);

    // knot point 2
    t3dKnot = new Transform3D();
    t3dKnot.set(pos2);
    TransformGroup k2TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k2TransformGroup);

    // knot point 3
    t3dKnot = new Transform3D();
    t3dKnot.set(pos3);
    TransformGroup k3TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k3TransformGroup);

    // knot point 4
    t3dKnot = new Transform3D();
    t3dKnot.set(pos4);
    TransformGroup k4TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k4TransformGroup);

    // knot point 5
    t3dKnot = new Transform3D();
    t3dKnot.set(pos5);
    TransformGroup k5TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k5TransformGroup);

    // Create spheres for each knot point's transform group
    ColoringAttributes sphereColorAttr = new ColoringAttributes();
    sphereColorAttr.setColor(sphereColor);
    Appearance sphereAppearance = new Appearance();
    sphereAppearance.setColoringAttributes(sphereColorAttr);
    k0TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));
    k1TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));
    k2TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));
    k3TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));
    k4TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));
    k5TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));

    return root;
}

From source file:MixedTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

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

    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);//  ww w. j a  va  2 s .  c  o  m

    objTrans.addChild(new ColorCube());
    objRoot.addChild(objTrans);

    return objRoot;
}