List of usage examples for javax.media.j3d Appearance setPolygonAttributes
public void setPolygonAttributes(PolygonAttributes polygonAttributes)
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 . j av a2 s .c o 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: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 ww . j a v a2s. c om // 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: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. j a va 2 s . co 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: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);//w ww .ja va2 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 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; }/* w ww . j ava 2s . co m*/ // 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:BehaviorTest.java
public void addBehaviorToParentGroup(Group nodeParentGroup) { nodeParentGroup.addChild(this); m_TransformGroup = new TransformGroup(); m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); m_BoundsSwitch = new Switch(); m_BoundsSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); Appearance app = new Appearance(); PolygonAttributes polyAttrbutes = new PolygonAttributes(); polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE); app.setPolygonAttributes(polyAttrbutes); m_BoundsSwitch.addChild(new Sphere(1, app)); ColorCube cube = new ColorCube(); cube.setAppearance(app);/*from ww w . jav a2 s.c o m*/ Group g = new Group(); g.addChild(cube); m_BoundsSwitch.addChild(g); m_BoundsSwitch.setWhichChild(Switch.CHILD_NONE); m_TransformGroup.addChild(m_BoundsSwitch); nodeParentGroup.addChild(m_TransformGroup); }
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);// ww w . j a va 2 s . 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:AppearanceTest.java
private Appearance createAppearance(int idx) { Appearance app = new Appearance(); // Globally used colors Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); switch (idx) { // Unlit solid case 0: {/* www. ja va 2 s . c om*/ // Set up the coloring properties Color3f objColor = new Color3f(1.0f, 0.2f, 0.4f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); break; } // Unlit wire frame case 1: { // Set up the coloring properties Color3f objColor = new Color3f(0.5f, 0.0f, 0.2f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setPolygonMode(pa.POLYGON_LINE); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); break; } // Unlit points case 2: { // Set up the coloring properties Color3f objColor = new Color3f(0.2f, 0.2f, 1.0f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setPolygonMode(pa.POLYGON_POINT); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); // Set up point attributes PointAttributes pta = new PointAttributes(); pta.setPointSize(5.0f); app.setPointAttributes(pta); break; } // Lit solid case 3: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } // Texture mapped, lit solid case 4: { // Set up the texture map TextureLoader tex = new TextureLoader(texImage, this); app.setTexture(tex.getTexture()); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); app.setTextureAttributes(texAttr); // Set up the material properties app.setMaterial(new Material(white, black, white, black, 1.0f)); break; } // Transparent, lit solid case 5: { // Set up the transparency properties TransparencyAttributes ta = new TransparencyAttributes(); ta.setTransparencyMode(ta.BLENDED); ta.setTransparency(0.6f); app.setTransparencyAttributes(ta); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); // Set up the material properties Color3f objColor = new Color3f(0.7f, 0.8f, 1.0f); app.setMaterial(new Material(objColor, black, objColor, black, 1.0f)); break; } // Lit solid, no specular case 6: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); break; } // Lit solid, specular only case 7: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(black, black, black, white, 80.0f)); break; } // Another lit solid with a different color case 8: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.8f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } default: { ColoringAttributes ca = new ColoringAttributes(); ca.setColor(new Color3f(0.0f, 1.0f, 0.0f)); app.setColoringAttributes(ca); } } return app; }
From source file:TickTockPicking.java
private Appearance createAppearance(int idx) { Appearance app = new Appearance(); // Globally used colors Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); switch (idx) { // Unlit solid case 0: {// ww w.j ava 2 s. co m // Set up the coloring properties Color3f objColor = new Color3f(1.0f, 0.2f, 0.4f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); break; } // Unlit wire frame case 1: { // Set up the coloring properties Color3f objColor = new Color3f(1.0f, 0.4f, 0.0f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setPolygonMode(pa.POLYGON_LINE); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); break; } // Unlit points case 2: { // Set up the coloring properties Color3f objColor = new Color3f(1.0f, 1.0f, 0.0f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setPolygonMode(pa.POLYGON_POINT); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); // Set up point attributes PointAttributes pta = new PointAttributes(); pta.setPointSize(5.0f); app.setPointAttributes(pta); break; } // Lit solid case 3: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } // Texture mapped, lit solid case 4: { // Set up the texture map TextureLoader tex = new TextureLoader(texImage, this); app.setTexture(tex.getTexture()); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); app.setTextureAttributes(texAttr); // Set up the material properties app.setMaterial(new Material(white, black, white, black, 1.0f)); break; } // Transparent, lit solid case 5: { // Set up the transparency properties TransparencyAttributes ta = new TransparencyAttributes(); ta.setTransparencyMode(ta.BLENDED); ta.setTransparency(0.6f); app.setTransparencyAttributes(ta); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); // Set up the material properties Color3f objColor = new Color3f(0.7f, 0.8f, 1.0f); app.setMaterial(new Material(objColor, black, objColor, black, 1.0f)); break; } // Lit solid, no specular case 6: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); break; } // Lit solid, specular only case 7: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(black, black, black, white, 80.0f)); break; } // Another lit solid with a different color case 8: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.8f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } default: { ColoringAttributes ca = new ColoringAttributes(); ca.setColor(new Color3f(0.0f, 1.0f, 0.0f)); app.setColoringAttributes(ca); } } return 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);/*www .j av a 2 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 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; }