Example usage for javax.media.j3d LineArray setColor

List of usage examples for javax.media.j3d LineArray setColor

Introduction

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

Prototype

public void setColor(int index, float color[]) 

Source Link

Document

Sets the color associated with the vertex at the specified index for this object.

Usage

From source file:edu.uci.ics.jung.visualization3d.PluggableRenderContext.java

public PluggableRenderContext() {
    super();//from  w  w w .  j a  v a 2  s.  c  o m
    Color3f lightGray = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f black = new Color3f(0, 0, 0);
    Color3f white = new Color3f(1, 1, 1);
    Color3f gray = new Color3f(.2f, .2f, .2f);
    Color3f red = new Color3f(1, 0, 0);
    Color3f yellow = new Color3f(0, 1, 1);
    Material lightGrayMaterial = new Material(lightGray, black, lightGray, white, 100.0f);
    Material blackMaterial = new Material(lightGray, black, black, lightGray, 10.0f);
    Material whiteMaterial = new Material(white, white, white, white, 100.0f);
    Material grayMaterial = new Material(gray, black, gray, gray, 100.0f);
    Material redMaterial = new Material(red, black, red, red, 100.0f);
    Material yellowMaterial = new Material(yellow, black, yellow, yellow, 100.0f);

    final Appearance lightGrayLook = new Appearance();
    lightGrayLook.setMaterial(lightGrayMaterial);
    Appearance blackLook = new Appearance();
    blackLook.setMaterial(blackMaterial);
    Appearance whiteLook = new Appearance();
    whiteLook.setMaterial(whiteMaterial);
    Appearance grayLook = new Appearance();
    grayLook.setMaterial(grayMaterial);

    //      grayLook.setCapability(Appearance.ALLOW_MATERIAL_READ);
    //      grayLook.setCapability(Appearance.ALLOW_MATERIAL_WRITE);

    final Appearance redLook = new Appearance();
    redLook.setMaterial(redMaterial);
    final Appearance yellowLook = new Appearance();
    yellowLook.setMaterial(yellowMaterial);

    final Cylinder cylinder = new Cylinder(1, 1, Cylinder.GENERATE_NORMALS | Cylinder.ENABLE_GEOMETRY_PICKING,
            26, 26, lightGrayLook);
    final Sphere sphere = new Sphere(10, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, redLook);
    final Box box = new Box(10, 10, 10, Box.GENERATE_NORMALS | Box.ENABLE_GEOMETRY_PICKING, redLook);

    this.edgeAppearanceTransformer = new ConstantTransformer(lightGrayLook);
    this.edgeShapeTransformer = new Transformer<Context<Graph<V, E>, E>, Node>() {

        public Node transform(Context<Graph<V, E>, E> ec) {
            LineArray lineArray = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3);
            lineArray.setCoordinates(0, new Point3f[] { new Point3f(0, -.5f, 0), new Point3f(0, .5f, 0) });
            lineArray.setColor(0, new Color3f(1, 1, 1));
            lineArray.setColor(1, new Color3f(1, 1, 1));
            Shape3D shape = new Shape3D();
            shape.setGeometry(lineArray);
            return shape;
            //            return new Cylinder(1, 1, 
            //                  Cylinder.GENERATE_NORMALS |
            //                  Cylinder.ENABLE_GEOMETRY_PICKING,
            //                   26, 26, lightGrayLook);
        }
    };
    this.vertexAppearanceTransformer = new ConstantTransformer(redLook);
    this.vertexShapeTransformer = new Transformer<V, Node>() {

        public Node transform(V arg0) {
            return new Sphere(10,
                    Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING | Sphere.ENABLE_APPEARANCE_MODIFY,
                    redLook);
        }
    };
}

From source file:KeyNavigatorApp.java

Shape3D createLand() {
    LineArray landGeom = new LineArray(44, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
    float l = -50.0f;
    for (int c = 0; c < 44; c += 4) {

        landGeom.setCoordinate(c + 0, new Point3f(-50.0f, 0.0f, l));
        landGeom.setCoordinate(c + 1, new Point3f(50.0f, 0.0f, l));
        landGeom.setCoordinate(c + 2, new Point3f(l, 0.0f, -50.0f));
        landGeom.setCoordinate(c + 3, new Point3f(l, 0.0f, 50.0f));
        l += 10.0f;//from  w w  w .  j  av a  2 s.c  o  m
    }

    Color3f c = new Color3f(0.1f, 0.8f, 0.1f);
    for (int i = 0; i < 44; i++)
        landGeom.setColor(i, c);

    return new Shape3D(landGeom);
}

From source file:ffx.potential.MolecularAssembly.java

private Shape3D renderWire() {
    ArrayList<ROLS> bonds = getBondList();
    int numbonds = bonds.size();
    if (numbonds < 1) {
        return null;
    }//from  ww w . j  a v a 2  s  .c  om

    Vector3d bondmidpoint = new Vector3d();
    double[] mid = { 0, 0, 0 };
    Vector3d v1 = new Vector3d();
    Vector3d v2 = new Vector3d();
    float[] a1 = { 0, 0, 0 };
    float[] a2 = { 0, 0, 0 };
    float[] col = new float[4];
    Bond bond;

    Atom atom1, atom2;
    LineArray la = new LineArray(4 * numbonds,
            GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS);
    la.setCapability(LineArray.ALLOW_COORDINATE_WRITE);
    la.setCapability(LineArray.ALLOW_COORDINATE_READ);
    la.setCapability(LineArray.ALLOW_COLOR_WRITE);
    la.setCapability(LineArray.ALLOW_COUNT_READ);
    la.setCapability(LineArray.ALLOW_INTERSECT);
    la.setCapability(LineArray.ALLOW_FORMAT_READ);
    atomLookUp = new Atom[4 * numbonds];
    int i = 0;
    col[3] = 0.9f;
    for (ListIterator li = bonds.listIterator(); li.hasNext();) {
        bond = (Bond) li.next();
        bond.setWire(la, i);
        atom1 = bond.getAtom(0);
        atom2 = bond.getAtom(1);
        atom1.getV3D(v1);
        atom2.getV3D(v2);
        a1[0] = (float) v1.x;
        a1[1] = (float) v1.y;
        a1[2] = (float) v1.z;
        a2[0] = (float) v2.x;
        a2[1] = (float) v2.y;
        a2[2] = (float) v2.z;
        // Find the bond center
        bondmidpoint.add(v1, v2);
        bondmidpoint.scale(0.5d);
        bondmidpoint.get(mid);
        // Atom #1
        Atom.AtomColor.get(atom1.getAtomicNumber()).get(col);
        atomLookUp[i] = atom1;
        la.setCoordinate(i, a1);
        la.setColor(i, col);
        la.setNormal(i, a2);
        i++;

        atomLookUp[i] = atom1;
        la.setCoordinate(i, mid);
        la.setColor(i, col);
        la.setNormal(i, a2);
        i++;
        // Atom #2

        Atom.AtomColor.get(atom2.getAtomicNumber()).get(col);
        atomLookUp[i] = atom2;
        la.setCoordinate(i, a2);
        la.setColor(i, col);
        la.setNormal(i, a1);
        i++;

        atomLookUp[i] = atom2;
        la.setCoordinate(i, mid);
        la.setColor(i, col);
        la.setNormal(i, a1);
        i++;

    }

    ColoringAttributes cola = new ColoringAttributes(new Color3f(), ColoringAttributes.SHADE_GOURAUD);
    Appearance app = new Appearance();
    lineAttributes = new LineAttributes();
    lineAttributes.setLineWidth(RendererCache.bondwidth);
    lineAttributes.setCapability(LineAttributes.ALLOW_WIDTH_WRITE);
    lineAttributes.setLineAntialiasingEnable(true);
    app.setLineAttributes(lineAttributes);
    app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);
    app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
    RenderingAttributes ra = new RenderingAttributes();
    ra.setAlphaTestValue(0.1f);
    ra.setAlphaTestFunction(RenderingAttributes.GREATER);
    ra.setDepthBufferEnable(true);
    ra.setDepthBufferWriteEnable(true);
    app.setRenderingAttributes(ra);
    app.setColoringAttributes(cola);
    Shape3D wireframe = new Shape3D(la, app);
    // PickTool.setCapabilities(wire, PickTool.INTERSECT_COORD);
    wireframe.setUserData(this);
    wireframe.setBounds(new BoundingSphere(new Point3d(0, 0, 0), 1000.0));
    try {
        wireframe.setBoundsAutoCompute(false);
    } catch (Exception e) {
        e.printStackTrace();
    }

    wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    wireframe.setCapability(Shape3D.ALLOW_LOCAL_TO_VWORLD_READ);
    return wireframe;
}