List of usage examples for javax.media.j3d Appearance Appearance
public Appearance()
From source file:PickWorld.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); Color3f gray = new Color3f(0.4f, 0.4f, 0.4f); idx = idx % 5;// ww w. j ava 2s . c om switch (idx) { // Lit solid case 0: { // Set up the material properties Color3f objColor = new Color3f(0.0f, 0.8f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } // Lit solid, specular only case 1: { // Set up the material properties Color3f objColor = new Color3f(0.0f, 0.4f, 0.2f); app.setMaterial(new Material(black, black, objColor, white, 80.0f)); break; } case 2: { // Set up the texture map TextureLoader tex = new TextureLoader("apimage.jpg", this); app.setTexture(tex.getTexture()); // Set up the material properties app.setMaterial(new Material(gray, black, gray, white, 1.0f)); break; } // Texture mapped, lit solid case 3: { // Set up the texture map TextureLoader tex = new TextureLoader("earth.jpg", this); app.setTexture(tex.getTexture()); // Set up the material properties app.setMaterial(new Material(gray, black, gray, white, 1.0f)); break; } // Another lit solid with a different color case 4: { // Set up the material properties Color3f objColor = new Color3f(1.0f, 1.0f, 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:ExText.java
public Group buildScene() { // Get the current font attributes Font font = (Font) fonts[currentFont].value; String textString = (String) fonts[currentFont].name; // Turn on the example headlight setHeadlightEnable(true);/*from www. j a v a2 s .c o m*/ // Build the scene group scene = new Group(); scene.setCapability(Group.ALLOW_CHILDREN_EXTEND); scene.setCapability(Group.ALLOW_CHILDREN_WRITE); // Build a branch group to hold the text shape // (this allows us to remove the text shape later, // change it, then put it back, all under menu control) textGroup = new BranchGroup(); textGroup.setCapability(BranchGroup.ALLOW_DETACH); scene.addChild(textGroup); // BEGIN EXAMPLE TOPIC // Create a font extrusion with a default extrusion shape extrusion = new FontExtrusion(); // Define a 3D font with a default extrusion path Font3D font3d = new Font3D(font, extrusion); // Build 3D text geometry using the 3D font Text3D tex = new Text3D(); tex.setFont3D(font3d); tex.setString(textString); tex.setAlignment(Text3D.ALIGN_CENTER); // Define a generic shaded appearance Appearance app = new Appearance(); Material mat = new Material(); mat.setLightingEnable(true); app.setMaterial(mat); // Assemble geometry and appearance into a shape // and add it to the scene shape = new Shape3D(tex, app); shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); textGroup.addChild(shape); // END EXAMPLE TOPIC return scene; }
From source file:edu.uci.ics.jung.visualization3d.VisualizationViewer.java
public BranchGroup createSceneGraph(final Canvas3D canvas) { objRoot = new BranchGroup(); objRoot.setCapability(Group.ALLOW_CHILDREN_EXTEND); objRoot.setCapability(Group.ALLOW_CHILDREN_WRITE); TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); // t3d.setScale(0.05); objScale.setTransform(t3d);//from www . j a v a 2 s .co m objRoot.addChild(objScale); Transform3D tt = new Transform3D(); tt.setScale(.05); tt.setTranslation(new Vector3f(0, 0, -30.f)); objTrans = new TransformGroup(tt); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objTrans.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); objScale.addChild(objTrans); // objRoot.addChild(objTrans); // Create Colors, Materials, and Appearances. Appearance look = new Appearance(); Color3f objColor = new Color3f(0.7f, 0.7f, 0.7f); Color3f black = new Color3f(0.f, 0.f, 0.f); Color3f white = new Color3f(1.0f, 1.0f, 0.6f); Color3f gray = new Color3f(.2f, .2f, .2f); Color3f red = new Color3f(1.0f, 0, 0); Color3f yellow = new Color3f(1, 1, 0); Material objMaterial = new Material(objColor, black, objColor, white, 100.0f); Material blackMaterial = new Material(objColor, black, black, objColor, 10.0f); Material whiteMaterial = new Material(white, white, white, white, 100.0f); Material grayMaterial = new Material(gray, black, gray, gray, 100.0f); Material redMaterial = new Material(red, black, red, red, 100.0f); Material yellowMaterial = new Material(yellow, black, yellow, yellow, 100); look.setMaterial(new Material(objColor, black, objColor, white, 100.0f)); Appearance blackLook = new Appearance(); blackLook.setMaterial(blackMaterial); Appearance whiteLook = new Appearance(); whiteLook.setMaterial(whiteMaterial); Appearance grayLook = new Appearance(); grayLook.setMaterial(grayMaterial); grayLook.setCapability(Appearance.ALLOW_MATERIAL_READ); grayLook.setCapability(Appearance.ALLOW_MATERIAL_WRITE); final Appearance redLook = new Appearance(); redLook.setMaterial(redMaterial); // vertexLook = redLook; Appearance objLook = new Appearance(); objLook.setMaterial(objMaterial); grayLook = objLook; final Appearance yellowLook = new Appearance(); yellowLook.setMaterial(yellowMaterial); Bounds bounds = new BoundingSphere(new Point3d(), 300); MouseRotate behavior1 = new MouseRotate(); behavior1.setTransformGroup(objTrans); objTrans.addChild(behavior1); behavior1.setSchedulingBounds(bounds); MouseWheelZoom behavior2 = new MouseWheelZoom(); behavior2.setTransformGroup(objTrans); // behavior2.setFactor(10); objTrans.addChild(behavior2); behavior2.setSchedulingBounds(bounds); MouseTranslate behavior3 = new MouseTranslate(); behavior3.setTransformGroup(objTrans); objTrans.addChild(behavior3); behavior3.setSchedulingBounds(bounds); PickTranslateBehavior ptb = new PickTranslateBehavior(objRoot, canvas, bounds, PickTool.GEOMETRY); ptb.setSchedulingBounds(bounds); // objTrans.addChild(ptb); ptb.setupCallback(new PickingCallback() { public void transformChanged(int type, TransformGroup tg) { if (tg == null) return; Transform3D t3d = new Transform3D(); tg.getTransform(t3d); // System.err.println(tg+" transformChanged \n"+t3d); Point3f p1 = new Point3f(); V v = vertexMap.getKey(tg); // Transform3D lvw = new Transform3D(); // tg.getLocalToVworld(lvw); // System.err.println("lvw = \n"+lvw); // lvw.invert(); // System.err.println("invert lvw = \n"+lvw); Point3f p0 = layout.transform(v); // Transform3D vwip = new Transform3D(); // canvas.getVworldToImagePlate(vwip); // System.err.println("vwip=\n"+vwip); // t3d.mul(lvw); t3d.transform(p1); // scale.transform(p1); System.err.println( "change location for vertex " + v + ", transformGroup " + tg + " from " + p0 + " to " + p1); // p1.set(p1.getX()*2,p1.getY()*2,p1.getZ()*2); // layout.setLocation(v, p1); } }); PickSphereBehavior psb = new PickSphereBehavior(objRoot, canvas, bounds); PickVertexBehavior pvb = new PickVertexBehavior(objRoot, canvas, bounds, renderContext.getPickedVertexState()); objTrans.addChild(pvb); pvb.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { for (V v : graph.getVertices()) { VertexGroup<V> vg = vertexMap.get(v); Appearance look = redLook; if (renderContext.getPickedVertexState().isPicked(v)) { look = yellowLook; } Node node = vg.getShape(); if (node instanceof Primitive) { ((Primitive) node).setAppearance(look); } } } }); //Shine it with two colored lights. Color3f lColor1 = new Color3f(.5f, .5f, .5f); Color3f lColor2 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lDir2 = new Vector3f(-1.0f, 0.0f, -1.0f); DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2); AmbientLight ambient = new AmbientLight(lColor1); lgt2.setInfluencingBounds(bounds); ambient.setInfluencingBounds(bounds); objRoot.addChild(lgt2); objRoot.addChild(ambient); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); // VisRunner runner = new VisRunner((IterativeContext)elayout); // runner.relax(); return objRoot; }
From source file:PickCollisionTest.java
protected void addSphere(BranchGroup bg, double x, double y, double z, Vector3d incVector, String name) { Appearance app = new Appearance(); TransformGroup sphereTg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, y, z)); sphereTg.setTransform(t3d);// w w w . ja va 2 s . co m sphereTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); sphereTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); sphereTg.addChild(new Sphere(1, app)); bg.addChild(sphereTg); recursiveSetUserData(sphereTg, name); // create the collision behaviour CollisionBehavior collisionBehavior = new CollisionBehavior(bg, sphereTg, app, new Vector3d(x, y, z), incVector); collisionBehavior.setSchedulingBounds(getApplicationBounds()); bg.addChild(collisionBehavior); }
From source file:BackgroundApp.java
public BranchGroup createBackGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); PointArray starGeom1 = new PointArray(7, PointArray.COORDINATES); Appearance starAppear1 = new Appearance(); starGeom1.setCoordinate(0, new Point3f(0.79483311f, -0.58810995f, 0.14955615f)); starGeom1.setCoordinate(1, new Point3f(0.44430932f, -0.55736839f, -0.70137505f)); starGeom1.setCoordinate(2, new Point3f(0.94901367f, -0.30404968f, 0.08322775f)); starGeom1.setCoordinate(3, new Point3f(0.68060123f, -0.43044807f, 0.59287173f)); starGeom1.setCoordinate(4, new Point3f(-0.11641672f, 0.47273532f, 0.87348049f)); starGeom1.setCoordinate(5, new Point3f(-0.10399289f, -0.98059412f, 0.16619437f)); starGeom1.setCoordinate(6, new Point3f(0.08024400f, -0.96944100f, -0.23182900f)); PointAttributes point1 = new PointAttributes(4.0f, false); starAppear1.setPointAttributes(point1); objRoot.addChild(new Shape3D(starGeom1, starAppear1)); PointArray starGeom2 = new PointArray(18, PointArray.COORDINATES); starGeom2.setCoordinate(0, new Point3f(0.050844f, -0.992329f, 0.112678f)); starGeom2.setCoordinate(1, new Point3f(-0.063091f, -0.997672f, 0.025869f)); starGeom2.setCoordinate(2, new Point3f(0.096706f, -0.980384f, 0.171736f)); starGeom2.setCoordinate(3, new Point3f(-0.562384f, 0.073568f, 0.823595f)); starGeom2.setCoordinate(4, new Point3f(-0.863904f, 0.059045f, 0.500180f)); starGeom2.setCoordinate(5, new Point3f(-0.727033f, 0.304149f, 0.615559f)); starGeom2.setCoordinate(6, new Point3f(-0.724850f, 0.535590f, 0.433281f)); starGeom2.setCoordinate(7, new Point3f(0.185904f, -0.976907f, -0.105311f)); starGeom2.setCoordinate(8, new Point3f(0.738028f, -0.531886f, -0.415221f)); starGeom2.setCoordinate(9, new Point3f(-0.402152f, 0.392690f, -0.827085f)); starGeom2.setCoordinate(10, new Point3f(-0.020020f, -0.999468f, -0.025724f)); starGeom2.setCoordinate(11, new Point3f(-0.384103f, -0.887075f, 0.256050f)); starGeom2.setCoordinate(12, new Point3f(-0.224464f, -0.968946f, -0.103720f)); starGeom2.setCoordinate(13, new Point3f(-0.828880f, -0.397932f, -0.393203f)); starGeom2.setCoordinate(14, new Point3f(-0.010557f, -0.998653f, 0.050797f)); starGeom2.setCoordinate(15, new Point3f(-0.282122f, 0.258380f, -0.923930f)); starGeom2.setCoordinate(16, new Point3f(-0.941342f, -0.030364f, 0.336082f)); starGeom2.setCoordinate(17, new Point3f(0.00057f, -0.99651f, -0.08344f)); Appearance starAppear2 = new Appearance(); PointAttributes point2 = new PointAttributes(2.0f, false); starAppear2.setPointAttributes(point2); objRoot.addChild(new Shape3D(starGeom2, starAppear2)); PointArray starGeom3 = new PointArray(20, PointArray.COORDINATES); starGeom3.setCoordinate(0, new Point3f(0.07292f, -0.98862f, -0.13153f)); starGeom3.setCoordinate(1, new Point3f(0.23133f, -0.87605f, -0.42309f)); starGeom3.setCoordinate(2, new Point3f(-0.08215f, -0.64657f, 0.75840f)); starGeom3.setCoordinate(3, new Point3f(-0.84545f, 0.53398f, 0.00691f)); starGeom3.setCoordinate(4, new Point3f(-0.49365f, -0.83645f, -0.23795f)); starGeom3.setCoordinate(5, new Point3f(0.06883f, -0.99319f, -0.09396f)); starGeom3.setCoordinate(6, new Point3f(0.87582f, -0.40662f, 0.25997f)); starGeom3.setCoordinate(7, new Point3f(-0.09095f, -0.99555f, 0.02467f)); starGeom3.setCoordinate(8, new Point3f(0.45306f, -0.81575f, -0.35955f)); starGeom3.setCoordinate(9, new Point3f(0.17669f, -0.97939f, 0.09776f)); starGeom3.setCoordinate(10, new Point3f(0.27421f, -0.83963f, 0.46884f)); starGeom3.setCoordinate(11, new Point3f(0.32703f, -0.94013f, -0.09584f)); starGeom3.setCoordinate(12, new Point3f(-0.01615f, -0.99798f, -0.06132f)); starGeom3.setCoordinate(13, new Point3f(-0.76665f, 0.45998f, -0.44791f)); starGeom3.setCoordinate(14, new Point3f(-0.91025f, -0.07102f, 0.40791f)); starGeom3.setCoordinate(15, new Point3f(-0.00240f, -0.97104f, -0.23887f)); starGeom3.setCoordinate(16, new Point3f(0.91936f, -0.39244f, 0.02740f)); starGeom3.setCoordinate(17, new Point3f(0.18290f, -0.97993f, 0.07920f)); starGeom3.setCoordinate(18, new Point3f(-0.48755f, 0.61592f, 0.61884f)); starGeom3.setCoordinate(19, new Point3f(-0.89375f, 0.36087f, -0.26626f)); objRoot.addChild(new Shape3D(starGeom3)); int[] stripCount = { 10 }; LineStripArray orion = new LineStripArray(10, LineStripArray.COORDINATES, stripCount); orion.setCoordinate(0, new Point3f(0.978330f, -0.033900f, 0.204426f)); orion.setCoordinate(1, new Point3f(0.968007f, -0.167860f, 0.186506f)); orion.setCoordinate(2, new Point3f(0.981477f, -0.142660f, 0.127873f)); orion.setCoordinate(3, new Point3f(0.983764f, -0.005220f, 0.179391f)); orion.setCoordinate(4, new Point3f(0.981112f, 0.110597f, 0.158705f)); orion.setCoordinate(5, new Point3f(0.967377f, 0.172516f, 0.185523f)); orion.setCoordinate(6, new Point3f(0.961385f, 0.128845f, 0.243183f)); orion.setCoordinate(7, new Point3f(0.978330f, -0.033900f, 0.204426f)); orion.setCoordinate(8, new Point3f(0.981293f, -0.020980f, 0.191375f)); orion.setCoordinate(9, new Point3f(0.983764f, -0.005220f, 0.179391f)); objRoot.addChild(new Shape3D(orion)); objRoot.compile();/* w w w. ja va2 s . c o m*/ return objRoot; }
From source file:AlternateAppearanceScopeTest.java
BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Create influencing bounds worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent Transform3D t = new Transform3D(); // move the object upwards t.set(new Vector3f(0.0f, 0.1f, 0.0f)); // Shrink the object t.setScale(0.8);/*from w ww .j a v a2 s.c o m*/ TransformGroup trans = new TransformGroup(t); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); otherApp = new Appearance(); altMat = new Material(); altMat.setCapability(Material.ALLOW_COMPONENT_WRITE); altMat.setDiffuseColor(new Color3f(0.0f, 1.0f, 0.0f)); otherApp.setMaterial(altMat); altApp = new AlternateAppearance(); altApp.setAppearance(otherApp); altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_WRITE); altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_READ); altApp.setInfluencingBounds(worldBounds); objRoot.addChild(altApp); // Build foreground geometry into two groups. We'll // create three directional lights below, one each with // scope to cover the first geometry group only, the // second geometry group only, or both geometry groups. Appearance app1 = new Appearance(); mat1 = new Material(); mat1.setCapability(Material.ALLOW_COMPONENT_WRITE); mat1.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f)); app1.setMaterial(mat1); content1 = new SphereGroup(0.05f, // radius of spheres 0.4f, // x spacing 0.2f, // y spacing 3, // number of spheres in X 5, // number of spheres in Y app1, // appearance true); // alt app override = true trans.addChild(content1); shapes1 = ((SphereGroup) content1).getShapes(); content2 = new SphereGroup(0.05f, // radius of spheres .4f, // x spacing 0.2f, // y spacing 2, // number of spheres in X 5, // number of spheres in Y app1, // appearance true); // alt app override = true trans.addChild(content2); shapes2 = ((SphereGroup) content2).getShapes(); // Add lights DirectionalLight light1 = null; light1 = new DirectionalLight(); light1.setEnable(true); light1.setColor(new Color3f(0.2f, 0.2f, 0.2f)); light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light1.setInfluencingBounds(worldBounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(); light2.setEnable(true); light2.setColor(new Color3f(0.2f, 0.2f, 0.2f)); light2.setDirection(new Vector3f(-1.0f, 0.0f, 1.0f)); light2.setInfluencingBounds(worldBounds); objRoot.addChild(light2); // Add an ambient light to dimly illuminate the rest of // the shapes in the scene to help illustrate that the // directional lights are being scoped... otherwise it looks // like we're just removing shapes from the scene AmbientLight ambient = new AmbientLight(); ambient.setEnable(true); ambient.setColor(new Color3f(1.0f, 1.0f, 1.0f)); ambient.setInfluencingBounds(worldBounds); objRoot.addChild(ambient); objRoot.addChild(trans); 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 w w w.j a v a 2 s .c o 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:TickTockPicking.java
public BranchGroup createSceneGraph(Canvas3D c) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4);/*ww w.j a va 2 s .c o m*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and behaviors BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // Set up the global lights Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objScale.addChild(aLgt); objScale.addChild(lgt1); // Create a pair of transform group nodes and initialize them to // identity. Enable the TRANSFORM_WRITE capability so that // our behaviors can modify them at runtime. Add them to the // root of the subgraph. TransformGroup objTrans1 = new TransformGroup(); objTrans1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objScale.addChild(objTrans1); TransformGroup objTrans2 = new TransformGroup(); objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans1.addChild(objTrans2); // Create the positioning and scaling transform group node. Transform3D t = new Transform3D(); t.set(0.3, new Vector3d(0.0, -1.5, 0.0)); TransformGroup objTrans3 = new TransformGroup(t); objTrans2.addChild(objTrans3); // Create a simple shape leaf node, set it's appearance, and // add it to the scene graph. Shape3D shape = new Cube(); Appearance a = new Appearance(); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); a.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); shape.setAppearance(a); shape.setCapability(shape.ALLOW_APPEARANCE_READ); shape.setCapability(shape.ALLOW_APPEARANCE_WRITE); objTrans3.addChild(shape); // Create a new Behavior object that will perform the desired // rotation on the specified transform object and add it into // the scene graph. Transform3D yAxis1 = new Transform3D(); yAxis1.rotX(Math.PI / 2.0); Alpha tickTockAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 2500, 200, 5000, 2500, 200); RotationInterpolator tickTock = new RotationInterpolator(tickTockAlpha, objTrans1, yAxis1, -(float) Math.PI / 2.0f, (float) Math.PI / 2.0f); tickTock.setSchedulingBounds(bounds); objTrans2.addChild(tickTock); // Create a new Behavior object that will perform the desired // rotation on the specified transform object and add it into // the scene graph. Transform3D yAxis2 = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans2, yAxis2, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans2.addChild(rotator); // Now create the simple picking behavior PickHighlightBehavior pickBeh = new PickHighlightBehavior(c, objRoot, bounds); // Create a bunch of objects with a behavior and add them // into the scene graph. int row, col; Appearance[][] app = new Appearance[3][3]; for (row = 0; row < 3; row++) for (col = 0; col < 3; col++) app[row][col] = createAppearance(row * 3 + col); for (int i = 0; i < 3; i++) { double ypos = (double) (i - 1) * 1.5; for (int j = 0; j < 3; j++) { double xpos = (double) (j - 1) * 1.5; objScale.addChild(createObject(app[i][j], 0.3, xpos, ypos)); } } // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:ExRaster.java
public Group buildScene() { // Turn on the headlight setHeadlightEnable(true);/*from w w w . j av a2 s . c o m*/ // Default to examine navigation setNavigationType(Examine); // Build the scene root Group scene = new Group(); if (debug) System.err.println(" rasters..."); // BEGIN EXAMPLE TOPIC // Create three raster geometry shapes, each with a // different annotation text image // Load the texture images TextureLoader texLoader = new TextureLoader("one.jpg", this); ImageComponent2D oneImage = texLoader.getImage(); if (oneImage == null) { System.err.println("Cannot load 'one.jpg'"); } texLoader = new TextureLoader("two.jpg", this); ImageComponent2D twoImage = texLoader.getImage(); if (twoImage == null) { System.err.println("Cannot load 'two.jpg'"); } texLoader = new TextureLoader("three.jpg", this); ImageComponent2D threeImage = texLoader.getImage(); if (threeImage == null) { System.err.println("Cannot load 'three.jpg'"); } // Create raster geometries and shapes Vector3f trans = new Vector3f(); Transform3D tr = new Transform3D(); TransformGroup tg; // Left Raster raster = new Raster(); raster.setPosition(new Point3f(-2.0f, 0.75f, 0.0f)); raster.setType(Raster.RASTER_COLOR); raster.setOffset(0, 0); raster.setSize(64, 32); raster.setImage(oneImage); Shape3D sh = new Shape3D(raster, new Appearance()); scene.addChild(sh); // Middle-back raster = new Raster(); raster.setPosition(new Point3f(0.0f, 0.75f, -2.0f)); raster.setType(Raster.RASTER_COLOR); raster.setOffset(0, 0); raster.setSize(64, 32); raster.setImage(twoImage); sh = new Shape3D(raster, new Appearance()); scene.addChild(sh); // Right raster = new Raster(); raster.setPosition(new Point3f(2.0f, 0.75f, 0.0f)); raster.setType(Raster.RASTER_COLOR); raster.setOffset(0, 0); raster.setSize(64, 32); raster.setImage(threeImage); sh = new Shape3D(raster, new Appearance()); scene.addChild(sh); // END EXAMPLE TOPIC // Build foreground geometry including a floor and // cones on which the raster images sit if (debug) System.err.println(" cones..."); Appearance app0 = new Appearance(); Material mat0 = new Material(); mat0.setAmbientColor(0.2f, 0.2f, 0.2f); mat0.setDiffuseColor(1.0f, 0.0f, 0.0f); mat0.setSpecularColor(0.7f, 0.7f, 0.7f); app0.setMaterial(mat0); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3f(-2.0f, 0.0f, 0.0f)); TransformGroup tg0 = new TransformGroup(t3d); Cone cone0 = new Cone(0.5f, // radius 1.5f, // height Primitive.GENERATE_NORMALS, // flags 16, // x division 16, // y division app0); // appearance tg0.addChild(cone0); scene.addChild(tg0); Appearance app1 = new Appearance(); Material mat1 = new Material(); mat1.setAmbientColor(0.2f, 0.2f, 0.2f); mat1.setDiffuseColor(0.0f, 1.0f, 0.0f); mat1.setSpecularColor(0.7f, 0.7f, 0.7f); app1.setMaterial(mat1); t3d = new Transform3D(); t3d.setTranslation(new Vector3f(0.0f, 0.0f, -2.0f)); TransformGroup tg1 = new TransformGroup(t3d); Cone cone1 = new Cone(0.5f, // radius 1.5f, // height Primitive.GENERATE_NORMALS, // flags 16, // x division 16, // y division app1); // appearance tg1.addChild(cone1); scene.addChild(tg1); Appearance app2 = new Appearance(); Material mat2 = new Material(); mat2.setAmbientColor(0.2f, 0.2f, 0.2f); mat2.setDiffuseColor(0.0f, 0.6f, 1.0f); mat2.setSpecularColor(0.7f, 0.7f, 0.7f); app2.setMaterial(mat2); t3d = new Transform3D(); t3d.setTranslation(new Vector3f(2.0f, 0.0f, 0.0f)); TransformGroup tg2 = new TransformGroup(t3d); Cone cone2 = new Cone(0.5f, // radius 1.5f, // height Primitive.GENERATE_NORMALS, // flags 16, // x division 16, // y division app2); // appearance tg2.addChild(cone2); scene.addChild(tg2); return scene; }
From source file:SimpleTextureGen.java
/** * This defines the appearance for the shape using a texture. It uses a * TextureLoader to load the texture image from an external file and a * TexCoordGeneration to define the texture coordinates. * /*from w w w. j a v a 2 s . c om*/ * @return Appearance that uses a texture. */ protected Appearance DefineAppearance() { //This is used to automatically define the texture coordinates. //The coordinates are generated in object coordinates, but by //commented out the line with 'OBJECT_LINEAR' and uncommenting //the line 'EYE_LINEAR' the program will use eye coordinates. TexCoordGeneration textCoorder = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, //TexCoordGeneration.EYE_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_2); //Load the texture from the external image file TextureLoader textLoad = new TextureLoader("housebrick.jpg", this); //Access the image from the loaded texture ImageComponent2D textImage = textLoad.getImage(); //Create a two dimensional texture Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture.RGB, textImage.getWidth(), textImage.getHeight()); //Set the texture from the image loaded texture.setImage(0, textImage); //Create the appearance that will use the texture Appearance app = new Appearance(); app.setTexture(texture); //Pass the coordinate generator to the appearance app.setTexCoordGeneration(textCoorder); //Define how the texture will be mapped onto the surface //by creating the appropriate texture attributes TextureAttributes textAttr = new TextureAttributes(); textAttr.setTextureMode(TextureAttributes.REPLACE); app.setTextureAttributes(textAttr); app.setMaterial(new Material()); return app; }