Example usage for javax.media.j3d AlternateAppearance AlternateAppearance

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

Introduction

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

Prototype

public AlternateAppearance() 

Source Link

Document

Constructs an AlternateAppearance node with default parameters.

Usage

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);//from   w w w.ja  v a 2 s  . com

    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:AlternateAppearanceScopeTest.java

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

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

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.1f, 0.0f));
    // Shrink the object
    t.setScale(0.8);/* w w w .j av  a  2 s  .  c  o  m*/

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

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

    altApp = new AlternateAppearance();
    altApp.setAppearance(otherApp);
    altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_WRITE);
    altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_READ);
    altApp.setInfluencingBounds(worldBounds);
    objRoot.addChild(altApp);

    // 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.
    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.4f, // x spacing
            0.2f, // y spacing
            3, // number of spheres in X
            5, // number of spheres in Y
            app1, // appearance
            true); // alt app override = true
    trans.addChild(content1);
    shapes1 = ((SphereGroup) content1).getShapes();

    content2 = new SphereGroup(0.05f, // radius of spheres
            .4f, // x spacing
            0.2f, // y spacing
            2, // number of spheres in X
            5, // number of spheres in Y
            app1, // appearance
            true); // alt app override = true
    trans.addChild(content2);
    shapes2 = ((SphereGroup) content2).getShapes();

    // Add lights
    DirectionalLight light1 = null;
    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);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight();
    light2.setEnable(true);
    light2.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    light2.setDirection(new Vector3f(-1.0f, 0.0f, 1.0f));
    light2.setInfluencingBounds(worldBounds);
    objRoot.addChild(light2);

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

    objRoot.addChild(trans);

    return objRoot;
}