Example usage for javax.media.j3d LineArray setColors

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

Introduction

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

Prototype

public void setColors(int index, float colors[]) 

Source Link

Document

Sets the colors associated with the vertices starting at the specified index for this object.

Usage

From source file:IntersectTest.java

public BranchGroup createSceneGraph() {

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

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);/*from ww  w.j  av  a  2s  .  co  m*/

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f);
    Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    Transform3D t3 = new Transform3D();

    // Shapes
    for (int x = 0; x < 3; x++) {
        for (int y = 0; y < 3; y++) {
            for (int z = 0; z < 3; z++) {
                t3.setTranslation(new Vector3d(-4 + x * 4.0, -4 + y * 4.0, -20 - z * 4.0));
                TransformGroup objTrans = new TransformGroup(t3);

                objRoot.addChild(objTrans);

                // Create a simple shape leaf node, add it to the scene
                // graph.
                GeometryArray geom = null;

                if (((x + y + z) % 2) == 0) {
                    geom = new RandomColorCube();
                } else {
                    geom = new RandomColorTetrahedron();
                }

                Shape3D shape = new Shape3D(geom);

                // use the utility method to set the capabilities
                PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);

                objTrans.addChild(shape);
            }
        }
    }

    // Lines
    Point3f[] verts = { new Point3f(-2.0f, 0.0f, 0.0f), new Point3f(2.0f, 0.0f, 0.0f) };
    Color3f grey = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f[] colors = { grey, grey };

    for (int y = 0; y < 5; y++) {
        for (int z = 0; z < 5; z++) {
            t3.setTranslation(new Vector3d(7.0, -4 + y * 2.0, -20.0 - z * 2.0));
            TransformGroup objTrans = new TransformGroup(t3);

            objRoot.addChild(objTrans);

            LineArray la = new LineArray(verts.length, LineArray.COORDINATES | LineArray.COLOR_3);
            la.setCoordinates(0, verts);
            la.setColors(0, colors);

            Shape3D shape = new Shape3D();
            shape.setGeometry(la);

            // use the utility method to set the capabilities
            PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);

            objTrans.addChild(shape);
        }
    }

    // Points
    for (double x = -2.0; x <= 2.0; x += 1.0) {
        for (double y = -2.0; y <= 2.0; y += 1.0) {
            for (double z = -2.0; z <= 2.0; z += 1.0) {
                t3.setTranslation(new Vector3d(-10.0 + 2.0 * x, 0.0 + 2.0 * y, -20.0 + 2.0 * z));
                TransformGroup objTrans = new TransformGroup(t3);

                objRoot.addChild(objTrans);

                PointArray pa = new PointArray(1, PointArray.COORDINATES | PointArray.COLOR_3);

                pa.setCoordinate(0, new Point3d(0.0, 0.0, 0.0));
                pa.setColor(0, grey);

                Shape3D shape = new Shape3D();
                shape.setGeometry(pa);

                // use the utility method to set the capabilities
                PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);

                objTrans.addChild(shape);
            }
        }
    }

    return objRoot;
}

From source file:AppearanceExplorer.java

Shape3D createLineArray() {

    Point3f pnt[] = new Point3f[4];
    pnt[0] = new Point3f(-1.0f, -1.0f, 0.0f);
    pnt[1] = new Point3f(1.0f, -1.0f, 0.0f);
    pnt[2] = new Point3f(1.0f, 1.0f, 0.0f);
    pnt[3] = new Point3f(-1.0f, 1.0f, 0.0f);
    Color3f colrs[] = new Color3f[4];
    colrs[0] = black;/*ww  w  .j av  a 2 s. c  om*/
    colrs[1] = white;
    colrs[2] = red;
    colrs[3] = green;

    LineArray la = new LineArray(4, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
    la.setCoordinates(0, pnt);
    la.setColors(0, colrs);

    return new Shape3D(la, appearance);
}