List of usage examples for javax.media.j3d GeometryArray setCoordinates
public void setCoordinates(int index, Point3d coordinates[])
From source file:CuboidTest.java
private GeometryArray processTriangles() { GeometryArray obj = null; int i;//w w w . ja v a 2 s. com int totalVerts = 0; for (i = 0; i < currPrimCnt; i++) { totalVerts += currPrimEndVertex[i] - currPrimStartVertex[i]; } if (debug >= 1) System.out.println("totalVerts " + totalVerts); if (((flags & GENERATE_NORMALS) != 0) && ((flags & GENERATE_TEXTURE_COORDS) != 0)) { obj = new TriangleArray(totalVerts, TriangleArray.COORDINATES | TriangleArray.NORMALS | TriangleArray.TEXTURE_COORDINATE_2); } else if (((flags & GENERATE_NORMALS) == 0) && ((flags & GENERATE_TEXTURE_COORDS) != 0)) { obj = new TriangleArray(totalVerts, TriangleArray.COORDINATES | TriangleArray.TEXTURE_COORDINATE_2); } else if (((flags & GENERATE_NORMALS) != 0) && ((flags & GENERATE_TEXTURE_COORDS) == 0)) { obj = new TriangleArray(totalVerts, TriangleArray.COORDINATES | TriangleArray.NORMALS); } else { obj = new TriangleArray(totalVerts, TriangleArray.COORDINATES); } Point3f[] newpts = new Point3f[totalVerts]; Vector3f[] newnormals = new Vector3f[totalVerts]; TexCoord2f[] newtcoords = new TexCoord2f[totalVerts]; int currVert = 0; for (i = 0; i < currPrimCnt; i++) { for (int j = currPrimStartVertex[i]; j < currPrimEndVertex[i] - 2; j += 3) { outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j); outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j + 1); outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j + 2); numTris += 1; } } numVerts = currVert; obj.setCoordinates(0, newpts); if ((flags & GENERATE_NORMALS) != 0) obj.setNormals(0, newnormals); if ((flags & GENERATE_TEXTURE_COORDS) != 0) obj.setTextureCoordinates(0, 0, newtcoords); geometry = obj; return obj; }
From source file:CuboidTest.java
private GeometryArray processQuadStrips() { GeometryArray obj = null; int i;/*from w w w. j a va2 s .c o m*/ int totalVerts = 0; for (i = 0; i < currPrimCnt; i++) { int numQuadStripVerts; numQuadStripVerts = currPrimEndVertex[i] - currPrimStartVertex[i]; totalVerts += (numQuadStripVerts / 2 - 1) * 4; } if (debug >= 1) System.out.println("totalVerts " + totalVerts); if (((flags & GENERATE_NORMALS) != 0) && ((flags & GENERATE_TEXTURE_COORDS) != 0)) { obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2); } else if (((flags & GENERATE_NORMALS) == 0) && ((flags & GENERATE_TEXTURE_COORDS) != 0)) { obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2); } else if (((flags & GENERATE_NORMALS) != 0) && ((flags & GENERATE_TEXTURE_COORDS) == 0)) { obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.NORMALS); } else { obj = new QuadArray(totalVerts, QuadArray.COORDINATES); } Point3f[] newpts = new Point3f[totalVerts]; Vector3f[] newnormals = new Vector3f[totalVerts]; TexCoord2f[] newtcoords = new TexCoord2f[totalVerts]; int currVert = 0; for (i = 0; i < currPrimCnt; i++) { for (int j = currPrimStartVertex[i] + 2; j < currPrimEndVertex[i]; j += 2) { outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j - 2); outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j - 1); outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j + 1); outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j); numTris += 2; } } numVerts = currVert; obj.setCoordinates(0, newpts); if ((flags & GENERATE_NORMALS) != 0) obj.setNormals(0, newnormals); if ((flags & GENERATE_TEXTURE_COORDS) != 0) obj.setTextureCoordinates(0, 0, newtcoords); geometry = obj; return obj; }
From source file:CuboidTest.java
private GeometryArray processQuads() { GeometryArray obj = null; int i;/*from www .j ava2s .c o m*/ int totalVerts = 0; for (i = 0; i < currPrimCnt; i++) { totalVerts += currPrimEndVertex[i] - currPrimStartVertex[i]; } if (debug >= 1) System.out.println("totalVerts " + totalVerts); if (((flags & GENERATE_NORMALS) != 0) && ((flags & GENERATE_TEXTURE_COORDS) != 0)) { obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2); } else if (((flags & GENERATE_NORMALS) == 0) && ((flags & GENERATE_TEXTURE_COORDS) != 0)) { obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2); } else if (((flags & GENERATE_NORMALS) != 0) && ((flags & GENERATE_TEXTURE_COORDS) == 0)) { obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.NORMALS); } else { obj = new QuadArray(totalVerts, QuadArray.COORDINATES); } Point3f[] newpts = new Point3f[totalVerts]; Vector3f[] newnormals = new Vector3f[totalVerts]; TexCoord2f[] newtcoords = new TexCoord2f[totalVerts]; int currVert = 0; if (debug > 1) System.out.println("total prims " + currPrimCnt); for (i = 0; i < currPrimCnt; i++) { if (debug > 1) System.out.println("start " + currPrimStartVertex[i] + " end " + currPrimEndVertex[i]); for (int j = currPrimStartVertex[i]; j < currPrimEndVertex[i] - 3; j += 4) { outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j); outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j + 1); outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j + 2); outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j + 3); numTris += 2; } } numVerts = currVert; obj.setCoordinates(0, newpts); if ((flags & GENERATE_NORMALS) != 0) obj.setNormals(0, newnormals); if ((flags & GENERATE_TEXTURE_COORDS) != 0) obj.setTextureCoordinates(0, 0, newtcoords); geometry = obj; return obj; }
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);/*from w ww.ja v a 2 s .co 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; }