Example usage for javax.media.j3d Appearance setMaterial

List of usage examples for javax.media.j3d Appearance setMaterial

Introduction

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

Prototype

public void setMaterial(Material material) 

Source Link

Document

Sets the material object to the specified object.

Usage

From source file:InterpolatorTest.java

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

    // create a root TG in case we need to scale the scene
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // create the Appearance for the Shape3D
    Appearance app = new Appearance();

    // create a Material, modified by the ColorInterpolator
    Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Material mat = new Material(objColor, black, objColor, black, 80.0f);
    mat.setCapability(Material.ALLOW_COMPONENT_WRITE);
    app.setMaterial(mat);

    // create a TransparencyAttributes, modified by the
    // TransparencyInterpolator
    TransparencyAttributes transparency = new TransparencyAttributes();
    transparency.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
    transparency.setTransparencyMode(TransparencyAttributes.NICEST);
    app.setTransparencyAttributes(transparency);

    // create a Switch Node and set capabilities
    Switch switchNode = new Switch();
    switchNode.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // create a Alpha object for the Interpolators
    Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 500, 100, 5000, 2000, 1000,
            5000, 2000, 500);/*from w  w w  .  j a  v  a 2s . c o  m*/

    // add each BG and Interpolator as a child of the Switch Node
    TransformGroup tg = createSharedGroup(app);
    switchNode.addChild(createBranchGroup(tg, new ColorInterpolator(alpha, app.getMaterial())));

    tg = createSharedGroup(app);
    switchNode.addChild(createBranchGroup(tg, new PositionInterpolator(alpha, tg)));

    tg = createSharedGroup(app);
    switchNode.addChild(createBranchGroup(tg, new RotationInterpolator(alpha, tg)));

    tg = createSharedGroup(app);
    switchNode.addChild(createBranchGroup(tg, new ScaleInterpolator(alpha, tg)));

    tg = createSharedGroup(app);
    switchNode.addChild(createBranchGroup(tg,
            new TransparencyInterpolator(alpha, app.getTransparencyAttributes(), 0, 0.8f)));

    // define the data for the RotPosScalePathInterpolator
    float[] knots = { 0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.6f, 0.8f, 0.9f, 1.0f };
    float[] scales = { 0.2f, 0.5f, 0.8f, 2.3f, 5.4f, 0.6f, 0.4f, 0.2f, 0.1f };
    Quat4f[] quats = new Quat4f[9];
    Point3f[] positions = new Point3f[9];

    quats[0] = new Quat4f(0.3f, 1.0f, 1.0f, 0.0f);
    quats[1] = new Quat4f(1.0f, 0.0f, 0.0f, 0.3f);
    quats[2] = new Quat4f(0.2f, 1.0f, 0.0f, 0.0f);
    quats[3] = new Quat4f(0.0f, 0.2f, 1.0f, 0.0f);
    quats[4] = new Quat4f(1.0f, 0.0f, 0.4f, 0.0f);
    quats[5] = new Quat4f(0.0f, 1.0f, 1.0f, 0.2f);
    quats[6] = new Quat4f(0.3f, 0.3f, 0.0f, 0.0f);
    quats[7] = new Quat4f(1.0f, 0.0f, 1.0f, 1.0f);
    quats[8] = quats[0];

    positions[0] = new Point3f(0.0f, 0.0f, -1.0f);
    positions[1] = new Point3f(1.0f, -2.0f, -2.0f);
    positions[2] = new Point3f(-2.0f, 2.0f, -3.0f);
    positions[3] = new Point3f(1.0f, 1.0f, -4.0f);
    positions[4] = new Point3f(-4.0f, -2.0f, -5.0f);
    positions[5] = new Point3f(2.0f, 0.3f, -6.0f);
    positions[6] = new Point3f(-4.0f, 0.5f, -7.0f);
    positions[7] = new Point3f(0.0f, -1.5f, -4.0f);
    positions[8] = positions[0];

    tg = createSharedGroup(app);

    // create the Interpolator
    RotPosScalePathInterpolator rotPosScalePathInterplator = new RotPosScalePathInterpolator(alpha, tg,
            new Transform3D(), knots, quats, positions, scales);

    // add a BG for the Interpolator
    switchNode.addChild(createBranchGroup(tg, rotPosScalePathInterplator));

    // create a RandomAlpha object to control a SwitchInterpolator
    // to set the Switches active child node randomly
    RandomAlpha randomAlpha = new RandomAlpha();

    // create the interpolator
    SwitchValueInterpolator switchInterpolator = new SwitchValueInterpolator(randomAlpha, switchNode);
    switchInterpolator.setSchedulingBounds(getApplicationBounds());

    // connect the scenegraph
    objTrans.addChild(switchNode);
    objTrans.addChild(switchInterpolator);

    // 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(getApplicationBounds());
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(getApplicationBounds());

    // add the lights
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    // connect
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:LightTest.java

protected Group createSphere(float x, float y, float z, float radius) {
    TransformGroup tg = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(x, y, z));
    tg.setTransform(t3d);//from  w ww .  j a  va 2 s . c  o  m

    // create an Appearance and Material
    Appearance app = new Appearance();
    Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    app.setMaterial(new Material(objColor, black, objColor, black, 80.0f));

    tg.addChild(new Sphere(radius, Primitive.GENERATE_NORMALS, app));

    return tg;
}

From source file:LightTest.java

public void synchLightToUi() {
    super.synchLightToUi();

    // set some defaults if things go wrong...
    double x = 0;
    double y = 0;
    double z = 0;

    double constant = 0.01;
    double linear = 0;
    double quadratic = 0;

    try {//w ww.j  a v  a2  s.  co  m
        x = Double.valueOf(m_XPositionTextField.getText()).doubleValue();
        y = Double.valueOf(m_YPositionTextField.getText()).doubleValue();
        z = Double.valueOf(m_ZPositionTextField.getText()).doubleValue();

        constant = Double.valueOf(m_ConstantAttenuationTextField.getText()).doubleValue();
        linear = Double.valueOf(m_LinearAttenuationTextField.getText()).doubleValue();
        quadratic = Double.valueOf(m_QuadraticAttenuationTextField.getText()).doubleValue();
    } catch (java.lang.NumberFormatException e) {
        // invalid numeric input - just ignore.
    }

    ((PointLight) m_Light).setPosition((float) x, (float) y, (float) z);
    ((PointLight) m_Light).setAttenuation((float) constant, (float) linear, (float) quadratic);

    if (m_TransformGroup != null) {
        Transform3D t3d = new Transform3D();
        m_TransformGroup.getTransform(t3d);
        t3d.setTranslation(new Vector3d(x, y, z));
        m_TransformGroup.setTransform(t3d);
    }

    if (m_Sphere != null) {
        Appearance app = new Appearance();

        Color3f objColor = new Color3f();
        m_Light.getColor(objColor);
        Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
        app.setMaterial(new Material(objColor, black, objColor, black, 80.0f));
        m_Sphere.getShape(Sphere.BODY).setAppearance(app);
    }
}

From source file:LightTest.java

public void synchLightToUi() {
    super.synchLightToUi();

    // set some defaults if things go wrong...
    double x = 0;
    double y = 0;
    double z = 0;

    try {//from www.j  a  va2  s .c o  m
        x = Double.valueOf(m_XDirectionTextField.getText()).doubleValue();
        y = Double.valueOf(m_YDirectionTextField.getText()).doubleValue();
        z = Double.valueOf(m_ZDirectionTextField.getText()).doubleValue();
    } catch (java.lang.NumberFormatException e) {
        // invalid numeric input - just ignore.
    }

    ((DirectionalLight) m_Light).setDirection((float) x, (float) y, (float) z);

    if (m_TransformGroup != null) {
        Vector3d coneVector = new Vector3d(0, 1, 0);
        Vector3d lightVector = new Vector3d(x, y, z);

        coneVector.normalize();
        lightVector.normalize();

        Vector3d axisVector = new Vector3d();
        axisVector.cross(coneVector, lightVector);
        double angle = java.lang.Math.acos(coneVector.dot(lightVector));

        AxisAngle4d rotAxis = new AxisAngle4d(axisVector.x, axisVector.y, axisVector.z, angle);

        Transform3D t3d = new Transform3D();
        t3d.setRotation(rotAxis);

        m_TransformGroup.setTransform(t3d);
    }

    if (m_Cone != null) {
        Appearance app = new Appearance();

        Color3f objColor = new Color3f();
        m_Light.getColor(objColor);
        Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
        app.setMaterial(new Material(objColor, black, objColor, black, 80.0f));
        m_Cone.setAppearance(app);
    }
}

From source file:LightTest.java

public void synchLightToUi() {
    super.synchLightToUi();

    // set some defaults if things go wrong...
    double x = 0;
    double y = 0;
    double z = 0;

    double conc = 1;
    double spread = 2;

    try {//  ww  w . jav  a  2  s .  c  o m
        x = Double.valueOf(m_XDirectionTextField.getText()).doubleValue();
        y = Double.valueOf(m_YDirectionTextField.getText()).doubleValue();
        z = Double.valueOf(m_ZDirectionTextField.getText()).doubleValue();

        conc = Double.valueOf(m_ConcentrationTextField.getText()).doubleValue();
        spread = Double.valueOf(m_SpreadAngleTextField.getText()).doubleValue();
    } catch (java.lang.NumberFormatException e) {
        // invalid numeric input - just ignore.
    }

    ((SpotLight) m_Light).setDirection((float) x, (float) y, (float) z);
    ((SpotLight) m_Light).setConcentration((float) conc);
    ((SpotLight) m_Light).setSpreadAngle((float) spread);

    if (m_DirectionTransformGroup != null) {
        Vector3d coneVector = new Vector3d(0, -1, 0);
        Vector3d lightVector = new Vector3d(x, y, z);

        coneVector.normalize();
        lightVector.normalize();

        Vector3d axisVector = new Vector3d();
        axisVector.cross(coneVector, lightVector);
        double angle = java.lang.Math.acos(coneVector.dot(lightVector));

        AxisAngle4d rotAxis = new AxisAngle4d(axisVector.x, axisVector.y, axisVector.z, angle);

        Transform3D t3d = new Transform3D();
        t3d.setRotation(rotAxis);

        m_DirectionTransformGroup.setTransform(t3d);
    }

    if (m_Cone != null) {
        Appearance app = new Appearance();

        Color3f objColor = new Color3f();
        m_Light.getColor(objColor);
        Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
        app.setMaterial(new Material(objColor, black, objColor, black, 80.0f));
        m_Cone.getShape(Cone.CAP).setAppearance(app);
    }
}

From source file:EnvironmentExplorer.java

void setupSpheres() {

    // create a Switch for the spheres, allow switch changes
    spheresSwitch = new Switch(Switch.CHILD_ALL);
    spheresSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // Set up an appearance to make the Sphere with objColor ambient,
    // black emmissive, objColor diffuse and white specular coloring
    Material material = new Material(objColor, black, objColor, white, 32);
    Appearance appearance = new Appearance();
    appearance.setMaterial(material);

    // create a sphere and put it into a shared group
    Sphere sphere = new Sphere(0.5f, appearance);
    SharedGroup sphereSG = new SharedGroup();
    sphereSG.addChild(sphere);/*ww  w .ja  va  2 s .  c om*/

    // create a grid of spheres in the z=0 plane
    // each has a TransformGroup to position the sphere which contains
    // a link to the shared group for the sphere
    for (int y = -2; y <= 2; y++) {
        for (int x = -2; x <= 2; x++) {
            TransformGroup tg = new TransformGroup();
            tmpVector.set(x * 1.2f, y * 1.2f, -0.1f);
            tmpTrans.set(tmpVector);
            tg.setTransform(tmpTrans);
            tg.addChild(new Link(sphereSG));
            spheresSwitch.addChild(tg);
        }
    }
}

From source file:edu.uci.ics.jung.visualization3d.VisualizationViewer.java

public BranchGroup createSceneGraph(final Canvas3D canvas) {

    objRoot = new BranchGroup();
    objRoot.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    objRoot.setCapability(Group.ALLOW_CHILDREN_WRITE);

    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    //      t3d.setScale(0.05);
    objScale.setTransform(t3d);/*from w w w  .  j av  a 2 s.co  m*/
    objRoot.addChild(objScale);

    Transform3D tt = new Transform3D();
    tt.setScale(.05);
    tt.setTranslation(new Vector3f(0, 0, -30.f));
    objTrans = new TransformGroup(tt);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objTrans.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
    objScale.addChild(objTrans);
    //      objRoot.addChild(objTrans);

    // Create Colors, Materials,  and Appearances.
    Appearance look = new Appearance();
    Color3f objColor = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f black = new Color3f(0.f, 0.f, 0.f);
    Color3f white = new Color3f(1.0f, 1.0f, 0.6f);
    Color3f gray = new Color3f(.2f, .2f, .2f);
    Color3f red = new Color3f(1.0f, 0, 0);
    Color3f yellow = new Color3f(1, 1, 0);

    Material objMaterial = new Material(objColor, black, objColor, white, 100.0f);
    Material blackMaterial = new Material(objColor, black, black, objColor, 10.0f);
    Material whiteMaterial = new Material(white, white, white, white, 100.0f);
    Material grayMaterial = new Material(gray, black, gray, gray, 100.0f);

    Material redMaterial = new Material(red, black, red, red, 100.0f);
    Material yellowMaterial = new Material(yellow, black, yellow, yellow, 100);

    look.setMaterial(new Material(objColor, black, objColor, white, 100.0f));
    Appearance blackLook = new Appearance();
    blackLook.setMaterial(blackMaterial);

    Appearance whiteLook = new Appearance();
    whiteLook.setMaterial(whiteMaterial);

    Appearance grayLook = new Appearance();
    grayLook.setMaterial(grayMaterial);
    grayLook.setCapability(Appearance.ALLOW_MATERIAL_READ);
    grayLook.setCapability(Appearance.ALLOW_MATERIAL_WRITE);

    final Appearance redLook = new Appearance();
    redLook.setMaterial(redMaterial);
    //      vertexLook = redLook;

    Appearance objLook = new Appearance();
    objLook.setMaterial(objMaterial);
    grayLook = objLook;
    final Appearance yellowLook = new Appearance();
    yellowLook.setMaterial(yellowMaterial);
    Bounds bounds = new BoundingSphere(new Point3d(), 300);

    MouseRotate behavior1 = new MouseRotate();
    behavior1.setTransformGroup(objTrans);
    objTrans.addChild(behavior1);
    behavior1.setSchedulingBounds(bounds);

    MouseWheelZoom behavior2 = new MouseWheelZoom();
    behavior2.setTransformGroup(objTrans);
    //      behavior2.setFactor(10);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    MouseTranslate behavior3 = new MouseTranslate();
    behavior3.setTransformGroup(objTrans);
    objTrans.addChild(behavior3);
    behavior3.setSchedulingBounds(bounds);

    PickTranslateBehavior ptb = new PickTranslateBehavior(objRoot, canvas, bounds, PickTool.GEOMETRY);
    ptb.setSchedulingBounds(bounds);
    //      objTrans.addChild(ptb);
    ptb.setupCallback(new PickingCallback() {

        public void transformChanged(int type, TransformGroup tg) {
            if (tg == null)
                return;
            Transform3D t3d = new Transform3D();
            tg.getTransform(t3d);
            //            System.err.println(tg+" transformChanged \n"+t3d);
            Point3f p1 = new Point3f();
            V v = vertexMap.getKey(tg);
            //            Transform3D lvw = new Transform3D();
            //            tg.getLocalToVworld(lvw);
            //            System.err.println("lvw = \n"+lvw);
            //            lvw.invert();
            //            System.err.println("invert lvw = \n"+lvw);
            Point3f p0 = layout.transform(v);
            //            Transform3D vwip = new Transform3D();
            //            canvas.getVworldToImagePlate(vwip);
            //            System.err.println("vwip=\n"+vwip);
            //            t3d.mul(lvw);
            t3d.transform(p1);
            //            scale.transform(p1);
            System.err.println(
                    "change location for vertex " + v + ", transformGroup " + tg + " from " + p0 + " to " + p1);
            //            p1.set(p1.getX()*2,p1.getY()*2,p1.getZ()*2);
            //            layout.setLocation(v, p1);

        }
    });

    PickSphereBehavior psb = new PickSphereBehavior(objRoot, canvas, bounds);

    PickVertexBehavior pvb = new PickVertexBehavior(objRoot, canvas, bounds,
            renderContext.getPickedVertexState());
    objTrans.addChild(pvb);
    pvb.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            for (V v : graph.getVertices()) {
                VertexGroup<V> vg = vertexMap.get(v);
                Appearance look = redLook;
                if (renderContext.getPickedVertexState().isPicked(v)) {
                    look = yellowLook;
                }
                Node node = vg.getShape();
                if (node instanceof Primitive) {
                    ((Primitive) node).setAppearance(look);
                }
            }

        }
    });

    //Shine it with two colored lights.
    Color3f lColor1 = new Color3f(.5f, .5f, .5f);
    Color3f lColor2 = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lDir2 = new Vector3f(-1.0f, 0.0f, -1.0f);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    AmbientLight ambient = new AmbientLight(lColor1);
    lgt2.setInfluencingBounds(bounds);
    ambient.setInfluencingBounds(bounds);
    objRoot.addChild(lgt2);
    objRoot.addChild(ambient);

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

    //      VisRunner runner = new VisRunner((IterativeContext)elayout);
    //      runner.relax();

    return objRoot;
}

From source file:EnvironmentExplorer.java

void setupGrid() {

    // create a Switch for the spheres, allow switch changes
    gridSwitch = new Switch(Switch.CHILD_NONE);
    gridSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // Set up an appearance to make the square3s with red ambient,
    // black emmissive, red diffuse and black specular coloring
    Material material = new Material(red, black, red, black, 64);
    Appearance appearance = new Appearance();
    appearance.setMaterial(material);

    // create a grid of quads
    int gridSize = 20; // grid is gridSize quads along each side
    int numQuads = gridSize * gridSize;
    int numVerts = numQuads * 4; // 4 verts per quad
    // there will be 3 floats per coord and 4 coords per quad
    float[] coords = new float[3 * numVerts];
    // All the quads will use the same normal at each vertex, so
    // allocate an array to hold references to the same normal
    Vector3f[] normals = new Vector3f[numVerts];
    Vector3f vertNormal = new Vector3f(0.0f, 0.0f, 1.0f);
    float edgeLength = 5.0f; // length of each edge of the grid
    float gridGap = 0.03f; // the gap between each quad
    // length of each quad is (total length - sum of the gaps) / gridSize
    float quadLength = (edgeLength - gridGap * (gridSize - 1)) / gridSize;

    // create a grid of quads in the z=0 plane
    // each has a TransformGroup to position the sphere which contains
    // a link to the shared group for the sphere
    float curX, curY;
    for (int y = 0; y < gridSize; y++) {
        curY = y * (quadLength + gridGap); // offset to lower left corner
        curY -= edgeLength / 2; // center on 0,0
        for (int x = 0; x < gridSize; x++) {
            // this is the offset into the vertex array for the first
            // vertex of the quad
            int vertexOffset = (y * gridSize + x) * 4;
            // this is the offset into the coord array for the first
            // vertex of the quad, where there are 3 floats per vertex
            int coordOffset = vertexOffset * 3;
            curX = x * (quadLength + gridGap); // offset to ll corner
            curX -= edgeLength / 2; // center on 0,0
            // lower left corner
            coords[coordOffset + 0] = curX;
            coords[coordOffset + 1] = curY;
            coords[coordOffset + 2] = 0.0f; // z
            // lower right corner
            coords[coordOffset + 3] = curX + quadLength;
            coords[coordOffset + 4] = curY;
            coords[coordOffset + 5] = 0.0f; // z
            // upper right corner
            coords[coordOffset + 6] = curX + quadLength;
            coords[coordOffset + 7] = curY + quadLength;
            coords[coordOffset + 8] = 0.0f; // z
            // upper left corner
            coords[coordOffset + 9] = curX;
            coords[coordOffset + 10] = curY + quadLength;
            coords[coordOffset + 11] = 0.0f; // z
            for (int i = 0; i < 4; i++) {
                normals[vertexOffset + i] = vertNormal;
            }//from  w w  w .jav a 2 s  .c o  m
        }
    }
    // now that we have the data, create the QuadArray
    QuadArray quads = new QuadArray(numVerts, QuadArray.COORDINATES | QuadArray.NORMALS);
    quads.setCoordinates(0, coords);
    quads.setNormals(0, normals);

    // create the shape
    Shape3D shape = new Shape3D(quads, appearance);

    // add it to the switch
    gridSwitch.addChild(shape);
}

From source file:LoaderTest.java

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

    // create a TransformGroup to flip the hand onto its end and enlarge it.
    TransformGroup objTrans1 = new TransformGroup();
    Transform3D tr = new Transform3D();
    objTrans1.getTransform(tr);/*ww w  .j av a2  s.co m*/
    tr.rotX(90.0 * Math.PI / 180.0);
    tr.setScale(10.0);
    objTrans1.setTransform(tr);

    // create a TransformGroup to rotate the hand
    TransformGroup objTrans2 = new TransformGroup();
    objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

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

    // create a RotationInterpolator behavior to rotate the hand
    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, objTrans2, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans2.addChild(rotator);

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

    // load the object file
    Scene scene = null;
    Shape3D shape = null;

    // read in the geometry information from the data file
    ObjectFile objFileloader = new ObjectFile(ObjectFile.RESIZE);

    try {
        scene = objFileloader.load("hand1.obj");
    } catch (Exception e) {
        scene = null;
        System.err.println(e);
    }

    if (scene == null)
        System.exit(1);

    // retrieve the Shape3D object from the scene
    BranchGroup branchGroup = scene.getSceneGroup();
    shape = (Shape3D) branchGroup.getChild(0);

    // create an Appearance and Material
    Appearance app = new Appearance();
    Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    app.setMaterial(new Material(objColor, black, objColor, black, 80.0f));

    // assign the appearance to the Shape
    shape.setAppearance(app);

    // connect the scenegraph
    objTrans2.addChild(scene.getSceneGroup());
    objTrans1.addChild(objTrans2);
    objRoot.addChild(objTrans1);

    return objRoot;
}

From source file:TransformExplorer.java

TransformGroup createConeTransformGroup() {

    // create a TransformGroup for the cone, allow tranform changes,
    coneTG = new TransformGroup();
    coneTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    coneTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // Set up an appearance to make the Cone with red ambient,
    // black emmissive, red diffuse and white specular coloring
    Material material = new Material(red, black, red, white, 64);
    // These are the colors used for the book figures:
    //Material material = new Material(white, black, white, black, 64);
    Appearance appearance = new Appearance();
    appearance.setMaterial(material);

    // create the cone and add it to the coneTG
    Cone cone = new Cone(coneRadius, coneHeight, appearance);
    coneTG.addChild(cone);/*from w w w.  jav  a2 s.  c o m*/

    return coneTG;
}