Example usage for javax.media.j3d MediaContainer setCacheEnable

List of usage examples for javax.media.j3d MediaContainer setCacheEnable

Introduction

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

Prototype

public void setCacheEnable(boolean flag) 

Source Link

Document

Set Cache Enable state flag.

Usage

From source file:ExSound.java

public Group buildScene() {
    // Get the initial sound volume
    float vol = ((Float) volumes[currentVolume].value).floatValue();

    // Turn off the example headlight
    setHeadlightEnable(false);//from   w w w.j  a v  a  2  s.  com

    // Default to walk navigation
    setNavigationType(Walk);

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

    //
    // Preload the sounds
    //
    if (debug)
        System.err.println("  sounds...");
    String path = getCurrentDirectory();
    MediaContainer backgroundMedia = new MediaContainer(path + "canon.wav");
    backgroundMedia.setCacheEnable(true);

    MediaContainer pointMedia = new MediaContainer(path + "willow1.wav");
    pointMedia.setCacheEnable(true);

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

    // Background sound
    backgroundSound = new BackgroundSound();
    backgroundSound.setEnable(backgroundSoundOnOff);
    backgroundSound.setLoop(Sound.INFINITE_LOOPS);
    backgroundSound.setSoundData(backgroundMedia);
    backgroundSound.setInitialGain(vol);
    backgroundSound.setSchedulingBounds(worldBounds);
    backgroundSound.setCapability(Sound.ALLOW_ENABLE_WRITE);
    backgroundSound.setCapability(Sound.ALLOW_INITIAL_GAIN_WRITE);
    scene.addChild(backgroundSound);

    // Create a distance gain array for the point sound
    Point2f[] distanceGain = { new Point2f(9.0f, 1.0f), // Full volume
            new Point2f(10.0f, 0.5f), // Half volume
            new Point2f(20.0f, 0.25f), // Quarter volume
            new Point2f(30.0f, 0.0f), // Zero volume
    };

    // Point sound
    pointSound = new PointSound();
    pointSound.setEnable(pointSoundOnOff);
    pointSound.setPosition(new Point3f(pointX, soundHeight, 0.0f));
    pointSound.setLoop(Sound.INFINITE_LOOPS);
    pointSound.setSoundData(pointMedia);
    pointSound.setInitialGain(vol);
    pointSound.setDistanceGain(distanceGain);
    pointSound.setSchedulingBounds(worldBounds);
    pointSound.setCapability(Sound.ALLOW_ENABLE_WRITE);
    pointSound.setCapability(Sound.ALLOW_INITIAL_GAIN_WRITE);
    scene.addChild(pointSound);
    // END EXAMPLE TOPIC

    // Build a few lights, one per sound. We'll turn them
    // on when the associated sound is on.
    ambientLight = new AmbientLight();
    ambientLight.setEnable(backgroundSoundOnOff);
    ambientLight.setColor(Gray);
    ambientLight.setInfluencingBounds(worldBounds);
    ambientLight.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(ambientLight);

    pointLight = new PointLight();
    pointLight.setEnable(pointSoundOnOff);
    pointLight.setColor(White);
    pointLight.setPosition(0.0f, soundHeight, 0.0f);
    pointLight.setInfluencingBounds(worldBounds);
    pointLight.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(pointLight);

    // Add a basic ambient light for when all sounds (and
    // their lights) are off so that the world isn't dark
    AmbientLight amb = new AmbientLight();
    amb.setEnable(true);
    amb.setColor(Gray);
    amb.setInfluencingBounds(worldBounds);
    amb.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(amb);

    // Build foreground geometry
    scene.addChild(buildForeground());

    return scene;
}