List of usage examples for javax.media.j3d Appearance Appearance
public Appearance()
From source file:KeyNavigateTest.java
void createExternalWall(Group mapGroup) { Vector3d squareSize = getMapSquareSize(); Appearance app = new Appearance(); app.setColoringAttributes(/* ww w . ja va2 s . c om*/ new ColoringAttributes(new Color3f(132f / 255f, 0, 66f / 255f), ColoringAttributes.FASTEST)); int imageWidth = m_MapImage.getWidth(); int imageHeight = m_MapImage.getHeight(); Point3d topLeft = convertToWorldCoordinatesPixelCenter(0, 0); Point3d bottomRight = convertToWorldCoordinatesPixelCenter(imageWidth - 1, imageHeight - 1); // top Cuboid wall = new Cuboid(this, mapGroup, ComplexObject.GEOMETRY); wall.createObject(app, new Vector3d(0, m_kFloorLevel, topLeft.z), new Vector3d(squareSize.x * imageWidth / 2, m_kCeilingHeight / 2, squareSize.z / 2), null, null, null); // bottom wall = new Cuboid(this, mapGroup, ComplexObject.GEOMETRY); wall.createObject(app, new Vector3d(0, m_kFloorLevel, bottomRight.z), new Vector3d(squareSize.x * imageWidth / 2, m_kCeilingHeight / 2, squareSize.z / 2), null, null, null); // left wall = new Cuboid(this, mapGroup, ComplexObject.GEOMETRY); wall.createObject(app, new Vector3d(topLeft.x, m_kFloorLevel, 0), new Vector3d(squareSize.x / 2, m_kCeilingHeight / 2, squareSize.z * imageHeight / 2), null, null, null); // right wall = new Cuboid(this, mapGroup, ComplexObject.GEOMETRY); wall.createObject(app, new Vector3d(bottomRight.x, m_kFloorLevel, 0), new Vector3d(squareSize.x / 2, m_kCeilingHeight / 2, squareSize.z * imageHeight / 2), null, null, null); }
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 w w . j a va 2 s . co 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:ffx.potential.MolecularAssembly.java
/** * <p>//ww w . j a va2 s .c o m * createBox</p> */ public void createBox() { int vertices = 8; LineArray la = new LineArray(4 * vertices, GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS); la.setCapability(LineArray.ALLOW_COORDINATE_WRITE); la.setCapability(LineArray.ALLOW_COORDINATE_READ); la.setCapability(LineArray.ALLOW_COLOR_WRITE); la.setCapability(LineArray.ALLOW_COUNT_READ); la.setCapability(LineArray.ALLOW_INTERSECT); la.setCapability(LineArray.ALLOW_FORMAT_READ); // Create a normal // for (ListIterator li = bondlist.listIterator(); li.hasNext(); ){ // la.setCoordinate(i, a1); // la.setColor(i, col); // la.setNormal(i++, a1); // } ColoringAttributes cola = new ColoringAttributes(new Color3f(), ColoringAttributes.SHADE_GOURAUD); Appearance app = new Appearance(); lineAttributes = new LineAttributes(); lineAttributes.setLineWidth(RendererCache.bondwidth); lineAttributes.setCapability(LineAttributes.ALLOW_WIDTH_WRITE); lineAttributes.setLineAntialiasingEnable(true); app.setLineAttributes(lineAttributes); app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ); app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE); RenderingAttributes ra = new RenderingAttributes(); ra.setAlphaTestValue(0.1f); ra.setAlphaTestFunction(RenderingAttributes.GREATER); ra.setDepthBufferEnable(true); ra.setDepthBufferWriteEnable(true); app.setRenderingAttributes(ra); app.setColoringAttributes(cola); Shape3D wireframe = new Shape3D(la, app); // PickTool.setCapabilities(wire, PickTool.INTERSECT_COORD); wireframe.setUserData(this); wireframe.setBounds(new BoundingSphere(new Point3d(0, 0, 0), 10.0)); try { wireframe.setBoundsAutoCompute(false); } catch (Exception e) { e.printStackTrace(); } wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ); wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ); // return wire; }
From source file:ExBackgroundImage.java
public Arch() { // Default to a sphere this(0.0, Math.PI / 2.0, 9, 0.0, Math.PI, 17, 1.0, 1.0, 0.0, 0.0, new Appearance()); }
From source file:SplineInterpolatorTest.java
public Group createHelicopter(Group g) { BranchGroup bg = new BranchGroup(); Helicopter heli = new Helicopter(this, bg, ComplexObject.GEOMETRY | ComplexObject.SOUND); heli.createObject(new Appearance(), new Vector3d(Utils.getRandomNumber(0, LAND_WIDTH), Utils.getRandomNumber(15, 5), Utils.getRandomNumber(0, LAND_LENGTH)), new Vector3d(10, 10, 10), null, "heli.wav", null); g.addChild(bg);//from w w w. j a va 2s.co m return bg; }
From source file:KeyNavigateTest.java
void createGuard(Group mapGroup, int nPixelX, int nPixelY) { Point3d point = convertToWorldCoordinatesPixelCenter(nPixelX, nPixelY); if (m_GuardAppearance == null) m_GuardAppearance = new Appearance(); Vector3d squareSize = getMapSquareSize(); Guard guard = new Guard(this, mapGroup, ComplexObject.GEOMETRY, this); guard.createObject(m_GuardAppearance, new Vector3d(point.x, (m_kFloorLevel + m_kCeilingLevel) / 2, point.z), new Vector3d(1, 1, 1), null, null, null); }
From source file:TickTockPicking.java
public Tetrahedron() { int i;//ww w . ja v a2 s.com TriangleArray tetra = new TriangleArray(12, TriangleArray.COORDINATES | TriangleArray.NORMALS | TriangleArray.TEXTURE_COORDINATE_2); tetra.setCoordinates(0, verts); for (i = 0; i < 12; i++) { tetra.setTextureCoordinate(0, i, texCoord[i % 3]); } int face; Vector3f normal = new Vector3f(); Vector3f v1 = new Vector3f(); Vector3f v2 = new Vector3f(); Point3f[] pts = new Point3f[3]; for (i = 0; i < 3; i++) pts[i] = new Point3f(); for (face = 0; face < 4; face++) { tetra.getCoordinates(face * 3, pts); v1.sub(pts[1], pts[0]); v2.sub(pts[2], pts[0]); normal.cross(v1, v2); normal.normalize(); for (i = 0; i < 3; i++) { tetra.setNormal((face * 3 + i), normal); } } tetra.setCapability(Geometry.ALLOW_INTERSECT); this.setGeometry(tetra); this.setAppearance(new Appearance()); }
From source file:KeyNavigateTest.java
void createLight(Group mapGroup, int nPixelX, int nPixelY) { Point3d point = convertToWorldCoordinatesPixelCenter(nPixelX, nPixelY); // we do not share an Appearance for lights // or they all animate in synch... final double lightHeight = m_kCeilingHeight / 1.5; Light light = new Light(this, mapGroup, ComplexObject.GEOMETRY | ComplexObject.TEXTURE); light.createObject(new Appearance(), new Vector3d(point.x, m_kFloorLevel + lightHeight / 2, point.z), new Vector3d(5, lightHeight, 5), "light.gif", null, null); }
From source file:BehaviorTest.java
public WakeupCondition restart(Shape3D shape3D, int nElapsedTime, int nNumFrames, ExplosionListener listener) { System.out.println("Will explode after: " + nElapsedTime / 1000 + " secs."); m_Shape3D = shape3D;// ww w .j a v a 2 s . co m m_nElapsedTime = nElapsedTime; m_nNumFrames = nNumFrames; m_nFrameNumber = 0; // create the WakeupCriterion for the behavior m_InitialWakeupCondition = new WakeupOnElapsedTime(m_nElapsedTime); m_Listener = listener; // save the GeometryArray that we are modifying m_GeometryArray = (GeometryArray) m_Shape3D.getGeometry(); if (m_Shape3D.isLive() == false && m_Shape3D.isCompiled() == false) { // set the capability bits that the behavior requires m_Shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ); m_Shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_POINT_ATTRIBUTES_WRITE); m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE); m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE); m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_TEXTURE_WRITE); m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_READ); m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); m_GeometryArray.setCapability(GeometryArray.ALLOW_COUNT_READ); } // make a copy of the object's original appearance m_Appearance = new Appearance(); m_Appearance = (Appearance) m_Shape3D.getAppearance().cloneNodeComponent(true); // allocate an array for the model coordinates m_CoordinateArray = new float[3 * m_GeometryArray.getVertexCount()]; // make a copy of the models original coordinates m_OriginalCoordinateArray = new float[3 * m_GeometryArray.getVertexCount()]; m_GeometryArray.getCoordinates(0, m_OriginalCoordinateArray); // start (or restart) the behavior setEnable(true); return m_InitialWakeupCondition; }
From source file:KeyNavigateTest.java
void createWater(Group mapGroup, int nPixelX, int nPixelY) { Point3d point = convertToWorldCoordinatesPixelCenter(nPixelX, nPixelY); if (m_WaterAppearance == null) { m_WaterAppearance = new Appearance(); m_WaterAppearance.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false)); m_WaterAppearance//from w w w.ja v a 2 s . c om .setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f)); m_WaterAppearance.setTextureAttributes(new TextureAttributes(TextureAttributes.REPLACE, new Transform3D(), new Color4f(0, 0, 0, 1), TextureAttributes.FASTEST)); } Land water = new Land(this, mapGroup, ComplexObject.GEOMETRY | ComplexObject.TEXTURE); water.createObject(m_WaterAppearance, new Vector3d(point.x, m_kFloorLevel + 0.1, point.z), new Vector3d(40, 1, 40), "water.gif", null, null); }