List of usage examples for javax.media.j3d GeometryArray TEXTURE_COORDINATE_2
int TEXTURE_COORDINATE_2
To view the source code for javax.media.j3d GeometryArray TEXTURE_COORDINATE_2.
Click Source Link
From source file:ExLinearFog.java
private void addBox(float width, float height, float depth, float y, float width2, float depth2, int flags) { float[] coordinates = { // around the bottom -width / 2.0f, -height / 2.0f, depth / 2.0f, width / 2.0f, -height / 2.0f, depth / 2.0f, width / 2.0f, -height / 2.0f, -depth / 2.0f, -width / 2.0f, -height / 2.0f, -depth / 2.0f, // around the top -width2 / 2.0f, height / 2.0f, depth2 / 2.0f, width2 / 2.0f, height / 2.0f, depth2 / 2.0f, width2 / 2.0f, height / 2.0f, -depth2 / 2.0f, -width2 / 2.0f, height / 2.0f, -depth2 / 2.0f, }; int[] fullCoordinateIndexes = { 0, 1, 5, 4, // front 1, 2, 6, 5, // right 2, 3, 7, 6, // back 3, 0, 4, 7, // left 4, 5, 6, 7, // top 3, 2, 1, 0, // bottom };/*from ww w. j a v a2 s .c om*/ float v = -(width2 - width) / height; float[] normals = { 0.0f, v, 1.0f, // front 1.0f, v, 0.0f, // right 0.0f, v, -1.0f, // back -1.0f, v, 0.0f, // left 0.0f, 1.0f, 0.0f, // top 0.0f, -1.0f, 0.0f, // bottom }; int[] fullNormalIndexes = { 0, 0, 0, 0, // front 1, 1, 1, 1, // right 2, 2, 2, 2, // back 3, 3, 3, 3, // left 4, 4, 4, 4, // top 5, 5, 5, 5, // bottom }; float[] textureCoordinates = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, }; int[] fullTextureCoordinateIndexes = { 0, 1, 2, 3, // front 0, 1, 2, 3, // right 0, 1, 2, 3, // back 0, 1, 2, 3, // left 0, 1, 2, 3, // top 0, 1, 2, 3, // bottom }; // Select indexes needed int[] coordinateIndexes; int[] normalIndexes; int[] textureCoordinateIndexes; if (flags == 0) { // build neither top or bottom coordinateIndexes = new int[4 * 4]; textureCoordinateIndexes = new int[4 * 4]; normalIndexes = new int[4 * 4]; for (int i = 0; i < 4 * 4; i++) { coordinateIndexes[i] = fullCoordinateIndexes[i]; textureCoordinateIndexes[i] = fullTextureCoordinateIndexes[i]; normalIndexes[i] = fullNormalIndexes[i]; } } else if ((flags & (BUILD_TOP | BUILD_BOTTOM)) == (BUILD_TOP | BUILD_BOTTOM)) { // build top and bottom coordinateIndexes = fullCoordinateIndexes; textureCoordinateIndexes = fullTextureCoordinateIndexes; normalIndexes = fullNormalIndexes; } else if ((flags & BUILD_TOP) != 0) { // build top but not bottom coordinateIndexes = new int[5 * 4]; textureCoordinateIndexes = new int[5 * 4]; normalIndexes = new int[5 * 4]; for (int i = 0; i < 5 * 4; i++) { coordinateIndexes[i] = fullCoordinateIndexes[i]; textureCoordinateIndexes[i] = fullTextureCoordinateIndexes[i]; normalIndexes[i] = fullNormalIndexes[i]; } } else { // build bottom but not top coordinateIndexes = new int[5 * 4]; textureCoordinateIndexes = new int[5 * 4]; normalIndexes = new int[5 * 4]; for (int i = 0; i < 4 * 4; i++) { coordinateIndexes[i] = fullCoordinateIndexes[i]; textureCoordinateIndexes[i] = fullTextureCoordinateIndexes[i]; normalIndexes[i] = fullNormalIndexes[i]; } for (int i = 5 * 4; i < 6 * 4; i++) { coordinateIndexes[i - 4] = fullCoordinateIndexes[i]; textureCoordinateIndexes[i - 4] = fullTextureCoordinateIndexes[i]; normalIndexes[i - 4] = fullNormalIndexes[i]; } } IndexedQuadArray quads = new IndexedQuadArray(coordinates.length, // number // of // vertexes GeometryArray.COORDINATES | // vertex coordinates given GeometryArray.NORMALS | // normals given GeometryArray.TEXTURE_COORDINATE_2, // texture // coordinates given coordinateIndexes.length); // number of coordinate indexes quads.setCoordinates(0, coordinates); quads.setCoordinateIndices(0, coordinateIndexes); quads.setNormals(0, normals); quads.setNormalIndices(0, normalIndexes); quads.setTextureCoordinates(0, textureCoordinates); quads.setTextureCoordinateIndices(0, textureCoordinateIndexes); Shape3D box = new Shape3D(quads, mainAppearance); Vector3f trans = new Vector3f(0.0f, y, 0.0f); Transform3D tr = new Transform3D(); tr.set(trans); // translate TransformGroup tg = new TransformGroup(tr); tg.addChild(box); addChild(tg); }
From source file:ExBackgroundImage.java
private void rebuild() { // Build a shape if (shape == null) { shape = new Shape3D(); shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); shape.setAppearance(mainAppearance); addChild(shape);//w w w . jav a2 s .com } else { shape.setAppearance(mainAppearance); } if (xDimension < 2 || zDimension < 2 || heights == null || heights.length < 4) { tristrip = null; shape.setGeometry(null); return; } // Create a list of coordinates, one per grid row/column double[] coordinates = new double[xDimension * zDimension * 3]; double x, z; int n = 0, k = 0; z = ((double) (zDimension - 1)) * zSpacing / 2.0; // start at front edge for (int i = 0; i < zDimension; i++) { x = -((double) (xDimension - 1)) * xSpacing / 2.0;// start at left // edge for (int j = 0; j < xDimension; j++) { coordinates[n++] = x; coordinates[n++] = heights[k++]; coordinates[n++] = z; x += xSpacing; } z -= zSpacing; } // Create a list of normals, one per grid row/column float[] normals = new float[xDimension * zDimension * 3]; Vector3f one = new Vector3f(0.0f, 0.0f, 0.0f); Vector3f two = new Vector3f(0.0f, 0.0f, 0.0f); Vector3f norm = new Vector3f(0.0f, 0.0f, 0.0f); n = 0; k = 0; for (int i = 0; i < zDimension - 1; i++) { for (int j = 0; j < xDimension - 1; j++) { // Vector to right in X one.set((float) xSpacing, (float) (heights[k + 1] - heights[k]), 0.0f); // Vector back in Z two.set(0.0f, (float) (heights[k + xDimension] - heights[k]), (float) -zSpacing); // Cross them to get the normal norm.cross(one, two); normals[n++] = norm.x; normals[n++] = norm.y; normals[n++] = norm.z; k++; } // Last normal in row is a copy of the previous one normals[n] = normals[n - 3]; // X normals[n + 1] = normals[n - 2]; // Y normals[n + 2] = normals[n - 1]; // Z n += 3; k++; } // Last row of normals is a copy of the previous row for (int j = 0; j < xDimension; j++) { normals[n] = normals[n - xDimension * 3]; // X normals[n + 1] = normals[n - xDimension * 3 + 1]; // Y normals[n + 2] = normals[n - xDimension * 3 + 2]; // Z n += 3; } // Create a list of texture coordinates, one per grid row/column float[] texcoordinates = new float[xDimension * zDimension * 2]; float deltaS = 1.0f / (float) (xDimension - 1); float deltaT = 1.0f / (float) (zDimension - 1); float s = 0.0f; float t = 0.0f; n = 0; for (int i = 0; i < zDimension; i++) { s = 0.0f; for (int j = 0; j < xDimension; j++) { texcoordinates[n++] = s; texcoordinates[n++] = t; s += deltaS; } t += deltaT; } // Create a list of triangle strip indexes. Each strip goes // down one row (X direction) of the elevation grid. int[] indexes = new int[xDimension * (zDimension - 1) * 2]; int[] stripCounts = new int[zDimension - 1]; n = 0; k = 0; for (int i = 0; i < zDimension - 1; i++) { stripCounts[i] = xDimension * 2; for (int j = 0; j < xDimension; j++) { indexes[n++] = k + xDimension; indexes[n++] = k; k++; } } // Create geometry for collection of triangle strips, one // strip per row of the elevation grid tristrip = new IndexedTriangleStripArray(coordinates.length, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2, indexes.length, stripCounts); tristrip.setCoordinates(0, coordinates); tristrip.setNormals(0, normals); tristrip.setTextureCoordinates(0, texcoordinates); tristrip.setCoordinateIndices(0, indexes); tristrip.setNormalIndices(0, indexes); tristrip.setTextureCoordinateIndices(0, indexes); // Set the geometry for the shape shape.setGeometry(tristrip); }
From source file:ExLinearFog.java
private void addCylinder(float radius, float height, float y) { //// ww w.java 2 s. c o m // Compute coordinates, normals, and texture coordinates // around the top and bottom of a cylinder // float[] coordinates = new float[NSTEPS * 2 * 3]; // xyz float[] normals = new float[NSTEPS * 2 * 3]; // xyz vector float[] textureCoordinates = new float[NSTEPS * 2 * 2]; // st float angle = 0.0f; float deltaAngle = 2.0f * (float) Math.PI / ((float) NSTEPS - 1); float s = 0.0f; float deltaS = 1.0f / ((float) NSTEPS - 1); int n = 0; int tn = 0; float h2 = height / 2.0f; for (int i = 0; i < NSTEPS; i++) { // bottom normals[n + 0] = (float) Math.cos(angle); normals[n + 1] = 0.0f; normals[n + 2] = -(float) Math.sin(angle); coordinates[n + 0] = radius * normals[n + 0]; coordinates[n + 1] = -h2; coordinates[n + 2] = radius * normals[n + 2]; textureCoordinates[tn + 0] = s; textureCoordinates[tn + 1] = 0.0f; n += 3; tn += 2; // top normals[n + 0] = normals[n - 3]; normals[n + 1] = 0.0f; normals[n + 2] = normals[n - 1]; coordinates[n + 0] = coordinates[n - 3]; coordinates[n + 1] = h2; coordinates[n + 2] = coordinates[n - 1]; textureCoordinates[tn + 0] = s; textureCoordinates[tn + 1] = 1.0f; n += 3; tn += 2; angle += deltaAngle; s += deltaS; } // // Compute coordinate indexes, normal indexes, and texture // coordinate indexes awround the sides of a cylinder. // For this application, we don't need top or bottom, so // skip them. // int[] indexes = new int[NSTEPS * 4]; n = 0; int p = 0; // panel count for (int i = 0; i < NSTEPS - 1; i++) { indexes[n + 0] = p; // bottom left indexes[n + 1] = p + 2; // bottom right (next panel) indexes[n + 2] = p + 3; // top right (next panel) indexes[n + 3] = p + 1; // top left n += 4; p += 2; } indexes[n + 0] = p; // bottom left indexes[n + 1] = 0; // bottom right (next panel) indexes[n + 2] = 1; // top right (next panel) indexes[n + 3] = p + 1; // top left IndexedQuadArray quads = new IndexedQuadArray(coordinates.length / 3, // number // of // vertexes GeometryArray.COORDINATES | // format GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2, indexes.length); // number // of // indexes quads.setCoordinates(0, coordinates); quads.setTextureCoordinates(0, textureCoordinates); quads.setNormals(0, normals); quads.setCoordinateIndices(0, indexes); quads.setTextureCoordinateIndices(0, indexes); quads.setNormalIndices(0, indexes); Shape3D shape = new Shape3D(quads, mainAppearance); Vector3f trans = new Vector3f(0.0f, y, 0.0f); Transform3D tr = new Transform3D(); tr.set(trans); // translate TransformGroup tg = new TransformGroup(tr); tg.addChild(shape); addChild(tg); }
From source file:KeyNavigateTest.java
protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile) {/* w w w .j a v a 2 s. c om*/ int nFlags = GeometryArray.COORDINATES | GeometryArray.NORMALS; if ((m_nFlags & TEXTURE) == TEXTURE) nFlags |= GeometryArray.TEXTURE_COORDINATE_2; QuadArray quadArray = new QuadArray(24, nFlags); quadArray.setCoordinates(0, verts, 0, 24); for (int n = 0; n < 24; n++) quadArray.setNormal(n, normals[n / 4]); if ((m_nFlags & TEXTURE) == TEXTURE) { quadArray.setTextureCoordinates(0, 0, tcoords, 0, 24); setTexture(app, szTextureFile); } Shape3D shape = new Shape3D(quadArray, app); BranchGroup bg = new BranchGroup(); bg.addChild(shape); return bg; }
From source file:KeyNavigateTest.java
protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile) {/* w w w . ja v a 2 s. co m*/ int nFlags = GeometryArray.COORDINATES | GeometryArray.NORMALS; if ((m_nFlags & TEXTURE) == TEXTURE) nFlags |= GeometryArray.TEXTURE_COORDINATE_2; QuadArray quadArray = new QuadArray(4, nFlags); float[] coordArray = { -WIDTH, HEIGHT, LENGTH, WIDTH, HEIGHT, LENGTH, WIDTH, HEIGHT, -LENGTH, -WIDTH, HEIGHT, -LENGTH }; quadArray.setCoordinates(0, coordArray, 0, coordArray.length / 3); for (int n = 0; n < coordArray.length / 3; n++) quadArray.setNormal(n, new Vector3f(0, 1, 0)); if ((m_nFlags & TEXTURE) == TEXTURE) { float[] texArray = { 0, 0, 1, 0, 1, 1, 0, 1 }; quadArray.setTextureCoordinates(0, 0, texArray, 0, coordArray.length / 3); setTexture(app, szTextureFile); } BranchGroup bg = new BranchGroup(); Shape3D shape = new Shape3D(quadArray, app); bg.addChild(shape); return bg; }