//
  //  Handle checkboxes and menu choices
  //
  public void itemStateChanged(ItemEvent event) {
    Object src = event.getSource();
    if (src == light1OnOffMenu) {
      light1OnOff = light1OnOffMenu.getState();
      light1.setEnable(light1OnOff);
      return;
    }
    if (src == light2OnOffMenu) {
      light2OnOff = light2OnOffMenu.getState();
      light2.setEnable(light2OnOff);
      return;
    }
    if (src == light3OnOffMenu) {
      light3OnOff = light3OnOffMenu.getState();
      light3.setEnable(light3OnOff);
      return;
    }

    // Handle all other checkboxes
    super.itemStateChanged(event);
  }
  //
  //  Build scene
  //
  public Group buildScene() {
    // Turn off the example headlight
    setHeadlightEnable(false);

    // Build the scene group
    Group scene = new Group();

    // Build foreground geometry into two groups.  We'll
    // create three directional lights below, one each with
    // scope to cover the first geometry group only, the
    // second geometry group only, or both geometry groups.
    content1 =
        new SphereGroup(
            0.25f, // radius of spheres
            1.5f, // x spacing
            0.75f, // y spacing
            3, // number of spheres in X
            5, // number of spheres in Y
            null); // appearance
    scene.addChild(content1);

    content2 =
        new SphereGroup(
            0.25f, // radius of spheres
            1.5f, // x spacing
            0.75f, // y spacing
            2, // number of spheres in X
            5, // number of spheres in Y
            null); // appearance
    scene.addChild(content2);

    // BEGIN EXAMPLE TOPIC
    // Create influencing bounds
    BoundingSphere worldBounds =
        new BoundingSphere(
            new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    // Add three directional lights whose scopes are set
    // to cover one, the other, or both of the shape groups
    // above.  Also set the lights' color and aim direction.

    // Light #1 with content1 scope
    light1 = new DirectionalLight();
    light1.setEnable(light1OnOff);
    light1.setColor(Red);
    light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light1.setInfluencingBounds(worldBounds);
    light1.addScope(content1);
    light1.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(light1);

    // Light #2 with content2 scope
    light2 = new DirectionalLight();
    light2.setEnable(light2OnOff);
    light2.setColor(Blue);
    light2.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light2.setInfluencingBounds(worldBounds);
    light2.addScope(content2);
    light2.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(light2);

    // Light #3 with universal scope (the default)
    light3 = new DirectionalLight();
    light3.setEnable(light3OnOff);
    light3.setColor(White);
    light3.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light3.setInfluencingBounds(worldBounds);
    light3.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(light3);

    // Add an ambient light to dimly illuminate the rest of
    // the shapes in the scene to help illustrate that the
    // directional lights are being scoped... otherwise it looks
    // like we're just removing shapes from the scene
    AmbientLight ambient = new AmbientLight();
    ambient.setEnable(true);
    ambient.setColor(White);
    ambient.setInfluencingBounds(worldBounds);
    scene.addChild(ambient);
    // END EXAMPLE TOPIC

    return scene;
  }
Exemple #3
0
 public DirectionalLight getLight() {
   if (light == null) {
     light = new DirectionalLight(visible, color, direction);
     BoundingSphere bounds = new BoundingSphere(location, Double.POSITIVE_INFINITY);
     light.setCapability(DirectionalLight.ALLOW_DIRECTION_READ);
     light.setCapability(DirectionalLight.ALLOW_DIRECTION_WRITE);
     light.setCapability(Light.ALLOW_COLOR_READ);
     light.setCapability(Light.ALLOW_COLOR_WRITE);
     light.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ);
     light.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
     light.setCapability(Light.ALLOW_SCOPE_READ);
     light.setCapability(Light.ALLOW_SCOPE_WRITE);
     light.setCapability(Light.ALLOW_STATE_READ);
     light.setCapability(Light.ALLOW_STATE_WRITE);
     light.setInfluencingBounds(bounds);
   }
   return light;
 }