Example usage for javax.media.j3d TransparencyAttributes TransparencyAttributes

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

Introduction

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

Prototype

public TransparencyAttributes(int tMode, float tVal) 

Source Link

Document

Construct TransparencyAttributes object with specified values.

Usage

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);/*from   w w  w  .  ja  v a 2s.  c  o m*/
    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:AppearanceExplorer.java

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

    // ColoringAttributes
    coloringColor = new Color3f(red);
    coloringAttr = new ColoringAttributes(coloringColor, coloringShadeModel);
    coloringAttr.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
    coloringAttr.setCapability(ColoringAttributes.ALLOW_SHADE_MODEL_WRITE);
    appearance.setColoringAttributes(coloringAttr);

    // set up the editor
    coloringAttrEditor = new ColoringAttributesEditor(coloringAttr);

    // PointAttributes
    pointAttr = new PointAttributes(pointSize, pointAAEnable);
    pointAttr.setCapability(PointAttributes.ALLOW_SIZE_WRITE);
    pointAttr.setCapability(PointAttributes.ALLOW_ANTIALIASING_WRITE);
    appearance.setPointAttributes(pointAttr);

    // set up the editor
    pointAttrEditor = new PointAttributesEditor(pointAttr);

    // LineAttributes
    lineAttr = new LineAttributes(lineWidth, linePattern, lineAAEnable);
    lineAttr.setCapability(LineAttributes.ALLOW_WIDTH_WRITE);
    lineAttr.setCapability(LineAttributes.ALLOW_PATTERN_WRITE);
    lineAttr.setCapability(LineAttributes.ALLOW_ANTIALIASING_WRITE);
    appearance.setLineAttributes(lineAttr);

    // set up the editor
    lineAttrEditor = new LineAttributesEditor(lineAttr);

    // PolygonAttributes
    polygonAttr = new PolygonAttributes(polygonMode, polygonCull, 0.0f);
    polygonAttr.setPolygonOffset(polygonOffsetBias);
    polygonAttr.setPolygonOffsetFactor(polygonOffsetFactor);
    polygonAttr.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
    polygonAttr.setCapability(PolygonAttributes.ALLOW_CULL_FACE_WRITE);
    polygonAttr.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE);
    appearance.setPolygonAttributes(polygonAttr);

    // set up the editor
    polygonAttrEditor = new PolygonAttributesEditor(polygonAttr);

    // Rendering attributes
    renderAttr = new RenderingAttributes(renderDepthBuffer, renderDepthBufferWrite, 0.0f,
            RenderingAttributes.ALWAYS, renderVisible, renderIgnoreVertexColor, renderRasterOpEnable,
            renderRasterOp);//from  ww  w  . ja v  a2s.co m
    renderAttr.setCapability(RenderingAttributes.ALLOW_IGNORE_VERTEX_COLORS_WRITE);
    renderAttr.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE);
    renderAttr.setCapability(RenderingAttributes.ALLOW_RASTER_OP_WRITE);
    renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_FUNCTION_WRITE);
    renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_VALUE_WRITE);
    appearance.setRenderingAttributes(renderAttr);
    appearance.setCapability(Appearance.ALLOW_RENDERING_ATTRIBUTES_WRITE);

    // set up the editor
    renderAttrEditor = new RenderingAttributesEditor(renderAttr);

    // TransparencyAttributes
    transpAttr = new TransparencyAttributes(transpMode, transpValue);
    transpAttr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transpAttr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
    transpAttr.setCapability(TransparencyAttributes.ALLOW_BLEND_FUNCTION_WRITE);
    appearance.setTransparencyAttributes(transpAttr);

    // set up the editor
    transpAttrEditor = new TransparencyAttributesEditor(transpAttr);

    // Material
    material = new Material(red, black, red, white, 20.f);
    material.setLightingEnable(false);
    material.setCapability(Material.ALLOW_COMPONENT_WRITE);
    appearance.setMaterial(material);

    // material presets
    String[] materialNames = { "Red", "White", "Red Ambient", "Red Diffuse", "Grey Emissive", "White Specular",
            "Aluminium", "Blue Plastic", "Copper", "Gold", "Red Alloy", "Black Onyx" };
    Material[] materialPresets = new Material[materialNames.length];
    materialPresets[0] = new Material(red, black, red, white, 20.0f);
    materialPresets[1] = new Material(white, black, white, white, 20.0f);
    materialPresets[2] = new Material(red, black, black, black, 20.0f);
    materialPresets[3] = new Material(black, black, red, black, 20.0f);
    materialPresets[4] = new Material(black, grey, black, black, 20.0f);
    materialPresets[5] = new Material(black, black, black, white, 20.0f);
    Color3f alum = new Color3f(0.37f, 0.37f, 0.37f);
    Color3f alumSpec = new Color3f(0.89f, 0.89f, 0.89f);
    materialPresets[6] = new Material(alum, black, alum, alumSpec, 17);
    Color3f bluePlastic = new Color3f(0.20f, 0.20f, 0.70f);
    Color3f bluePlasticSpec = new Color3f(0.85f, 0.85f, 0.85f);
    materialPresets[7] = new Material(bluePlastic, black, bluePlastic, bluePlasticSpec, 22);
    Color3f copper = new Color3f(0.30f, 0.10f, 0.00f);
    ;
    Color3f copperSpec = new Color3f(0.75f, 0.30f, 0.00f);
    materialPresets[8] = new Material(copper, black, copper, copperSpec, 10);
    Color3f gold = new Color3f(0.49f, 0.34f, 0.00f);
    Color3f goldSpec = new Color3f(0.89f, 0.79f, 0.00f);
    materialPresets[9] = new Material(gold, black, gold, goldSpec, 15);
    Color3f redAlloy = new Color3f(0.34f, 0.00f, 0.34f);
    Color3f redAlloySpec = new Color3f(0.84f, 0.00f, 0.00f);
    materialPresets[10] = new Material(redAlloy, black, redAlloy, redAlloySpec, 15);
    Color3f blackOnyxSpec = new Color3f(0.72f, 0.72f, 0.72f);
    materialPresets[11] = new Material(black, black, black, blackOnyxSpec, 23);

    // set up the editor
    materialEditor = new MaterialPresetEditor(material, materialNames, materialPresets);

    // Texture2D

    // 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(0.0f, 0.0f, 0.0f, 0.0f);

    // set up the image choices
    String[] texImageNames = { "Earth", "Fish", };
    String[] texImageFileNames = { "earth.jpg", "fish1.gif", };
    int texImageFileIndex = 0;

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

    // set up the editor (this will create the initial Texture2D and
    // assign it to the appearance)
    texture2DEditor = new Texture2DEditor(appearance, codeBaseString, texImageNames, texImageFileNames,
            texImageFileIndex, texEnable, texBoundaryModeS, texBoundaryModeT, texMinFilter, texMagFilter,
            texMipMapMode, texBoundaryColor);

    // TextureAttributes
    texMode = TextureAttributes.REPLACE;
    texBlendColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f);
    texTransform = new Transform3D();
    texPerspCorrect = TextureAttributes.NICEST;
    textureAttr = new TextureAttributes(texMode, texTransform, texBlendColor, texPerspCorrect);

    // set the capabilities to allow run time changes
    textureAttr.setCapability(TextureAttributes.ALLOW_MODE_WRITE);
    textureAttr.setCapability(TextureAttributes.ALLOW_BLEND_COLOR_WRITE);
    textureAttr.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE);

    // connect it to the appearance
    appearance.setTextureAttributes(textureAttr);

    // setup the editor
    textureAttrEditor = new TextureAttributesEditor(textureAttr);

    // set up the tex coordinate generation
    texGenEnable = false;
    texGenMode = TexCoordGeneration.OBJECT_LINEAR;
    texGenPlaneS = new Vector4f(1.0f, 0.0f, 0.0f, 0.0f);
    texGenPlaneT = new Vector4f(0.0f, 1.0f, 0.0f, 0.0f);

    // set the appearance so that we can replace the tex gen when live
    appearance.setCapability(Appearance.ALLOW_TEXGEN_WRITE);

    // setup the editor
    texGenEditor = new TexCoordGenerationEditor(appearance, texGenEnable, texGenMode, texGenPlaneS,
            texGenPlaneT);

}

From source file:KeyNavigateTest.java

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

    if (m_WaterAppearance == null) {
        m_WaterAppearance = new Appearance();
        m_WaterAppearance.setPolygonAttributes(
                new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false));
        m_WaterAppearance//w  w  w.  ja v a  2  s  .  co m
                .setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f));
        m_WaterAppearance.setTextureAttributes(new TextureAttributes(TextureAttributes.REPLACE,
                new Transform3D(), new Color4f(0, 0, 0, 1), TextureAttributes.FASTEST));

    }

    Land water = new Land(this, mapGroup, ComplexObject.GEOMETRY | ComplexObject.TEXTURE);
    water.createObject(m_WaterAppearance, new Vector3d(point.x, m_kFloorLevel + 0.1, point.z),
            new Vector3d(40, 1, 40), "water.gif", null, null);
}

From source file:BehaviorTest.java

public void processStimulus(java.util.Enumeration criteria) {
    while (criteria.hasMoreElements()) {
        WakeupCriterion wakeUp = (WakeupCriterion) criteria.nextElement();

        if (wakeUp instanceof WakeupOnElapsedTime) {
            // we are starting the explosion, apply the
            // appearance changes we require
            PolygonAttributes polyAttribs = new PolygonAttributes(PolygonAttributes.POLYGON_POINT,
                    PolygonAttributes.CULL_NONE, 0);
            m_Shape3D.getAppearance().setPolygonAttributes(polyAttribs);

            PointAttributes pointAttribs = new PointAttributes(3, false);
            m_Shape3D.getAppearance().setPointAttributes(pointAttribs);

            m_Shape3D.getAppearance().setTexture(null);

            m_TransparencyAttributes = new TransparencyAttributes(TransparencyAttributes.NICEST, 0);
            m_TransparencyAttributes.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
            m_Shape3D.getAppearance().setTransparencyAttributes(m_TransparencyAttributes);
        } else {/*from  w  w  w . java 2s  . co  m*/
            // we are mid explosion, modify the GeometryArray
            m_nFrameNumber++;

            m_GeometryArray.getCoordinates(0, m_CoordinateArray);

            m_TransparencyAttributes.setTransparency(((float) m_nFrameNumber) / ((float) m_nNumFrames));
            m_Shape3D.getAppearance().setTransparencyAttributes(m_TransparencyAttributes);

            for (int n = 0; n < m_CoordinateArray.length; n += 3) {
                m_Vector.x = m_CoordinateArray[n];
                m_Vector.y = m_CoordinateArray[n + 1];
                m_Vector.z = m_CoordinateArray[n + 2];

                m_Vector.normalize();

                m_CoordinateArray[n] += m_Vector.x * Math.random() + Math.random();
                m_CoordinateArray[n + 1] += m_Vector.y * Math.random() + Math.random();
                m_CoordinateArray[n + 2] += m_Vector.z * Math.random() + Math.random();
            }

            // assign the new coordinates
            m_GeometryArray.setCoordinates(0, m_CoordinateArray);
        }
    }

    if (m_nFrameNumber < m_nNumFrames) {
        // assign the next WakeUpCondition, so we are notified again
        wakeupOn(m_FrameWakeupCondition);
    } else {
        // we are at the end of the explosion
        // reapply the original appearance and GeometryArray
        // coordinates
        setEnable(false);
        m_Shape3D.setAppearance(m_Appearance);

        m_GeometryArray.setCoordinates(0, m_OriginalCoordinateArray);

        m_OriginalCoordinateArray = null;
        m_GeometryArray = null;
        m_CoordinateArray = null;
        m_TransparencyAttributes = null;

        // if we have a listener notify them that we are done
        if (m_Listener != null)
            wakeupOn(m_Listener.onExplosionFinished(this, m_Shape3D));
    }
}

From source file:KeyNavigateTest.java

protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile,
        String szSoundFile) {//  ww  w . j  a va 2s .  c o m
    Group g = new Group();

    app.setPolygonAttributes(
            new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false));
    app.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f));

    m_TextureAttributes = new TextureAttributes(TextureAttributes.REPLACE, new Transform3D(),
            new Color4f(0, 0, 0, 1), TextureAttributes.FASTEST);
    app.setTextureAttributes(m_TextureAttributes);

    if ((m_nFlags & ComplexObject.TEXTURE) == ComplexObject.TEXTURE)
        setTexture(app, szTextureFile);

    Cone cone = new Cone(1, 1, Primitive.GENERATE_TEXTURE_COORDS, app);

    g.addChild(cone);

    attachBehavior(new TextureAnimationBehavior(m_TextureAttributes));

    return g;
}

From source file:Demo3D.java

/**
 * Construction of the desired tetrahedron.
 * /*from   w  ww .j a v  a2 s .c  o m*/
 * @return javax.media.j3d.Shape3D myTetrahedron - the constructed
 *         tetrahedron
 */
public Shape3D myTetrahedron() {

    ////////////////////// Geometric part ///////////////////////////

    // The 4 vertices p0, p1, p2 and p3 of the tetrahedron.
    vertices = new Point3f[lengthVertices]; // 4
    vertices[0] = new Point3f(0.0f, 0.0f, 0.0f);
    vertices[1] = new Point3f(1.0f, 0.0f, 0.0f);
    vertices[2] = new Point3f(0.0f, 1.0f, 0.0f);
    vertices[3] = new Point3f(0.0f, 0.0f, 1.0f);

    // Scaling of vertices
    for (int i = 0; i < lengthVertices; i++)
        // lengthVertices = 4
        vertices[i].scale(scale_XYZ);

    // Set the face's indices for the tetrahedron (referenced to the array
    // of vertices
    // by setCoordinates(vertices) and
    // setCoordinateIndices(tetraFaceIndices)).
    tetraFaceIndices = new int[lengthTetraFaceIndices]; // 12
    // From the camera in the view coordinate system
    // bottom
    tetraFaceIndices[0] = 0;
    tetraFaceIndices[1] = 1;
    tetraFaceIndices[2] = 3;
    // back-left face
    tetraFaceIndices[3] = 0;
    tetraFaceIndices[4] = 3;
    tetraFaceIndices[5] = 2;
    // back face
    tetraFaceIndices[6] = 0;
    tetraFaceIndices[7] = 2;
    tetraFaceIndices[8] = 1;
    // front face
    tetraFaceIndices[9] = 1;
    tetraFaceIndices[10] = 2;
    tetraFaceIndices[11] = 3;

    // Create the GeometryInfo instance and set the vertices
    tetra_GeometryInfo = new GeometryInfo(GeometryInfo.TRIANGLE_ARRAY);
    tetra_GeometryInfo.setCoordinates(vertices);
    tetra_GeometryInfo.setCoordinateIndices(tetraFaceIndices);

    //      triangulator = new Triangulator(); // only for polygons:
    // POLYGON_ARRAY
    //      triangulator.triangulate(tetra_GeometryInfo); // and with: int
    // stripCounts[]
    //           gi.setStripCounts(...)
    //           int contourCounts[]

    // Set the parameters (1 texture with dimension 2) for the texture's
    // coordinates
    tetra_GeometryInfo.setTextureCoordinateParams(1, 2);

    //    case #1: each face of the tetrahedron has the same texture portion.

    // The coordinates of the 3 points in the 2D texture space.
    textCoord2f = new TexCoord2f[3];
    textCoord2f[0] = new TexCoord2f(0.0f, 0.2f);
    textCoord2f[1] = new TexCoord2f(0.5f, 1.0f);
    textCoord2f[2] = new TexCoord2f(1.0f, 0.5f);

    // Set the texture coordinate's indices (referenced to the array of 2D
    // points
    // in the texture space by setTextureCoordinates(0, textCoord2f) and
    // setTextureCoordinateIndices(0, textCoordIndices)).
    textCoordIndices = new int[lengthTetraFaceIndices]; // 12

    // From the camera in the view coordinate system (inverse of
    // tetraFaceIndices !!!)
    // front face
    textCoordIndices[0] = 0;
    textCoordIndices[1] = 1;
    textCoordIndices[2] = 2;
    // back face
    textCoordIndices[3] = 0;
    textCoordIndices[4] = 1;
    textCoordIndices[5] = 2;
    // back-left face
    textCoordIndices[6] = 2;
    textCoordIndices[7] = 0;
    textCoordIndices[8] = 1;
    // bottom
    textCoordIndices[9] = 0;
    textCoordIndices[10] = 1;
    textCoordIndices[11] = 2;

    /*
     * // case #2: each face of the tetrahedron has a different part of the
     * texture.
     *  // The coordinates of the 4 points in the 2D texture space.
     * textCoord2f = new TexCoord2f[4]; textCoord2f[0] = new
     * TexCoord2f(0.0f, 0.5f); textCoord2f[1] = new TexCoord2f(1.0f, 0.5f);
     * textCoord2f[2] = new TexCoord2f(0.6f, 0.7f); textCoord2f[3] = new
     * TexCoord2f(0.6f, 0.3f);
     * 
     *  // Set the texture coordinate's indices (referenced to the array of
     * 2D points // in the texture space by setTextureCoordinates(0,
     * textCoord2f) and // setTextureCoordinateIndices(0,
     * textCoordIndices)). textCoordIndices = new
     * int[lengthTetraFaceIndices]; // 12
     *  // From the camera in the view coordinate system (inverse of
     * tetraFaceIndices !!!) // front face textCoordIndices[0] = 3;
     * textCoordIndices[1] = 2; textCoordIndices[2] = 0; // back face
     * textCoordIndices[3] = 1; textCoordIndices[4] = 2; textCoordIndices[5] =
     * 3; // back-left face textCoordIndices[6] = 1; textCoordIndices[7] =
     * 0; textCoordIndices[8] = 2; // bottom textCoordIndices[9] = 1;
     * textCoordIndices[10]= 3; textCoordIndices[11]= 0;
     */
    // just one set
    tetra_GeometryInfo.setTextureCoordinates(0, textCoord2f);
    // just one set
    tetra_GeometryInfo.setTextureCoordinateIndices(0, textCoordIndices);

    normalGenerator = new NormalGenerator();
    normalGenerator.generateNormals(tetra_GeometryInfo);

    if (crAngle)
        normalGenerator.setCreaseAngle(0.0f); // with 0 radian ===> creased

    stripifier = new Stripifier();
    stripifier.stripify(tetra_GeometryInfo);

    tetra_GeometryArray = tetra_GeometryInfo.getGeometryArray();

    // The geonometry is passed to the instance this of the tetrahedron.
    this.setGeometry(tetra_GeometryArray);

    ////////////////////// Appearance part ///////////////////////////

    appearance = new Appearance();

    // Optical properties of the tetrahedron.

    // Ambient-diffuse-reflection coefficient
    diffAmb = new Color3f(1.0f, 0.5f, 1.0f);
    // Diffuse-reflection coefficient
    reflDiff = new Color3f(1.0f, 0.5f, 1.0f);
    // Specular-reflection coefficient (reflectance function)
    reflSpec = new Color3f(1.0f, 0.5f, 1.0f);
    // c = shininess: cos^c in the specular reflection
    float c = 15;
    // Emitted light
    emittedLight = new Color3f(0.0f, 0.0f, 0.0f);

    material = new Material(diffAmb, emittedLight, reflDiff, reflSpec, c);
    appearance.setMaterial(material);

    // This instance acts only on the tetrahedron and not on its texture.
    trAttr = new TransparencyAttributes(TransparencyAttributes.NICEST, 0.0f);
    // 0.0 = fully opaque
    // 1.0 = fully transparent
    appearance.setTransparencyAttributes(trAttr);

    // Loading the texture
    newTextureLoader = new NewTextureLoader("Images/Claude.jpg");
    newTextureLoader.setImageObserver(newTextureLoader.getImageObserver());

    texture = newTextureLoader.getTexture();

    appearance.setTexture(texture);

    // Application mode of the texture
    textAttr = new TextureAttributes();
    textAttr.setTextureMode(TextureAttributes.MODULATE); // there still are:
    // BLEND, COMBINE,
    // DECAL, and REPLACE
    appearance.setTextureAttributes(textAttr);

    // The appearance is passed to the instance this of the tetrahedron.
    this.setAppearance(appearance);

    return this;
}