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

public AppearanceTest() {
    m_Appearance = new Appearance();

    TextureComponent.setComponent(this);

    m_ComponentArray = new AppearanceComponent[] { new PolygonComponent(m_Appearance),
            new ColoringComponent(m_Appearance), new LineComponent(m_Appearance),
            new MaterialComponent(m_Appearance), new PointComponent(m_Appearance),
            new RenderingComponent(m_Appearance), new TransparencyComponent(m_Appearance),
            new TextureComponent(m_Appearance), new TextureAttributesComponent(m_Appearance),
            new TexGenComponent(m_Appearance) };
}

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  w  w  w.j a  va  2s .c  o  m
    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:AvatarTest.java

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

    for (int n = (int) Road.ROAD_LENGTH; n < 0; n = n + 10) {
        Building building = new Building(this, bg,
                ComplexObject.GEOMETRY | ComplexObject.TEXTURE | ComplexObject.COLLISION);

        building.createObject(new Appearance(), new Vector3d(getRandomNumber(-4.0f, 0.25f),
                getRandomNumber(1.0f, 0.5f), getRandomNumber(n, 0.5f)), new Vector3d(1, 1, 1), "house.jpg",
                null, null);/*from   w ww . j av a 2s .  co  m*/

        building = new Building(this, bg,
                ComplexObject.GEOMETRY | ComplexObject.TEXTURE | ComplexObject.COLLISION);

        building.createObject(new Appearance(), new Vector3d(getRandomNumber(4.0f, 0.25f),
                getRandomNumber(1.0f, 0.5f), getRandomNumber(n, 0.5f)), new Vector3d(1, 1, 1), "house.jpg",
                null, null);

    }

    g.addChild(bg);

    return bg;
}

From source file:ExSwitch.java

public Group buildScene() {
    // Turn on the example headlight
    setHeadlightEnable(true);//from   ww  w .j  a va  2  s  .co m

    // Default to walk navigation
    setNavigationType(Walk);

    // Build the scene group
    Group scene = new Group();

    if (debug)
        System.err.println("  switch shapes...");

    // BEGIN EXAMPLE TOPIC
    // Build the switch group and allow its switch
    // value to be changed via menu items
    swtch = new Switch();
    swtch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    //  Create several shapes to place in a switch group

    // Child 0: a red sphere
    Appearance app0 = new Appearance();
    Material mat0 = new Material();
    mat0.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat0.setDiffuseColor(1.0f, 0.0f, 0.2f);
    mat0.setSpecularColor(0.7f, 0.7f, 0.7f);
    app0.setMaterial(mat0);

    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3f(-2.0f, 1.5f, 0.0f));
    TransformGroup tg0 = new TransformGroup(t3d);
    Sphere sph0 = new Sphere(0.5f, // radius
            Primitive.GENERATE_NORMALS, // components
            16, // facets
            app0); // appearance
    tg0.addChild(sph0);
    swtch.addChild(tg0); // Child 0

    // Child 1: a green sphere
    Appearance app1 = new Appearance();
    Material mat1 = new Material();
    mat1.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat1.setDiffuseColor(0.0f, 1.0f, 0.0f);
    mat1.setSpecularColor(0.7f, 0.7f, 0.7f);
    app1.setMaterial(mat1);
    t3d.setTranslation(new Vector3f(0.0f, 1.5f, 0.0f));
    TransformGroup tg1 = new TransformGroup(t3d);
    Sphere sph1 = new Sphere(0.5f, // radius
            Primitive.GENERATE_NORMALS, // components
            16, // facets
            app1); // appearance
    tg1.addChild(sph1);
    swtch.addChild(tg1); // Child 1

    // Child 2: a blue sphere
    Appearance app2 = new Appearance();
    Material mat2 = new Material();
    mat2.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat2.setDiffuseColor(0.0f, 0.6f, 1.0f);
    mat2.setSpecularColor(0.7f, 0.7f, 0.7f);
    app2.setMaterial(mat2);
    t3d.setTranslation(new Vector3f(2.0f, 1.5f, 0.0f));
    TransformGroup tg2 = new TransformGroup(t3d);
    Sphere sph2 = new Sphere(0.5f, // radius
            Primitive.GENERATE_NORMALS, // components
            16, // facets
            app2); // appearance
    tg2.addChild(sph2);
    swtch.addChild(tg2);

    // Set the initial child choice
    swtch.setWhichChild(options[currentSwitch].child);
    scene.addChild(swtch);
    // END EXAMPLE TOPIC

    // Build foreground geometry including a floor and
    // columns on which the switchable shapes stand

    // Load textures
    TextureLoader texLoader = new TextureLoader("granite07rev.jpg", this);
    Texture columnTex = texLoader.getTexture();
    if (columnTex == null)
        System.err.println("Cannot load granite07rev.jpg texture");
    else {
        columnTex.setBoundaryModeS(Texture.WRAP);
        columnTex.setBoundaryModeT(Texture.WRAP);
        columnTex.setMinFilter(Texture.NICEST);
        columnTex.setMagFilter(Texture.NICEST);
        columnTex.setMipMapMode(Texture.BASE_LEVEL);
        columnTex.setEnable(true);
    }

    texLoader = new TextureLoader("flooring.jpg", this);
    Texture groundTex = texLoader.getTexture();
    if (groundTex == null)
        System.err.println("Cannot load flooring.jpg texture");
    else {
        groundTex.setBoundaryModeS(Texture.WRAP);
        groundTex.setBoundaryModeT(Texture.WRAP);
        groundTex.setMinFilter(Texture.NICEST);
        groundTex.setMagFilter(Texture.NICEST);
        groundTex.setMipMapMode(Texture.BASE_LEVEL);
        groundTex.setEnable(true);
    }

    //
    // Build several columns on the floor
    //
    if (debug)
        System.err.println("  columns...");
    SharedGroup column = new SharedGroup();
    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);

    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(1.8f, // height
            0.25f, // radius
            GothicColumn.BUILD_TOP, // flags
            columnApp); // appearance
    column.addChild(columnShape);

    Vector3f trans = new Vector3f();
    Transform3D tr = new Transform3D();
    TransformGroup tg;

    // Left
    trans.set(-2.0f, -1.0f, 0.0f);
    tr.set(trans);
    tg = new TransformGroup(tr);
    tg.addChild(new Link(column));
    scene.addChild(tg);

    // Middle
    trans.set(0.0f, -1.0f, 0.0f);
    tr.set(trans);
    tg = new TransformGroup(tr);
    tg.addChild(new Link(column));
    scene.addChild(tg);

    // Right
    trans.set(2.0f, -1.0f, 0.0f);
    tr.set(trans);
    tg = new TransformGroup(tr);
    tg.addChild(new Link(column));
    scene.addChild(tg);

    //
    //  Add the ground
    //
    if (debug)
        System.err.println("  ground...");

    Appearance groundApp = new Appearance();

    Material groundMat = new Material();
    groundMat.setAmbientColor(0.6f, 0.6f, 0.6f);
    groundMat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    groundMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    groundApp.setMaterial(groundMat);

    tr = new Transform3D();
    tr.setScale(new Vector3d(4.0, 4.0, 1.0));

    TextureAttributes groundTexAtt = new TextureAttributes();
    groundTexAtt.setTextureMode(TextureAttributes.MODULATE);
    groundTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    groundTexAtt.setTextureTransform(tr);
    groundApp.setTextureAttributes(groundTexAtt);

    if (groundTex != null)
        groundApp.setTexture(groundTex);

    ElevationGrid ground = new ElevationGrid(11, // X dimension
            11, // Z dimension
            2.0f, // X spacing
            2.0f, // Z spacing
            // Automatically use zero heights
            groundApp); // Appearance

    trans.set(0.0f, -1.0f, 0.0f);
    tr.set(trans);
    tg = new TransformGroup(tr);
    tg.addChild(ground);
    scene.addChild(tg);

    // Add a light
    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    DirectionalLight light = new DirectionalLight();
    light.setEnable(true);
    light.setColor(new Color3f(1.0f, 1.0f, 1.0f));
    light.setDirection(new Vector3f(0.5f, -1.0f, -0.5f));
    light.setInfluencingBounds(worldBounds);
    scene.addChild(light);

    return scene;
}

From source file:SimpleGeometry.java

PlatformGeometry createAimer() {

    PlatformGeometry pg = new PlatformGeometry();

    // This TransformGroup will be used by the MouseTranslate
    // utiltiy to move the cylinder around the canvas. when the
    // the user holds down mouse button 3.
    TransformGroup moveTG = new TransformGroup();
    moveTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    moveTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    MouseTranslate mouseT = new MouseTranslate(moveTG);
    moveTG.addChild(mouseT);/* w  ww .  j  a va  2s .com*/
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    mouseT.setSchedulingBounds(bounds);
    pg.addChild(moveTG);

    // This TransformGroup is used to place the cylinder in the scene.
    // The cylinder will be rotated 90 degrees so it will appear as
    // a circle on the screen (could be made into a nice gun site...).
    // The cylinder is also displaced a little in Z so it is in front
    // of the viewer.
    Transform3D xForm = new Transform3D();
    xForm.rotX(Math.PI / 2.0);
    xForm.setTranslation(new Vector3d(0.0, 0.0, -0.7));
    TransformGroup placementTG = new TransformGroup(xForm);
    moveTG.addChild(placementTG);

    // Create the cylinder - make it thin and transparent.
    Appearance cylinderAppearance = new Appearance();
    TransparencyAttributes transAttrs = new TransparencyAttributes(TransparencyAttributes.FASTEST, 0.5f);
    //        cylinderAppearance.setTransparencyAttributes(transAttrs);
    Cylinder aimer = new Cylinder(0.06f, 0.005f, 0, cylinderAppearance);
    placementTG.addChild(aimer);

    return pg;
}

From source file:MixedTest.java

public void renderField(int fieldDesc) {
    super.renderField(fieldDesc);

    GraphicsContext3D g = getGraphicsContext3D();

    // first time initialization
    if (m_nRender == 0) {
        // set the start time
        m_StartTime = System.currentTimeMillis();

        // add a light to the graphics context
        DirectionalLight light = new DirectionalLight();
        light.setEnable(true);//from   w  ww . ja v  a2 s  .  c om
        g.addLight((Light) light);

        // create the material for the points
        Appearance a = new Appearance();
        Material mat = new Material();
        mat.setLightingEnable(true);
        mat.setAmbientColor(0.5f, 1.0f, 1.0f);
        a.setMaterial(mat);
        a.setColoringAttributes(new ColoringAttributes(1.0f, 0.5f, 0.5f, ColoringAttributes.NICEST));

        // enlarge the points
        a.setPointAttributes(new PointAttributes(4, true));

        // make the appearance current in the graphics context
        g.setAppearance(a);
    }

    // set the current transformation for the graphics context
    g.setModelTransform(m_t3d);

    // finally render the PointArray
    g.draw(m_PointArray);

    // calculate and display the Frames Per Second for the
    // Immediate Mode rendering of the PointArray
    m_nRender++;

    if ((m_nRender % m_kReportInterval) == 0) {
        float fps = (float) 1000.0f / ((System.currentTimeMillis() - m_StartTime) / (float) m_kReportInterval);
        System.out.println("FPS:\t" + fps);

        m_StartTime = System.currentTimeMillis();
    }
}

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 ava  2 s .c o  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:TwistStripApp.java

public BranchGroup createSceneGraph() {

    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);//from w  ww. j ava 2  s  . c o m

    Shape3D twist = new Twist();
    objSpin.addChild(twist);

    // Duplicate the twist strip geometry and set the
    // appearance of the new Shape3D object to line mode
    // without culling.
    // Add the POLYGON_FILLED and POLYGON_LINE strips
    // in the scene graph at the same point.
    // This will show the triangles of the original Mobius strip that
    // are clipped. The PolygonOffset is set to prevent stitching.
    PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
    polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrib.setPolygonOffset(0.001f);
    Appearance polyAppear = new Appearance();
    polyAppear.setPolygonAttributes(polyAttrib);
    objSpin.addChild(new Shape3D(twist.getGeometry(), polyAppear));

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

    // make background white
    Background background = new Background(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:PointTest.java

private BranchGroup createPoints(final int nPointSize, final int nNumPoints, boolean bAliased) {
    BranchGroup bg = new BranchGroup();

    String szText = new String();
    szText += (nNumPoints + "X, Size:" + nPointSize + ", aliased: " + bAliased);

    Font3D f3d = new Font3D(new Font("SansSerif", Font.PLAIN, 1), new FontExtrusion());
    Text3D label3D = new Text3D(f3d, szText, new Point3f(-5, 0, 0));
    Shape3D sh = new Shape3D(label3D);

    bg.addChild(sh);/* w w  w.j  av  a2 s  . co  m*/

    PointArray pointArray = new PointArray(nNumPoints * nNumPoints,
            GeometryArray.COORDINATES | GeometryArray.COLOR_3);

    // create the PointArray that we will be rendering
    int nPoint = 0;
    final double factor = 1.0 / nNumPoints;

    for (int n = 0; n < nNumPoints; n++) {
        for (int i = 0; i < nNumPoints; i++) {
            Point3f point = new Point3f(n - nNumPoints / 2, i - nNumPoints / 2, 0.0f);
            pointArray.setCoordinate(nPoint, point);
            pointArray.setColor(nPoint++, new Color3f(0.5f, (float) (n * factor), (float) (i * factor)));
        }
    }

    // create the material for the points
    Appearance pointApp = new Appearance();

    // enlarge the points
    pointApp.setPointAttributes(new PointAttributes(nPointSize, bAliased));

    Shape3D pointShape = new Shape3D(pointArray, pointApp);

    bg.addChild(pointShape);
    return bg;
}

From source file:TexBug.java

void setupAppearance() {
    appearance = new Appearance();

    // Texture2D/*from  w  ww  . j ava 2 s. co  m*/

    // set the values to the defaults
    texEnable = false;
    texMipMapMode = Texture.BASE_LEVEL;
    texBoundaryModeS = Texture.WRAP;
    texBoundaryModeT = Texture.WRAP;
    texMinFilter = Texture.BASE_LEVEL_POINT;
    texMagFilter = Texture.BASE_LEVEL_POINT;
    texBoundaryColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f);

    // set up the appearance to allow the texture to be changed
    appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    // set the texture
    setTexture();
}