List of usage examples for javax.media.j3d ColoringAttributes setColor
public void setColor(float r, float g, float b)
From source file:Text3DApp.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); Transform3D t3D = new Transform3D(); t3D.setTranslation(new Vector3f(0.0f, 0.0f, -3.0f)); TransformGroup objMove = new TransformGroup(t3D); objRoot.addChild(objMove);/*from w w w. j a v a2 s . c o m*/ // 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); objMove.addChild(objSpin); Appearance textAppear = new Appearance(); ColoringAttributes textColor = new ColoringAttributes(); textColor.setColor(1.0f, 0.0f, 0.0f); textAppear.setColoringAttributes(textColor); textAppear.setMaterial(new Material()); // Create a simple shape leaf node, add it to the scene graph. Font3D font3D = new Font3D(new Font("Helvetica", Font.PLAIN, 1), new FontExtrusion()); Text3D textGeom = new Text3D(font3D, new String("3DText")); textGeom.setAlignment(Text3D.ALIGN_CENTER); Shape3D textShape = new Shape3D(); textShape.setGeometry(textGeom); textShape.setAppearance(textAppear); objSpin.addChild(textShape); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Alpha rotationAlpha = new Alpha(-1, 10000); 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 100 BoundingSphere bounds = new BoundingSphere(); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); DirectionalLight lightD = new DirectionalLight(); lightD.setInfluencingBounds(bounds); lightD.setDirection(new Vector3f(0.0f, 0.0f, -1.0f)); lightD.setColor(new Color3f(1.0f, 0.0f, 1.0f)); objMove.addChild(lightD); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(bounds); objMove.addChild(lightA); return objRoot; }
From source file:TickTockCollision.java
private Group createBox(double scale, Vector3d pos) { // Create a transform group node to scale and position the object. Transform3D t = new Transform3D(); t.set(scale, pos);//from w w w . j a va 2 s .c o m TransformGroup objTrans = new TransformGroup(t); // Create a simple shape leaf node and add it to the scene graph Shape3D shape = new Box(0.5, 5.0, 1.0); objTrans.addChild(shape); // Create a new ColoringAttributes object for the shape's // appearance and make it writable at runtime. Appearance app = shape.getAppearance(); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(0.6f, 0.3f, 0.0f); app.setCapability(app.ALLOW_COLORING_ATTRIBUTES_WRITE); app.setColoringAttributes(ca); // Create a new Behavior object that will perform the collision // detection on the specified object, and add it into // the scene graph. CollisionDetector cd = new CollisionDetector(shape); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); cd.setSchedulingBounds(bounds); // Add the behavior to the scene graph objTrans.addChild(cd); return objTrans; }
From source file:GeomInfoApp.java
Appearance createWireFrameAppearance() { Appearance materialAppear = new Appearance(); PolygonAttributes polyAttrib = new PolygonAttributes(); polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE); materialAppear.setPolygonAttributes(polyAttrib); ColoringAttributes redColoring = new ColoringAttributes(); redColoring.setColor(1.0f, 0.0f, 0.0f); materialAppear.setColoringAttributes(redColoring); return materialAppear; }
From source file:GeomInfoApp.java
public BranchGroup createSceneGraph(boolean wireFrame) { int total = 0; System.out.println("\n --- geometry debug information --- \n"); float[] coordinateData = null; coordinateData = createCoordinateData(); int[] stripCount = { 17, 17, 5, 5, 5, 5, 5, 5, 5 }; // ****** // int[] stripCount = {17,17,17}; // ****** for (int i = 0; i < stripCount.length; i++) { System.out.println("stripCount[" + i + "] = " + stripCount[i]); total += stripCount[i];//from w ww .ja v a 2s . c om } if (total != coordinateData.length / 3) { System.out.println(" coordinateData vertex count: " + coordinateData.length / 3); System.out.println("stripCount total vertex count: " + total); } GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); gi.setCoordinates(coordinateData); gi.setStripCounts(stripCount); Triangulator tr = new Triangulator(); // Triangulator tr = new Triangulator(1); System.out.println("begin triangulation"); tr.triangulate(gi); System.out.println(" END triangulation"); gi.recomputeIndices(); NormalGenerator ng = new NormalGenerator(); ng.generateNormals(gi); gi.recomputeIndices(); Stripifier st = new Stripifier(); st.stripify(gi); gi.recomputeIndices(); Shape3D part = new Shape3D(); if (wireFrame == true) part.setAppearance(createWireFrameAppearance()); else part.setAppearance(createMaterialAppearance()); part.setGeometry(gi.getGeometryArray()); ///////////////////////////// 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); objSpin.addChild(part); //////////////////////// LineStripArray lineArray = new LineStripArray(69, LineArray.COORDINATES, stripCount); //***** // LineStripArray lineArray = new LineStripArray(51, // LineArray.COORDINATES, stripCount); //***** lineArray.setCoordinates(0, coordinateData); Appearance blueColorAppearance = new Appearance(); ColoringAttributes blueColoring = new ColoringAttributes(); blueColoring.setColor(0.0f, 0.0f, 1.0f); blueColorAppearance.setColoringAttributes(blueColoring); LineAttributes lineAttrib = new LineAttributes(); lineAttrib.setLineWidth(2.0f); blueColorAppearance.setLineAttributes(lineAttrib); objSpin.addChild(new Shape3D(lineArray, blueColorAppearance)); 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); DirectionalLight lightD = new DirectionalLight(); lightD.setDirection(new Vector3f(0.0f, -0.7f, -0.7f)); lightD.setInfluencingBounds(bounds); contentRoot.addChild(lightD); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(bounds); contentRoot.addChild(lightA); Background background = new Background(); background.setColor(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:ExDepthCue.java
public Shape3D buildSurface(double freqAlpha, double freqTheta, double radius, float red, float green, float blue) { int nAngles = 64; double amp = radius / 4.0; int nAlpha = nAngles / 2; double theta, alpha; double x, y, z, rprime, r; double deltaTheta, deltaAlpha; int i, j;// w w w . j av a2s . c o m int i1, i2, i3, i4; deltaTheta = 360.0 / (nAngles - 1.0); deltaAlpha = 180.0 / (nAlpha - 1.0); // Build an appearance Appearance app = new Appearance(); LineAttributes latt = new LineAttributes(); latt.setLineWidth(1.0f); app.setLineAttributes(latt); ColoringAttributes catt = new ColoringAttributes(); catt.setColor(red, green, blue); app.setColoringAttributes(catt); PolygonAttributes patt = new PolygonAttributes(); patt.setCullFace(PolygonAttributes.CULL_NONE); patt.setPolygonMode(PolygonAttributes.POLYGON_LINE); app.setPolygonAttributes(patt); // Compute coordinates double[] coordinates = new double[nAlpha * nAngles * 3]; alpha = 90.0; int n = 0; for (i = 0; i < nAlpha; i++) { theta = 0.0; for (j = 0; j < nAngles; j++) { r = radius + amp * Math.sin((freqAlpha * ((double) i / (double) (nAlpha - 1)) + freqTheta * ((double) j / (double) (nAngles - 1))) * 2.0 * Math.PI); y = r * Math.sin(alpha / 180.0 * Math.PI); rprime = y / Math.tan(alpha / 180.0 * Math.PI); x = rprime * Math.cos(theta / 180.0 * Math.PI); z = rprime * Math.sin(theta / 180.0 * Math.PI); coordinates[n + 0] = x; coordinates[n + 1] = y; coordinates[n + 2] = z; n += 3; theta += deltaTheta; } alpha -= deltaAlpha; } // Compute coordinate indexes int[] indexes = new int[(nAlpha - 1) * nAngles * 4]; n = 0; for (i = 0; i < nAlpha - 1; i++) { for (j = 0; j < nAngles; j++) { i1 = i * nAngles + j; if (j == nAngles - 1) { i2 = i1 - j; i3 = (i + 1) * nAngles; } else { i2 = i1 + 1; i3 = (i + 1) * nAngles + j + 1; } i4 = (i + 1) * nAngles + j; indexes[n + 0] = i1; indexes[n + 1] = i2; indexes[n + 2] = i3; indexes[n + 3] = i4; n += 4; } } // Build the shape IndexedQuadArray lines = new IndexedQuadArray(coordinates.length / 3, // Number // of // coordinates GeometryArray.COORDINATES, // coordinates only indexes.length); // Number of indexes lines.setCoordinates(0, coordinates); lines.setCoordinateIndices(0, indexes); Shape3D shape = new Shape3D(lines, app); return shape; }
From source file:ExBluePrint.java
private Group buildGadget() { if (debug)/*from w ww. j av a 2 s.c om*/ 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; }