Example usage for javax.media.j3d DistanceLOD DistanceLOD

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

Introduction

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

Prototype

public DistanceLOD(float[] distances) 

Source Link

Document

Constructs and initializes a DistanceLOD node with the specified array of distances and a default position of (0,0,0).

Usage

From source file:LOD.java

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

    createLights(objRoot);//from  ww  w .  j  a  v  a2  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:SplineInterpolatorTest.java

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

    Group hiResGroup = createLand(switchNode);
    createEnvirons(switchNode);//www. j a  v a2 s  .  co 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;
}