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

public void run() {
    // Set up Graphics context
    gc = canvas.getGraphicsContext3D();//from   ww  w  . ja v a2 s. c o  m

    // We always need to set this for PureImmediate
    // stereo mode
    gc.setBufferOverride(true);

    Color3f lightColor = new Color3f(1, 1, 1);
    Vector3f lightDir = new Vector3f(0, 0, -1);
    DirectionalLight light = new DirectionalLight(lightColor, lightDir);

    gc.addLight(light);

    Appearance redApp = new Appearance();
    Appearance greenApp = new Appearance();
    Color3f ambientColor = new Color3f(0, 0, 0);
    Color3f emissiveColor = new Color3f(0, 0, 0);
    Color3f diffuseColor = new Color3f(1, 0, 0);
    Color3f specularColor = new Color3f(1, 1, 1);
    redApp.setMaterial(new Material(ambientColor, emissiveColor, diffuseColor, specularColor, 5));
    diffuseColor = new Color3f(0, 1, 0);

    greenApp.setMaterial(new Material(ambientColor, emissiveColor, diffuseColor, specularColor, 5));

    // Set up geometry
    Cone leftCone = new Cone(0.4f, 0.6f, Primitive.GENERATE_NORMALS, redApp);
    Cone rightCone = new Cone(0.4f, 0.6f, Primitive.GENERATE_NORMALS, greenApp);
    leftConeBody = leftCone.getShape(Cone.BODY);
    leftConeCap = leftCone.getShape(Cone.CAP);

    rightConeBody = rightCone.getShape(Cone.BODY);
    rightConeCap = rightCone.getShape(Cone.CAP);
    leftTrans = new Vector3f(-0.6f, 0, 0);
    rightTrans = new Vector3f(0.6f, 0, 0);

    while (true) {
        // compute data which is can be used
        // for both left and right eye
        computeSharedData();

        if (stereoSupport) {
            if (!sharedStereoZbuffer) {
                gc.setStereoMode(GraphicsContext3D.STEREO_BOTH);
                // This clear both left and right buffers, we
                // must set STEREO_BOTH before it. Otherwise
                // it only clear LEFT or RIGHT buffer unless
                // this is invoke twice for each buffer.
                gc.clear();
            }

            gc.setStereoMode(GraphicsContext3D.STEREO_LEFT);
            renderLeft();

            gc.setStereoMode(GraphicsContext3D.STEREO_RIGHT);
            renderRight();
        } else {
            gc.clear();
            renderLeft();
        }

        // This swap both left and right buffers so
        // there is no need to set STEREO_BOTH before it
        canvas.swap();

        // Be polite to other threads !
        Thread.yield();
    }
}

From source file:AvatarTest.java

public Group createLand(Group g) {
    Land land = new Land(this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE);
    return land.createObject(new Appearance(), new Vector3d(0, 0, 0), new Vector3d(1, 1, 1), "land.jpg", null,
            null);// ww  w  .j ava2s. c  o  m
}

From source file:ConicWorld.java

private Appearance createAppearance(int idx) {
    Appearance app = new Appearance();

    // Globally used colors
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);

    idx = idx % 5;/*from  w ww  .  j a  va  2s  .  co m*/

    switch (idx) {
    // Lit solid
    case 0: {
        // Set up the material properties
        Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f);
        app.setMaterial(new Material(objColor, black, objColor, white, 80.0f));
        break;
    }
    // Lit solid, no specular
    case 1: {
        // Set up the material properties
        Color3f objColor = new Color3f(0.0f, 0.8f, 0.0f);
        app.setMaterial(new Material(objColor, black, objColor, white, 80.0f));
        break;
    }

    // Lit solid, specular only
    case 2: {
        // Set up the material properties
        Color3f objColor = new Color3f(0.0f, 0.8f, 0.8f);
        app.setMaterial(new Material(black, black, objColor, white, 80.0f));
        break;
    }

    // Texture mapped, lit solid
    case 3: {
        // Set up the texture map
        TextureLoader tex = new TextureLoader(texImage, this);
        app.setTexture(tex.getTexture());

        // Set up the material properties
        app.setMaterial(new Material(white, black, white, black, 1.0f));
        TextureAttributes texAttr = new TextureAttributes();
        texAttr.setTextureMode(TextureAttributes.MODULATE);
        app.setTextureAttributes(texAttr);

        break;
    }

    // Another lit solid with a different color
    case 4: {
        // Set up the material properties
        Color3f objColor = new Color3f(1.0f, 1.0f, 0.0f);
        app.setMaterial(new Material(objColor, black, objColor, white, 80.0f));
        break;
    }

    default: {
        ColoringAttributes ca = new ColoringAttributes();
        ca.setColor(new Color3f(0.0f, 1.0f, 0.0f));
        app.setColoringAttributes(ca);
    }
    }

    return app;
}

From source file:PickCollisionTest.java

protected void addCube(BranchGroup bg, double x, double y, double z, double sx, double sy, double sz,
        String name, boolean wireframe) {
    // create four ColorCube objects
    TransformGroup cubeTg = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(x, y, z));
    t3d.setScale(new Vector3d(sx, sy, sz));
    cubeTg.setTransform(t3d);/*from w  ww  . j av a  2  s.c o m*/
    ColorCube cube = new ColorCube(1.0);

    // we have to make the front face wireframe
    // or we can't see inside the box!
    if (wireframe) {
        Appearance app = new Appearance();
        app.setPolygonAttributes(
                new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0));
        cube.setAppearance(app);
    }

    cubeTg.addChild(cube);
    recursiveSetUserData(cubeTg, name);

    bg.addChild(cubeTg);
}

From source file:BooksDemo.java

public void createScene() {
    BufferedImage image = new BufferedImage(xpanel.getWidth(), xpanel.getHeight(), BufferedImage.TYPE_INT_RGB);
    getContentPane().paint(image.getGraphics());

    BufferedImage subImage = new BufferedImage(CANVAS3D_WIDTH, CANVAS3D_HEIGHT, BufferedImage.TYPE_INT_RGB);
    ((Graphics2D) subImage.getGraphics()).drawImage(image, null, -c3d.getX(), -c3d.getY());

    Background bg = new Background(new ImageComponent2D(ImageComponent2D.FORMAT_RGB, subImage));
    BoundingSphere bounds = new BoundingSphere();
    bounds.setRadius(100.0);/*www .  ja v a 2s.co m*/
    bg.setApplicationBounds(bounds);

    BranchGroup objRoot = new BranchGroup();
    objRoot.addChild(bg);

    TransformGroup objTg = new TransformGroup();
    objTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    Transform3D yAxis = new Transform3D();
    rotor1Alpha = new Alpha(1, 400);
    rotator1 = new RotationInterpolator(rotor1Alpha, objTg, yAxis, (float) Math.PI * 1.0f,
            (float) Math.PI * 2.0f);
    rotator1.setSchedulingBounds(bounds);

    textures.put("pages_top", createTexture("pages_top.jpg"));
    textures.put("pages", createTexture("amazon.jpg"));
    textures.put("amazon", createTexture("amazon.jpg"));
    textures.put("cover1", createTexture("cover1.jpg"));
    textures.put("cover2", createTexture("cover2.jpg"));
    textures.put("cover3", createTexture("cover3.jpg"));

    book = new com.sun.j3d.utils.geometry.Box(0.5f, 0.7f, 0.15f,
            com.sun.j3d.utils.geometry.Box.GENERATE_TEXTURE_COORDS, new Appearance());
    book.getShape(book.TOP).setAppearance((Appearance) textures.get("pages_top"));
    book.getShape(book.RIGHT).setAppearance((Appearance) textures.get("pages"));
    book.getShape(book.LEFT).setAppearance((Appearance) textures.get("amazon"));
    book.getShape(book.FRONT).setAppearance((Appearance) textures.get("cover1"));

    book.getShape(book.BACK).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    book.getShape(book.FRONT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    // book.getShape(book.LEFT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    // book.getShape(book.RIGHT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

    objTg.addChild(book);
    objTg.addChild(rotator1);

    Transform3D spin = new Transform3D();
    Transform3D tempspin = new Transform3D();

    spin.rotX(Math.PI / 8.0d);
    tempspin.rotY(Math.PI / 7.0d);
    spin.mul(tempspin);

    TransformGroup objTrans = new TransformGroup(spin);
    objTrans.addChild(objTg);

    objRoot.addChild(objTrans);

    SimpleUniverse u = new SimpleUniverse(c3d);
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(objRoot);

    View view = u.getViewer().getView();
    view.setSceneAntialiasingEnable(true);
}

From source file:SimpleTexture.java

/**
 * This defines the appearance with a texture. The texture is loaded from an
 * external file./*  w w w .ja va 2 s.c o  m*/
 * 
 * @return Appearance that uses the texture.
 */
protected Appearance DefineAppearance() {
    //Load the texture from the external image file
    TextureLoader textLoad = new TextureLoader("housebrick.jpg", this);
    //Access the image from the loaded texture
    ImageComponent2D textImage = textLoad.getImage();
    //Create a two dimensional texture
    Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture.RGB, textImage.getWidth(),
            textImage.getHeight());
    //Set the texture from the image loaded
    texture.setImage(0, textImage);
    //Create the appearance that will use the texture
    Appearance app = new Appearance();
    app.setTexture(texture);
    //Define how the texture will be mapped onto the surface
    //by creating the appropriate texture attributes
    TextureAttributes textAttr = new TextureAttributes();
    textAttr.setTextureMode(TextureAttributes.REPLACE);
    app.setTextureAttributes(textAttr);
    app.setMaterial(new Material());
    return app;
}

From source file:PolygonOffset.java

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

    // 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);
    objRoot.addChild(objTrans);/* ww w .j a v a 2s .  com*/

    // Create a Sphere. We will display this as both wireframe and
    // solid to make a hidden line display
    // wireframe
    Appearance wireApp = new Appearance();

    ColoringAttributes wireCa = new ColoringAttributes();
    wireCa.setColor(black);
    wireApp.setColoringAttributes(wireCa);
    wirePa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0.0f);
    wireApp.setPolygonAttributes(wirePa);
    Sphere outWireSphere = new Sphere(sphereRadius, 0, 15, wireApp);
    objTrans.addChild(outWireSphere);

    // solid
    ColoringAttributes outCa = new ColoringAttributes(red, ColoringAttributes.SHADE_FLAT);
    Appearance outSolid = new Appearance();
    outSolid.setColoringAttributes(outCa);
    solidPa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_BACK, 0.0f);
    solidPa.setPolygonOffsetFactor(dynamicOffset);
    solidPa.setPolygonOffset(staticOffset);
    solidPa.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE);
    outSolid.setPolygonAttributes(solidPa);
    Sphere outSolidSphere = new Sphere(sphereRadius, 0, 15, outSolid);
    objTrans.addChild(outSolidSphere);

    innerTG = new TransformGroup();
    innerTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    scale = new Transform3D();
    updateInnerScale();
    objTrans.addChild(innerTG);

    // Create a smaller sphere to go inside. This sphere has a different
    // tesselation and color
    Sphere inWireSphere = new Sphere(sphereRadius, 0, 10, wireApp);
    innerTG.addChild(inWireSphere);

    // inside solid
    ColoringAttributes inCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT);
    Appearance inSolid = new Appearance();
    inSolid.setColoringAttributes(inCa);
    inSolid.setPolygonAttributes(solidPa);
    Sphere inSolidSphere = new Sphere(sphereRadius, 0, 10, inSolid);
    innerTG.addChild(inSolidSphere);

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    AxisAngle4f axisAngle = new AxisAngle4f(0.0f, 0.0f, 1.0f, -(float) Math.PI / 2.0f);
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 80000, 0, 0, 0, 0, 0);

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

    // set up a white background
    Background bgWhite = new Background(new Color3f(1.0f, 1.0f, 1.0f));
    bgWhite.setApplicationBounds(bounds);
    objTrans.addChild(bgWhite);

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

    return objRoot;
}

From source file:MultiTextureTest.java

public BranchGroup createSceneGraph() {
    // 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.4);// w  w  w  . j a  va2 s .  c  o  m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    TransformGroup objTrans = new TransformGroup();
    //write-enable for behaviors
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objTrans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    objScale.addChild(objTrans);

    Appearance ap = new Appearance();

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

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

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

    lightTex = createLightMap();

    textureUnitState[0] = new TextureUnitState(stoneTex, texAttr1, null);
    textureUnitState[0].setCapability(TextureUnitState.ALLOW_STATE_WRITE);

    textureUnitState[1] = new TextureUnitState(lightTex, texAttr2, null);
    textureUnitState[1].setCapability(TextureUnitState.ALLOW_STATE_WRITE);

    ap.setTextureUnitState(textureUnitState);

    //Create a Box
    Box BoxObj = new Box(1.5f, 1.5f, 0.8f, Box.GENERATE_NORMALS | Box.GENERATE_TEXTURE_COORDS, ap, 2);
    // add it to the scene graph.
    objTrans.addChild(BoxObj);

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

    //Shine it with two lights.
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f lColor2 = new Color3f(0.2f, 0.2f, 0.1f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

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

    return objRoot;
}

From source file:AvatarTest.java

public Group createRoad(Group g) {
    Road road = new Road(this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE);
    return road.createObject(new Appearance(), new Vector3d(0, 0, 0), new Vector3d(1, 1, 1), "road.jpg", null,
            null);//ww w . j ava  2s.  co  m
}

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);// w  ww .jav  a  2s. 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;
}