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: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 ww w. j a v a 2s . 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:AvatarTest.java
protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile) {//from w ww. j a va2 s . com QuadArray quadArray = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); float[] coordArray = { -LAND_WIDTH, LAND_HEIGHT, 0, LAND_WIDTH, LAND_HEIGHT, 0, LAND_WIDTH, LAND_HEIGHT, LAND_LENGTH, -LAND_WIDTH, LAND_HEIGHT, LAND_LENGTH }; float[] texArray = { 0, 0, 1, 0, 1, 1, 0, 1 }; quadArray.setCoordinates(0, coordArray, 0, 4); if ((m_nFlags & TEXTURE) == TEXTURE) { quadArray.setTextureCoordinates(0, 0, texArray, 0, 4); setTexture(app, szTextureFile); } Shape3D sh = new Shape3D(quadArray, app); BranchGroup bg = new BranchGroup(); bg.addChild(sh); return bg; }
From source file:ExSound.java
private Shape3D buildBox(float width, float height, float depth, Appearance app) { float w2 = width / 2.0f; float h2 = height / 2.0f; float d2 = depth / 2.0f; float[] coordinates = new float[8 * 3]; int n = 0;// w ww .ja v a 2 s . com // Around the bottom of the box coordinates[n + 0] = -w2; coordinates[n + 1] = -h2; coordinates[n + 2] = d2; n += 3; coordinates[n + 0] = w2; coordinates[n + 1] = -h2; coordinates[n + 2] = d2; n += 3; coordinates[n + 0] = w2; coordinates[n + 1] = -h2; coordinates[n + 2] = -d2; n += 3; coordinates[n + 0] = -w2; coordinates[n + 1] = -h2; coordinates[n + 2] = -d2; n += 3; // Around the top of the box coordinates[n + 0] = -w2; coordinates[n + 1] = h2; coordinates[n + 2] = d2; n += 3; coordinates[n + 0] = w2; coordinates[n + 1] = h2; coordinates[n + 2] = d2; n += 3; coordinates[n + 0] = w2; coordinates[n + 1] = h2; coordinates[n + 2] = -d2; n += 3; coordinates[n + 0] = -w2; coordinates[n + 1] = h2; coordinates[n + 2] = -d2; n += 3; IndexedQuadArray quads = new IndexedQuadArray(coordinates.length, // vertex // count GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2, coordinateIndices.length); quads.setCoordinates(0, coordinates); quads.setCoordinateIndices(0, coordinateIndices); quads.setNormals(0, normals); quads.setNormalIndices(0, normalIndices); quads.setTextureCoordinates(0, textureCoordinates); quads.setTextureCoordinateIndices(0, textureCoordinateIndices); Shape3D shape = new Shape3D(quads, app); return shape; }
From source file:ExBackgroundImage.java
public Arch(double startPhi, double endPhi, int nPhi, double startTheta, double endTheta, int nTheta, double startPhiRadius, double endPhiRadius, double startPhiThickness, double endPhiThickness, Appearance app) {/* w w w . j a v a2 s . c o m*/ double theta, phi, radius, radius2, thickness; double x, y, z; double[] xyz = new double[3]; float[] norm = new float[3]; float[] tex = new float[3]; // Compute some values for our looping double deltaTheta = (endTheta - startTheta) / (double) (nTheta - 1); double deltaPhi = (endPhi - startPhi) / (double) (nPhi - 1); double deltaTexX = 1.0 / (double) (nTheta - 1); double deltaTexY = 1.0 / (double) (nPhi - 1); double deltaPhiRadius = (endPhiRadius - startPhiRadius) / (double) (nPhi - 1); double deltaPhiThickness = (endPhiThickness - startPhiThickness) / (double) (nPhi - 1); boolean doThickness = true; if (startPhiThickness == 0.0 && endPhiThickness == 0.0) doThickness = false; // Create geometry int vertexCount = nTheta * nPhi; if (doThickness) vertexCount *= 2; int indexCount = (nTheta - 1) * (nPhi - 1) * 4; // Outer surface if (doThickness) { indexCount *= 2; // plus inner surface indexCount += (nPhi - 1) * 4 * 2; // plus left & right edges } IndexedQuadArray polys = new IndexedQuadArray(vertexCount, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2, indexCount); // // Compute coordinates, normals, and texture coordinates // theta = startTheta; tex[0] = 0.0f; int index = 0; for (int i = 0; i < nTheta; i++) { phi = startPhi; radius = startPhiRadius; thickness = startPhiThickness; tex[1] = 0.0f; for (int j = 0; j < nPhi; j++) { norm[0] = (float) (Math.cos(phi) * Math.cos(theta)); norm[1] = (float) (Math.sin(phi)); norm[2] = (float) (-Math.cos(phi) * Math.sin(theta)); xyz[0] = radius * norm[0]; xyz[1] = radius * norm[1]; xyz[2] = radius * norm[2]; polys.setCoordinate(index, xyz); polys.setNormal(index, norm); polys.setTextureCoordinate(index, tex); index++; if (doThickness) { radius2 = radius - thickness; xyz[0] = radius2 * norm[0]; xyz[1] = radius2 * norm[1]; xyz[2] = radius2 * norm[2]; norm[0] *= -1.0f; norm[1] *= -1.0f; norm[2] *= -1.0f; polys.setCoordinate(index, xyz); polys.setNormal(index, norm); polys.setTextureCoordinate(index, tex); index++; } phi += deltaPhi; radius += deltaPhiRadius; thickness += deltaPhiThickness; tex[1] += deltaTexY; } theta += deltaTheta; tex[0] += deltaTexX; } // // Compute coordinate indexes // (also used as normal and texture indexes) // index = 0; int phiRow = nPhi; int phiCol = 1; if (doThickness) { phiRow += nPhi; phiCol += 1; } int[] indices = new int[indexCount]; // Outer surface int n; for (int i = 0; i < nTheta - 1; i++) { for (int j = 0; j < nPhi - 1; j++) { n = i * phiRow + j * phiCol; indices[index + 0] = n; indices[index + 1] = n + phiRow; indices[index + 2] = n + phiRow + phiCol; indices[index + 3] = n + phiCol; index += 4; } } // Inner surface if (doThickness) { for (int i = 0; i < nTheta - 1; i++) { for (int j = 0; j < nPhi - 1; j++) { n = i * phiRow + j * phiCol; indices[index + 0] = n + 1; indices[index + 1] = n + phiCol + 1; indices[index + 2] = n + phiRow + phiCol + 1; indices[index + 3] = n + phiRow + 1; index += 4; } } } // Edges if (doThickness) { for (int j = 0; j < nPhi - 1; j++) { n = j * phiCol; indices[index + 0] = n; indices[index + 1] = n + phiCol; indices[index + 2] = n + phiCol + 1; indices[index + 3] = n + 1; index += 4; } for (int j = 0; j < nPhi - 1; j++) { n = (nTheta - 1) * phiRow + j * phiCol; indices[index + 0] = n; indices[index + 1] = n + 1; indices[index + 2] = n + phiCol + 1; indices[index + 3] = n + phiCol; index += 4; } } polys.setCoordinateIndices(0, indices); polys.setNormalIndices(0, indices); polys.setTextureCoordinateIndices(0, indices); // // Build a shape // arch = new Shape3D(); arch.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); arch.setGeometry(polys); arch.setAppearance(app); addChild(arch); }
From source file:AvatarTest.java
protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile) {/*from ww w.j a v a 2s . c om*/ // creates a segment of road 200 x 2 QuadArray quadArray = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); float[] coordArray = { -ROAD_WIDTH, ROAD_HEIGHT, 0, ROAD_WIDTH, ROAD_HEIGHT, 0, ROAD_WIDTH, ROAD_HEIGHT, ROAD_LENGTH, -ROAD_WIDTH, ROAD_HEIGHT, ROAD_LENGTH }; float[] texArray = { 0, 0, 1, 0, 1, 1, 0, 1 }; quadArray.setCoordinates(0, coordArray, 0, 4); if ((m_nFlags & TEXTURE) == TEXTURE) { quadArray.setTextureCoordinates(0, 0, texArray, 0, 4); setTexture(app, szTextureFile); } Shape3D sh = new Shape3D(quadArray, app); BranchGroup bg = new BranchGroup(); bg.addChild(sh); return bg; }
From source file:ExTexture.java
public QuadArray buildGeometry() { QuadArray cube = new QuadArray(24, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2); cube.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); cube.setCapability(GeometryArray.ALLOW_TEXCOORD_WRITE); VertexList vl = new VertexList(cube); float MAX = 1.0f; float MIN = 0.0f; // Coordinate Normal Texture // X Y Z I J K S T // Front/*w w w .j a v a2s. com*/ vl.xyzijkst(-1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, MIN, MIN); vl.xyzijkst(1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, MAX, MIN); vl.xyzijkst(1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, MAX, MAX); vl.xyzijkst(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, MIN, MAX); // Back vl.xyzijkst(1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, MAX, MIN); vl.xyzijkst(-1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, MIN, MIN); vl.xyzijkst(-1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, MIN, MAX); vl.xyzijkst(1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, MAX, MAX); // Right vl.xyzijkst(1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, MIN, MAX); vl.xyzijkst(1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, MIN, MIN); vl.xyzijkst(1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, MAX, MIN); vl.xyzijkst(1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, MAX, MAX); // Left vl.xyzijkst(-1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, MIN, MIN); vl.xyzijkst(-1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, MIN, MAX); vl.xyzijkst(-1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, MAX, MAX); vl.xyzijkst(-1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, MAX, MIN); // Top vl.xyzijkst(-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, MIN, MAX); vl.xyzijkst(1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, MAX, MAX); vl.xyzijkst(1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, MAX, MIN); vl.xyzijkst(-1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, MIN, MIN); // Bottom vl.xyzijkst(-1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, MIN, MIN); vl.xyzijkst(1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, MAX, MIN); vl.xyzijkst(1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, MAX, MAX); vl.xyzijkst(-1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, MIN, MAX); return cube; }
From source file:AppearanceExplorer.java
Shape3D createTexTris() { Point3f pnt[] = new Point3f[9]; pnt[0] = new Point3f(-0.8f, -0.8f, 0.0f); pnt[1] = new Point3f(-0.5f, -0.7f, 0.0f); pnt[2] = new Point3f(-0.7f, 0.7f, 0.0f); pnt[3] = new Point3f(-0.4f, 0.7f, 0.0f); pnt[4] = new Point3f(0.0f, -0.7f, 0.0f); pnt[5] = new Point3f(0.4f, 0.7f, 0.0f); pnt[6] = new Point3f(0.5f, 0.7f, 0.0f); pnt[7] = new Point3f(0.5f, -0.7f, 0.0f); pnt[8] = new Point3f(0.9f, 0.0f, 0.0f); TexCoord2f texCoord[] = new TexCoord2f[9]; texCoord[0] = new TexCoord2f(0.05f, 0.90f); texCoord[1] = new TexCoord2f(0.25f, 0.10f); texCoord[2] = new TexCoord2f(1.00f, 0.60f); texCoord[3] = texCoord[0];// w w w. j ava 2 s. c o m texCoord[4] = texCoord[1]; texCoord[5] = texCoord[2]; texCoord[6] = texCoord[0]; texCoord[7] = texCoord[1]; texCoord[8] = texCoord[2]; TriangleArray ta = new TriangleArray(9, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); ta.setCoordinates(0, pnt); ta.setTextureCoordinates(0, 0, texCoord); return new Shape3D(ta, appearance); }
From source file:AppearanceExplorer.java
Shape3D createTexSquare() { // color cube 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); TexCoord2f texCoord[] = new TexCoord2f[4]; texCoord[0] = new TexCoord2f(0.0f, 0.0f); texCoord[1] = new TexCoord2f(1.0f, 0.0f); texCoord[2] = new TexCoord2f(1.0f, 1.0f); texCoord[3] = new TexCoord2f(0.0f, 1.0f); QuadArray qa = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); qa.setCoordinates(0, pnt);/* w w w. j a va 2s . com*/ qa.setTextureCoordinates(0, 0, texCoord); return new Shape3D(qa, appearance); }
From source file:AppearanceExplorer.java
Shape3D createLargeTexSquare() { // color cube 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); TexCoord2f texCoord[] = new TexCoord2f[4]; texCoord[0] = new TexCoord2f(-1.0f, -1.0f); texCoord[1] = new TexCoord2f(2.0f, -1.0f); texCoord[2] = new TexCoord2f(2.0f, 2.0f); texCoord[3] = new TexCoord2f(-1.0f, 2.0f); QuadArray qa = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); qa.setCoordinates(0, pnt);// ww w. java 2s .c om qa.setTextureCoordinates(0, 0, texCoord); return new Shape3D(qa, appearance); }
From source file:ExSpotLight.java
public AnnotationLine(float x, float y, float z, float x2, float y2, float z2) { float[] coord = new float[3]; float[] texcoord = new float[2]; // Build a shape shape = new Shape3D(); shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); // Create geometry for a 2-vertex straight line line = new LineArray(2, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); line.setCapability(GeometryArray.ALLOW_COLOR_WRITE); // Starting point coord[0] = x;//from ww w. j a v a2 s. co m coord[1] = y; coord[2] = z; texcoord[0] = 0.0f; texcoord[1] = 0.0f; line.setCoordinate(0, coord); line.setTextureCoordinate(0, texcoord); // Ending point coord[0] = x2; coord[1] = y2; coord[2] = z2; texcoord[0] = 1.0f; texcoord[1] = 0.0f; line.setCoordinate(1, coord); line.setTextureCoordinate(1, texcoord); shape.setGeometry(line); // Create an appearance mainAppearance = new Appearance(); mainAppearance.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE); mainAppearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE); lineAttributes = new LineAttributes(); lineAttributes.setLineWidth(lineWidth); mainAppearance.setLineAttributes(lineAttributes); coloringAttributes = new ColoringAttributes(); coloringAttributes.setColor(lineColor); coloringAttributes.setShadeModel(ColoringAttributes.SHADE_FLAT); mainAppearance.setColoringAttributes(coloringAttributes); addChild(shape); }