Example usage for javax.media.j3d GeometryArray COLOR_4

List of usage examples for javax.media.j3d GeometryArray COLOR_4

Introduction

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

Prototype

int COLOR_4

To view the source code for javax.media.j3d GeometryArray COLOR_4.

Click Source Link

Document

Specifies that this GeometryArray contains an array of colors with alpha.

Usage

From source file:BoundsTest.java

protected Group createPoints() {
    Group group = new Group();

    final int kNumPoints = 200;
    final double kRadius = 10.0;
    Point3d points[] = new Point3d[kNumPoints];

    for (int n = 0; n < kNumPoints; n++) {
        double randX = (java.lang.Math.random() * kRadius) - kRadius / 2;
        double randY = (java.lang.Math.random() * kRadius) - kRadius / 2;
        double randZ = (java.lang.Math.random() * kRadius) - kRadius / 2;

        points[n] = new Point3d(randX, randY, randZ);
    }/*  www .  j  a  v a 2 s  .  c om*/

    PointArray pointArray = new PointArray(points.length, GeometryArray.COLOR_4 | GeometryArray.COORDINATES);
    pointArray.setCoordinates(0, points);
    Shape3D shapePoints = new Shape3D(pointArray, new Appearance());

    group.addChild(shapePoints);
    return group;
}

From source file:AppearanceTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    TransformGroup zoomTg = new TransformGroup();
    zoomTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    zoomTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // attach a navigation behavior to the position of the viewer
    KeyNavigatorBehavior key = new KeyNavigatorBehavior(zoomTg);
    key.setSchedulingBounds(createApplicationBounds());
    key.setEnable(true);// w w  w  .j av a  2  s  . c o  m
    objRoot.addChild(key);

    // create a TransformGroup to flip the hand onto its end and enlarge it.
    TransformGroup objTrans1 = new TransformGroup();
    Transform3D tr = new Transform3D();
    objTrans1.getTransform(tr);
    tr.setEuler(new Vector3d(0.5 * Math.PI, 0.6, 0));
    objTrans1.setTransform(tr);

    // 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(getApplicationBounds());
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(getApplicationBounds());

    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    int nScale = 50;

    Box box = new Box(nScale, nScale, nScale, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS,
            m_Appearance);

    Shape3D frontFace = box.getShape(Box.LEFT);

    // create a new left face so we can
    // assign per-vertex colors

    GeometryArray geometry = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.NORMALS
            | GeometryArray.COLOR_4 | GeometryArray.TEXTURE_COORDINATE_2);

    nScale = 40;

    final float[] verts = {
            // left face
            -1.0f * nScale, -1.0f * nScale, 1.0f * nScale, -1.0f * nScale, 1.0f * nScale, 1.0f * nScale,
            -1.0f * nScale, 1.0f * nScale, -1.0f * nScale, -1.0f * nScale, -1.0f * nScale, -1.0f * nScale };

    final float[] colors = {
            // left face
            1, 0, 0, 0, 0, 1, 0, 0.2f, 0, 0, 1, 0.8f, 0, 0, 0, 1, };

    float[] tcoords = {
            // left
            1, 0, 1, 1, 0, 1, 0, 0 };

    Vector3f normalVector = new Vector3f(-1.0f, 0.0f, 0.0f);

    geometry.setColors(0, colors, 0, 4);

    for (int n = 0; n < 4; n++)
        geometry.setNormal(n, normalVector);

    geometry.setTextureCoordinates(0, tcoords, 0, 4);

    geometry.setCoordinates(0, verts);

    frontFace.setGeometry(geometry);

    // connect the scenegraph
    objTrans1.addChild(box);
    zoomTg.addChild(objTrans1);
    objRoot.addChild(zoomTg);

    return objRoot;
}

From source file:J3dSwingFrame.java

private void constructGeometry() {
    int flags = GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS;

    geom = new IndexedQuadArray(4, flags, 4);

    double[] coordinates = { 0.5, 0.5, 0, 0.5, -0.5, 0, -0.5, -0.5, 0, -0.5, 0.5, 0 };

    int[] indices = { 0, 1, 2, 3 };

    geom.setCoordinates(0, coordinates);
    geom.setCoordinateIndices(0, indices);

    float[] colors = { 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0 };

    geom.setColors(0, colors);//from w ww. j a  v  a  2s .  c om
    geom.setColorIndices(0, indices);

    float[] normal = { 0, 0, 1 };

    geom.setNormal(0, normal);
    geom.setNormal(1, normal);
    geom.setNormal(2, normal);
    geom.setNormal(3, normal);

    setGeometry(geom);
}

From source file:ffx.potential.MolecularAssembly.java

/**
 * <p>/* w ww. j a  va  2  s.c  o  m*/
 * createBox</p>
 */
public void createBox() {
    int vertices = 8;
    LineArray la = new LineArray(4 * vertices,
            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);
    // Create a normal
    // for (ListIterator li = bondlist.listIterator(); li.hasNext(); ){
    // la.setCoordinate(i, a1);
    // la.setColor(i, col);
    // la.setNormal(i++, a1);
    // }
    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), 10.0));
    try {
        wireframe.setBoundsAutoCompute(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    // return wire;
}

From source file:IntersectTest.java

public void processStimulus(Enumeration criteria) {
    WakeupCriterion wakeup;//  w ww.  j  av  a 2s.  c  o  m
    AWTEvent[] event;
    int eventId;

    while (criteria.hasMoreElements()) {
        wakeup = (WakeupCriterion) criteria.nextElement();
        if (wakeup instanceof WakeupOnAWTEvent) {
            event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
            for (int i = 0; i < event.length; i++) {
                eventId = event[i].getID();
                if (eventId == MouseEvent.MOUSE_PRESSED) {
                    int x = ((MouseEvent) event[i]).getX();
                    int y = ((MouseEvent) event[i]).getY();
                    pickCanvas.setShapeLocation(x, y);

                    Point3d eyePos = pickCanvas.getStartPosition();
                    pickResult = pickCanvas.pickAllSorted();
                    // Use this to do picking benchmarks
                    /*
                     * long start = System.currentTimeMillis(); for (int
                     * l=0;l <3;l++) { if (l == 0) System.out.print
                     * ("BOUNDS: "); if (l == 1) System.out.print
                     * ("GEOMETRY: "); if (l == 2) System.out.print
                     * ("GEOMETRY_INTERSECT_INFO: ");
                     * 
                     * for (int k=0;k <1000;k++) { if (l == 0) {
                     * pickCanvas.setMode(PickTool.BOUNDS); pickResult =
                     * pickCanvas.pickAllSorted(); } if (l == 1) {
                     * pickCanvas.setMode(PickTool.GEOMETRY); pickResult =
                     * pickCanvas.pickAllSorted(); } if (l == 2) {
                     * pickCanvas.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
                     * pickResult = pickCanvas.pickAllSorted(); } } long
                     * delta = System.currentTimeMillis() - start;
                     * System.out.println ("\t"+delta+" ms / 1000 picks"); }
                     */
                    if (pickResult != null) {

                        // Get closest intersection results
                        PickIntersection pi = pickResult[0].getClosestIntersection(eyePos);

                        GeometryArray curGeomArray = pi.getGeometryArray();

                        // Position sphere at intersection point
                        Vector3d v = new Vector3d();
                        Point3d intPt = pi.getPointCoordinatesVW();
                        v.set(intPt);
                        spht3.setTranslation(v);
                        sphTrans[0].setTransform(spht3);

                        // Position sphere at closest vertex
                        Point3d closestVert = pi.getClosestVertexCoordinatesVW();
                        v.set(closestVert);
                        spht3.setTranslation(v);
                        sphTrans[1].setTransform(spht3);

                        Point3d[] ptw = pi.getPrimitiveCoordinatesVW();
                        Point3d[] pt = pi.getPrimitiveCoordinates();
                        int[] coordidx = pi.getPrimitiveCoordinateIndices();
                        Point3d ptcoord = new Point3d();
                        for (int k = 0; k < pt.length; k++) {
                            v.set(ptw[k]);
                            spht3.setTranslation(v);
                            sphTrans[k + 2].setTransform(spht3);
                        }

                        // Get interpolated color (if available)
                        Color4f iColor4 = null;
                        Color3f iColor = null;
                        Vector3f iNormal = null;

                        if (curGeomArray != null) {
                            int vf = curGeomArray.getVertexFormat();

                            if (((vf & (GeometryArray.COLOR_3 | GeometryArray.COLOR_4)) != 0)
                                    && (null != (iColor4 = pi.getPointColor()))) {
                                iColor = new Color3f(iColor4.x, iColor4.y, iColor4.z);

                                // Change the point's color
                                redlook.setMaterial(new Material(iColor, new Color3f(0.0f, 0.0f, 0.0f), iColor,
                                        new Color3f(1.0f, 1.0f, 1.0f), 50.0f));
                            }
                            if (((vf & GeometryArray.NORMALS) != 0)
                                    && (null != (iNormal = pi.getPointNormal()))) {
                                System.out.println("Interpolated normal: " + iNormal);
                            }
                        }

                        System.out.println("=============");
                        System.out.println("Coordinates of intersection pt:" + intPt);
                        System.out.println("Coordinates of vertices: ");
                        for (int k = 0; k < pt.length; k++) {
                            System.out.println(k + ":" + ptw[k].x + " " + ptw[k].y + " " + ptw[k].z);
                        }
                        System.out.println("Closest vertex: " + closestVert);
                        if (iColor != null) {
                            System.out.println("Interpolated color: " + iColor);
                        }
                        if (iNormal != null) {
                            System.out.println("Interpolated normal: " + iNormal);
                        }
                    }
                }
            }
        }
    }
    wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED));
}

From source file:ffx.potential.MolecularAssembly.java

private Shape3D renderWire() {
    ArrayList<ROLS> bonds = getBondList();
    int numbonds = bonds.size();
    if (numbonds < 1) {
        return null;
    }//  ww  w .j a va2  s  .co m

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