Example usage for javax.media.j3d BranchGroup ALLOW_DETACH

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

Introduction

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

Prototype

int ALLOW_DETACH

To view the source code for javax.media.j3d BranchGroup ALLOW_DETACH.

Click Source Link

Document

For BranchGroup nodes, specifies that this BranchGroup allows detaching from its parent.

Usage

From source file:ExText.java

public Group buildScene() {
    // Get the current font attributes
    Font font = (Font) fonts[currentFont].value;
    String textString = (String) fonts[currentFont].name;

    // Turn on the example headlight
    setHeadlightEnable(true);/*from  www  .jav a  2s  .  c  o m*/

    // Build the scene group
    scene = new Group();
    scene.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scene.setCapability(Group.ALLOW_CHILDREN_WRITE);

    // Build a branch group to hold the text shape
    // (this allows us to remove the text shape later,
    // change it, then put it back, all under menu control)
    textGroup = new BranchGroup();
    textGroup.setCapability(BranchGroup.ALLOW_DETACH);
    scene.addChild(textGroup);

    // BEGIN EXAMPLE TOPIC
    // Create a font extrusion with a default extrusion shape
    extrusion = new FontExtrusion();

    // Define a 3D font with a default extrusion path
    Font3D font3d = new Font3D(font, extrusion);

    // Build 3D text geometry using the 3D font
    Text3D tex = new Text3D();
    tex.setFont3D(font3d);
    tex.setString(textString);
    tex.setAlignment(Text3D.ALIGN_CENTER);

    // Define a generic shaded appearance
    Appearance app = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    app.setMaterial(mat);

    // Assemble geometry and appearance into a shape
    // and add it to the scene
    shape = new Shape3D(tex, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    textGroup.addChild(shape);
    // END EXAMPLE TOPIC

    return scene;
}

From source file:ViewProj.java

public BranchGroup createVWorldViewSG() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    objRoot.setCapability(BranchGroup.ALLOW_DETACH);

    // setup a transform group to hold the scaled scene
    TransformGroup objTrans = new TransformGroup();
    objRoot.addChild(objTrans);/*from ww w  .j  av a2  s  .c  o  m*/

    // get the eye point, field of view and clip distances
    float fov = (float) view.getFieldOfView();

    // figure out the angle factors to find points along the edges
    // of the FOV
    // X = fovSpreadX * (Y - eyeVW.y) + eyeVW.x;
    float fovSpreadX = (float) Math.tan(fov / 2);
    // Z = fovSpreadZ * (X - eyeVW.x) + eyeVW.z;
    float fovSpreadZ = 1.0f / fovSpreadX;
    //System.out.println("fovSpreadX = " + fovSpreadX);
    //System.out.println("fovSpreadZ = " + fovSpreadZ);

    Transform3D vpTransform = new Transform3D();
    viewingPlatform.getViewPlatformTransform().getTransform(vpTransform);
    Vector3f vpTranslation = new Vector3f();
    vpTransform.get(vpTranslation);
    eyePtVW.set(vpTranslation);
    eyePtVW.negate();
    // get the eye point in our 2D coord system.
    Point3f eyePt = new Point3f(0.0f, eyePtVW.z, 0.1f);
    float frontClipDist = (float) view.getFrontClipDistance();
    float backClipDist = (float) view.getBackClipDistance();

    // set up the clip plane lines
    Point3f[] cpPoints = new Point3f[5];
    cpPoints[0] = new Point3f(frontClipDist * fovSpreadX, eyePtVW.z + frontClipDist, 0.1f);
    cpPoints[1] = new Point3f(cpPoints[0]);
    cpPoints[1].x *= -1;
    Point3f backLeft = new Point3f(-backClipDist * fovSpreadX, eyePtVW.z + backClipDist, 0.1f);
    cpPoints[2] = backLeft;
    Point3f backRight = new Point3f(backLeft);
    backRight.x *= -1;
    cpPoints[3] = backRight;
    cpPoints[4] = cpPoints[0];
    //for (int i = 0; i < 4; i++) {
    //    System.out.println("cpPoints[" + i + "] = " + cpPoints[i]);
    //}
    int[] cpLength = new int[1];
    cpLength[0] = 5;
    LineStripArray cpLines = new LineStripArray(5, LineArray.COORDINATES, cpLength);
    cpLines.setCoordinates(0, cpPoints);
    Appearance cpApp = new Appearance();
    ColoringAttributes cpCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT);
    cpApp.setColoringAttributes(cpCa);
    Shape3D cpShape = new Shape3D(cpLines, cpApp);
    objTrans.addChild(cpShape);

    // get the limits of the space
    float minY = eyePt.y;
    float maxY = backLeft.y;
    float minX = backLeft.x;
    float maxX = backRight.x;

    // figure out the X and Y extents and offsets
    float deltaX = maxX - minX;
    float deltaY = maxY - minY;
    float offsetX = -(maxX + minX) / 2.0f;
    float offsetY = -(maxY + minY) / 2.0f;
    float gridSize = Math.max(deltaX, deltaY);

    // scale the grid slightly to give a border around the edge
    gridSize *= 1.1f;

    //System.out.println("offsetX = " + offsetX);
    //System.out.println("offsetY = " + offsetY);

    // Scale the view to fit -1 to 1
    Transform3D trans = new Transform3D();
    trans.set(new Vector3f(offsetX, offsetY, 0.0f), 2.0f / gridSize);
    objTrans.setTransform(trans);

    // figure out a grid step that is a multiple of 10 which keeps the
    // number of steps less than 30.
    float gridStep = 1.0f;
    while ((gridSize / gridStep) > 30.0) {
        gridStep *= 10;
    }
    int gridNumSteps = (int) Math.ceil(gridSize / gridStep) + 1;

    // allocate the grid points array, four points for each step (x and y)
    // with a couple extra points for the extra grid points added
    // below
    int gridNumPoints = 4 * (gridNumSteps + 4);
    Point3f[] gridPts = new Point3f[gridNumPoints];
    for (int i = 0; i < gridNumPoints; i++) {
        gridPts[i] = new Point3f();
    }

    // find the grid limits. Add a step on each side to make sure
    // the grid is larger than the view
    float gridMinY = gridStepFloor(minY, gridStep) - gridStep;
    float gridMaxY = gridStepCeil(maxY, gridStep) + gridStep;
    float gridMinX = gridStepFloor(minX, gridStep) - gridStep;
    float gridMaxX = gridStepCeil(maxX, gridStep) + gridStep;
    //System.out.println("gridMinY = " + gridMinY);
    //System.out.println("gridMaxY = " + gridMaxY);
    //System.out.println("gridMinX = " + gridMinX);
    //System.out.println("gridMaxX = " + gridMaxX);

    // set up the background grid
    Appearance bgApp = new Appearance();
    ColoringAttributes bgCa = new ColoringAttributes();
    bgCa.setColor(grey);
    LineAttributes bgLa = new LineAttributes();
    bgApp.setColoringAttributes(bgCa);

    // clear out the clip grid point list
    numClipGridPts = 0;

    // set up the vertical lines
    int numPts = 0;
    for (float x = gridMinX; x <= gridMaxX; x += gridStep) {
        gridPts[numPts].x = x;
        gridPts[numPts].y = gridMinY;
        gridPts[numPts].z = -0.2f;
        gridPts[numPts + 1].x = x;
        gridPts[numPts + 1].y = gridMaxY;
        gridPts[numPts + 1].z = -0.2f;
        numPts += 2;

        // try to add a line to the clipped grid
        // find the intersection of the clipped line with the FOV sides
        // this is a distance relative to the eye
        float clipZ = fovSpreadZ * Math.abs(x - eyePtVW.x);
        if (clipZ < frontClipDist) { // clip to front clip plane
            clipZ = frontClipDist;
        }
        if (clipZ < backClipDist) { // clip to back clip plane
            // line is not clipped
            clipGridPtsVW[numClipGridPts].x = x;
            clipGridPtsVW[numClipGridPts].y = clipZ + eyePtVW.z;
            clipGridPtsVW[numClipGridPts].z = -0.1f;
            clipGridPtsVW[numClipGridPts + 1].x = x;
            clipGridPtsVW[numClipGridPts + 1].y = backClipDist + eyePtVW.z;
            clipGridPtsVW[numClipGridPts + 1].z = -0.1f;
            numClipGridPts += 2;
        }
    }
    LineArray vertLa = new LineArray(numPts, LineArray.COORDINATES);
    vertLa.setCoordinates(0, gridPts, 0, numPts);
    Shape3D vertShape = new Shape3D(vertLa, bgApp);
    objTrans.addChild(vertShape);

    // set up the horizontal lines
    numPts = 0;
    for (float y = gridMinY; y <= gridMaxY; y += gridStep) {
        gridPts[numPts].x = gridMinX;
        gridPts[numPts].y = y;
        gridPts[numPts++].z = -0.2f;
        gridPts[numPts].x = gridMaxX;
        gridPts[numPts].y = y;
        gridPts[numPts++].z = -0.2f;

        // try to add a line to the clipped grid
        // find the intersection of the clipped line with the FOV sides
        // this is a distance relative to the eye
        float clipDist = (y - eyePtVW.z);
        if ((clipDist > frontClipDist) && (clipDist < backClipDist)) {

            float clipX = fovSpreadX * clipDist;
            clipGridPtsVW[numClipGridPts].x = -clipX;
            clipGridPtsVW[numClipGridPts].y = y;
            clipGridPtsVW[numClipGridPts].z = -0.1f;
            clipGridPtsVW[numClipGridPts + 1].x = clipX;
            clipGridPtsVW[numClipGridPts + 1].y = y;
            clipGridPtsVW[numClipGridPts + 1].z = -0.1f;
            numClipGridPts += 2;
        }
    }
    LineArray horizLa = new LineArray(numPts, LineArray.COORDINATES);
    horizLa.setCoordinates(0, gridPts, 0, numPts);
    Shape3D horizShape = new Shape3D(horizLa, bgApp);
    objTrans.addChild(horizShape);

    // draw the clipped grid.
    if (numClipGridPts > 0) {
        LineArray clipLa = new LineArray(numClipGridPts, LineArray.COORDINATES);
        clipLa.setCoordinates(0, clipGridPtsVW, 0, numClipGridPts);
        Appearance clipGridApp = new Appearance();
        ColoringAttributes clipCa = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT);
        clipGridApp.setColoringAttributes(clipCa);
        LineAttributes clipGridLa = new LineAttributes();
        Shape3D clipShape = new Shape3D(clipLa, clipGridApp);
        objTrans.addChild(clipShape);
    }

    // set up the coordinate system
    Appearance coordSysApp = new Appearance();
    LineAttributes coordSysLa = new LineAttributes();
    coordSysLa.setLineWidth(3.0f);
    coordSysApp.setLineAttributes(coordSysLa);
    ColoringAttributes coordSysCa = new ColoringAttributes(grey, ColoringAttributes.SHADE_FLAT);
    coordSysApp.setColoringAttributes(coordSysCa);
    Point3f[] coordSysPts = new Point3f[4];
    coordSysPts[0] = new Point3f(gridMinX, 0, -0.5f);
    coordSysPts[1] = new Point3f(gridMaxX, 0, -0.5f);
    coordSysPts[2] = new Point3f(0, gridMinY, -0.5f);
    coordSysPts[3] = new Point3f(0, gridMaxY, -0.5f);
    LineArray coordSysLines = new LineArray(4, LineArray.COORDINATES);
    coordSysLines.setCoordinates(0, coordSysPts);
    Shape3D coordSysShape = new Shape3D(coordSysLines, coordSysApp);
    objTrans.addChild(coordSysShape);

    // set up the circle
    Appearance circleApp = new Appearance();
    ColoringAttributes circleCa = new ColoringAttributes();
    circleCa.setColor(red);
    circleApp.setColoringAttributes(circleCa);
    PolygonAttributes pa = new PolygonAttributes();
    pa.setCullFace(PolygonAttributes.CULL_NONE);
    circleApp.setPolygonAttributes(pa);
    int step = 360 / (numCirclePts - 1);
    for (int deg = 0; deg < 360; deg += step) {
        double angle = Math.toRadians(deg);
        circlePtsVW[deg / 10].x = sphereRadius * (float) Math.sin(angle);
        circlePtsVW[deg / 10].y = sphereRadius * (float) Math.cos(angle);
        circlePtsVW[deg / 10].z = -0.3f;
    }
    circlePtsVW[numCirclePts - 1].set(circlePtsVW[0]);
    int[] lineStripLength = new int[1];
    lineStripLength[0] = numCirclePts;
    //LineStripArray circleLineStrip = new LineStripArray(numCirclePts,
    //        LineArray.COORDINATES, lineStripLength);
    TriangleFanArray circleLineStrip = new TriangleFanArray(numCirclePts, LineArray.COORDINATES,
            lineStripLength);
    circleLineStrip.setCoordinates(0, circlePtsVW);
    Shape3D circleShape = new Shape3D(circleLineStrip, circleApp);
    objTrans.addChild(circleShape);

    return objRoot;
}

From source file:SwingTest.java

/**
 * Create a BranchGroup that contains a Cube. The user data for the
 * BranchGroup is set so the BranchGroup can be identified.
 *//*w w  w .j  ava  2s . com*/
protected BranchGroup createCube() {
    BranchGroup bg = new BranchGroup();
    bg.setCapability(BranchGroup.ALLOW_DETACH);
    bg.addChild(new com.sun.j3d.utils.geometry.ColorCube());
    bg.setUserData("Cube");
    return bg;
}

From source file:SwingTest.java

/**
 * Create a BranchGroup that contains a Sphere. The user data for the
 * BranchGroup is set so the BranchGroup can be identified.
 *///  w w w  .j  a va  2  s .com
protected BranchGroup createSphere() {
    BranchGroup bg = new BranchGroup();
    bg.setCapability(BranchGroup.ALLOW_DETACH);

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

    bg.addChild(new com.sun.j3d.utils.geometry.Sphere(1, app));
    bg.setUserData("Sphere");
    return bg;
}

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  w  w w . j  ava  2s.co 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:ViewProj.java

public BranchGroup createProjViewSG() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    objRoot.setCapability(BranchGroup.ALLOW_DETACH);

    // setup a transform group to hold the scaled scene
    TransformGroup objTrans = new TransformGroup();
    Transform3D scale = new Transform3D();
    scale.set(0.9);/*from w w w.  jav a2s.c  o  m*/
    objTrans.setTransform(scale);
    objRoot.addChild(objTrans);

    // create the clip limits line
    Point3f[] cpPoints = new Point3f[5];
    cpPoints[0] = new Point3f(-1, -1, 0.1f);
    cpPoints[1] = new Point3f(1, -1, 0.1f);
    cpPoints[2] = new Point3f(1, 1, 0.1f);
    cpPoints[3] = new Point3f(-1, 1, 0.1f);
    cpPoints[4] = cpPoints[0];
    int[] cpLength = new int[1];
    cpLength[0] = 5;
    LineStripArray cpLines = new LineStripArray(5, LineArray.COORDINATES, cpLength);
    cpLines.setCoordinates(0, cpPoints);
    Appearance cpApp = new Appearance();
    ColoringAttributes cpCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT);
    cpApp.setColoringAttributes(cpCa);
    LineAttributes cpLa = new LineAttributes();
    Shape3D cpShape = new Shape3D(cpLines, cpApp);
    objTrans.addChild(cpShape);

    // transform and render the clip grid points
    updateProjTrans();

    if (numClipGridPts > 0) {
        // transform the clipGridPts
        for (int i = 0; i < numClipGridPts; i++) {
            projectPoint(clipGridPtsVW[i], clipGridPtsProj[i]);
        }

        LineArray clipLn = new LineArray(numClipGridPts, LineArray.COORDINATES);
        clipLn.setCoordinates(0, clipGridPtsProj, 0, numClipGridPts);
        Appearance clipGridApp = new Appearance();
        ColoringAttributes clipCa = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT);
        clipGridApp.setColoringAttributes(clipCa);
        LineAttributes clipLa = new LineAttributes();
        Shape3D clipShape = new Shape3D(clipLn, clipGridApp);
        objTrans.addChild(clipShape);
    }

    // set up the circle
    Appearance circleApp = new Appearance();
    ColoringAttributes circleCa = new ColoringAttributes();
    circleCa.setColor(red);
    circleApp.setColoringAttributes(circleCa);
    PolygonAttributes pa = new PolygonAttributes();
    pa.setCullFace(PolygonAttributes.CULL_NONE);
    circleApp.setPolygonAttributes(pa);

    // transform the circlePts
    for (int i = 0; i < numCirclePts; i++) {
        projectPoint(circlePtsVW[i], circlePtsProj[i]);
    }

    int[] lineStripLength = new int[1];
    lineStripLength[0] = numCirclePts;
    //LineStripArray circleLineStrip = new LineStripArray(numCirclePts,
    //        LineArray.COORDINATES, lineStripLength);
    TriangleFanArray circleLineStrip = new TriangleFanArray(numCirclePts, LineArray.COORDINATES,
            lineStripLength);
    circleLineStrip.setCoordinates(0, circlePtsProj);
    Shape3D circleShape = new Shape3D(circleLineStrip, circleApp);
    objTrans.addChild(circleShape);

    return objRoot;
}

From source file:AppearanceExplorer.java

void setupSceneSwitch() {

    // create a Switch for the scene, allow switch changes
    sceneSwitch = new Switch();
    sceneSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    sceneSwitch.setCapability(Switch.ALLOW_CHILDREN_READ);
    sceneSwitch.setCapability(Switch.ALLOW_CHILDREN_WRITE);
    sceneSwitch.setCapability(Switch.ALLOW_CHILDREN_EXTEND);

    Shape3D pointArray = createPointArray();
    sceneSwitch.addChild(pointArray);/*from   w  w  w.  j  a  v a2  s . c  om*/

    Shape3D lineArray = createLineArray();
    sceneSwitch.addChild(lineArray);

    Shape3D triangleArray = createTriangleArray();
    sceneSwitch.addChild(triangleArray);

    Shape3D lineStripArray = createLineStripArray();
    sceneSwitch.addChild(lineStripArray);

    Shape3D triangleStripArray = createTriangleStripArray();
    sceneSwitch.addChild(triangleStripArray);

    Shape3D triangleFanArray = createTriangleFanArray();
    sceneSwitch.addChild(triangleFanArray);

    Shape3D texTris = createTexTris();
    sceneSwitch.addChild(texTris);

    Shape3D texSquare = createTexSquare();
    sceneSwitch.addChild(texSquare);

    Shape3D largeTexSquare = createLargeTexSquare();
    sceneSwitch.addChild(largeTexSquare);

    Shape3D colorCube = createColorCube();
    sceneSwitch.addChild(colorCube);

    Shape3D ngCreaseCube = createNGCube(45);
    sceneSwitch.addChild(ngCreaseCube);

    Shape3D ngSmoothCube = createNGCube(100);
    sceneSwitch.addChild(ngSmoothCube);

    Shape3D triWithHole = createTriWithHole();
    sceneSwitch.addChild(triWithHole);

    // create a sphere with the shared appearance
    Sphere sphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, appearance);
    sceneSwitch.addChild(sphere);

    // create a sphere with the shared appearance
    Sphere lrSphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, 10,
            appearance);
    sceneSwitch.addChild(lrSphere);

    // create a sphere with the shared appearance
    Sphere hrSphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, 45,
            appearance);
    sceneSwitch.addChild(hrSphere);

    // Text3D
    Shape3D text3D = createText3D();
    sceneSwitch.addChild(text3D);

    // galleon -- use a placeholder to indicate it hasn't been loaded yet
    // then load it the first time it gets asked for
    //was:
    //Group galleon = createGalleon();
    //sceneSwitch.addChild(galleon);
    galleonIndex = sceneSwitch.numChildren();
    galleonPlaceholder = new BranchGroup();
    galleonPlaceholder.setCapability(BranchGroup.ALLOW_DETACH);
    sceneSwitch.addChild(galleonPlaceholder);

    // beethoven -- use a placeholder to indicate it hasn't been loaded yet
    // then load it the first time it gets asked for
    //was:
    //Group beethoven = createBeethoven();
    //sceneSwitch.addChild(beethoven);
    beethovenIndex = sceneSwitch.numChildren();
    beethovenPlaceholder = new BranchGroup();
    beethovenPlaceholder.setCapability(BranchGroup.ALLOW_DETACH);
    sceneSwitch.addChild(beethovenPlaceholder);
}

From source file:Demo3D.java

/**
 * Create the subgraph #32/*w ww .  j a v  a  2s .  c om*/
 * 
 * @return javax.media.j3d.TransformGroup trGr32_3 - the root of the
 *         subgraph #32
 */
public BranchGroup mySubGraph32() {
    // A BoundingSphere instance as general bounding region.
    boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Create the first TransformGroup node trGr32_1 to:
    // 1) attach the Switch node with the five different earth's
    //    representations to the subgraph32
    // 2) attach a coordinate system to each earth's representation
    // 3) rotate each earth about its own y-axis.
    trGr32_1 = new TransformGroup();

    // With the ALLOW_TRANSFORM_WRITE capability, we allow the
    // modification of the TransformGroup's code by the behavior's
    // code at run time.
    trGr32_1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // SwitchBehavior is the class which controls the fonctioning of
    // the switchEarths node.

    switchBehavior = new SwitchBehavior(this);
    switchBehavior.setSchedulingBounds(boundsGen);
    trGr32_1.addChild(switchBehavior);

    // The Switch which allows the rendering of the five different
    // earth's representations.
    switchEarths = new Switch();
    // With the ALLOW_TRANSFORM_WRITE, ALLOW_SWITCH_WRITE and
    // ALLOW_CHILDREN_READ
    // capabilities we allow to get or set new capabilities.
    switchEarths.setCapability(Switch.ALLOW_SWITCH_READ);
    switchEarths.setCapability(Switch.ALLOW_SWITCH_WRITE);
    switchEarths.setCapability(Switch.ALLOW_CHILDREN_READ);

    // Attach the different earth's representations to the Switch node.
    // Increasing
    earth_Points = new Earth("points", 0.4f);
    switchEarths.addChild(earth_Points.myEarth()); // # 0

    earth_Lines = new Earth("lines", 0.4f);
    switchEarths.addChild(earth_Lines.myEarth()); // # 1

    earth_Polygons = new Earth("polygons", 0.4f);
    switchEarths.addChild(earth_Polygons.myEarth()); // # 2

    earth_Gouraud = new Earth("gouraud", 0.4f);
    switchEarths.addChild(earth_Gouraud.myEarth()); // # 3

    earth_Texture = new Earth("texture", 0.4f);
    switchEarths.addChild(earth_Texture.myEarth()); // # 4

    // Decreasing
    switchEarths.addChild(earth_Texture.myEarth()); // # 4
    switchEarths.addChild(earth_Gouraud.myEarth()); // # 3
    switchEarths.addChild(earth_Polygons.myEarth()); // # 2
    switchEarths.addChild(earth_Lines.myEarth()); // # 1
    switchEarths.addChild(earth_Points.myEarth()); // # 0

    // Attach the Switch node with the five different earth's
    // representations to the TransformGroup node trGr32_1.
    trGr32_1.addChild(switchEarths);

    // Create and attach a coordinate system to the TransformGroup node
    // trGr32_1, that is to each earth's representation.
    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.6f); // Lenght of the 3 axes
    trGr32_1.addChild(coordSyst);

    // Create the alpha(t) function for the earth's rotation about
    // its own y-axis.
    rotationAlpha_1 = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 10000, 0, 0, 0, 0, 0);
    // Create the earth's rotation about its own y-axis.
    rotator_1 = new RotationInterpolator(rotationAlpha_1, trGr32_1, new Transform3D(), 0.0f,
            (float) Math.PI * 2.0f);
    rotator_1.setSchedulingBounds(boundsGen);
    trGr32_1.addChild(rotator_1);

    // Create a Transform3D instance to execute the desired "static
    // translation" of the earth, that is the rotation radius around
    // the sun.
    transl = new Transform3D();
    vectTransl = new Vector3d(2.5, 0.0, 0.0);
    transl.set(vectTransl);

    // Create the second TransformGroup node trGr32_2 and attach the
    // "static translation" transl to it.
    trGr32_2 = new TransformGroup(transl);

    // Attach the trGr32_1 node to the trGr32_2 node.
    trGr32_2.addChild(trGr32_1);

    // Create the third TransformGroup node trGr32_3 for the earth's
    // rotation around the sun.
    trGr32_3 = new TransformGroup();

    // With the ALLOW_TRANSFORM_WRITE capability, we allow the
    // modification of the TransformGroup's code by the behavior's
    // code at run time.
    trGr32_3.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // Attach the trGr32_2 node to the trGr32_3 node.
    trGr32_3.addChild(trGr32_2);

    // Create the alpha(t) function for the earth's rotation around the sun.
    rotationAlpha_2 = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 20000, 0, 0, 0, 0, 0);

    // To restart correctly the rotation of the earth around the
    // sun after a detach/add process of the subgraph32 from the
    // BranchGroup node brGr3.
    rotationAlpha_2.setStartTime(System.currentTimeMillis());

    // Create the earth's rotation around the sun.
    rotator_2 = new RotationInterpolator(rotationAlpha_2, trGr32_3, new Transform3D(), 0.0f,
            (float) Math.PI * 2.0f);
    rotator_2.setSchedulingBounds(boundsGen);
    trGr32_3.addChild(rotator_2);

    // To allow the detaching of this subgraph32 from the
    // BranchGroup node brGr3.
    brGr32 = new BranchGroup();
    brGr32.setCapability(BranchGroup.ALLOW_DETACH);
    brGr32.addChild(trGr32_3);

    // Return the final version of the BranchGroup node brGr32.
    return brGr32;
}

From source file:ffx.potential.MolecularAssembly.java

/**
 * <p>//  w w w . j ava 2s.co m
 * loadVRML</p>
 *
 * @return a {@link javax.media.j3d.BranchGroup} object.
 */
public BranchGroup loadVRML() {
    try {
        VrmlLoader loader = new VrmlLoader();
        VrmlScene scene = null;
        if (vrmlFile != null && vrmlFile.exists()) {
            scene = (VrmlScene) loader.load(vrmlFile.getAbsolutePath());
        } else if (vrmlURL != null) {
            scene = (VrmlScene) loader.load(vrmlURL);
        } else {
            return null;
        }
        BranchGroup bg = scene.getSceneGroup();
        recurseVRML(bg);
        bg.setCapability(BranchGroup.ALLOW_DETACH);
        bg.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
        bg.compile();
        return bg;
    } catch (Exception e) {
        String message = "Fatal exception loading VRML.\n";
        logger.log(Level.SEVERE, message, e);
        System.exit(-1);
        return null;
    }

}