Example usage for javax.media.j3d Background Background

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

Introduction

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

Prototype

public Background() 

Source Link

Document

Constructs a Background node with default parameters.

Usage

From source file:LightScopeApp.java

BranchGroup createScene() {
    BranchGroup scene = new BranchGroup();
    TransformGroup tableTG = new TransformGroup();
    TransformGroup lampTG = new TransformGroup();
    TransformGroup litBoxTG = new TransformGroup();
    TransformGroup unLitBoxTG = new TransformGroup();

    scene.addChild(tableTG);/*from   w  w w .ja va  2s . c  o m*/
    tableTG.addChild(lampTG);
    tableTG.addChild(litBoxTG);
    tableTG.addChild(unLitBoxTG);

    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f blue = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f green = new Color3f(0.0f, 0.0f, 1.0f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);

    Vector3f transVector = new Vector3f();
    Transform3D transTransform = new Transform3D();

    transVector.set(0.0f, -0.4f, 0.5f);
    transTransform.setTranslation(transVector);
    tableTG.setTransform(transTransform);

    transVector.set(-0.4f, 0.001f, 0.1f);
    transTransform.setTranslation(transVector);
    lampTG.setTransform(transTransform);

    transVector.set(-0.2f, 0.1f, 0.2f);
    transTransform.setTranslation(transVector);
    litBoxTG.setTransform(transTransform);

    transVector.set(0.3f, 0.1f, -0.4f);
    transTransform.setTranslation(transVector);
    unLitBoxTG.setTransform(transTransform);

    Shape3D tablePlane = createXZPlane(new Point3f(-1.0f, 0.0f, -1.0f), new Point3f(-1.0f, 0.0f, 1.0f),
            new Point3f(1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, -1.0f));
    tablePlane.setAppearance(createMaterialAppearance(white));
    tableTG.addChild(tablePlane);
    litBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, createMaterialAppearance(red)));
    Shape3D shadowPlane = createXZPlane(new Point3f(0.1f, -0.095f, -0.1f), new Point3f(0.1f, -0.095f, 0.1f),
            new Point3f(0.2f, -0.095f, 0.15f), new Point3f(0.2f, -0.095f, -0.15f));
    shadowPlane.setAppearance(createMaterialAppearance(black));
    litBoxTG.addChild(shadowPlane);

    Appearance redGlowMat = createMaterialAppearance(red);
    //    redGlowMat.getMaterial().setEmissiveColor(0.5f, 0.5f, 0.5f);
    unLitBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, redGlowMat));

    Shape3D lamp = createLampShape();
    Appearance lampAppearance = createMaterialAppearance(blue);
    PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
    polyAttrib.setBackFaceNormalFlip(true);
    lampAppearance.setPolygonAttributes(polyAttrib);
    lamp.setAppearance(lampAppearance);
    lampTG.addChild(lamp);

    PointLight lampLight = new PointLight();
    lampLight.setPosition(0.1f, 0.5f, -0.1f);
    lampLight.setInfluencingBounds(new BoundingSphere());
    lampTG.addChild(lampLight);

    Shape3D litPlane = createXZPlane(new Point3f(-0.4f, 0.0f, -0.4f), new Point3f(-0.4f, 0.0f, 0.4f),
            new Point3f(0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, -0.4f));
    litPlane.setAppearance(createMaterialAppearance(white));
    lampTG.addChild(litPlane);

    lampLight.addScope(lampTG);
    lampLight.addScope(litBoxTG);

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);

    DirectionalLight lightD1 = new DirectionalLight();
    lightD1.setInfluencingBounds(new BoundingSphere());
    lightD1.setColor(new Color3f(0.4f, 0.4f, 0.4f));
    Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f);
    lightDir.normalize();
    lightD1.setDirection(lightDir);
    scene.addChild(lightD1);

    DirectionalLight lightD2 = new DirectionalLight();
    lightD2.setInfluencingBounds(new BoundingSphere());
    lightD2.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    lightDir.set(1.0f, -1.0f, -1.0f);
    lightDir.normalize();
    lightD2.setDirection(lightDir);
    scene.addChild(lightD2);

    Background bg = new Background();
    bg.setColor(1.0f, 1.0f, 1.0f);
    bg.setApplicationBounds(new BoundingSphere());
    scene.addChild(bg);

    return scene;
}

From source file:GeomInfoApp.java

public BranchGroup createSceneGraph(boolean wireFrame) {
    int total = 0;

    System.out.println("\n --- geometry debug information --- \n");

    float[] coordinateData = null;
    coordinateData = createCoordinateData();
    int[] stripCount = { 17, 17, 5, 5, 5, 5, 5, 5, 5 }; // ******
    //        int[] stripCount = {17,17,17}; // ******

    for (int i = 0; i < stripCount.length; i++) {
        System.out.println("stripCount[" + i + "] = " + stripCount[i]);
        total += stripCount[i];/*  www  .  jav  a  2  s .  c o m*/
    }

    if (total != coordinateData.length / 3) {
        System.out.println("  coordinateData vertex count: " + coordinateData.length / 3);
        System.out.println("stripCount total vertex count: " + total);
    }

    GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
    gi.setCoordinates(coordinateData);
    gi.setStripCounts(stripCount);

    Triangulator tr = new Triangulator();
    //        Triangulator tr = new Triangulator(1);
    System.out.println("begin triangulation");
    tr.triangulate(gi);
    System.out.println("  END triangulation");
    gi.recomputeIndices();

    NormalGenerator ng = new NormalGenerator();
    ng.generateNormals(gi);
    gi.recomputeIndices();

    Stripifier st = new Stripifier();
    st.stripify(gi);
    gi.recomputeIndices();

    Shape3D part = new Shape3D();
    if (wireFrame == true)
        part.setAppearance(createWireFrameAppearance());
    else
        part.setAppearance(createMaterialAppearance());
    part.setGeometry(gi.getGeometryArray());

    /////////////////////////////

    BranchGroup contentRoot = new BranchGroup();

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    contentRoot.addChild(objSpin);

    objSpin.addChild(part);

    ////////////////////////
    LineStripArray lineArray = new LineStripArray(69, LineArray.COORDINATES, stripCount); //*****
    //        LineStripArray lineArray = new LineStripArray(51,
    // LineArray.COORDINATES, stripCount); //*****
    lineArray.setCoordinates(0, coordinateData);
    Appearance blueColorAppearance = new Appearance();
    ColoringAttributes blueColoring = new ColoringAttributes();
    blueColoring.setColor(0.0f, 0.0f, 1.0f);
    blueColorAppearance.setColoringAttributes(blueColoring);
    LineAttributes lineAttrib = new LineAttributes();
    lineAttrib.setLineWidth(2.0f);
    blueColorAppearance.setLineAttributes(lineAttrib);
    objSpin.addChild(new Shape3D(lineArray, blueColorAppearance));

    Alpha rotationAlpha = new Alpha(-1, 16000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 1
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    DirectionalLight lightD = new DirectionalLight();
    lightD.setDirection(new Vector3f(0.0f, -0.7f, -0.7f));
    lightD.setInfluencingBounds(bounds);
    contentRoot.addChild(lightD);

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(bounds);
    contentRoot.addChild(lightA);

    Background background = new Background();
    background.setColor(1.0f, 1.0f, 1.0f);
    background.setApplicationBounds(bounds);
    contentRoot.addChild(background);

    // Let Java 3D perform optimizations on this scene graph.
    // contentRoot.compile();

    return contentRoot;
}