Example usage for javax.media.j3d DistanceLOD addSwitch

List of usage examples for javax.media.j3d DistanceLOD addSwitch

Introduction

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

Prototype

public void addSwitch(Switch switchNode) 

Source Link

Document

Appends the specified switch node to this LOD's list of switches.

Usage

From source file:LOD.java

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

    createLights(objRoot);//from   w w  w  .  ja v  a 2  s  .c  o  m

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

    // Create a switch to hold the different levels of detail
    Switch sw = new Switch(0);
    sw.setCapability(javax.media.j3d.Switch.ALLOW_SWITCH_READ);
    sw.setCapability(javax.media.j3d.Switch.ALLOW_SWITCH_WRITE);

    // Create several levels for the switch, with less detailed
    // spheres for the ones which will be used when the sphere is
    // further away
    sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 40));
    sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 20));
    sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 10));
    sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 3));

    // Add the switch to the main group
    objTrans.addChild(sw);

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

    // set up the DistanceLOD behavior
    float[] distances = new float[3];
    distances[0] = 5.0f;
    distances[1] = 10.0f;
    distances[2] = 25.0f;
    DistanceLOD lod = new DistanceLOD(distances);
    lod.addSwitch(sw);
    lod.setSchedulingBounds(bounds);
    objTrans.addChild(lod);

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

    return objRoot;
}

From source file:SimpleLOD.java

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

    contentBranch.addChild(LODswitch);
    return contentBranch;

}

From source file:SplineInterpolatorTest.java

public Group createLodLand(Group g) {
    Switch switchNode = new Switch();
    switchNode.setCapability(Switch.ALLOW_SWITCH_WRITE);

    Group hiResGroup = createLand(switchNode);
    createEnvirons(switchNode);/*  w  ww  .j  ava2s  .  c o m*/

    // create a DistanceLOD that will select the child of
    // the Switch node based on distance. Here we are selecting
    // child 0 (high res) if we are closer than 180 units to
    // 0,0,0 and child 1 (low res) otherwise.
    float[] distanceArray = { 180 };

    DistanceLOD distanceLod = new DistanceLOD(distanceArray);
    distanceLod.setSchedulingBounds(getApplicationBounds());
    distanceLod.addSwitch(switchNode);

    g.addChild(distanceLod);
    g.addChild(switchNode);

    return hiResGroup;
}