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

public BranchGroup createSceneGraph(boolean wireFrame) {
    int total = 0;

    System.out.println("\n --- geometry debug information --- \n");

    float[] coordinateData = null;
    coordinateData = createCoordinateData();
    int[] stripCount = { 17, 17, 5, 5, 5, 5, 5, 5, 5 }; // ******
    //        int[] stripCount = {17,17,17}; // ******

    for (int i = 0; i < stripCount.length; i++) {
        System.out.println("stripCount[" + i + "] = " + stripCount[i]);
        total += stripCount[i];/*from  w w  w  .  ja  v  a  2 s .c om*/
    }

    if (total != coordinateData.length / 3) {
        System.out.println("  coordinateData vertex count: " + coordinateData.length / 3);
        System.out.println("stripCount total vertex count: " + total);
    }

    GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
    gi.setCoordinates(coordinateData);
    gi.setStripCounts(stripCount);

    Triangulator tr = new Triangulator();
    //        Triangulator tr = new Triangulator(1);
    System.out.println("begin triangulation");
    tr.triangulate(gi);
    System.out.println("  END triangulation");
    gi.recomputeIndices();

    NormalGenerator ng = new NormalGenerator();
    ng.generateNormals(gi);
    gi.recomputeIndices();

    Stripifier st = new Stripifier();
    st.stripify(gi);
    gi.recomputeIndices();

    Shape3D part = new Shape3D();
    if (wireFrame == true)
        part.setAppearance(createWireFrameAppearance());
    else
        part.setAppearance(createMaterialAppearance());
    part.setGeometry(gi.getGeometryArray());

    /////////////////////////////

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

    objSpin.addChild(part);

    ////////////////////////
    LineStripArray lineArray = new LineStripArray(69, LineArray.COORDINATES, stripCount); //*****
    //        LineStripArray lineArray = new LineStripArray(51,
    // LineArray.COORDINATES, stripCount); //*****
    lineArray.setCoordinates(0, coordinateData);
    Appearance blueColorAppearance = new Appearance();
    ColoringAttributes blueColoring = new ColoringAttributes();
    blueColoring.setColor(0.0f, 0.0f, 1.0f);
    blueColorAppearance.setColoringAttributes(blueColoring);
    LineAttributes lineAttrib = new LineAttributes();
    lineAttrib.setLineWidth(2.0f);
    blueColorAppearance.setLineAttributes(lineAttrib);
    objSpin.addChild(new Shape3D(lineArray, blueColorAppearance));

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

    DirectionalLight lightD = new DirectionalLight();
    lightD.setDirection(new Vector3f(0.0f, -0.7f, -0.7f));
    lightD.setInfluencingBounds(bounds);
    contentRoot.addChild(lightD);

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(bounds);
    contentRoot.addChild(lightA);

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

/**
 * Creates the View side BranchGroup. The ViewPlatform is wired in beneath
 * the TransformGroups./*from w ww.  jav a2s.c o 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:SplineInterpolatorTest.java

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

    Texture tex = new TextureLoader("boston.gif", this).getTexture();
    BufferedImage image = ((ImageComponent2D) tex.getImage(0)).getImage();

    final int nMaxBuildings = 120;

    for (int n = 0; n < nMaxBuildings; n++) {
        Cuboid building = new Cuboid(this, bg, ComplexObject.GEOMETRY | ComplexObject.TEXTURE);

        float posX = (int) Utils.getRandomNumber(0, LAND_WIDTH);
        float posZ = (int) Utils.getRandomNumber(0, LAND_LENGTH);

        if (isLocationWater(image, posX, posZ) == false) {
            building.createObject(m_BuildingAppearance, new Vector3d(posX, 0, posZ),
                    new Vector3d(Utils.getRandomNumber(3, 2), Utils.getRandomNumber(8, 7),
                            Utils.getRandomNumber(3, 2)),
                    "house.gif", null, null);
        }/*  ww w  . ja v a2 s  . co  m*/
    }

    g.addChild(bg);
    return bg;
}

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  w w w . j a  va  2s  .  c  o  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:Demo3D.java

/**
 * Create the ViewBranch/*from  www .  j a  va  2  s. c  om*/
 * 
 * @return javax.media.j3d.BranchGroup vbBrGr - the root of the ViewBranch
 */
public BranchGroup myViewBranch() {
    // Create the minimal PhysicalBody and PhysicalEnvironnement
    // instances with default parameters.
    body = new PhysicalBody();
    environment = new PhysicalEnvironment();

    // Create a View instance and attach the Canvas3D, the PhysicalBody
    // and the PhysicalEnvironment to it.
    view = new View();
    view.setFrontClipDistance(0.02); // Default value is 0.1 m
    view.setBackClipDistance(40.0); // Default value is 10 m
    // Rem.: BackClipDistance / FrontClipDistance = 2000 > 1000 but < 3000
    view.addCanvas3D(canvas3D);
    view.setPhysicalBody(body);
    view.setPhysicalEnvironment(environment);
    /*
     * // Choices of the projection type. They are 2 possibilities, namely: //
     * PERSPECTIVE_PROJECTION and PARALLEL_PROJECTION. // Note: the default
     * value is PERSPECTIVE_PROJECTION
     * view.setProjectionPolicy(View.PARALLEL_PROJECTION);
     */
    // Create a ViewPlatform instance and bind it with the View instance.
    viewPlat = new ViewPlatform();
    viewPlat.setActivationRadius(40.0f); // Default value is 62 m
    view.attachViewPlatform(viewPlat);

    // Create the action volume for the camera's navigation.
    cameraBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Create the two necessary TransformGroups for the ViewPlatform's
    // motion (6 translations and 4 rotations).
    vpTrGrKeys_Rot_Up_Down = new TransformGroup();
    vpTrGrKeys_Transl_Turn = new TransformGroup();

    // With the ALLOW_TRANSFORM_READ and ALLOW_TRANSFORM_WRITE
    // capabilities, we allow the modification of the TransformGroup's
    // code by the Behavior's code at run time.
    vpTrGrKeys_Transl_Turn.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    vpTrGrKeys_Transl_Turn.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

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

    // Attach the ViewPlatform to the vpTrGrKeys_Rot_Up_Down node.
    vpTrGrKeys_Rot_Up_Down.addChild(viewPlat);

    // Create and attach an aimer to the TransformGroup node
    // vpTrGrKeys_Rot_Up_Down.
    aimer = new Aimer(1.5f);
    vpTrGrKeys_Rot_Up_Down.addChild(aimer.myAimer());

    // View-platform's motion ==> camera's navigation: 6 translations and 4
    // rotations.

    // Create and attach the camera's rotation on the vpTrGrKeys_Rot_Up_Down
    // node.
    camera_Rot_Up_Down = new Camera_Rot_Up_Down(vpTrGrKeys_Rot_Up_Down);
    camera_Rot_Up_Down.setSchedulingBounds(cameraBounds);
    vpTrGrKeys_Rot_Up_Down.addChild(camera_Rot_Up_Down);

    // Create and attach the camera's translation and rotation instances
    // on the vpTrGrKeys_Transl_Turn node.
    camera_Transl_Turn = new Camera_Transl_Turn(vpTrGrKeys_Transl_Turn);
    camera_Transl_Turn.setSchedulingBounds(cameraBounds);
    vpTrGrKeys_Transl_Turn.addChild(camera_Transl_Turn);

    // Attach the vpTrGrKeys_Rot_Up_Down node to the vpTrGrKeys_Transl_Turn
    // node.
    vpTrGrKeys_Transl_Turn.addChild(vpTrGrKeys_Rot_Up_Down);

    // Give the starting position of the ViewPlatform.
    trStart = new Transform3D(); // Identity matrix
    trStart.set(new Vector3f(0.0f, 0.0f, 10.0f)); // Translation of the
    // camera (0,0,10)

    // Create the TransformGroup node for the ViewPlatform's
    // starting position.
    vpTrGrStart = new TransformGroup(trStart);

    // Attach the vpTrGrKeys_Transl_Turn node to the TransformGroup
    // node vpTrGrStart.
    vpTrGrStart.addChild(vpTrGrKeys_Transl_Turn);

    // Add the TransformGroup node vpTrGrStart to the view
    // BranchGroup node vbBrGr.
    vbBrGr = new BranchGroup();
    vbBrGr.addChild(vpTrGrStart);

    // Compile the ViewBranch to optimize the performances.
    vbBrGr.compile();

    // Return the final version of the view branch BranchGroup node vbBrGr.
    return vbBrGr;
}

From source file:SplineInterpolatorTest.java

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

    Helicopter heli = new Helicopter(this, bg, ComplexObject.GEOMETRY | ComplexObject.SOUND);

    heli.createObject(new Appearance(), new Vector3d(Utils.getRandomNumber(0, LAND_WIDTH),
            Utils.getRandomNumber(15, 5), Utils.getRandomNumber(0, LAND_LENGTH)), new Vector3d(10, 10, 10),
            null, "heli.wav", null);

    g.addChild(bg);/*from  w  w  w .  j a  va  2  s .  c om*/

    return bg;
}

From source file:Demo3D.java

/**
 * Create the subgraph #1/*from  ww w.j  a  va  2 s  .  c om*/
 * 
 * @return javax.media.j3d.BranchGroup brGr1 - the root of the subgraph #1
 */
public BranchGroup mySubGraph1() {
    // Create the BranchGroup brGr1 of the subgraph #1.
    brGr1 = new BranchGroup();

    // Create and attach the coordinate system to the brGr1.
    coordSyst = new CoordSyst(1.0f, 1.0f, 0.0f, // Color of the x-axis
            0.0f, 0.0f, 1.0f, // Color of the y-axis
            1.0f, 0.0f, 0.0f, // Color of the z-axis
            0.75f); // Lenght of the 3 axes
    brGr1.addChild(coordSyst);

    // Background setting for the scene.
    newTextureLoader = new NewTextureLoader("Images/Ciel_Out.jpg");
    newTextureLoader.setImageObserver(newTextureLoader.getImageObserver());
    backGr = new Background(newTextureLoader.getImage());
    backGr.setImageScaleMode(Background.SCALE_FIT_ALL);
    boundsBackGr = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0);
    backGr.setApplicationBounds(boundsBackGr);
    brGr1.addChild(backGr);

    // A BoundingSphere instance as general bounding region.
    boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Lighting of the scene.

    // Create and attach an ambient light.
    ambientLight = new AmbientLight(true, new Color3f(0.2f, 0.2f, 0.2f));
    ambientLight.setInfluencingBounds(boundsGen);
    brGr1.addChild(ambientLight);

    // Create and attach a point light.
    pointLight = new PointLight(true, new Color3f(1.0f, 1.0f, 0.3f), new Point3f(-100.0f, 0.0f, 100.0f),
            new Point3f(0.0f, 0.05f, 0.1f));
    pointLight.setInfluencingBounds(boundsGen);
    brGr1.addChild(pointLight);

    // Create and attach a directional light.
    directionalLight = new DirectionalLight(true, new Color3f(0.8f, 1.0f, 1.0f),
            new Vector3f(-0.5f, -0.5f, -0.5f));
    directionalLight.setInfluencingBounds(boundsGen);
    brGr1.addChild(directionalLight);

    // Create the borders of the virtual universe for the inside view of the
    // scene.
    bordersIn = new BordersIn(dimUniverse);
    brGr1.addChild(bordersIn.myInternalUniverse());

    // Create the borders of the virtual universe for the outside view of
    // the scene.
    bordersOut = new BordersOut(dimUniverse);
    brGr1.addChild(bordersOut.myExternalUniverse());

    // Compile the subgraph to optimize the performances.
    brGr1.compile();

    // Return the final version of the BranchGroup node brGr1
    return brGr1;
}

From source file:ExText.java

/**
 * Builds the 3D universe by constructing a virtual universe (via
 * SimpleUniverse), a view platform (via SimpleUniverse), and a view (via
 * SimpleUniverse). A headlight is added and a set of behaviors initialized
 * to handle navigation types./*from  w ww  .  j ava2 s  .  c  om*/
 */
protected void buildUniverse() {
    //
    //  Create a SimpleUniverse object, which builds:
    //
    //    - a Locale using the given hi-res coordinate origin
    //
    //    - a ViewingPlatform which in turn builds:
    //          - a MultiTransformGroup with which to move the
    //            the ViewPlatform about
    //
    //          - a ViewPlatform to hold the view
    //
    //          - a BranchGroup to hold avatar geometry (if any)
    //
    //          - a BranchGroup to hold view platform
    //            geometry (if any)
    //
    //    - a Viewer which in turn builds:
    //          - a PhysicalBody which characterizes the user's
    //            viewing preferences and abilities
    //
    //          - a PhysicalEnvironment which characterizes the
    //            user's rendering hardware and software
    //
    //          - a JavaSoundMixer which initializes sound
    //            support within the 3D environment
    //
    //          - a View which renders the scene into a Canvas3D
    //
    //  All of these actions could be done explicitly, but
    //  using the SimpleUniverse utilities simplifies the code.
    //
    if (debug)
        System.err.println("Building scene graph...");
    SimpleUniverse universe = new SimpleUniverse(null, // Hi-res coordinate
            // for the origin -
            // use default
            1, // Number of transforms in MultiTransformGroup
            exampleCanvas, // Canvas3D into which to draw
            null); // URL for user configuration file - use defaults

    //
    //  Get the viewer and create an audio device so that
    //  sound will be enabled in this content.
    //
    Viewer viewer = universe.getViewer();
    viewer.createAudioDevice();

    //
    //  Get the viewing platform created by SimpleUniverse.
    //  From that platform, get the inner-most TransformGroup
    //  in the MultiTransformGroup. That inner-most group
    //  contains the ViewPlatform. It is this inner-most
    //  TransformGroup we need in order to:
    //
    //    - add a "headlight" that always aims forward from
    //       the viewer
    //
    //    - change the viewing direction in a "walk" style
    //
    //  The inner-most TransformGroup's transform will be
    //  changed by the walk behavior (when enabled).
    //
    ViewingPlatform viewingPlatform = universe.getViewingPlatform();
    exampleViewTransform = viewingPlatform.getViewPlatformTransform();

    //
    //  Create a "headlight" as a forward-facing directional light.
    //  Set the light's bounds to huge. Since we want the light
    //  on the viewer's "head", we need the light within the
    //  TransformGroup containing the ViewPlatform. The
    //  ViewingPlatform class creates a handy hook to do this
    //  called "platform geometry". The PlatformGeometry class is
    //  subclassed off of BranchGroup, and is intended to contain
    //  a description of the 3D platform itself... PLUS a headlight!
    //  So, to add the headlight, create a new PlatformGeometry group,
    //  add the light to it, then add that platform geometry to the
    //  ViewingPlatform.
    //
    BoundingSphere allBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100000.0);

    PlatformGeometry pg = new PlatformGeometry();
    headlight = new DirectionalLight();
    headlight.setColor(White);
    headlight.setDirection(new Vector3f(0.0f, 0.0f, -1.0f));
    headlight.setInfluencingBounds(allBounds);
    headlight.setCapability(Light.ALLOW_STATE_WRITE);
    pg.addChild(headlight);
    viewingPlatform.setPlatformGeometry(pg);

    //
    //  Create the 3D content BranchGroup, containing:
    //
    //    - a TransformGroup who's transform the examine behavior
    //      will change (when enabled).
    //
    //    - 3D geometry to view
    //
    // Build the scene root
    BranchGroup sceneRoot = new BranchGroup();

    // Build a transform that we can modify
    exampleSceneTransform = new TransformGroup();
    exampleSceneTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    exampleSceneTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    exampleSceneTransform.setCapability(Group.ALLOW_CHILDREN_EXTEND);

    //
    //  Build the scene, add it to the transform, and add
    //  the transform to the scene root
    //
    if (debug)
        System.err.println("  scene...");
    Group scene = this.buildScene();
    exampleSceneTransform.addChild(scene);
    sceneRoot.addChild(exampleSceneTransform);

    //
    //  Create a pair of behaviors to implement two navigation
    //  types:
    //
    //    - "examine": a style where mouse drags rotate about
    //      the scene's origin as if it is an object under
    //      examination. This is similar to the "Examine"
    //      navigation type used by VRML browsers.
    //
    //    - "walk": a style where mouse drags rotate about
    //      the viewer's center as if the viewer is turning
    //      about to look at a scene they are in. This is
    //      similar to the "Walk" navigation type used by
    //      VRML browsers.
    //
    //  Aim the examine behavior at the scene's TransformGroup
    //  and add the behavior to the scene root.
    //
    //  Aim the walk behavior at the viewing platform's
    //  TransformGroup and add the behavior to the scene root.
    //
    //  Enable one (and only one!) of the two behaviors
    //  depending upon the current navigation type.
    //
    examineBehavior = new ExamineViewerBehavior(exampleSceneTransform, // Transform
            // gorup
            // to
            // modify
            exampleFrame); // Parent frame for cusor changes
    examineBehavior.setSchedulingBounds(allBounds);
    sceneRoot.addChild(examineBehavior);

    walkBehavior = new WalkViewerBehavior(exampleViewTransform, // Transform
            // group to
            // modify
            exampleFrame); // Parent frame for cusor changes
    walkBehavior.setSchedulingBounds(allBounds);
    sceneRoot.addChild(walkBehavior);

    if (navigationType == Walk) {
        examineBehavior.setEnable(false);
        walkBehavior.setEnable(true);
    } else {
        examineBehavior.setEnable(true);
        walkBehavior.setEnable(false);
    }

    //
    //  Compile the scene branch group and add it to the
    //  SimpleUniverse.
    //
    if (shouldCompile)
        sceneRoot.compile();
    universe.addBranchGraph(sceneRoot);

    reset();
}

From source file:ffx.potential.MolecularAssembly.java

/**
 * The MolecularAssembly BranchGroup has two TransformGroups between it and
 * the "base" node where geometry is attached. If the point between the two
 * transformations is where user rotation occurs. For example, if rotating
 * about the center of mass of the system, the RotToCOM transformation will
 * be an identity transformation (ie. none). If rotation is about some atom
 * or group of atoms within the system, then the RotToCOM transformation
 * will be a translation from that point to the COM.
 *
 * @param zero boolean//from www.ja v a  2  s  . c o  m
 * @return BranchGroup
 */
public BranchGroup createScene(boolean zero) {
    originToRotT3D = new Transform3D();
    originToRotV3D = new Vector3d();
    originToRot = new TransformGroup(originToRotT3D);
    branchGroup = new BranchGroup();
    rotToCOM = new TransformGroup();
    rotToCOMT3D = new Transform3D();
    rotToCOMV3D = new Vector3d();
    // Set capabilities needed for picking and moving the MolecularAssembly
    branchGroup.setCapability(BranchGroup.ALLOW_DETACH);
    originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    originToRot.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // Put the MolecularAssembly in the middle of the scene
    if (zero) {
        originToRotV3D.set(0.0, 0.0, 0.0);
        originToRotT3D.set(originToRotV3D);
        originToRot.setTransform(originToRotT3D);
    }
    wire = renderWire();
    switchGroup = new Switch(Switch.CHILD_NONE);
    switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE);
    base = new BranchGroup();
    base.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    base.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    childNodes = new BranchGroup();
    childNodes.setCapability(BranchGroup.ALLOW_DETACH);
    childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    switchGroup.addChild(base);
    if (wire != null) {
        base.addChild(wire);
    }
    vrml = loadVRML();
    if (vrml != null) {
        vrmlTG = new TransformGroup();
        vrmlTd = new Transform3D();
        vrmlTG.setTransform(vrmlTd);
        vrmlTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        vrmlTG.addChild(vrml);
        switchGroup.addChild(vrmlTG);
        setView(RendererCache.ViewModel.INVISIBLE, null);
    }
    switchGroup.setWhichChild(Switch.CHILD_ALL);
    rotToCOM.addChild(switchGroup);
    originToRot.addChild(rotToCOM);
    branchGroup.addChild(originToRot);
    branchGroup.compile();
    return branchGroup;
}

From source file:EnvironmentExplorer.java

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

    // Add the primitives to the scene
    setupSpheres();/*  ww  w.  j  a va2s. c  om*/
    objRoot.addChild(spheresSwitch);
    setupGrid();
    objRoot.addChild(gridSwitch);
    objRoot.addChild(lightGroup);
    objRoot.addChild(bgSwitch);
    objRoot.addChild(fogSwitch);
    objRoot.addChild(soundSwitch);

    KeyPrintBehavior key = new KeyPrintBehavior();
    key.setSchedulingBounds(infiniteBounds);
    objRoot.addChild(key);
    return objRoot;
}