List of usage examples for javax.media.j3d DirectionalLight setDirection
public void setDirection(Vector3f direction)
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);/* w w w .j av 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:LitSphereApp.java
BranchGroup createScene() { BranchGroup scene = new BranchGroup(); scene.addChild(new Sphere(0.9f, Sphere.GENERATE_NORMALS, createAppearance())); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA);/*from w w w .j av a2 s . c o m*/ DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere()); Vector3f direction1 = new Vector3f(-1.0f, -1.0f, -0.5f); direction1.normalize(); lightD1.setDirection(direction1); lightD1.setColor(new Color3f(0.0f, 0.0f, 1.0f)); scene.addChild(lightD1); DirectionalLight lightD2 = new DirectionalLight(); lightD2.setInfluencingBounds(new BoundingSphere()); Vector3f direction2 = new Vector3f(1.0f, -1.0f, -0.5f); direction2.normalize(); lightD2.setDirection(direction2); lightD2.setColor(new Color3f(1.0f, 0.0f, 0.0f)); scene.addChild(lightD2); Background bg = new Background(); bg.setColor(1.0f, 1.0f, 1.0f); bg.setApplicationBounds(new BoundingSphere()); scene.addChild(bg); return scene; }
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 . j a v a2 s . 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:ShadowApp.java
public ShadowApp() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); BranchGroup scene = new BranchGroup(); Shape3D plane = new LitQuad(new Point3f(-0.3f, 0.6f, 0.2f), new Point3f(-0.3f, -0.3f, 0.2f), new Point3f(0.6f, -0.3f, -0.3f), new Point3f(0.6f, 0.6f, -0.3f)); scene.addChild(plane);//www. ja v a 2 s. c o m Shape3D floor = new LitQuad(new Point3f(-1.0f, -0.5f, -1.0f), new Point3f(-1.0f, -0.5f, 1.0f), new Point3f(1.0f, -0.5f, 1.0f), new Point3f(1.0f, -0.5f, -1.0f)); scene.addChild(floor); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA); DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere()); Vector3f direction = new Vector3f(-1.0f, -1.0f, -1.0f); direction.normalize(); lightD1.setDirection(direction); scene.addChild(lightD1); Shape3D shadow = new SimpleShadow((GeometryArray) plane.getGeometry(), direction, new Color3f(0.2f, 0.2f, 0.2f), -0.5f); scene.addChild(shadow); 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:Licht.java
/** * Erstellt den Szenegraphen//from w w w. j a v a 2 s.c o m * * @return BranchGroup */ public BranchGroup macheSzene() { BranchGroup objWurzel = new BranchGroup(); // Transformation, 2 Rotationen: Transform3D drehung = new Transform3D(); Transform3D drehung2 = new Transform3D(); drehung.rotX(Math.PI / 4.0d); drehung2.rotY(Math.PI / 5.0d); drehung.mul(drehung2); TransformGroup objDreh = new TransformGroup(drehung); Sphere kugel = new Sphere(0.5f, Sphere.GENERATE_NORMALS, 50, makeAppearance()); objWurzel.addChild(kugel); objWurzel.addChild(objDreh); //directes Licht DirectionalLight d_Licht = new DirectionalLight(); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), Double.MAX_VALUE)); d_Licht.setColor(new Color3f(1.0f, 0.0f, 0.0f)); Vector3f dir = new Vector3f(1.0f, 2.0f, -1.0f); dir.normalize(); d_Licht.setDirection(dir); objWurzel.addChild(d_Licht); // ambient Licht AmbientLight a_licht = new AmbientLight(); a_licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0f, 0.0f, 0.0f), Double.MAX_VALUE)); a_licht.setColor(new Color3f(1.0f, 0.0f, 0.0f)); objWurzel.addChild(a_licht); return objWurzel; }
From source file:MaterialApp.java
public MaterialApp() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); Color3f white = new Color3f(1.0f, 1.0f, 1.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 w w w . j a v a 2 s.co m*/ trans11.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 0.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, 1.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, 2.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, 5.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, 10.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, 20.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, 50.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, 100.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(-1.0f, -1.0f, -1.0f); direction.normalize(); lightD1.setDirection(direction); lightD1.setColor(new Color3f(1.0f, 1.0f, 1.0f)); scene.addChild(lightD1); Background background = new Background(); background.setApplicationBounds(new BoundingSphere()); background.setColor(1.0f, 1.0f, 1.0f); 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(); // setLocalEyeViewing u.getViewer().getView().setLocalEyeLightingEnable(true); u.addBranchGraph(scene); }
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 w ww. jav a 2s . com*/ 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:LightScopeApp.java
BranchGroup createScene() { BranchGroup scene = new BranchGroup(); TransformGroup tableTG = new TransformGroup(); TransformGroup lampTG = new TransformGroup(); TransformGroup litBoxTG = new TransformGroup(); TransformGroup unLitBoxTG = new TransformGroup(); scene.addChild(tableTG);//from ww w.ja v a 2 s .co m tableTG.addChild(lampTG); tableTG.addChild(litBoxTG); tableTG.addChild(unLitBoxTG); 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, 1.0f, 0.0f); Color3f green = new Color3f(0.0f, 0.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Vector3f transVector = new Vector3f(); Transform3D transTransform = new Transform3D(); transVector.set(0.0f, -0.4f, 0.5f); transTransform.setTranslation(transVector); tableTG.setTransform(transTransform); transVector.set(-0.4f, 0.001f, 0.1f); transTransform.setTranslation(transVector); lampTG.setTransform(transTransform); transVector.set(-0.2f, 0.1f, 0.2f); transTransform.setTranslation(transVector); litBoxTG.setTransform(transTransform); transVector.set(0.3f, 0.1f, -0.4f); transTransform.setTranslation(transVector); unLitBoxTG.setTransform(transTransform); Shape3D tablePlane = createXZPlane(new Point3f(-1.0f, 0.0f, -1.0f), new Point3f(-1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, -1.0f)); tablePlane.setAppearance(createMaterialAppearance(white)); tableTG.addChild(tablePlane); litBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, createMaterialAppearance(red))); Shape3D shadowPlane = createXZPlane(new Point3f(0.1f, -0.095f, -0.1f), new Point3f(0.1f, -0.095f, 0.1f), new Point3f(0.2f, -0.095f, 0.15f), new Point3f(0.2f, -0.095f, -0.15f)); shadowPlane.setAppearance(createMaterialAppearance(black)); litBoxTG.addChild(shadowPlane); Appearance redGlowMat = createMaterialAppearance(red); // redGlowMat.getMaterial().setEmissiveColor(0.5f, 0.5f, 0.5f); unLitBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, redGlowMat)); Shape3D lamp = createLampShape(); Appearance lampAppearance = createMaterialAppearance(blue); PolygonAttributes polyAttrib = new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); polyAttrib.setBackFaceNormalFlip(true); lampAppearance.setPolygonAttributes(polyAttrib); lamp.setAppearance(lampAppearance); lampTG.addChild(lamp); PointLight lampLight = new PointLight(); lampLight.setPosition(0.1f, 0.5f, -0.1f); lampLight.setInfluencingBounds(new BoundingSphere()); lampTG.addChild(lampLight); Shape3D litPlane = createXZPlane(new Point3f(-0.4f, 0.0f, -0.4f), new Point3f(-0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, -0.4f)); litPlane.setAppearance(createMaterialAppearance(white)); lampTG.addChild(litPlane); lampLight.addScope(lampTG); lampLight.addScope(litBoxTG); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA); DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere()); lightD1.setColor(new Color3f(0.4f, 0.4f, 0.4f)); Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f); lightDir.normalize(); lightD1.setDirection(lightDir); scene.addChild(lightD1); DirectionalLight lightD2 = new DirectionalLight(); lightD2.setInfluencingBounds(new BoundingSphere()); lightD2.setColor(new Color3f(0.2f, 0.2f, 0.2f)); lightDir.set(1.0f, -1.0f, -1.0f); lightDir.normalize(); lightD2.setDirection(lightDir); scene.addChild(lightD2); Background bg = new Background(); bg.setColor(1.0f, 1.0f, 1.0f); bg.setApplicationBounds(new BoundingSphere()); scene.addChild(bg); return scene; }
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 2 s.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: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 www. j av 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; }