Example usage for javax.media.j3d AmbientLight setInfluencingBounds

List of usage examples for javax.media.j3d AmbientLight setInfluencingBounds

Introduction

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

Prototype

public void setInfluencingBounds(Bounds region) 

Source Link

Document

Sets the Light's influencing region to the specified bounds.

Usage

From source file:OrientedPtTest.java

public BranchGroup createSceneGraph() {

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

    TransformGroup objScale = new TransformGroup();
    Transform3D textMat = new Transform3D();
    // Assuming uniform size chars, set scale to fit string in view
    textMat.setScale(1.2 / sl);// w w w.  j av a 2 s .c o  m
    objScale.setTransform(textMat);

    // 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);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    Appearance apText = new Appearance();
    Material m = new Material();
    m.setLightingEnable(true);
    apText.setMaterial(m);

    Appearance apEarth = new Appearance();
    Material mm = new Material();
    mm.setLightingEnable(true);
    apEarth.setMaterial(mm);

    Appearance apStone = new Appearance();
    apStone.setMaterial(mm);

    // create 3D text
    Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
    Point3f textPt = new Point3f(-sl / 2.0f, 3.0f, 0.0f);
    Text3D txt = new Text3D(f3d, textString, textPt);
    OrientedShape3D textShape = new OrientedShape3D();
    textShape.setGeometry(txt);
    textShape.setAppearance(apText);

    textShape.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_POINT);
    // text is centered around 0, 3, 0. Make it rotate around 0,5,0
    Point3f rotationPt = new Point3f(0.0f, 5.0f, 0.0f);
    textShape.setRotationPoint(rotationPt);
    objScale.addChild(textShape);

    // also add a small Sphere at the rotation point to
    // show that we are rotating around the right point
    Sphere sphere = new Sphere(0.2f);
    TransformGroup sphereGroup = new TransformGroup();
    Transform3D sphereXform = new Transform3D();
    sphereXform.set(new Vector3f(rotationPt));
    sphereGroup.setTransform(sphereXform);
    sphereGroup.addChild(sphere);
    objScale.addChild(sphereGroup);

    // Create a simple shape leaf node, add it to the scene graph.

    Transform3D cubeMat = new Transform3D();
    TransformGroup cubeTrans = new TransformGroup(cubeMat);
    cubeMat.set(new Vector3d(0.9, 0.0, -1.0));
    cubeTrans.setTransform(cubeMat);
    cubeTrans.addChild(new ColorCube(0.3));
    objTrans.addChild(cubeTrans);

    TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this);
    if (stoneTex != null)
        apStone.setTexture(stoneTex.getTexture());

    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.REPLACE);
    apStone.setTextureAttributes(texAttr);

    Transform3D coneMat = new Transform3D();
    TransformGroup coneTrans = new TransformGroup(coneMat);
    coneMat.set(new Vector3d(0.0, 0.0, 0.0));
    coneTrans.setTransform(coneMat);
    coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone));
    objTrans.addChild(coneTrans);

    TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this);
    if (earthTex != null)
        apEarth.setTexture(earthTex.getTexture());
    apEarth.setTextureAttributes(texAttr);

    Transform3D cylinderMat = new Transform3D();
    TransformGroup cylinderTrans = new TransformGroup(cylinderMat);
    cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0));
    cylinderTrans.setTransform(cylinderMat);
    cylinderTrans.addChild(
            new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth));
    objTrans.addChild(cylinderTrans);

    objTrans.addChild(objScale);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    apText.setMaterial(mm);

    // Have Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:LineTypes.java

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

    // Create a TransformGroup to scale the scene down by 3.5x
    // TODO: move view platform instead of scene using orbit behavior
    TransformGroup objScale = new TransformGroup();
    Transform3D scaleTrans = new Transform3D();
    //scaleTrans.set(1 / 3.5f); // scale down by 3.5x
    objScale.setTransform(scaleTrans);//from   w  w  w  .j a  v  a  2  s  . c om
    objRoot.addChild(objScale);

    // Create a TransformGroup and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // the mouse behaviors 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);
    objScale.addChild(objTrans);

    // Add the primitives to the scene
    objTrans.addChild(createLineTypes());

    BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0);

    Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f));
    bg.setApplicationBounds(bounds);
    objTrans.addChild(bg);

    // set up the mouse rotation behavior
    MouseRotate mr = new MouseRotate();
    mr.setTransformGroup(objTrans);
    mr.setSchedulingBounds(bounds);
    mr.setFactor(0.007);
    objTrans.addChild(mr);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f light1Direction = new Vector3f(0.0f, -0.2f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    return objRoot;
}

From source file:AppearanceTest.java

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

    // Create a bounds for the background and lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the background
    TextureLoader bgTexture = new TextureLoader(bgImage, this);
    Background bg = new Background(bgTexture.getImage());
    bg.setApplicationBounds(bounds);/*w  w  w. j a v  a 2 s  . co  m*/
    objRoot.addChild(bg);

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    // Create a bunch of objects with a behavior and add them
    // into the scene graph.

    int row, col;
    Appearance[][] app = new Appearance[3][3];

    for (row = 0; row < 3; row++)
        for (col = 0; col < 3; col++)
            app[row][col] = createAppearance(row * 3 + col);

    for (int i = 0; i < 3; i++) {
        double ypos = (double) (i - 1) * 0.6;
        for (int j = 0; j < 3; j++) {
            double xpos = (double) (j - 1) * 0.6;
            objRoot.addChild(createObject(app[i][j], 0.12, xpos, ypos));
        }
    }

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

    return objRoot;
}

From source file:LightsNPlanesApp.java

public LightsNPlanesApp() {
    setLayout(new BorderLayout());
    Canvas3D c = new Canvas3D(null);
    add("Center", c);

    BoundingSphere bounds = new BoundingSphere(new Point3d(), 0.1);

    Vector3f direction = new Vector3f(0.0f, -1.0f, 0.0f);
    Point3f position = new Point3f(0.0f, 0.5f, -0.3f);

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

    BranchGroup scene = new BranchGroup();

    IndexedQuadArray qa = new IndexedQuadArray(9, QuadArray.COORDINATES | QuadArray.NORMALS, 16);
    qa.setCoordinate(0, new Point3f(-0.3f, 0.3f, -0.3f));
    qa.setCoordinate(1, new Point3f(0.0f, 0.3f, -0.3f));
    qa.setCoordinate(2, new Point3f(0.3f, 0.3f, -0.3f));
    qa.setCoordinate(3, new Point3f(-0.3f, 0.0f, 0.0f));
    qa.setCoordinate(4, new Point3f(0.0f, 0.0f, 0.0f));
    qa.setCoordinate(5, new Point3f(0.3f, 0.0f, 0.0f));
    qa.setCoordinate(6, new Point3f(-0.3f, -0.3f, 0.3f));
    qa.setCoordinate(7, new Point3f(0.0f, -0.3f, 0.3f));
    qa.setCoordinate(8, new Point3f(0.3f, -0.3f, 0.3f));
    Vector3f n = new Vector3f(0.0f, 0.6f, 0.8f);
    n.normalize();//from  ww w  . ja va 2  s .com
    qa.setNormal(0, n);
    qa.setNormal(1, n);
    qa.setNormal(2, n);
    qa.setNormal(3, n);
    qa.setNormal(4, n);
    qa.setNormal(5, n);
    qa.setNormal(6, n);
    qa.setNormal(7, n);
    qa.setNormal(8, n);

    qa.setCoordinateIndex(0, 0);
    qa.setCoordinateIndex(1, 3);
    qa.setCoordinateIndex(2, 4);
    qa.setCoordinateIndex(3, 1);
    qa.setCoordinateIndex(4, 1);
    qa.setCoordinateIndex(5, 4);
    qa.setCoordinateIndex(6, 5);
    qa.setCoordinateIndex(7, 2);
    qa.setCoordinateIndex(8, 3);
    qa.setCoordinateIndex(9, 6);
    qa.setCoordinateIndex(10, 7);
    qa.setCoordinateIndex(11, 4);
    qa.setCoordinateIndex(12, 4);
    qa.setCoordinateIndex(13, 7);
    qa.setCoordinateIndex(14, 8);
    qa.setCoordinateIndex(15, 5);

    TransformGroup trans1 = createTG(-0.7f, 0.0f, -0.5f);
    scene.addChild(trans1);

    TransformGroup trans2 = createTG(0.0f, 0.0f, -0.5f);
    scene.addChild(trans2);

    TransformGroup trans3 = createTG(0.7f, 0.0f, -0.5f);
    scene.addChild(trans3);

    Appearance qAppear = createMatAppear(white, white, 5.0f);
    Shape3D p1 = new Shape3D(qa, qAppear);
    //    p1.setBoundsAutoCompute(false);
    p1.setBounds(bounds);
    p1.setCapability(Node.ALLOW_BOUNDS_READ);
    trans1.addChild(p1);

    Shape3D p2 = new Shape3D(qa, qAppear);
    p2.setBounds(bounds);
    p2.setCapability(Node.ALLOW_BOUNDS_READ);
    trans2.addChild(p2);

    Shape3D p3 = new Shape3D(qa, qAppear);
    p3.setBounds(bounds);
    p3.setCapability(Node.ALLOW_BOUNDS_READ);
    trans3.addChild(p3);

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

    DirectionalLight lightD = new DirectionalLight();
    lightD.setInfluencingBounds(bounds);
    lightD.setBoundsAutoCompute(false);
    lightD.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ);
    lightD.setDirection(direction);
    lightD.setColor(red);
    trans1.addChild(lightD);

    PointLight lightP = new PointLight();
    lightP.setInfluencingBounds(bounds);
    lightP.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ);
    lightP.setPosition(position);
    lightP.setColor(green);
    trans2.addChild(lightP);

    SpotLight lightS = new SpotLight();
    lightS.setInfluencingBounds(bounds);
    lightS.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ);
    lightS.setPosition(position);
    lightS.setDirection(direction);
    lightS.setSpreadAngle(0.3f);
    lightS.setConcentration(1.0f);
    lightS.setColor(blue);
    trans3.addChild(lightS);

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

    scene.compile();
    System.out.print("bounds object: ");
    System.out.println(bounds);

    System.out.print("influencing bounds for lightA: ");
    System.out.println(lightA.getInfluencingBounds());

    System.out.print("influencing bounds for lightD: ");
    System.out.println(lightD.getInfluencingBounds());

    System.out.print("influencing bounds for lightP: ");
    System.out.println(lightP.getInfluencingBounds());

    System.out.print("influencing bounds for lightS: ");
    System.out.println(lightS.getInfluencingBounds());

    System.out.print("bounds for plane1: ");
    System.out.println(p1.getBounds());

    System.out.print("bounds for plane2: ");
    System.out.println(p2.getBounds());

    System.out.print("bounds for plane3: ");
    System.out.println(p3.getBounds());

    BoundingSphere bs0 = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 0.2);
    BoundingSphere bs1 = new BoundingSphere(new Point3d(-0.1, 0.0, 0.0), 0.2);
    BoundingSphere bs2 = new BoundingSphere(new Point3d(-0.2, 0.0, 0.0), 0.2);
    BoundingSphere bs3 = new BoundingSphere(new Point3d(-0.3, 0.0, 0.0), 0.2);
    BoundingSphere bs4 = new BoundingSphere(new Point3d(-0.4, 0.0, 0.0), 0.2);
    BoundingSphere bs5 = new BoundingSphere(new Point3d(-0.5, 0.0, 0.0), 0.2);
    BoundingSphere bs6 = new BoundingSphere(new Point3d(-0.6, 0.0, 0.0), 0.2);
    BoundingSphere bs7 = new BoundingSphere(new Point3d(-0.7, 0.0, 0.0), 0.2);
    BoundingSphere bs8 = new BoundingSphere(new Point3d(-0.8, 0.0, 0.0), 0.2);
    BoundingBox bb1 = new BoundingBox(bs1);
    BoundingBox bb2 = new BoundingBox(bs2);
    BoundingBox bb3 = new BoundingBox(bs3);
    BoundingBox bb4 = new BoundingBox(bs4);
    BoundingBox bb5 = new BoundingBox(bs5);
    BoundingBox bb6 = new BoundingBox(bs6);
    BoundingBox bb7 = new BoundingBox(bs7);
    BoundingBox bb8 = new BoundingBox(bs8);

    if (bs0.intersect(bs1))
        System.out.println("bs0 intersects bs1");
    if (bs0.intersect(bs2))
        System.out.println("bs0 intersects bs2");
    if (bs0.intersect(bs3))
        System.out.println("bs0 intersects bs3");
    if (bs0.intersect(bs4))
        System.out.println("bs0 intersects bs4");
    if (bs0.intersect(bs5))
        System.out.println("bs0 intersects bs5");
    if (bs0.intersect(bs6))
        System.out.println("bs0 intersects bs6");
    if (bs0.intersect(bs7))
        System.out.println("bs0 intersects bs7");
    if (bs0.intersect(bs8))
        System.out.println("bs0 intersects bs8");

    if (bs0.intersect(bb1))
        System.out.println("bs0 intersects bb1");
    if (bs0.intersect(bb2))
        System.out.println("bs0 intersects bb2");
    if (bs0.intersect(bb3))
        System.out.println("bs0 intersects bb3");
    if (bs0.intersect(bb4))
        System.out.println("bs0 intersects bb4");
    if (bs0.intersect(bb5))
        System.out.println("bs0 intersects bb5");
    if (bs0.intersect(bb6))
        System.out.println("bs0 intersects bb6");
    if (bs0.intersect(bb7))
        System.out.println("bs0 intersects bb7");
    if (bs0.intersect(bb8))
        System.out.println("bs0 intersects bb8");

    SimpleUniverse u = new SimpleUniverse(c);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();

    u.addBranchGraph(scene);
}

From source file:InterleavedTest.java

BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();

    // Set up attributes to render lines
    app = new Appearance();
    app.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE);

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);/*ww w .j  a v a 2 s.c  o m*/
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

    // load textures
    TextureAttributes texAttr1 = new TextureAttributes();
    texAttr1.setTextureMode(TextureAttributes.DECAL);
    TextureAttributes texAttr2 = new TextureAttributes();
    texAttr2.setTextureMode(TextureAttributes.MODULATE);

    TextureLoader tex = new TextureLoader(texImage1, new String("RGB"), this);
    if (tex == null)
        return null;
    tex1 = tex.getTexture();

    tex = new TextureLoader(texImage2, new String("RGB"), this);
    if (tex == null)
        return null;
    tex2 = tex.getTexture();

    textureUnitState[0] = new TextureUnitState(tex1, texAttr1, null);
    textureUnitState[1] = new TextureUnitState(tex2, texAttr2, null);

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

    TransformGroup trans = new TransformGroup(t);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(trans);
    trans.addChild(shape);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

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

    return objRoot;
}

From source file:cgview.java

public BranchGroup createSceneGraph(CompressedGeometry cg) {
    // 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.7);/*from   ww w  . j av a  2s  .  c om*/
    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. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(objTrans);

    // Add compressed geometry to the scene graph.
    CompressedGeometryHeader hdr = new CompressedGeometryHeader();
    cg.getCompressedGeometryHeader(hdr);

    // There isn't really enough information in the compressed geometry
    // header to unamiguously determine the proper rendering attributes.
    // The bufferDataPresent field specifies whether or not normals are
    // bundled with vertices, but the compressed buffer can still contain
    // normals that should be lit. Assume that any surface geometry
    // should be lit and that lines and points should not unless the
    // header contains the NORMAL_IN_BUFFER bit.
    Material m = new Material();
    if ((hdr.bufferType == hdr.TRIANGLE_BUFFER) || ((hdr.bufferDataPresent & hdr.NORMAL_IN_BUFFER) == 1))
        m.setLightingEnable(true);
    else
        m.setLightingEnable(false);

    Appearance a = new Appearance();
    a.setMaterial(m);

    objTrans.addChild(new Shape3D(cg, a));

    // Create mouse behavior scheduling bounds.
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -0.9f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    return objRoot;
}

From source file:AlternateAppearanceBoundsTest.java

BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();

    // Create an alternate appearance
    otherApp = new Appearance();
    altMat = new Material();
    altMat.setCapability(Material.ALLOW_COMPONENT_WRITE);
    altMat.setDiffuseColor(new Color3f(0.0f, 1.0f, 0.0f));
    otherApp.setMaterial(altMat);// www  .  j a  va2 s .  c o  m

    altApp = new AlternateAppearance();
    altApp.setAppearance(otherApp);
    altApp.setCapability(AlternateAppearance.ALLOW_BOUNDS_WRITE);
    altApp.setCapability(AlternateAppearance.ALLOW_INFLUENCING_BOUNDS_WRITE);
    altApp.setInfluencingBounds(worldBounds);
    objRoot.addChild(altApp);

    // Build foreground geometry
    Appearance app1 = new Appearance();
    mat1 = new Material();
    mat1.setCapability(Material.ALLOW_COMPONENT_WRITE);
    mat1.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f));
    app1.setMaterial(mat1);
    content1 = new SphereGroup(0.05f, // radius of spheres
            0.15f, // x spacing
            0.15f, // y spacing
            5, // number of spheres in X
            5, // number of spheres in Y
            app1, // appearance
            true); // alt app override = true
    objRoot.addChild(content1);
    shapes1 = ((SphereGroup) content1).getShapes();

    // Add lights
    light1 = new DirectionalLight();
    light1.setEnable(true);
    light1.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light1.setInfluencingBounds(worldBounds);
    light1.setCapability(DirectionalLight.ALLOW_INFLUENCING_BOUNDS_WRITE);
    light1.setCapability(DirectionalLight.ALLOW_BOUNDS_WRITE);
    objRoot.addChild(light1);

    // 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(new Color3f(1.0f, 1.0f, 1.0f));
    ambient.setInfluencingBounds(worldBounds);
    objRoot.addChild(ambient);

    // Define a bounding leaf
    leafBounds = new BoundingLeaf(allBounds[currentBounds]);
    leafBounds.setCapability(BoundingLeaf.ALLOW_REGION_WRITE);
    objRoot.addChild(leafBounds);
    if (boundingLeafOn) {
        altApp.setInfluencingBoundingLeaf(leafBounds);
    } else {
        altApp.setInfluencingBounds(allBounds[currentBounds]);
    }

    return objRoot;
}

From source file:InterleavedNIOBuffer.java

BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();

    // Set up attributes to render lines
    app = new Appearance();
    app.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE);

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);//from w ww  . j av a 2  s.  c om
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

    // load textures
    TextureAttributes texAttr1 = new TextureAttributes();
    texAttr1.setTextureMode(TextureAttributes.DECAL);
    TextureAttributes texAttr2 = new TextureAttributes();
    texAttr2.setTextureMode(TextureAttributes.MODULATE);

    TextureLoader tex = new TextureLoader(texImage1, new String("RGB"), this);
    if (tex == null)
        return null;
    tex1 = tex.getTexture();

    tex = new TextureLoader(texImage2, new String("RGB"), this);
    if (tex == null)
        return null;
    tex2 = tex.getTexture();

    textureUnitState[0] = new TextureUnitState(tex1, texAttr1, null);
    textureUnitState[1] = new TextureUnitState(tex2, texAttr2, null);

    createInterleavedBuffers();

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

    TransformGroup trans = new TransformGroup(t);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(trans);
    trans.addChild(shape);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

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

    return objRoot;
}

From source file:GeometryByReferenceNIOBuffer.java

BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();

    // Set up attributes to render lines
    app = new Appearance();

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);//from w ww .  java 2 s .  c  o m
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

    //create the direct nio buffer
    createJ3DBuffers();

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

    TransformGroup trans = new TransformGroup(t);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(trans);
    trans.addChild(shape);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

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

    return objRoot;
}

From source file:ScenegraphTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    // create some lights for the scene
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(createApplicationBounds());
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(createApplicationBounds());
    objRoot.addChild(aLgt);//  ww w . jav  a  2  s.  c om
    objRoot.addChild(lgt1);

    // create a rotator to spin the whole model around the Y axis
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(createApplicationBounds());
    objTrans.addChild(rotator);

    // build the model itself using helper methods
    addHead(objTrans);
    objTrans.addChild(createArm(0, 0, -Math.PI * 0.5));
    objTrans.addChild(createArm(0, Math.PI, Math.PI * 0.5));

    objRoot.addChild(objTrans);

    return objRoot;
}