List of usage examples for javax.media.j3d QuadArray QuadArray
public QuadArray(int vertexCount, int vertexFormat)
From source file:EnvironmentExplorer.java
void setupGrid() { // create a Switch for the spheres, allow switch changes gridSwitch = new Switch(Switch.CHILD_NONE); gridSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); // Set up an appearance to make the square3s with red ambient, // black emmissive, red diffuse and black specular coloring Material material = new Material(red, black, red, black, 64); Appearance appearance = new Appearance(); appearance.setMaterial(material);/*w ww.j a v a 2 s.c o m*/ // create a grid of quads int gridSize = 20; // grid is gridSize quads along each side int numQuads = gridSize * gridSize; int numVerts = numQuads * 4; // 4 verts per quad // there will be 3 floats per coord and 4 coords per quad float[] coords = new float[3 * numVerts]; // All the quads will use the same normal at each vertex, so // allocate an array to hold references to the same normal Vector3f[] normals = new Vector3f[numVerts]; Vector3f vertNormal = new Vector3f(0.0f, 0.0f, 1.0f); float edgeLength = 5.0f; // length of each edge of the grid float gridGap = 0.03f; // the gap between each quad // length of each quad is (total length - sum of the gaps) / gridSize float quadLength = (edgeLength - gridGap * (gridSize - 1)) / gridSize; // create a grid of quads in the z=0 plane // each has a TransformGroup to position the sphere which contains // a link to the shared group for the sphere float curX, curY; for (int y = 0; y < gridSize; y++) { curY = y * (quadLength + gridGap); // offset to lower left corner curY -= edgeLength / 2; // center on 0,0 for (int x = 0; x < gridSize; x++) { // this is the offset into the vertex array for the first // vertex of the quad int vertexOffset = (y * gridSize + x) * 4; // this is the offset into the coord array for the first // vertex of the quad, where there are 3 floats per vertex int coordOffset = vertexOffset * 3; curX = x * (quadLength + gridGap); // offset to ll corner curX -= edgeLength / 2; // center on 0,0 // lower left corner coords[coordOffset + 0] = curX; coords[coordOffset + 1] = curY; coords[coordOffset + 2] = 0.0f; // z // lower right corner coords[coordOffset + 3] = curX + quadLength; coords[coordOffset + 4] = curY; coords[coordOffset + 5] = 0.0f; // z // upper right corner coords[coordOffset + 6] = curX + quadLength; coords[coordOffset + 7] = curY + quadLength; coords[coordOffset + 8] = 0.0f; // z // upper left corner coords[coordOffset + 9] = curX; coords[coordOffset + 10] = curY + quadLength; coords[coordOffset + 11] = 0.0f; // z for (int i = 0; i < 4; i++) { normals[vertexOffset + i] = vertNormal; } } } // now that we have the data, create the QuadArray QuadArray quads = new QuadArray(numVerts, QuadArray.COORDINATES | QuadArray.NORMALS); quads.setCoordinates(0, coords); quads.setNormals(0, normals); // create the shape Shape3D shape = new Shape3D(quads, appearance); // add it to the switch gridSwitch.addChild(shape); }
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 ww .j a v a 2 s. c om 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:TickTockPicking.java
public Cube() { super();//from w ww .j a v a 2s . co m int i; QuadArray cube = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS); cube.setCoordinates(0, verts); for (i = 0; i < 24; i++) { cube.setNormal(i, normals[i / 4]); } cube.setCapability(Geometry.ALLOW_INTERSECT); setGeometry(cube); setAppearance(new 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);//from w w w . j av a2 s . c o m 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);//from w ww .j a va 2s. co m qa.setTextureCoordinates(0, 0, texCoord); return new Shape3D(qa, appearance); }
From source file:GearTest.java
/** * Construct a SpurGear's teeth by adding the teeth shape nodes * //from ww w . j av a 2 s. c om * @param pitchCircleRadius * radius at center of teeth * @param rootRadius * distance from pitch circle to top of teeth * @param outsideRadius * distance from pitch circle to root of teeth * @param gearThickness * thickness of the gear * @param toothTipThickness * thickness of the tip of the tooth * @param toothToValleyAngleRatio * the ratio of the angle subtended by the tooth to the angle * subtended by the valley (must be <= .25) * @param look * the gear's appearance object */ void addTeeth(float pitchCircleRadius, float rootRadius, float outsideRadius, float gearThickness, float toothTipThickness, float toothToValleyAngleRatio, Appearance look) { int index; Shape3D newShape; // Temporaries that store start angle for each portion of tooth facet double toothStartAngle, toothTopStartAngle, toothDeclineStartAngle, toothValleyStartAngle, nextToothStartAngle; // The x and y coordinates at each point of a facet and at each // point on the gear: at the shaft, the root of the teeth, and // the outer point of the teeth float xRoot0, yRoot0; float xOuter1, yOuter1; float xOuter2, yOuter2; float xRoot3, yRoot3; float xRoot4, yRoot4; // The z coordinates for the gear final float frontZ = -0.5f * gearThickness; final float rearZ = 0.5f * gearThickness; // The z coordinates for the tooth tip of the gear final float toothTipFrontZ = -0.5f * toothTipThickness; final float toothTipRearZ = 0.5f * toothTipThickness; int toothFacetVertexCount; // #(vertices) per tooth facet int toothFacetCount; // #(facets) per tooth int toothFaceTotalVertexCount; // #(vertices) in all teeth int toothFaceStripCount[] = new int[toothCount]; // per tooth vertex count int topVertexCount; // #(vertices) for teeth tops int topStripCount[] = new int[1]; // #(vertices) in strip/strip // Front and rear facing normals for the teeth faces Vector3f frontToothNormal = new Vector3f(0.0f, 0.0f, -1.0f); Vector3f rearToothNormal = new Vector3f(0.0f, 0.0f, 1.0f); // Normals for teeth tops up incline, tooth top, and down incline Vector3f leftNormal = new Vector3f(-1.0f, 0.0f, 0.0f); Vector3f rightNormal = new Vector3f(1.0f, 0.0f, 0.0f); Vector3f outNormal = new Vector3f(1.0f, 0.0f, 0.0f); Vector3f inNormal = new Vector3f(-1.0f, 0.0f, 0.0f); // Temporary variables for storing coordinates and vectors Point3f coordinate = new Point3f(0.0f, 0.0f, 0.0f); Point3f tempCoordinate1 = new Point3f(0.0f, 0.0f, 0.0f); Point3f tempCoordinate2 = new Point3f(0.0f, 0.0f, 0.0f); Point3f tempCoordinate3 = new Point3f(0.0f, 0.0f, 0.0f); Vector3f tempVector1 = new Vector3f(0.0f, 0.0f, 0.0f); Vector3f tempVector2 = new Vector3f(0.0f, 0.0f, 0.0f); /* * Construct the gear's front facing teeth facets 0______2 / /\ / / \ / / \ * //___________\ 1 3 */ toothFacetVertexCount = 4; toothFaceTotalVertexCount = toothFacetVertexCount * toothCount; for (int i = 0; i < toothCount; i++) toothFaceStripCount[i] = toothFacetVertexCount; TriangleStripArray frontGearTeeth = new TriangleStripArray(toothFaceTotalVertexCount, GeometryArray.COORDINATES | GeometryArray.NORMALS, toothFaceStripCount); for (int count = 0; count < toothCount; count++) { index = count * toothFacetVertexCount; toothStartAngle = gearStartAngle + circularPitchAngle * (double) count; toothTopStartAngle = toothStartAngle + toothTopAngleIncrement; toothDeclineStartAngle = toothStartAngle + toothDeclineAngleIncrement; toothValleyStartAngle = toothStartAngle + toothValleyAngleIncrement; xRoot0 = rootRadius * (float) Math.cos(toothStartAngle); yRoot0 = rootRadius * (float) Math.sin(toothStartAngle); xOuter1 = outsideRadius * (float) Math.cos(toothTopStartAngle); yOuter1 = outsideRadius * (float) Math.sin(toothTopStartAngle); xOuter2 = outsideRadius * (float) Math.cos(toothDeclineStartAngle); yOuter2 = outsideRadius * (float) Math.sin(toothDeclineStartAngle); xRoot3 = rootRadius * (float) Math.cos(toothValleyStartAngle); yRoot3 = rootRadius * (float) Math.sin(toothValleyStartAngle); tempCoordinate1.set(xRoot0, yRoot0, frontZ); tempCoordinate2.set(xRoot3, yRoot3, frontZ); tempVector1.sub(tempCoordinate2, tempCoordinate1); tempCoordinate2.set(xOuter1, yOuter1, toothTipFrontZ); tempVector2.sub(tempCoordinate2, tempCoordinate1); frontToothNormal.cross(tempVector1, tempVector2); frontToothNormal.normalize(); coordinate.set(xOuter1, yOuter1, toothTipFrontZ); frontGearTeeth.setCoordinate(index, coordinate); frontGearTeeth.setNormal(index, frontToothNormal); coordinate.set(xRoot0, yRoot0, frontZ); frontGearTeeth.setCoordinate(index + 1, coordinate); frontGearTeeth.setNormal(index + 1, frontToothNormal); coordinate.set(xOuter2, yOuter2, toothTipFrontZ); frontGearTeeth.setCoordinate(index + 2, coordinate); frontGearTeeth.setNormal(index + 2, frontToothNormal); coordinate.set(xRoot3, yRoot3, frontZ); frontGearTeeth.setCoordinate(index + 3, coordinate); frontGearTeeth.setNormal(index + 3, frontToothNormal); } newShape = new Shape3D(frontGearTeeth, look); this.addChild(newShape); /* * Construct the gear's rear facing teeth facets (Using Quads) 1______2 / \ / \ / \ * /____________\ 0 3 */ toothFacetVertexCount = 4; toothFaceTotalVertexCount = toothFacetVertexCount * toothCount; QuadArray rearGearTeeth = new QuadArray(toothCount * toothFacetVertexCount, GeometryArray.COORDINATES | GeometryArray.NORMALS); for (int count = 0; count < toothCount; count++) { index = count * toothFacetVertexCount; toothStartAngle = gearStartAngle + circularPitchAngle * (double) count; toothTopStartAngle = toothStartAngle + toothTopAngleIncrement; toothDeclineStartAngle = toothStartAngle + toothDeclineAngleIncrement; toothValleyStartAngle = toothStartAngle + toothValleyAngleIncrement; xRoot0 = rootRadius * (float) Math.cos(toothStartAngle); yRoot0 = rootRadius * (float) Math.sin(toothStartAngle); xOuter1 = outsideRadius * (float) Math.cos(toothTopStartAngle); yOuter1 = outsideRadius * (float) Math.sin(toothTopStartAngle); xOuter2 = outsideRadius * (float) Math.cos(toothDeclineStartAngle); yOuter2 = outsideRadius * (float) Math.sin(toothDeclineStartAngle); xRoot3 = rootRadius * (float) Math.cos(toothValleyStartAngle); yRoot3 = rootRadius * (float) Math.sin(toothValleyStartAngle); tempCoordinate1.set(xRoot0, yRoot0, rearZ); tempCoordinate2.set(xRoot3, yRoot3, rearZ); tempVector1.sub(tempCoordinate2, tempCoordinate1); tempCoordinate2.set(xOuter1, yOuter1, toothTipRearZ); tempVector2.sub(tempCoordinate2, tempCoordinate1); rearToothNormal.cross(tempVector2, tempVector1); rearToothNormal.normalize(); coordinate.set(xRoot0, yRoot0, rearZ); rearGearTeeth.setCoordinate(index, coordinate); rearGearTeeth.setNormal(index, rearToothNormal); coordinate.set(xOuter1, yOuter1, toothTipRearZ); rearGearTeeth.setCoordinate(index + 1, coordinate); rearGearTeeth.setNormal(index + 1, rearToothNormal); coordinate.set(xOuter2, yOuter2, toothTipRearZ); rearGearTeeth.setCoordinate(index + 2, coordinate); rearGearTeeth.setNormal(index + 2, rearToothNormal); coordinate.set(xRoot3, yRoot3, rearZ); rearGearTeeth.setCoordinate(index + 3, coordinate); rearGearTeeth.setNormal(index + 3, rearToothNormal); } newShape = new Shape3D(rearGearTeeth, look); this.addChild(newShape); /* * Construct the gear's top teeth faces (As seen from above) Root0 * Outer1 Outer2 Root3 Root4 (RearZ) 0_______3 2_______5 4_______7 * 6_______9 |0 3| |4 7| |8 11| |12 15| | | | | | | | | | | | | | | | | * |1_____2| |5_____6| |9____10| |13___14| 1 2 3 4 5 6 7 8 Root0 Outer1 * Outer2 Root3 Root4 (FrontZ) * * Quad 0123 uses a left normal Quad 2345 uses an out normal Quad 4567 * uses a right normal Quad 6789 uses an out normal */ topVertexCount = 8 * toothCount + 2; topStripCount[0] = topVertexCount; toothFacetVertexCount = 4; toothFacetCount = 4; QuadArray topGearTeeth = new QuadArray(toothCount * toothFacetVertexCount * toothFacetCount, GeometryArray.COORDINATES | GeometryArray.NORMALS); for (int count = 0; count < toothCount; count++) { index = count * toothFacetCount * toothFacetVertexCount; toothStartAngle = gearStartAngle + circularPitchAngle * (double) count; toothTopStartAngle = toothStartAngle + toothTopAngleIncrement; toothDeclineStartAngle = toothStartAngle + toothDeclineAngleIncrement; toothValleyStartAngle = toothStartAngle + toothValleyAngleIncrement; nextToothStartAngle = toothStartAngle + circularPitchAngle; xRoot0 = rootRadius * (float) Math.cos(toothStartAngle); yRoot0 = rootRadius * (float) Math.sin(toothStartAngle); xOuter1 = outsideRadius * (float) Math.cos(toothTopStartAngle); yOuter1 = outsideRadius * (float) Math.sin(toothTopStartAngle); xOuter2 = outsideRadius * (float) Math.cos(toothDeclineStartAngle); yOuter2 = outsideRadius * (float) Math.sin(toothDeclineStartAngle); xRoot3 = rootRadius * (float) Math.cos(toothValleyStartAngle); yRoot3 = rootRadius * (float) Math.sin(toothValleyStartAngle); xRoot4 = rootRadius * (float) Math.cos(nextToothStartAngle); yRoot4 = rootRadius * (float) Math.sin(nextToothStartAngle); // Compute normal for quad 1 tempCoordinate1.set(xRoot0, yRoot0, frontZ); tempCoordinate2.set(xOuter1, yOuter1, toothTipFrontZ); tempVector1.sub(tempCoordinate2, tempCoordinate1); leftNormal.cross(frontNormal, tempVector1); leftNormal.normalize(); // Coordinate labeled 0 in the quad coordinate.set(xRoot0, yRoot0, rearZ); topGearTeeth.setCoordinate(index, coordinate); topGearTeeth.setNormal(index, leftNormal); // Coordinate labeled 1 in the quad coordinate.set(tempCoordinate1); topGearTeeth.setCoordinate(index + 1, coordinate); topGearTeeth.setNormal(index + 1, leftNormal); // Coordinate labeled 2 in the quad topGearTeeth.setCoordinate(index + 2, tempCoordinate2); topGearTeeth.setNormal(index + 2, leftNormal); topGearTeeth.setCoordinate(index + 5, tempCoordinate2); // Coordinate labeled 3 in the quad coordinate.set(xOuter1, yOuter1, toothTipRearZ); topGearTeeth.setCoordinate(index + 3, coordinate); topGearTeeth.setNormal(index + 3, leftNormal); topGearTeeth.setCoordinate(index + 4, coordinate); // Compute normal for quad 2 tempCoordinate1.set(xOuter1, yOuter1, toothTipFrontZ); tempCoordinate2.set(xOuter2, yOuter2, toothTipFrontZ); tempVector1.sub(tempCoordinate2, tempCoordinate1); outNormal.cross(frontNormal, tempVector1); outNormal.normalize(); topGearTeeth.setNormal(index + 4, outNormal); topGearTeeth.setNormal(index + 5, outNormal); // Coordinate labeled 4 in the quad topGearTeeth.setCoordinate(index + 6, tempCoordinate2); topGearTeeth.setNormal(index + 6, outNormal); topGearTeeth.setCoordinate(index + 9, tempCoordinate2); // Coordinate labeled 5 in the quad coordinate.set(xOuter2, yOuter2, toothTipRearZ); topGearTeeth.setCoordinate(index + 7, coordinate); topGearTeeth.setNormal(index + 7, outNormal); topGearTeeth.setCoordinate(index + 8, coordinate); // Compute normal for quad 3 tempCoordinate1.set(xOuter2, yOuter2, toothTipFrontZ); tempCoordinate2.set(xRoot3, yRoot3, frontZ); tempVector1.sub(tempCoordinate2, tempCoordinate1); rightNormal.cross(frontNormal, tempVector1); rightNormal.normalize(); topGearTeeth.setNormal(index + 8, rightNormal); topGearTeeth.setNormal(index + 9, rightNormal); // Coordinate labeled 7 in the quad topGearTeeth.setCoordinate(index + 10, tempCoordinate2); topGearTeeth.setNormal(index + 10, rightNormal); topGearTeeth.setCoordinate(index + 13, tempCoordinate2); // Coordinate labeled 6 in the quad coordinate.set(xRoot3, yRoot3, rearZ); topGearTeeth.setCoordinate(index + 11, coordinate); topGearTeeth.setNormal(index + 11, rightNormal); topGearTeeth.setCoordinate(index + 12, coordinate); // Compute normal for quad 4 tempCoordinate1.set(xRoot3, yRoot3, frontZ); tempCoordinate2.set(xRoot4, yRoot4, frontZ); tempVector1.sub(tempCoordinate2, tempCoordinate1); outNormal.cross(frontNormal, tempVector1); outNormal.normalize(); topGearTeeth.setNormal(index + 12, outNormal); topGearTeeth.setNormal(index + 13, outNormal); // Coordinate labeled 9 in the quad topGearTeeth.setCoordinate(index + 14, tempCoordinate2); topGearTeeth.setNormal(index + 14, outNormal); // Coordinate labeled 8 in the quad coordinate.set(xRoot4, yRoot4, rearZ); topGearTeeth.setCoordinate(index + 15, coordinate); topGearTeeth.setNormal(index + 15, outNormal); // Prepare for the loop by computing the new normal toothTopStartAngle = nextToothStartAngle + toothTopAngleIncrement; xOuter1 = outsideRadius * (float) Math.cos(toothTopStartAngle); yOuter1 = outsideRadius * (float) Math.sin(toothTopStartAngle); tempCoordinate1.set(xRoot4, yRoot4, toothTipFrontZ); tempCoordinate2.set(xOuter1, yOuter1, toothTipFrontZ); tempVector1.sub(tempCoordinate2, tempCoordinate1); leftNormal.cross(frontNormal, tempVector1); leftNormal.normalize(); } newShape = new Shape3D(topGearTeeth, look); this.addChild(newShape); }
From source file:KeyNavigateTest.java
protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile) {//from w ww . j a v a 2 s . c o m 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:Demo3D.java
/** * Construction of the desired borders of the virtual universe (cube). * //from w w w. j ava 2 s . co m * @return javax.media.j3d.Shape3D myUniverse - the constructed borders of * the virtual universe */ public Shape3D myInternalUniverse() { cube = new QuadArray(cubeFaces.length, QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2); ////////////////////// Geometric part /////////////////////////// // Scaling of the faces. for (int i = 0; i < cubeFaces.length; i++) cubeFaces[i].scale(scale_XYZ); cube.setCoordinates(0, cubeFaces); for (int i = 0; i < cubeFaces.length; i++) { // With i mod 4 ==> 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 for // the 4 vertices of the 6 faces, thus each vertex has // a point in the texture space. In this case, each cube's // face has the same texture coordinates. cube.setTextureCoordinate(0, i, textCoord[i % 4]); } // The geometry is passed to the instance this of the cube. this.setGeometry(cube); ////////////////////// Appearance part /////////////////////////// Appearance appearance = new Appearance(); // This code block is only necessary to insure, in all cases, the // correct // rendering of the 6 faces of the cube (bug in Java3D version 1.2.0 !). // Set up the polygon's rendering-mode PolygonAttributes polygonAttributes = new PolygonAttributes(); polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL); appearance.setPolygonAttributes(polygonAttributes); // Loading the texture for the 6 cube's faces. newTextureLoader = new NewTextureLoader("Images/Galaxies.gif"); newTextureLoader.setImageObserver(newTextureLoader.getImageObserver()); texture = newTextureLoader.getTexture(); appearance.setTexture(texture); // Application modes of the texture textAttr = new TextureAttributes(); textAttr.setTextureMode(TextureAttributes.MODULATE); // there still are: // BLEND, COMBINE, // DECAL, and REPLACE appearance.setTextureAttributes(textAttr); // The appearance is passed to the instance this of the cube. this.setAppearance(appearance); return this; }
From source file:Demo3D.java
/** * Construction of the desired borders of the virtual universe (cube). * //from w ww . j av a 2 s .co m * @return javax.media.j3d.Shape3D myUniverse - the constructed borders of * the virtual universe */ public Shape3D myExternalUniverse() { cube = new QuadArray(cubeFaces.length, QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2); ////////////////////// Geometric part /////////////////////////// // Scaling of the faces. for (int i = 0; i < cubeFaces.length; i++) cubeFaces[i].scale(scale_XYZ); cube.setCoordinates(0, cubeFaces); for (int i = 0; i < cubeFaces.length; i++) { // With i mod 4 ==> 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 for // the 4 vertices of the 6 faces, thus each vertex has // a point in the texture space. In this case, each cube's // face has the same texture coordinates. cube.setTextureCoordinate(0, i, textCoord[i % 4]); } // The geometry is passed to the instance this of the cube. this.setGeometry(cube); ////////////////////// Appearance part /////////////////////////// Appearance appearance = new Appearance(); // This code block is only necessary to insure, in all cases, the // correct // rendering of the 6 faces of the cube (bug in Java3D version 1.2.0 !). // Set up the polygon's rendering-mode PolygonAttributes polygonAttributes = new PolygonAttributes(); polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL); appearance.setPolygonAttributes(polygonAttributes); // Loading the texture for the 6 cube's faces. newTextureLoader = new NewTextureLoader("Images/Ciel_Outside.jpg"); newTextureLoader.setImageObserver(newTextureLoader.getImageObserver()); texture = newTextureLoader.getTexture(); appearance.setTexture(texture); // Application modes of the texture textAttr = new TextureAttributes(); textAttr.setTextureMode(TextureAttributes.MODULATE); // there still are: // BLEND, COMBINE, // DECAL, and REPLACE appearance.setTextureAttributes(textAttr); // The appearance is passed to the instance this of the cube. this.setAppearance(appearance); return this; }
From source file:KeyNavigateTest.java
protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile) {//from w w w. j a v a 2s .c o 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; }