List of usage examples for javax.media.j3d BranchGroup BranchGroup
public BranchGroup()
From source file:IntersectTest.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode);/*from w w w . j a va 2 s . co m*/ // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f); Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objRoot.addChild(light2); Transform3D t3 = new Transform3D(); // Shapes for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { t3.setTranslation(new Vector3d(-4 + x * 4.0, -4 + y * 4.0, -20 - z * 4.0)); TransformGroup objTrans = new TransformGroup(t3); objRoot.addChild(objTrans); // Create a simple shape leaf node, add it to the scene // graph. GeometryArray geom = null; if (((x + y + z) % 2) == 0) { geom = new RandomColorCube(); } else { geom = new RandomColorTetrahedron(); } Shape3D shape = new Shape3D(geom); // use the utility method to set the capabilities PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL); objTrans.addChild(shape); } } } // Lines Point3f[] verts = { new Point3f(-2.0f, 0.0f, 0.0f), new Point3f(2.0f, 0.0f, 0.0f) }; Color3f grey = new Color3f(0.7f, 0.7f, 0.7f); Color3f[] colors = { grey, grey }; for (int y = 0; y < 5; y++) { for (int z = 0; z < 5; z++) { t3.setTranslation(new Vector3d(7.0, -4 + y * 2.0, -20.0 - z * 2.0)); TransformGroup objTrans = new TransformGroup(t3); objRoot.addChild(objTrans); LineArray la = new LineArray(verts.length, LineArray.COORDINATES | LineArray.COLOR_3); la.setCoordinates(0, verts); la.setColors(0, colors); Shape3D shape = new Shape3D(); shape.setGeometry(la); // use the utility method to set the capabilities PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL); objTrans.addChild(shape); } } // Points for (double x = -2.0; x <= 2.0; x += 1.0) { for (double y = -2.0; y <= 2.0; y += 1.0) { for (double z = -2.0; z <= 2.0; z += 1.0) { t3.setTranslation(new Vector3d(-10.0 + 2.0 * x, 0.0 + 2.0 * y, -20.0 + 2.0 * z)); TransformGroup objTrans = new TransformGroup(t3); objRoot.addChild(objTrans); PointArray pa = new PointArray(1, PointArray.COORDINATES | PointArray.COLOR_3); pa.setCoordinate(0, new Point3d(0.0, 0.0, 0.0)); pa.setColor(0, grey); Shape3D shape = new Shape3D(); shape.setGeometry(pa); // use the utility method to set the capabilities PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL); objTrans.addChild(shape); } } } return objRoot; }
From source file:Viewer3D.java
public void init() { if (filename == null) { // the path to the file for an applet try {// ww w. j ava2s. co m java.net.URL path = getCodeBase(); filename = new java.net.URL(path.toString() + "./ballcone.lws"); } catch (java.net.MalformedURLException ex) { System.err.println(ex.getMessage()); ex.printStackTrace(); System.exit(1); } } // Construct the Lw3d loader and load the file Loader lw3dLoader = new Lw3dLoader(Loader.LOAD_ALL); Scene loaderScene = null; try { loaderScene = lw3dLoader.load(filename); } catch (Exception e) { e.printStackTrace(); System.exit(1); } // Construct the applet canvas setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); // Create a basic universe setup and the root of our scene u = new SimpleUniverse(c); BranchGroup sceneRoot = new BranchGroup(); // Change the back clip distance; the default is small for // some lw3d worlds View theView = u.getViewer().getView(); theView.setBackClipDistance(50000f); // Now add the scene graph defined in the lw3d file if (loaderScene.getSceneGroup() != null) { // Instead of using the default view location (which may be // completely bogus for the particular file you're loading), // let's use the initial view from the file. We can get // this by getting the view groups from the scene (there's // only one for Lightwave 3D), then using the inverse of the // transform on that view as the transform for the entire scene. // First, get the view groups (shouldn't be null unless there // was something wrong in the load TransformGroup viewGroups[] = loaderScene.getViewGroups(); // Get the Transform3D from the view and invert it Transform3D t = new Transform3D(); viewGroups[0].getTransform(t); Matrix4d m = new Matrix4d(); t.get(m); m.invert(); t.set(m); // Now we've got the transform we want. Create an // appropriate TransformGroup and parent the scene to it. // Then insert the new group into the main BranchGroup. TransformGroup sceneTransform = new TransformGroup(t); sceneTransform.addChild(loaderScene.getSceneGroup()); sceneRoot.addChild(sceneTransform); } // Make the scene graph live by inserting the root into the universe u.addBranchGraph(sceneRoot); }
From source file:OrientedTest.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objScale = new TransformGroup(); Transform3D textMat = new Transform3D(); // Assuming uniform size chars, set scale to fit string in view textMat.setScale(1.2 / sl);//ww w. j a v a 2 s. c om objScale.setTransform(textMat); // 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); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(objTrans); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Appearance apText = new Appearance(); Material m = new Material(); m.setLightingEnable(true); apText.setMaterial(m); Appearance apEarth = new Appearance(); Material mm = new Material(); mm.setLightingEnable(true); apEarth.setMaterial(mm); Appearance apStone = new Appearance(); apStone.setMaterial(mm); // create 3D text Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion()); Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, 3.0f, 0.0f)); OrientedShape3D textShape = new OrientedShape3D(); textShape.setGeometry(txt); textShape.setAppearance(apText); textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f); objScale.addChild(textShape); // Create a simple shape leaf node, add it to the scene graph. Transform3D cubeMat = new Transform3D(); TransformGroup cubeTrans = new TransformGroup(cubeMat); cubeMat.set(new Vector3d(0.9, 0.0, -1.0)); cubeTrans.setTransform(cubeMat); cubeTrans.addChild(new ColorCube(0.3)); objTrans.addChild(cubeTrans); TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this); if (stoneTex != null) apStone.setTexture(stoneTex.getTexture()); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); apStone.setTextureAttributes(texAttr); Transform3D coneMat = new Transform3D(); TransformGroup coneTrans = new TransformGroup(coneMat); coneMat.set(new Vector3d(0.0, 0.0, 0.0)); coneTrans.setTransform(coneMat); coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone)); objTrans.addChild(coneTrans); TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this); if (earthTex != null) apEarth.setTexture(earthTex.getTexture()); apEarth.setTextureAttributes(texAttr); Transform3D cylinderMat = new Transform3D(); TransformGroup cylinderTrans = new TransformGroup(cylinderMat); cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0)); cylinderTrans.setTransform(cylinderMat); cylinderTrans.addChild( new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth)); objTrans.addChild(cylinderTrans); objTrans.addChild(objScale); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); objRoot.addChild(bgNode); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objRoot.addChild(light2); apText.setMaterial(mm); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:LitPlaneApp.java
public LitPlaneApp() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); BranchGroup scene = new BranchGroup(); Shape3D plane = new LitPlane(); scene.addChild(new LitPlane()); scene.addChild(new Sphere(0.5f, Sphere.GENERATE_NORMALS, plane.getAppearance())); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA);//from ww w. ja va 2s . c om DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere(new Point3d(0.0, 0.5, 0.0), 0.1)); Vector3f direction = new Vector3f(-1.0f, -1.0f, -1.0f); direction.normalize(); lightD1.setDirection(direction); lightD1.setColor(new Color3f(1.0f, 1.0f, 1.0f)); scene.addChild(lightD1); SimpleUniverse u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); }
From source file:BackgroundApp.java
public BranchGroup createSceneGraph(SimpleUniverse su) { // Create the root of the branch graph BranchGroup objRootBG = new BranchGroup(); Vector3f translate = new Vector3f(); Transform3D T3D = new Transform3D(); translate.set(0.0f, -0.3f, 0.0f);/*from www. ja va 2 s. co m*/ T3D.setTranslation(translate); TransformGroup objRoot = new TransformGroup(T3D); objRootBG.addChild(objRoot); objRoot.addChild(createLand()); BoundingLeaf boundingLeaf = new BoundingLeaf(new BoundingSphere()); PlatformGeometry platformGeom = new PlatformGeometry(); platformGeom.addChild(boundingLeaf); platformGeom.compile(); su.getViewingPlatform().setPlatformGeometry(platformGeom); KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior( su.getViewingPlatform().getViewPlatformTransform()); keyNavBeh.setSchedulingBoundingLeaf(boundingLeaf); objRootBG.addChild(keyNavBeh); Background background = new Background(); background.setApplicationBounds(new BoundingSphere(new Point3d(), 1000.0)); background.setGeometry(createBackGraph()); objRoot.addChild(background); AmbientLight ambientLight = new AmbientLight(); ambientLight.setInfluencingBounds(new BoundingSphere()); objRootBG.addChild(ambientLight); return objRootBG; }
From source file:LightsNPlanesApp.java
public LightsNPlanesApp() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); BoundingSphere bounds = new BoundingSphere(new Point3d(), 0.1); Vector3f direction = new Vector3f(0.0f, -1.0f, 0.0f); Point3f position = new Point3f(0.0f, 0.5f, -0.3f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); Color3f green = new Color3f(0.0f, 1.0f, 0.0f); Color3f blue = new Color3f(0.0f, 0.0f, 1.0f); BranchGroup scene = new BranchGroup(); IndexedQuadArray qa = new IndexedQuadArray(9, QuadArray.COORDINATES | QuadArray.NORMALS, 16); qa.setCoordinate(0, new Point3f(-0.3f, 0.3f, -0.3f)); qa.setCoordinate(1, new Point3f(0.0f, 0.3f, -0.3f)); qa.setCoordinate(2, new Point3f(0.3f, 0.3f, -0.3f)); qa.setCoordinate(3, new Point3f(-0.3f, 0.0f, 0.0f)); qa.setCoordinate(4, new Point3f(0.0f, 0.0f, 0.0f)); qa.setCoordinate(5, new Point3f(0.3f, 0.0f, 0.0f)); qa.setCoordinate(6, new Point3f(-0.3f, -0.3f, 0.3f)); qa.setCoordinate(7, new Point3f(0.0f, -0.3f, 0.3f)); qa.setCoordinate(8, new Point3f(0.3f, -0.3f, 0.3f)); Vector3f n = new Vector3f(0.0f, 0.6f, 0.8f); n.normalize();/* w w w .j a v a 2 s .c o m*/ qa.setNormal(0, n); qa.setNormal(1, n); qa.setNormal(2, n); qa.setNormal(3, n); qa.setNormal(4, n); qa.setNormal(5, n); qa.setNormal(6, n); qa.setNormal(7, n); qa.setNormal(8, n); qa.setCoordinateIndex(0, 0); qa.setCoordinateIndex(1, 3); qa.setCoordinateIndex(2, 4); qa.setCoordinateIndex(3, 1); qa.setCoordinateIndex(4, 1); qa.setCoordinateIndex(5, 4); qa.setCoordinateIndex(6, 5); qa.setCoordinateIndex(7, 2); qa.setCoordinateIndex(8, 3); qa.setCoordinateIndex(9, 6); qa.setCoordinateIndex(10, 7); qa.setCoordinateIndex(11, 4); qa.setCoordinateIndex(12, 4); qa.setCoordinateIndex(13, 7); qa.setCoordinateIndex(14, 8); qa.setCoordinateIndex(15, 5); TransformGroup trans1 = createTG(-0.7f, 0.0f, -0.5f); scene.addChild(trans1); TransformGroup trans2 = createTG(0.0f, 0.0f, -0.5f); scene.addChild(trans2); TransformGroup trans3 = createTG(0.7f, 0.0f, -0.5f); scene.addChild(trans3); Appearance qAppear = createMatAppear(white, white, 5.0f); Shape3D p1 = new Shape3D(qa, qAppear); // p1.setBoundsAutoCompute(false); p1.setBounds(bounds); p1.setCapability(Node.ALLOW_BOUNDS_READ); trans1.addChild(p1); Shape3D p2 = new Shape3D(qa, qAppear); p2.setBounds(bounds); p2.setCapability(Node.ALLOW_BOUNDS_READ); trans2.addChild(p2); Shape3D p3 = new Shape3D(qa, qAppear); p3.setBounds(bounds); p3.setCapability(Node.ALLOW_BOUNDS_READ); trans3.addChild(p3); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); lightA.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); scene.addChild(lightA); DirectionalLight lightD = new DirectionalLight(); lightD.setInfluencingBounds(bounds); lightD.setBoundsAutoCompute(false); lightD.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); lightD.setDirection(direction); lightD.setColor(red); trans1.addChild(lightD); PointLight lightP = new PointLight(); lightP.setInfluencingBounds(bounds); lightP.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); lightP.setPosition(position); lightP.setColor(green); trans2.addChild(lightP); SpotLight lightS = new SpotLight(); lightS.setInfluencingBounds(bounds); lightS.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); lightS.setPosition(position); lightS.setDirection(direction); lightS.setSpreadAngle(0.3f); lightS.setConcentration(1.0f); lightS.setColor(blue); trans3.addChild(lightS); Background background = new Background(); background.setApplicationBounds(new BoundingSphere()); background.setColor(1.0f, 1.0f, 1.0f); scene.addChild(background); scene.compile(); System.out.print("bounds object: "); System.out.println(bounds); System.out.print("influencing bounds for lightA: "); System.out.println(lightA.getInfluencingBounds()); System.out.print("influencing bounds for lightD: "); System.out.println(lightD.getInfluencingBounds()); System.out.print("influencing bounds for lightP: "); System.out.println(lightP.getInfluencingBounds()); System.out.print("influencing bounds for lightS: "); System.out.println(lightS.getInfluencingBounds()); System.out.print("bounds for plane1: "); System.out.println(p1.getBounds()); System.out.print("bounds for plane2: "); System.out.println(p2.getBounds()); System.out.print("bounds for plane3: "); System.out.println(p3.getBounds()); BoundingSphere bs0 = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 0.2); BoundingSphere bs1 = new BoundingSphere(new Point3d(-0.1, 0.0, 0.0), 0.2); BoundingSphere bs2 = new BoundingSphere(new Point3d(-0.2, 0.0, 0.0), 0.2); BoundingSphere bs3 = new BoundingSphere(new Point3d(-0.3, 0.0, 0.0), 0.2); BoundingSphere bs4 = new BoundingSphere(new Point3d(-0.4, 0.0, 0.0), 0.2); BoundingSphere bs5 = new BoundingSphere(new Point3d(-0.5, 0.0, 0.0), 0.2); BoundingSphere bs6 = new BoundingSphere(new Point3d(-0.6, 0.0, 0.0), 0.2); BoundingSphere bs7 = new BoundingSphere(new Point3d(-0.7, 0.0, 0.0), 0.2); BoundingSphere bs8 = new BoundingSphere(new Point3d(-0.8, 0.0, 0.0), 0.2); BoundingBox bb1 = new BoundingBox(bs1); BoundingBox bb2 = new BoundingBox(bs2); BoundingBox bb3 = new BoundingBox(bs3); BoundingBox bb4 = new BoundingBox(bs4); BoundingBox bb5 = new BoundingBox(bs5); BoundingBox bb6 = new BoundingBox(bs6); BoundingBox bb7 = new BoundingBox(bs7); BoundingBox bb8 = new BoundingBox(bs8); if (bs0.intersect(bs1)) System.out.println("bs0 intersects bs1"); if (bs0.intersect(bs2)) System.out.println("bs0 intersects bs2"); if (bs0.intersect(bs3)) System.out.println("bs0 intersects bs3"); if (bs0.intersect(bs4)) System.out.println("bs0 intersects bs4"); if (bs0.intersect(bs5)) System.out.println("bs0 intersects bs5"); if (bs0.intersect(bs6)) System.out.println("bs0 intersects bs6"); if (bs0.intersect(bs7)) System.out.println("bs0 intersects bs7"); if (bs0.intersect(bs8)) System.out.println("bs0 intersects bs8"); if (bs0.intersect(bb1)) System.out.println("bs0 intersects bb1"); if (bs0.intersect(bb2)) System.out.println("bs0 intersects bb2"); if (bs0.intersect(bb3)) System.out.println("bs0 intersects bb3"); if (bs0.intersect(bb4)) System.out.println("bs0 intersects bb4"); if (bs0.intersect(bb5)) System.out.println("bs0 intersects bb5"); if (bs0.intersect(bb6)) System.out.println("bs0 intersects bb6"); if (bs0.intersect(bb7)) System.out.println("bs0 intersects bb7"); if (bs0.intersect(bb8)) System.out.println("bs0 intersects bb8"); SimpleUniverse u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); }
From source file:AvatarTest.java
public BranchGroup createSceneGraph() { BranchGroup bg = new BranchGroup(); TransformGroup tgRoot = addBehaviors(bg); createBuildings(tgRoot);//from w ww .j a va2s .co m createRoad(tgRoot); createLand(tgRoot); createCars(tgRoot); createBackground(bg); return bg; }
From source file:SimpleTest.java
public BranchGroup createSceneGraph() { // create a parent BranchGroup node for the Sphere BranchGroup bg = new BranchGroup(); // create an Appearance for the Sphere. // The Appearance object controls various rendering // options for the Sphere geometry. Appearance app = new Appearance(); // assign a Material to the Appearance. For the Sphere // to respond to the light in the scene it must have a Material. // Assign some colors to the Material and a shininess setting // that controls how reflective the surface is to lighting. Color3f objColor = new Color3f(0.8f, 0.2f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); // create a Sphere with a radius of 0.1 // and associate the Appearance that we described. // the option GENERATE_NORMALS is required to ensure that the // Sphere responds correctly to lighting. Sphere sphere = new Sphere(0.1f, Primitive.GENERATE_NORMALS, app); // add the sphere to the BranchGroup to wire // it into the scene. bg.addChild(sphere);//from w ww . j a v a 2 s . com return bg; }
From source file:LocalEyeApp.java
public LocalEyeApp() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); Color3f blue = new Color3f(0.0f, 0.0f, 1.0f); BranchGroup scene = new BranchGroup(); TransformGroup trans11 = createTG(-0.7f, 0.7f, -0.5f); scene.addChild(trans11);//from www . j a va 2 s .c o m trans11.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans12 = createTG(0.0f, 0.7f, -0.5f); scene.addChild(trans12); trans12.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans13 = createTG(0.7f, 0.7f, -0.5f); scene.addChild(trans13); trans13.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans21 = createTG(-0.7f, 0.0f, -0.5f); scene.addChild(trans21); trans21.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans22 = createTG(0.0f, 0.0f, -0.5f); scene.addChild(trans22); trans22.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans23 = createTG(0.7f, 0.0f, -0.5f); scene.addChild(trans23); trans23.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans31 = createTG(-0.7f, -0.7f, -0.5f); scene.addChild(trans31); trans31.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans32 = createTG(0.0f, -0.7f, -0.5f); scene.addChild(trans32); trans32.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans33 = createTG(0.7f, -0.7f, -0.5f); scene.addChild(trans33); trans33.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA); DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere()); Vector3f direction = new Vector3f(0.0f, 0.0f, -1.0f); direction.normalize(); lightD1.setDirection(direction); lightD1.setColor(red); scene.addChild(lightD1); PointLight lightP1 = new PointLight(); lightP1.setInfluencingBounds(new BoundingSphere()); Point3f position = new Point3f(0.0f, 0.0f, 1.0f); lightP1.setPosition(position); scene.addChild(lightP1); Background background = new Background(); background.setApplicationBounds(new BoundingSphere()); background.setColor(white); scene.addChild(background); SimpleUniverse u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); //Enable Local Eye Lighting u.getViewer().getView().setLocalEyeLightingEnable(true); u.addBranchGraph(scene); }
From source file:SimpleTransform.java
/** * This builds the content branch of our scene graph. The root of the shapes * supplied as a parameter is slightly tilted to reveal its 3D shape. It * also uses the addLights function to add some lights to the scene. The * group that the shape is added to has its capabilities set so that we can * read and write it.// ww w .ja v a2s .co m * * @param shape * Node that represents the geometry for the content * @return BranchGroup that is the root of the content branch */ protected BranchGroup buildContentBranch(Node shape) { BranchGroup contentBranch = new BranchGroup(); Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); rotationGroup = new TransformGroup(rotateCube); //Set the capabilities so that the transform can be accessed rotationGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); rotationGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); contentBranch.addChild(rotationGroup); rotationGroup.addChild(shape); addLights(contentBranch); return contentBranch; }