Example usage for javax.media.j3d Appearance setPolygonAttributes

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

Introduction

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

Prototype

public void setPolygonAttributes(PolygonAttributes polygonAttributes) 

Source Link

Document

Sets the polygonAttributes object to the specified object.

Usage

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  www. j av a2  s  .c  om*/

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

/**
 * Wurfeldarstellung/* ww  w.  j  a  v  a 2s.  com*/
 * 
 * @return Appearance
 */
private Appearance makeAppearance() {
    Appearance a = new Appearance();
    PolygonAttributes p = new PolygonAttributes();
    p.setCullFace(PolygonAttributes.CULL_NONE);
    a.setPolygonAttributes(p);
    return a;
}

From source file:ModelClipTest.java

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

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

    // 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);//from  www  .j ava 2 s .c o m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // This Transformgroup is used by the mouse manipulators to
    // move the CYlinder.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(objTrans);

    //Create Model Clip
    ModelClip mc = new ModelClip();
    boolean enables[] = { false, false, false, false, false, false };
    Vector4d eqn1 = new Vector4d(0.0, 1.0, 0.0, 0.0);
    Vector4d eqn2 = new Vector4d(1.0, 1.0, 0.0, 0.0);
    mc.setEnables(enables);
    mc.setPlane(1, eqn1);
    mc.setPlane(2, eqn2);
    mc.setEnable(1, true);
    mc.setEnable(2, true);
    mc.setInfluencingBounds(bounds);
    objTrans.addChild(mc);

    //Create a cylinder
    PolygonAttributes attr = new PolygonAttributes();
    attr.setCullFace(PolygonAttributes.CULL_NONE);
    Appearance ap = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    ap.setPolygonAttributes(attr);

    Cylinder CylinderObj = new Cylinder(1.0f, 2.0f, ap);
    objTrans.addChild(CylinderObj);

    // Create the rotate behavior node
    MouseRotate behavior = new MouseRotate(objTrans);
    objTrans.addChild(behavior);
    behavior.setSchedulingBounds(bounds);

    // Create the zoom behavior node
    MouseZoom behavior2 = new MouseZoom(objTrans);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    //Shine it with two colored lights.
    Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f);
    Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f);
    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:ModelClipTest2.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);/*from ww w .j  a va  2s . c o m*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

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

    //Shine it with two colored lights.
    Color3f lColor0 = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f);
    Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);

    AmbientLight lgt0 = new AmbientLight(true, lColor2);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt0.setInfluencingBounds(bounds);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt0);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

    // Create a Transformgroup for the geometry
    TransformGroup objRot = new TransformGroup();
    Transform3D t3d1 = new Transform3D();
    AxisAngle4f rot1 = new AxisAngle4f(0.0f, 1.0f, 0.0f, 45.0f);
    t3d1.setRotation(rot1);
    objRot.setTransform(t3d1);
    objScale.addChild(objRot);

    //Create a cylinder
    PolygonAttributes attr = new PolygonAttributes();
    attr.setCullFace(PolygonAttributes.CULL_NONE);
    Appearance ap = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    ap.setPolygonAttributes(attr);

    Cylinder CylinderObj = new Cylinder(0.5f, 2.2f, ap);
    objRot.addChild(CylinderObj);

    //Create a box
    Box BoxObj = new Box(0.8f, 0.8f, 0.8f, ap);
    objRot.addChild(BoxObj);

    // This Transformgroup is used by the mouse manipulators to
    // move the model clip planes.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRot.addChild(objTrans);

    // Create the rotate behavior node
    MouseRotate behavior = new MouseRotate(objTrans);
    objTrans.addChild(behavior);
    behavior.setSchedulingBounds(bounds);

    // Create the zoom behavior node
    MouseZoom behavior2 = new MouseZoom(objTrans);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    //Create Model Clip
    ModelClip mc = new ModelClip();
    boolean enables[] = { false, false, false, false, false, false };
    Vector4d eqn = new Vector4d(0.0, 1.0, 1.0, 0.0);
    mc.setEnables(enables);
    mc.setPlane(1, eqn);
    mc.setEnable(1, true);
    mc.setInfluencingBounds(bounds);
    objTrans.addChild(mc);

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

    return objRoot;
}

From source file:SimpleWire.java

/**
 * This constructs a cube using the Box utility class. The attributes are
 * set so that the lines are drawn and not the faces.
 * /*  w w  w.ja  v a  2  s  .  c  o m*/
 * @return Node that is the cube
 */
protected Node buildShape() {
    Appearance app = new Appearance();
    //Create the polygon attributes
    PolygonAttributes polyAttr = new PolygonAttributes();
    //Set them so that the draw mode is polygon line
    polyAttr.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    //Use these in the appearance
    app.setPolygonAttributes(polyAttr);
    return new Box(1.0f, 1.0f, 1.0f, app);
}

From source file:BooksDemo.java

private Appearance createTexture(String fileName) {
    Image sourceImage = UIHelper.readImage(fileName);
    if (sourceImage == null)
        System.out.println("Image could not be loaded from " + fileName);

    TextureLoader loader = new TextureLoader(sourceImage, this);
    ImageComponent2D image = loader.getImage();

    if (image == null)
        System.out.println("Texture could not be loaded from " + fileName);

    Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image.getWidth(), image.getHeight());
    texture.setImage(0, image);/*from www.  j a  v  a 2  s  . co  m*/
    texture.setEnable(true);
    texture.setMagFilter(Texture.BASE_LEVEL_LINEAR);
    texture.setMinFilter(Texture.BASE_LEVEL_LINEAR);

    Appearance appearance = new Appearance();
    PolygonAttributes polyAttributes = new PolygonAttributes(PolygonAttributes.POLYGON_FILL,
            PolygonAttributes.CULL_NONE, 0f);
    appearance.setPolygonAttributes(polyAttributes);
    appearance.setTexture(texture);

    TextureAttributes textureAttributes = new TextureAttributes();
    appearance.setTextureAttributes(textureAttributes);

    return appearance;
}

From source file:Text2DTest.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);//from   w w w  . j a va2  s  .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);

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

    TransformGroup textTranslationGroup;
    Transform3D textTranslation;
    float yPos = -.5f;
    Shape3D textObject = new Text2D("Rotating Yellow Text", new Color3f(1f, 1f, 0f), "Serif", 60, Font.BOLD);
    Appearance app = textObject.getAppearance();

    PolygonAttributes pa = app.getPolygonAttributes();
    if (pa == null)
        pa = new PolygonAttributes();
    pa.setCullFace(PolygonAttributes.CULL_NONE);
    if (app.getPolygonAttributes() == null)
        app.setPolygonAttributes(pa);
    objTrans.addChild(textObject);

    textTranslation = new Transform3D();
    textTranslation.setTranslation(new Vector3f(0f, yPos, 0f));
    textTranslationGroup = new TransformGroup(textTranslation);
    textTranslationGroup.addChild(objTrans);
    objScale.addChild(textTranslationGroup);
    yPos += .5f;

    /* Blue 40point text */
    textObject = new Text2D("Blue 40point Text", new Color3f(0f, 0f, 1f), "Serif", 40, Font.BOLD);
    textTranslation = new Transform3D();
    textTranslation.setTranslation(new Vector3f(0f, yPos, 0f));
    textTranslationGroup = new TransformGroup(textTranslation);
    textTranslationGroup.addChild(textObject);
    objScale.addChild(textTranslationGroup);
    yPos += .5f;

    /* Green italic text */
    textObject = new Text2D("Green Italic Text", new Color3f(0f, 1f, 0f), "Serif", 70, Font.ITALIC);
    textTranslation = new Transform3D();
    textTranslation.setTranslation(new Vector3f(0f, yPos, 0f));
    textTranslationGroup = new TransformGroup(textTranslation);
    textTranslationGroup.addChild(textObject);
    objScale.addChild(textTranslationGroup);
    yPos += .5f;

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    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, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);

    return objRoot;
}

From source file:LightScopeApp.java

BranchGroup createScene() {
    BranchGroup scene = new BranchGroup();
    TransformGroup tableTG = new TransformGroup();
    TransformGroup lampTG = new TransformGroup();
    TransformGroup litBoxTG = new TransformGroup();
    TransformGroup unLitBoxTG = new TransformGroup();

    scene.addChild(tableTG);/*from   w ww  .j a  v a2s  . c om*/
    tableTG.addChild(lampTG);
    tableTG.addChild(litBoxTG);
    tableTG.addChild(unLitBoxTG);

    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f blue = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f green = new Color3f(0.0f, 0.0f, 1.0f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);

    Vector3f transVector = new Vector3f();
    Transform3D transTransform = new Transform3D();

    transVector.set(0.0f, -0.4f, 0.5f);
    transTransform.setTranslation(transVector);
    tableTG.setTransform(transTransform);

    transVector.set(-0.4f, 0.001f, 0.1f);
    transTransform.setTranslation(transVector);
    lampTG.setTransform(transTransform);

    transVector.set(-0.2f, 0.1f, 0.2f);
    transTransform.setTranslation(transVector);
    litBoxTG.setTransform(transTransform);

    transVector.set(0.3f, 0.1f, -0.4f);
    transTransform.setTranslation(transVector);
    unLitBoxTG.setTransform(transTransform);

    Shape3D tablePlane = createXZPlane(new Point3f(-1.0f, 0.0f, -1.0f), new Point3f(-1.0f, 0.0f, 1.0f),
            new Point3f(1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, -1.0f));
    tablePlane.setAppearance(createMaterialAppearance(white));
    tableTG.addChild(tablePlane);
    litBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, createMaterialAppearance(red)));
    Shape3D shadowPlane = createXZPlane(new Point3f(0.1f, -0.095f, -0.1f), new Point3f(0.1f, -0.095f, 0.1f),
            new Point3f(0.2f, -0.095f, 0.15f), new Point3f(0.2f, -0.095f, -0.15f));
    shadowPlane.setAppearance(createMaterialAppearance(black));
    litBoxTG.addChild(shadowPlane);

    Appearance redGlowMat = createMaterialAppearance(red);
    //    redGlowMat.getMaterial().setEmissiveColor(0.5f, 0.5f, 0.5f);
    unLitBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, redGlowMat));

    Shape3D lamp = createLampShape();
    Appearance lampAppearance = createMaterialAppearance(blue);
    PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
    polyAttrib.setBackFaceNormalFlip(true);
    lampAppearance.setPolygonAttributes(polyAttrib);
    lamp.setAppearance(lampAppearance);
    lampTG.addChild(lamp);

    PointLight lampLight = new PointLight();
    lampLight.setPosition(0.1f, 0.5f, -0.1f);
    lampLight.setInfluencingBounds(new BoundingSphere());
    lampTG.addChild(lampLight);

    Shape3D litPlane = createXZPlane(new Point3f(-0.4f, 0.0f, -0.4f), new Point3f(-0.4f, 0.0f, 0.4f),
            new Point3f(0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, -0.4f));
    litPlane.setAppearance(createMaterialAppearance(white));
    lampTG.addChild(litPlane);

    lampLight.addScope(lampTG);
    lampLight.addScope(litBoxTG);

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);

    DirectionalLight lightD1 = new DirectionalLight();
    lightD1.setInfluencingBounds(new BoundingSphere());
    lightD1.setColor(new Color3f(0.4f, 0.4f, 0.4f));
    Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f);
    lightDir.normalize();
    lightD1.setDirection(lightDir);
    scene.addChild(lightD1);

    DirectionalLight lightD2 = new DirectionalLight();
    lightD2.setInfluencingBounds(new BoundingSphere());
    lightD2.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    lightDir.set(1.0f, -1.0f, -1.0f);
    lightDir.normalize();
    lightD2.setDirection(lightDir);
    scene.addChild(lightD2);

    Background bg = new Background();
    bg.setColor(1.0f, 1.0f, 1.0f);
    bg.setApplicationBounds(new BoundingSphere());
    scene.addChild(bg);

    return scene;
}

From source file:GeomInfoApp.java

Appearance createMaterialAppearance() {

    Appearance materialAppear = new Appearance();
    PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
    materialAppear.setPolygonAttributes(polyAttrib);

    Material material = new Material();
    material.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f));
    materialAppear.setMaterial(material);

    return materialAppear;
}

From source file:GeomInfoApp.java

Appearance createWireFrameAppearance() {

    Appearance materialAppear = new Appearance();
    PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    materialAppear.setPolygonAttributes(polyAttrib);
    ColoringAttributes redColoring = new ColoringAttributes();
    redColoring.setColor(1.0f, 0.0f, 0.0f);
    materialAppear.setColoringAttributes(redColoring);

    return materialAppear;
}