Example usage for javax.media.j3d Appearance Appearance

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

Introduction

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

Prototype

public Appearance() 

Source Link

Document

Constructs an Appearance component object using defaults for all state variables.

Usage

From source file:ExLinearFog.java

private SharedGroup buildSharedColumn() {
    Appearance columnApp = new Appearance();

    Material columnMat = new Material();
    columnMat.setAmbientColor(0.6f, 0.6f, 0.6f);
    columnMat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    columnMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    columnApp.setMaterial(columnMat);//w w w  .j  a v a  2s  .  co  m

    TextureAttributes columnTexAtt = new TextureAttributes();
    columnTexAtt.setTextureMode(TextureAttributes.MODULATE);
    columnTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    columnApp.setTextureAttributes(columnTexAtt);

    if (columnTex != null)
        columnApp.setTexture(columnTex);

    GothicColumn columnShape = new GothicColumn(ColumnHeight, // height
            ColumnRadius, // radius
            GothicColumn.BUILD_TOP, // flags
            columnApp); // appearance

    // BEGIN EXAMPLE TOPIC
    // Build a shared group to hold the column shape
    SharedGroup column = new SharedGroup();
    column.addChild(columnShape);
    // END EXAMPLE TOPIC

    return column;
}

From source file:SplineInterpolatorTest.java

public Group createEnvirons(Group g) {
    Land environs = new Land(this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE);
    return environs.createObject(new Appearance(), new Vector3d(),
            new Vector3d(2 * LAND_WIDTH, 1, 2 * LAND_LENGTH), "environs.gif", null, null);
}

From source file:TextureByReference.java

public BranchGroup createSceneGraph() {

    // create the root of the branch group
    BranchGroup objRoot = new BranchGroup();

    // create the transform group node and initialize it
    // enable the TRANSFORM_WRITE capability so that it can be modified
    // at runtime. Add it to the root of the subgraph
    Transform3D rotate = new Transform3D();
    TransformGroup objTrans = new TransformGroup(rotate);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);/*from  w  ww  .jav  a2 s  . c  o m*/

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

    // set up some light
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -0.5f, -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);

    Appearance appearance = new Appearance();

    // enable the TEXTURE_WRITE so we can modify it at runtime
    appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    // load the first texture
    TextureLoader loader = new TextureLoader(urls[0], TextureLoader.BY_REFERENCE | TextureLoader.Y_UP, this);
    // get the texture from the loader
    Texture2D tex = (Texture2D) loader.getTexture();

    // get the BufferedImage to convert to TYPE_4BYTE_ABGR and flip
    // get the ImageComponent because we need it anyway
    ImageComponent2D imageComp = (ImageComponent2D) tex.getImage(0);
    BufferedImage bImage = imageComp.getImage();
    // convert the image
    bImage = ImageOps.convertImage(bImage, BufferedImage.TYPE_4BYTE_ABGR);
    // flip the image
    ImageOps.flipImage(bImage);
    imageComp.set(bImage);

    tex.setCapability(Texture.ALLOW_IMAGE_WRITE);
    tex.setBoundaryModeS(Texture.CLAMP);
    tex.setBoundaryModeT(Texture.CLAMP);
    tex.setBoundaryColor(1.0f, 1.0f, 1.0f, 1.0f);

    // set the image of the texture
    tex.setImage(0, imageComp);

    // set the texture on the appearance
    appearance.setTexture(tex);

    // set texture attributes
    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    appearance.setTextureAttributes(texAttr);

    // set material properties
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    appearance.setMaterial(new Material(white, black, white, black, 1.0f));

    // create a scale transform
    Transform3D scale = new Transform3D();
    scale.set(.6);
    TransformGroup objScale = new TransformGroup(scale);
    objTrans.addChild(objScale);

    tetra = new Tetrahedron(true);
    tetra.setAppearance(appearance);
    objScale.addChild(tetra);

    // create the behavior
    animate = new AnimateTexturesBehavior(tex, urls, appearance, this);
    animate.setSchedulingBounds(bounds);

    objTrans.addChild(animate);

    // add a rotation behavior so we can see all sides of the tetrahedron
    Transform3D yAxis = new Transform3D();
    Alpha rotorAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);
    RotationInterpolator rotator = new RotationInterpolator(rotorAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);

    // have java3d perform optimizations on this scene graph
    objRoot.compile();

    return objRoot;
}

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);//from  w  ww. j  av a 2  s  .c om

    // create a sphere and put it into a shared group
    Sphere sphere = new Sphere(0.5f, appearance);
    SharedGroup sphereSG = new SharedGroup();
    sphereSG.addChild(sphere);

    // 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:IntersectTest.java

public IntersectInfoBehavior(Canvas3D canvas3D, BranchGroup branchGroup, float size) {
    pickCanvas = new PickCanvas(canvas3D, branchGroup);
    pickCanvas.setTolerance(5.0f);//www.jav  a  2s.c  om
    pickCanvas.setMode(PickCanvas.GEOMETRY_INTERSECT_INFO);
    this.size = size;
    // Create an Appearance.
    redlook = new Appearance();
    Color3f objColor = new Color3f(0.5f, 0.0f, 0.0f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    redlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    redlook.setCapability(Appearance.ALLOW_MATERIAL_WRITE);

    redlookwf = new Appearance();
    redlookwf.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    PolygonAttributes pa = new PolygonAttributes();
    pa.setPolygonMode(pa.POLYGON_LINE);
    pa.setCullFace(pa.CULL_NONE);
    redlookwf.setPolygonAttributes(pa);

    oldlook = new Appearance();
    objColor = new Color3f(1.0f, 1.0f, 1.0f);
    oldlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));

    greenlook = new Appearance();
    objColor = new Color3f(0.0f, 0.8f, 0.0f);
    greenlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    bluelook = new Appearance();
    objColor = new Color3f(0.0f, 0.0f, 0.8f);
    bluelook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    for (int i = 0; i < 6; i++) {
        switch (i) {
        case 0:
            sph[i] = new Sphere(size * 1.15f, redlook);
            break;
        case 1:
            sph[i] = new Sphere(size * 1.1f, greenlook);
            break;
        default:
            sph[i] = new Sphere(size, bluelook);
            break;
        }
        sph[i].setPickable(false);
        sphTrans[i] = new TransformGroup();
        sphTrans[i].setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        sphTrans[i].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        // Add sphere, transform
        branchGroup.addChild(sphTrans[i]);
        sphTrans[i].addChild(sph[i]);
    }
}

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];/*from   w  w w .j  av a  2  s  .c  om*/
    }

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

From source file:KeyNavigateTest.java

void createWall(Group mapGroup, int nPixelX, int nPixelY) {
    Point3d point = convertToWorldCoordinatesPixelCenter(nPixelX, nPixelY);

    if (m_WallAppearance == null)
        m_WallAppearance = new Appearance();

    Vector3d squareSize = getMapSquareSize();

    Cuboid wall = new Cuboid(this, mapGroup, ComplexObject.GEOMETRY | ComplexObject.TEXTURE);
    wall.createObject(m_WallAppearance, new Vector3d(point.x, m_kFloorLevel, point.z),
            new Vector3d(squareSize.x / 2, m_kCeilingHeight / 2, squareSize.z / 2), "wall.gif", null, null);
}

From source file:AlternateAppearanceScopeTest.java

public SphereGroup(float radius, float xSpacing, float ySpacing, int xCount, int yCount, Appearance app,
        boolean overrideflag) {
    if (app == null) {
        app = new Appearance();
        Material material = new Material();
        material.setDiffuseColor(new Color3f(0.8f, 0.8f, 0.8f));
        material.setSpecularColor(new Color3f(0.0f, 0.0f, 0.0f));
        material.setShininess(0.0f);/* www .j  a va  2s  .  co  m*/
        app.setMaterial(material);
    }

    double xStart = -xSpacing * (double) (xCount - 1) / 2.0;
    double yStart = -ySpacing * (double) (yCount - 1) / 2.0;

    Sphere sphere = null;
    TransformGroup trans = null;
    Transform3D t3d = new Transform3D();
    Vector3d vec = new Vector3d();
    double x, y = yStart, z = 0.0;
    shapes = new Shape3D[xCount * yCount];
    for (int i = 0; i < yCount; i++) {
        x = xStart;
        for (int j = 0; j < xCount; j++) {
            vec.set(x, y, z);
            t3d.setTranslation(vec);
            trans = new TransformGroup(t3d);
            addChild(trans);

            sphere = new Sphere(radius, // sphere radius
                    Primitive.GENERATE_NORMALS, // generate normals
                    16, // 16 divisions radially
                    app); // it's appearance
            trans.addChild(sphere);
            x += xSpacing;
            shapes[numShapes] = sphere.getShape();
            if (overrideflag)
                shapes[numShapes].setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_WRITE);
            numShapes++;
        }
        y += ySpacing;
    }
}

From source file:SplineInterpolatorTest.java

public Group createBuildings(Group g) {
    m_BuildingAppearance = new Appearance();
    BranchGroup bg = new BranchGroup();

    Texture tex = new TextureLoader("boston.gif", this).getTexture();
    BufferedImage image = ((ImageComponent2D) tex.getImage(0)).getImage();

    final int nMaxBuildings = 120;

    for (int n = 0; n < nMaxBuildings; n++) {
        Cuboid building = new Cuboid(this, bg, ComplexObject.GEOMETRY | ComplexObject.TEXTURE);

        float posX = (int) Utils.getRandomNumber(0, LAND_WIDTH);
        float posZ = (int) Utils.getRandomNumber(0, LAND_LENGTH);

        if (isLocationWater(image, posX, posZ) == false) {
            building.createObject(m_BuildingAppearance, new Vector3d(posX, 0, posZ),
                    new Vector3d(Utils.getRandomNumber(3, 2), Utils.getRandomNumber(8, 7),
                            Utils.getRandomNumber(3, 2)),
                    "house.gif", null, null);
        }// ww  w  .  j  a va2s  .  c o  m
    }

    g.addChild(bg);
    return bg;
}

From source file:AppearanceTest.java

public Tetrahedron() {
    int i;/*from  w ww . j a  v  a 2s  .  c  o m*/

    TriangleArray tetra = new TriangleArray(12,
            TriangleArray.COORDINATES | TriangleArray.NORMALS | TriangleArray.TEXTURE_COORDINATE_2);

    tetra.setCoordinates(0, verts);
    for (i = 0; i < 12; i++) {
        tetra.setTextureCoordinate(0, i, texCoord[i % 3]);
    }

    int face;
    Vector3f normal = new Vector3f();
    Vector3f v1 = new Vector3f();
    Vector3f v2 = new Vector3f();
    Point3f[] pts = new Point3f[3];
    for (i = 0; i < 3; i++)
        pts[i] = new Point3f();

    for (face = 0; face < 4; face++) {
        tetra.getCoordinates(face * 3, pts);
        v1.sub(pts[1], pts[0]);
        v2.sub(pts[2], pts[0]);
        normal.cross(v1, v2);
        normal.normalize();
        for (i = 0; i < 3; i++) {
            tetra.setNormal((face * 3 + i), normal);
        }
    }
    this.setGeometry(tetra);
    this.setAppearance(new Appearance());
}