List of usage examples for javax.media.j3d PolygonAttributes POLYGON_LINE
int POLYGON_LINE
To view the source code for javax.media.j3d PolygonAttributes POLYGON_LINE.
Click Source Link
From source file:SimpleWire.java
/** * This constructs a cube using the Box utility class. The attributes are * set so that the lines are drawn and not the faces. * //w ww . j av a 2s. c o m * @return Node that is the cube */ protected Node buildShape() { Appearance app = new Appearance(); //Create the polygon attributes PolygonAttributes polyAttr = new PolygonAttributes(); //Set them so that the draw mode is polygon line polyAttr.setPolygonMode(PolygonAttributes.POLYGON_LINE); //Use these in the appearance app.setPolygonAttributes(polyAttr); return new Box(1.0f, 1.0f, 1.0f, app); }
From source file:TriangulatorTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 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);//from w w w .j a v a 2s.co m // triangulate the polygon GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); gi.setCoordinates(m_VertexArray); int[] stripCountArray = { 10, 5 }; int[] countourCountArray = { stripCountArray.length }; gi.setContourCounts(countourCountArray); gi.setStripCounts(stripCountArray); Triangulator triangulator = new Triangulator(); triangulator.triangulate(gi); NormalGenerator normalGenerator = new NormalGenerator(); normalGenerator.generateNormals(gi); // create an appearance Appearance ap = new Appearance(); // render as a wireframe PolygonAttributes polyAttrbutes = new PolygonAttributes(); polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE); ap.setPolygonAttributes(polyAttrbutes); // add both a wireframe and a solid version // of the triangulated surface Shape3D shape1 = new Shape3D(gi.getGeometryArray(), ap); Shape3D shape2 = new Shape3D(gi.getGeometryArray()); objTrans.addChild(shape1); objTrans.addChild(shape2); objRoot.addChild(objTrans); return objRoot; }
From source file:CuboidTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator);/*from w ww.j a va 2s . c o m*/ // create an appearance Appearance ap = new Appearance(); // render as a wireframe PolygonAttributes polyAttrbutes = new PolygonAttributes(); polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE); ap.setPolygonAttributes(polyAttrbutes); objTrans.addChild(new Cuboid(50, 30, 20, ap)); objTrans.addChild(new Box(25, 15, 10, ap)); objRoot.addChild(objTrans); return objRoot; }
From source file:Text3DTest.java
TransformGroup createText3D(TornadoRotation rotator, String szText, int nSize, float scale, float trans, int nPath) { TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(scale);/*from w w w. ja va 2 s.c o m*/ t3d.setTranslation(new Vector3d(0.0, trans, -10.0)); tg.setTransform(t3d); // use a customized FontExtrusion object to control the depth of the // text double X1 = 0; double Y1 = 0; double X2 = 3; double Y2 = 0; Shape extrusionShape = new java.awt.geom.Line2D.Double(X1, Y1, X2, Y2); FontExtrusion fontEx = new FontExtrusion(extrusionShape); Font3D f3d = new Font3D(new Font("TimesRoman", Font.PLAIN, nSize), fontEx); TornadoText3D text3D = new TornadoText3D(f3d, szText, new Point3f(0.0f, 0.0f, 0.0f), Text3D.ALIGN_CENTER, nPath); rotator.addTornadoText3D(text3D); // create an appearance Color3f black = new Color3f(0.1f, 0.1f, 0.1f); Color3f objColor = new Color3f(0.2f, 0.2f, 0.2f); Appearance app = new Appearance(); app.setMaterial(new Material(objColor, black, objColor, black, 90.0f)); // render as a wireframe PolygonAttributes polyAttrbutes = new PolygonAttributes(); polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE); app.setPolygonAttributes(polyAttrbutes); tg.addChild(new Shape3D(text3D, app)); return tg; }
From source file:PickCollisionTest.java
protected void addCube(BranchGroup bg, double x, double y, double z, double sx, double sy, double sz, String name, boolean wireframe) { // create four ColorCube objects TransformGroup cubeTg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, y, z)); t3d.setScale(new Vector3d(sx, sy, sz)); cubeTg.setTransform(t3d);/*from w w w . ja v a 2 s . co m*/ ColorCube cube = new ColorCube(1.0); // we have to make the front face wireframe // or we can't see inside the box! if (wireframe) { Appearance app = new Appearance(); app.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0)); cube.setAppearance(app); } cubeTg.addChild(cube); recursiveSetUserData(cubeTg, name); bg.addChild(cubeTg); }
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 ww .jav a2 s.c om // 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:TwistStripApp.java
public BranchGroup createSceneGraph() { BranchGroup contentRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Add it to the root of the subgraph. TransformGroup objSpin = new TransformGroup(); objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); contentRoot.addChild(objSpin);// w w w .j a v a2 s . c om Shape3D twist = new Twist(); objSpin.addChild(twist); // Duplicate the twist strip geometry and set the // appearance of the new Shape3D object to line mode // without culling. // Add the POLYGON_FILLED and POLYGON_LINE strips // in the scene graph at the same point. // This will show the triangles of the original Mobius strip that // are clipped. The PolygonOffset is set to prevent stitching. PolygonAttributes polyAttrib = new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrib.setPolygonOffset(0.001f); Appearance polyAppear = new Appearance(); polyAppear.setPolygonAttributes(polyAttrib); objSpin.addChild(new Shape3D(twist.getGeometry(), polyAppear)); Alpha rotationAlpha = new Alpha(-1, 16000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin); // a bounding sphere specifies a region a behavior is active // create a sphere centered at the origin with radius of 1 BoundingSphere bounds = new BoundingSphere(); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); // make background white Background background = new Background(1.0f, 1.0f, 1.0f); background.setApplicationBounds(bounds); contentRoot.addChild(background); // Let Java 3D perform optimizations on this scene graph. contentRoot.compile(); return contentRoot; }
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 w ww. java 2 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: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 a 2 s .com // 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:ExBluePrint.java
private Group buildGadget() { if (debug)// w w w .j av a2 s .c o m System.err.println(" gadget..."); // // Create two appearances: // wireframeApp: draw as blue wireframe // shadedApp: draw as metalic shaded polygons // // Wireframe: // no Material - defaults to coloring attributes color // polygons as lines, with backfaces // thick lines Appearance wireframeApp = new Appearance(); ColoringAttributes wireframeCatt = new ColoringAttributes(); wireframeCatt.setColor(0.0f, 0.2559f, 0.4213f); wireframeCatt.setShadeModel(ColoringAttributes.SHADE_FLAT); wireframeApp.setColoringAttributes(wireframeCatt); PolygonAttributes wireframePatt = new PolygonAttributes(); wireframePatt.setPolygonMode(PolygonAttributes.POLYGON_LINE); wireframePatt.setCullFace(PolygonAttributes.CULL_NONE); wireframeApp.setPolygonAttributes(wireframePatt); LineAttributes wireframeLatt = new LineAttributes(); wireframeLatt.setLineWidth(2.0f); wireframeApp.setLineAttributes(wireframeLatt); // Shaded: // silver material Appearance shadedApp = new Appearance(); Material shadedMat = new Material(); shadedMat.setAmbientColor(0.30f, 0.30f, 0.30f); shadedMat.setDiffuseColor(0.30f, 0.30f, 0.50f); shadedMat.setSpecularColor(0.60f, 0.60f, 0.80f); shadedMat.setShininess(0.10f); shadedApp.setMaterial(shadedMat); ColoringAttributes shadedCatt = new ColoringAttributes(); shadedCatt.setShadeModel(ColoringAttributes.SHADE_GOURAUD); shadedApp.setColoringAttributes(shadedCatt); // // Create a switch group to hold two versions of the // shape: one wireframe, and one shaded // Transform3D tr = new Transform3D(); tr.set(new Vector3f(-1.0f, 0.2f, 0.0f)); TransformGroup gadget = new TransformGroup(tr); shadingSwitch = new Switch(); shadingSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); Group wireframe = new Group(); Group shaded = new Group(); shadingSwitch.addChild(wireframe); shadingSwitch.addChild(shaded); shadingSwitch.setWhichChild(1); // shaded gadget.addChild(shadingSwitch); // // Build a gear (wireframe and shaded) // tr = new Transform3D(); tr.rotY(Math.PI / 2.0); TransformGroup tg = new TransformGroup(tr); SpurGear gear = new SpurGearThinBody(24, // tooth count 1.6f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness wireframeApp);// appearance tg.addChild(gear); wireframe.addChild(tg); tg = new TransformGroup(tr); gear = new SpurGearThinBody(24, // tooth count 1.6f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness shadedApp); // appearance tg.addChild(gear); shaded.addChild(tg); // // Build another gear (wireframe and shaded) // tr.rotY(Math.PI / 2.0); Vector3f trans = new Vector3f(-0.5f, 0.0f, 0.0f); tr.setTranslation(trans); tg = new TransformGroup(tr); gear = new SpurGearThinBody(30, // tooth count 2.0f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness wireframeApp);// appearance tg.addChild(gear); wireframe.addChild(tg); tg = new TransformGroup(tr); gear = new SpurGearThinBody(30, // tooth count 2.0f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness shadedApp); // appearance tg.addChild(gear); shaded.addChild(tg); // // Build a cylindrical shaft (wireframe and shaded) // tr.rotZ(-Math.PI / 2.0); trans = new Vector3f(1.0f, 0.0f, 0.0f); tr.setTranslation(trans); tg = new TransformGroup(tr); Cylinder cyl = new Cylinder(0.3f, // radius 4.0f, // length Primitive.GENERATE_NORMALS, // format 16, // radial resolution 1, // length-wise resolution wireframeApp);// appearance tg.addChild(cyl); wireframe.addChild(tg); tg = new TransformGroup(tr); cyl = new Cylinder(0.3f, // radius 4.0f, // length Primitive.GENERATE_NORMALS, // format 16, // radial resolution 1, // length-wise resolution shadedApp); // appearance tg.addChild(cyl); shaded.addChild(tg); // // Build shaft teeth (wireframe and shaded) // tr.rotY(Math.PI / 2.0); trans = new Vector3f(2.05f, 0.0f, 0.0f); tr.setTranslation(trans); tg = new TransformGroup(tr); gear = new SpurGear(12, // tooth count 0.5f, // pitch circle radius 0.3f, // shaft radius 0.05f, // addendum 0.05f, // dedendum 1.5f, // gear thickness 0.8f, // tooth tip thickness wireframeApp);// appearance tg.addChild(gear); wireframe.addChild(tg); tg = new TransformGroup(tr); gear = new SpurGear(12, // tooth count 0.5f, // pitch circle radius 0.3f, // shaft radius 0.05f, // addendum 0.05f, // dedendum 1.5f, // gear thickness 0.8f, // tooth tip thickness shadedApp); // appearance tg.addChild(gear); shaded.addChild(tg); return gadget; }