List of usage examples for javax.media.j3d PolygonAttributes POLYGON_FILL
int POLYGON_FILL
To view the source code for javax.media.j3d PolygonAttributes POLYGON_FILL.
Click Source Link
From source file:PolygonOffset.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans);//from w w w . ja va 2s . co m // Create a Sphere. We will display this as both wireframe and // solid to make a hidden line display // wireframe Appearance wireApp = new Appearance(); ColoringAttributes wireCa = new ColoringAttributes(); wireCa.setColor(black); wireApp.setColoringAttributes(wireCa); wirePa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0.0f); wireApp.setPolygonAttributes(wirePa); Sphere outWireSphere = new Sphere(sphereRadius, 0, 15, wireApp); objTrans.addChild(outWireSphere); // solid ColoringAttributes outCa = new ColoringAttributes(red, ColoringAttributes.SHADE_FLAT); Appearance outSolid = new Appearance(); outSolid.setColoringAttributes(outCa); solidPa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_BACK, 0.0f); solidPa.setPolygonOffsetFactor(dynamicOffset); solidPa.setPolygonOffset(staticOffset); solidPa.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE); outSolid.setPolygonAttributes(solidPa); Sphere outSolidSphere = new Sphere(sphereRadius, 0, 15, outSolid); objTrans.addChild(outSolidSphere); innerTG = new TransformGroup(); innerTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); scale = new Transform3D(); updateInnerScale(); objTrans.addChild(innerTG); // Create a smaller sphere to go inside. This sphere has a different // tesselation and color Sphere inWireSphere = new Sphere(sphereRadius, 0, 10, wireApp); innerTG.addChild(inWireSphere); // inside solid ColoringAttributes inCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT); Appearance inSolid = new Appearance(); inSolid.setColoringAttributes(inCa); inSolid.setPolygonAttributes(solidPa); Sphere inSolidSphere = new Sphere(sphereRadius, 0, 10, inSolid); innerTG.addChild(inSolidSphere); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. AxisAngle4f axisAngle = new AxisAngle4f(0.0f, 0.0f, 1.0f, -(float) Math.PI / 2.0f); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 80000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); // set up a white background Background bgWhite = new Background(new Color3f(1.0f, 1.0f, 1.0f)); bgWhite.setApplicationBounds(bounds); objTrans.addChild(bgWhite); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:TextureTest.java
protected Shape3D createTextureGeometry(String szFile, boolean bWireframe) { // load all the texture data from the file and create the geometry // coordinates TextureGeometryInfo texInfo = createTextureCoordinates(szFile); if (texInfo == null) { System.err.println("Could not load texture info for file:" + szFile); return null; }/*from ww w . ja v a2 s. c om*/ // print some stats on the loaded file System.out.println("Loaded File: " + szFile); System.out.println(" Texture image: " + texInfo.m_szImage); System.out.println(" Texture coordinates: " + texInfo.m_TexCoordArray.length); // create an Appearance and assign a Material Appearance app = new Appearance(); PolygonAttributes polyAttribs = null; // create the PolygonAttributes and attach to the Appearance, // note that we use CULL_NONE so that the "rear" side of the geometry // is visible with the applied texture image if (bWireframe == false) polyAttribs = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0); else polyAttribs = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0); app.setPolygonAttributes(polyAttribs); // load the texture image and assign to the appearance TextureLoader texLoader = new TextureLoader(texInfo.m_szImage, Texture.RGB, this); Texture tex = texLoader.getTexture(); app.setTexture(tex); // create a GeometryInfo for the QuadArray that was populated. GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); gi.setCoordinates(texInfo.m_CoordArray); gi.setTextureCoordinates(texInfo.m_TexCoordArray); // use the triangulator utility to triangulate the polygon int[] stripCountArray = { texInfo.m_CoordArray.length }; int[] countourCountArray = { stripCountArray.length }; gi.setContourCounts(countourCountArray); gi.setStripCounts(stripCountArray); Triangulator triangulator = new Triangulator(); triangulator.triangulate(gi); // generate normal vectors for the triangles, not // strictly necessary as we are not lighting the scene // but generally useful NormalGenerator normalGenerator = new NormalGenerator(); normalGenerator.generateNormals(gi); // wrap the GeometryArray in a Shape3D and assign appearance return new Shape3D(gi.getGeometryArray(), app); }
From source file:BooksDemo.java
private Appearance createTexture(String fileName) { Image sourceImage = UIHelper.readImage(fileName); if (sourceImage == null) System.out.println("Image could not be loaded from " + fileName); TextureLoader loader = new TextureLoader(sourceImage, this); ImageComponent2D image = loader.getImage(); if (image == null) System.out.println("Texture could not be loaded from " + fileName); Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image.getWidth(), image.getHeight()); texture.setImage(0, image);/*from w w w . j ava2s. co m*/ texture.setEnable(true); texture.setMagFilter(Texture.BASE_LEVEL_LINEAR); texture.setMinFilter(Texture.BASE_LEVEL_LINEAR); Appearance appearance = new Appearance(); PolygonAttributes polyAttributes = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0f); appearance.setPolygonAttributes(polyAttributes); appearance.setTexture(texture); TextureAttributes textureAttributes = new TextureAttributes(); appearance.setTextureAttributes(textureAttributes); return appearance; }
From source file:ViewProj.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans);/* w w w . j av a2 s .c o m*/ // Create a Sphere. We will display this as both wireframe and // solid to make a hidden line display // wireframe Appearance wireApp = new Appearance(); ColoringAttributes ca = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT); wireApp.setColoringAttributes(ca); wirePa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0.0f); wireApp.setPolygonAttributes(wirePa); Sphere outWireSphere = new Sphere(sphereRadius, 0, 10, wireApp); objTrans.addChild(outWireSphere); // solid ColoringAttributes outCa = new ColoringAttributes(red, ColoringAttributes.SHADE_FLAT); Appearance outSolid = new Appearance(); outSolid.setColoringAttributes(outCa); solidPa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_BACK, 0.0f); solidPa.setPolygonOffsetFactor(dynamicOffset); solidPa.setPolygonOffset(staticOffset); solidPa.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE); outSolid.setPolygonAttributes(solidPa); Sphere outSolidSphere = new Sphere(sphereRadius, 0, 10, outSolid); objTrans.addChild(outSolidSphere); innerTG = new TransformGroup(); innerTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); scale = new Transform3D(); updateInnerScale(); objTrans.addChild(innerTG); // Create a smaller sphere to go inside. This sphere has a different // tesselation and color Sphere inWireSphere = new Sphere(sphereRadius, 0, 15, wireApp); innerTG.addChild(inWireSphere); // inside solid ColoringAttributes inCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT); Appearance inSolid = new Appearance(); inSolid.setColoringAttributes(inCa); inSolid.setPolygonAttributes(solidPa); Sphere inSolidSphere = new Sphere(sphereRadius, 0, 15, inSolid); innerTG.addChild(inSolidSphere); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. AxisAngle4f axisAngle = new AxisAngle4f(0.0f, 0.0f, 1.0f, -(float) Math.PI / 2.0f); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 80000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); //objTrans.addChild(rotator); Background bgWhite = new Background(white); bgWhite.setApplicationBounds(bounds); objTrans.addChild(bgWhite); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:KeyNavigateTest.java
public Group createCeiling(Group g) { System.out.println("Creating ceiling"); Group ceilingGroup = new Group(); Land ceilingTile = null;//w w w . j a v a 2 s . c o m // because we are technically viewing the ceiling from below // we want to switch the normals using a PolygonAttributes. Appearance app = new Appearance(); app.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false)); g.addChild(ceilingGroup); final double kNumTiles = 6; for (double x = -FLOOR_WIDTH + FLOOR_WIDTH / (2 * kNumTiles); x < FLOOR_WIDTH; x = x + FLOOR_WIDTH / kNumTiles) { for (double z = -FLOOR_LENGTH + FLOOR_LENGTH / (2 * kNumTiles); z < FLOOR_LENGTH; z = z + FLOOR_LENGTH / kNumTiles) { ceilingTile = new Land(this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE); ceilingTile.createObject(app, new Vector3d(x, m_kCeilingLevel, z), new Vector3d(FLOOR_WIDTH / (2 * kNumTiles), 1, FLOOR_LENGTH / (2 * kNumTiles)), "ceiling.gif", null, null); } } return ceilingGroup; }
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 ww .jav a 2 s .c o m .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); }
From source file:AppearanceTest.java
public void onFill() { getPolygonAttributes().setPolygonMode(PolygonAttributes.POLYGON_FILL); }
From source file:KeyNavigateTest.java
protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile) {/*from w w w . ja v a 2s .c om*/ Group g = new Group(); app.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false)); app.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f)); m_TextureAttributes = new TextureAttributes(TextureAttributes.REPLACE, new Transform3D(), new Color4f(0, 0, 0, 1), TextureAttributes.FASTEST); app.setTextureAttributes(m_TextureAttributes); if ((m_nFlags & ComplexObject.TEXTURE) == ComplexObject.TEXTURE) setTexture(app, szTextureFile); Cone cone = new Cone(1, 1, Primitive.GENERATE_TEXTURE_COORDS, app); g.addChild(cone); attachBehavior(new TextureAnimationBehavior(m_TextureAttributes)); return g; }
From source file:Demo3D.java
/** * Construction of the desired borders of the virtual universe (cube). * //www .j a v a 2 s . c o 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). * // w w w . j a va2 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; }