Example usage for javax.media.j3d Background setGeometry

List of usage examples for javax.media.j3d Background setGeometry

Introduction

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

Prototype

public void setGeometry(BranchGroup branch) 

Source Link

Document

Sets the background geometry to the specified BranchGroup node.

Usage

From source file:BackgroundApp.java

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

    Vector3f translate = new Vector3f();
    Transform3D T3D = new Transform3D();

    translate.set(0.0f, -0.3f, 0.0f);/*from ww w  .j  a  v a 2 s  . c o  m*/
    T3D.setTranslation(translate);
    TransformGroup objRoot = new TransformGroup(T3D);
    objRootBG.addChild(objRoot);

    objRoot.addChild(createLand());

    BoundingLeaf boundingLeaf = new BoundingLeaf(new BoundingSphere());

    PlatformGeometry platformGeom = new PlatformGeometry();
    platformGeom.addChild(boundingLeaf);
    platformGeom.compile();
    su.getViewingPlatform().setPlatformGeometry(platformGeom);

    KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(
            su.getViewingPlatform().getViewPlatformTransform());
    keyNavBeh.setSchedulingBoundingLeaf(boundingLeaf);
    objRootBG.addChild(keyNavBeh);

    Background background = new Background();
    background.setApplicationBounds(new BoundingSphere(new Point3d(), 1000.0));
    background.setGeometry(createBackGraph());
    objRoot.addChild(background);

    AmbientLight ambientLight = new AmbientLight();
    ambientLight.setInfluencingBounds(new BoundingSphere());
    objRootBG.addChild(ambientLight);

    return objRootBG;
}

From source file:BackgroundGeometry.java

public BranchGroup createSceneGraph() {

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

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);/*  w  w w . j  a v  a  2s.  co  m*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // 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.
    TransformGroup objTrans = new TransformGroup();
    objScale.addChild(objTrans);

    Background bg = new Background();
    bg.setApplicationBounds(bounds);
    BranchGroup backGeoBranch = new BranchGroup();
    Sphere sphereObj = new Sphere(1.0f,
            Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 45);
    Appearance backgroundApp = sphereObj.getAppearance();
    backGeoBranch.addChild(sphereObj);
    bg.setGeometry(backGeoBranch);
    objTrans.addChild(bg);

    TextureLoader tex = new TextureLoader(bgImage, new String("RGB"), this);
    if (tex != null)
        backgroundApp.setTexture(tex.getTexture());

    Vector3f tranlation = new Vector3f(2.0f, 0.0f, 0.0f);
    Transform3D modelTransform = new Transform3D();
    Transform3D tmpTransform = new Transform3D();
    double angleInc = Math.PI / 8.0;
    double angle = 0.0;
    int numBoxes = 16;

    float scaleX[] = { 0.1f, 0.2f, 0.2f, 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f,
            0.3f };

    float scaleY[] = { 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f,
            0.4f };

    float scaleZ[] = { 0.3f, 0.2f, 0.1f, 0.1f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f,
            0.2f };

    Appearance a1 = new Appearance();
    Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor = new Color3f(0.5f, 0.5f, 1.0f);
    Color3f oColor = new Color3f(0.5f, 0.5f, 0.3f);

    Material m = new Material(oColor, eColor, oColor, sColor, 100.0f);
    m.setLightingEnable(true);
    a1.setMaterial(m);

    for (int i = 0; i < numBoxes; i++, angle += angleInc) {
        modelTransform.rotY(angle);
        tmpTransform.set(tranlation);
        modelTransform.mul(tmpTransform);

        TransformGroup tgroup = new TransformGroup(modelTransform);
        objTrans.addChild(tgroup);

        tgroup.addChild(new Box(scaleX[i], scaleY[i], scaleZ[i], Box.GENERATE_NORMALS, a1));
    }

    // Shine it with two lights.
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f lColor2 = new Color3f(0.2f, 0.2f, 0.1f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

    return objRoot;
}

From source file:AvatarTest.java

public void createBackground(Group bg) {
    // add the sky backdrop
    Background back = new Background();
    back.setApplicationBounds(getBoundingSphere());
    bg.addChild(back);//from w  w w . jav  a  2 s .  com

    BranchGroup bgGeometry = new BranchGroup();

    // create an appearance and assign the texture image
    Appearance app = new Appearance();
    Texture tex = new TextureLoader("back.jpg", this).getTexture();
    app.setTexture(tex);

    Sphere sphere = new Sphere(1.0f, Primitive.GENERATE_TEXTURE_COORDS | Primitive.GENERATE_NORMALS_INWARD,
            app);

    bgGeometry.addChild(sphere);
    back.setGeometry(bgGeometry);
}

From source file:SimpleTest.java

public BranchGroup createBackground() {
    // create a parent BranchGroup for the Background
    BranchGroup backgroundGroup = new BranchGroup();

    // create a new Background node
    Background back = new Background();

    // set the range of influence of the background
    back.setApplicationBounds(getBoundingSphere());

    // create a BranchGroup that will hold
    // our Sphere geometry
    BranchGroup bgGeometry = new BranchGroup();

    // create an appearance for the Sphere
    Appearance app = new Appearance();

    // load a texture image using the Java 3D texture loader
    Texture tex = new TextureLoader("back.jpg", this).getTexture();

    // apply the texture to the Appearance
    app.setTexture(tex);/*from  w  ww.java 2  s  .c om*/

    // create the Sphere geometry with radius 1.0
    // we tell the Sphere to generate texture coordinates
    // to enable the texture image to be rendered
    // and because we are *inside* the Sphere we have to generate
    // Normal coordinates inwards or the Sphere will not be visible.
    Sphere sphere = new Sphere(1.0f, Primitive.GENERATE_TEXTURE_COORDS | Primitive.GENERATE_NORMALS_INWARD,
            app);

    // start wiring everything together
    // add the Sphere to its parent BranchGroup
    bgGeometry.addChild(sphere);

    // assign the BranchGroup to the Background as geometry.
    back.setGeometry(bgGeometry);

    // add the Background node to its parent BranchGroup
    backgroundGroup.addChild(back);

    return backgroundGroup;
}

From source file:AppearanceExplorer.java

BackgroundTool(String codeBaseString) {

    bgSwitch = new Switch(Switch.CHILD_NONE);
    bgSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // set up the dark grey BG color node
    Background bgDarkGrey = new Background(darkGrey);
    bgDarkGrey.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgDarkGrey);/* w w w .  j  a v a 2 s.  c om*/

    // set up the grey BG color node
    Background bgGrey = new Background(grey);
    bgGrey.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgGrey);

    // set up the light grey BG color node
    Background bgLightGrey = new Background(lightGrey);
    bgLightGrey.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgLightGrey);

    // set up the white BG color node
    Background bgWhite = new Background(white);
    bgWhite.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgWhite);

    // set up the blue BG color node
    Background bgBlue = new Background(skyBlue);
    bgBlue.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgBlue);

    // set up the image
    java.net.URL bgImageURL = null;
    try {
        bgImageURL = new java.net.URL(codeBaseString + "bg.jpg");
    } catch (java.net.MalformedURLException ex) {
        System.out.println(ex.getMessage());
        System.exit(1);
    }
    if (bgImageURL == null) { // application, try file URL
        try {
            bgImageURL = new java.net.URL("file:./bg.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }
    TextureLoader bgTexture = new TextureLoader(bgImageURL, null);

    // Create a background with the static image
    Background bgImage = new Background(bgTexture.getImage());
    bgImage.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgImage);

    // create a background with the image mapped onto a sphere which
    // will enclose the world
    Background bgGeo = new Background();
    bgGeo.setApplicationBounds(infiniteBounds);
    BranchGroup bgGeoBG = new BranchGroup();
    Appearance bgGeoApp = new Appearance();
    bgGeoApp.setTexture(bgTexture.getTexture());
    Sphere sphereObj = new Sphere(1.0f,
            Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 45,
            bgGeoApp);
    bgGeoBG.addChild(sphereObj);
    bgGeo.setGeometry(bgGeoBG);
    bgSwitch.addChild(bgGeo);

    // Create the chooser GUI
    String[] bgNames = { "No Background (Black)", "Dark Grey", "Grey", "Light Grey", "White", "Blue",
            "Sky Image", "Sky Geometry", };
    int[] bgValues = { Switch.CHILD_NONE, 0, 1, 2, 3, 4, 5, 6 };

    bgChooser = new IntChooser("Background:", bgNames, bgValues, 0);
    bgChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            int value = event.getValue();
            bgSwitch.setWhichChild(value);
        }
    });
    bgChooser.setValue(Switch.CHILD_NONE);
}

From source file:SplineInterpolatorTest.java

protected Background createBackground() {
    // add the sky backdrop
    Background back = new Background();
    back.setApplicationBounds(getApplicationBounds());

    BranchGroup bgGeometry = new BranchGroup();

    // create an appearance and assign the texture image
    Appearance app = new Appearance();
    Texture tex = new TextureLoader("sky.gif", this).getTexture();
    app.setTexture(tex);/*from   ww w  .  ja v a 2  s .c o  m*/

    Sphere sphere = new Sphere(1.0f, Primitive.GENERATE_TEXTURE_COORDS | Primitive.GENERATE_NORMALS_INWARD,
            app);

    bgGeometry.addChild(sphere);
    back.setGeometry(bgGeometry);

    return back;
}