List of usage examples for javax.media.j3d PointArray setColor
public void setColor(int index, float color[])
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 www .j a va2 s .c o 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:PointTest.java
private BranchGroup createPoints(final int nPointSize, final int nNumPoints, boolean bAliased) { BranchGroup bg = new BranchGroup(); String szText = new String(); szText += (nNumPoints + "X, Size:" + nPointSize + ", aliased: " + bAliased); Font3D f3d = new Font3D(new Font("SansSerif", Font.PLAIN, 1), new FontExtrusion()); Text3D label3D = new Text3D(f3d, szText, new Point3f(-5, 0, 0)); Shape3D sh = new Shape3D(label3D); bg.addChild(sh);/*from ww w . j a v a 2s . co m*/ PointArray pointArray = new PointArray(nNumPoints * nNumPoints, GeometryArray.COORDINATES | GeometryArray.COLOR_3); // create the PointArray that we will be rendering int nPoint = 0; final double factor = 1.0 / nNumPoints; for (int n = 0; n < nNumPoints; n++) { for (int i = 0; i < nNumPoints; i++) { Point3f point = new Point3f(n - nNumPoints / 2, i - nNumPoints / 2, 0.0f); pointArray.setCoordinate(nPoint, point); pointArray.setColor(nPoint++, new Color3f(0.5f, (float) (n * factor), (float) (i * factor))); } } // create the material for the points Appearance pointApp = new Appearance(); // enlarge the points pointApp.setPointAttributes(new PointAttributes(nPointSize, bAliased)); Shape3D pointShape = new Shape3D(pointArray, pointApp); bg.addChild(pointShape); return bg; }