List of usage examples for javax.media.j3d Background Background
public Background()
From source file:BackgroundGeometry.java
public BranchGroup createSceneGraph() { // 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);/*from w ww . j ava2 s . co m*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // 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. TransformGroup objTrans = new TransformGroup(); objScale.addChild(objTrans); Background bg = new Background(); bg.setApplicationBounds(bounds); BranchGroup backGeoBranch = new BranchGroup(); Sphere sphereObj = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 45); Appearance backgroundApp = sphereObj.getAppearance(); backGeoBranch.addChild(sphereObj); bg.setGeometry(backGeoBranch); objTrans.addChild(bg); TextureLoader tex = new TextureLoader(bgImage, new String("RGB"), this); if (tex != null) backgroundApp.setTexture(tex.getTexture()); Vector3f tranlation = new Vector3f(2.0f, 0.0f, 0.0f); Transform3D modelTransform = new Transform3D(); Transform3D tmpTransform = new Transform3D(); double angleInc = Math.PI / 8.0; double angle = 0.0; int numBoxes = 16; float scaleX[] = { 0.1f, 0.2f, 0.2f, 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f, 0.3f }; float scaleY[] = { 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.4f }; float scaleZ[] = { 0.3f, 0.2f, 0.1f, 0.1f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f, 0.2f }; Appearance a1 = new Appearance(); Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(0.5f, 0.5f, 1.0f); Color3f oColor = new Color3f(0.5f, 0.5f, 0.3f); Material m = new Material(oColor, eColor, oColor, sColor, 100.0f); m.setLightingEnable(true); a1.setMaterial(m); for (int i = 0; i < numBoxes; i++, angle += angleInc) { modelTransform.rotY(angle); tmpTransform.set(tranlation); modelTransform.mul(tmpTransform); TransformGroup tgroup = new TransformGroup(modelTransform); objTrans.addChild(tgroup); tgroup.addChild(new Box(scaleX[i], scaleY[i], scaleZ[i], Box.GENERATE_NORMALS, a1)); } // Shine it with two lights. Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Color3f lColor2 = new Color3f(0.2f, 0.2f, 0.1f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); objScale.addChild(lgt1); objScale.addChild(lgt2); 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 ww. jav a 2 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:AvatarTest.java
public void createBackground(Group bg) { // add the sky backdrop Background back = new Background(); back.setApplicationBounds(getBoundingSphere()); bg.addChild(back);// w ww . ja v a2s . c o m BranchGroup bgGeometry = new BranchGroup(); // create an appearance and assign the texture image Appearance app = new Appearance(); Texture tex = new TextureLoader("back.jpg", this).getTexture(); app.setTexture(tex); Sphere sphere = new Sphere(1.0f, Primitive.GENERATE_TEXTURE_COORDS | Primitive.GENERATE_NORMALS_INWARD, app); bgGeometry.addChild(sphere); back.setGeometry(bgGeometry); }
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 w ww . ja va2 s .c o 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:Text2DApp.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. Add it to the root of the subgraph. TransformGroup objSpin = new TransformGroup(); objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objSpin);/*w w w . j a v a 2s . com*/ // Create a simple Text2D leaf node, add it to the scene graph. Text2D text2d = new Text2D("2D text in Java 3D", new Color3f(0.9f, 1.0f, 1.0f), "Helvetica", 24, Font.ITALIC); objSpin.addChild(text2d); Appearance textAppear = text2d.getAppearance(); // The following 4 lines of code (commented out) make the Text2D object // 2-sided. // This code depends on the line of code above that sets TextAppear. // PolygonAttributes polyAttrib = new PolygonAttributes(); // polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); // polyAttrib.setBackFaceNormalFlip(true); // textAppear.setPolygonAttributes(polyAttrib); // The following 12 lines of code (commented out) use the texture from // the previous Text2D object on another object. // This code depends on the line of code above that sets TextAppear. // QuadArray qa = new QuadArray(4, QuadArray.COORDINATES | // QuadArray.TEXTURE_COORDINATE_2); // qa.setCoordinate(0, new Point3f(-10.0f, 1.0f, -5.0f)); // qa.setCoordinate(1, new Point3f(-10.0f, -1.0f, -5.0f)); // qa.setCoordinate(2, new Point3f(10.0f, -1.0f, -5.0f)); // qa.setCoordinate(3, new Point3f(10.0f, 1.0f, -5.0f)); // qa.setTextureCoordinate(0, new Point2f(0.0f, 1.0f)); // qa.setTextureCoordinate(1, new Point2f(0.0f, 0.0f)); // qa.setTextureCoordinate(2, new Point2f(1.0f, 0.0f)); // qa.setTextureCoordinate(3, new Point2f(1.0f, 1.0f)); // // objRoot.addChild(new Shape3D(qa, textAppear)); // 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, 8000); 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); Background backg = new Background(); backg.setColor(0.4f, 0.4f, 1.0f); backg.setApplicationBounds(new BoundingSphere()); objRoot.addChild(backg); return objRoot; }
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 ww w. j a v a 2s.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:ExBackgroundColor.java
public Group buildScene() { // Get the current color Color3f color = (Color3f) colors[currentColor].value; // Turn off the example headlight setHeadlightEnable(false);/* ww w . jav a 2s.com*/ // Default to walk navigation setNavigationType(Walk); // Create the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create application bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the background color and its application bounds background = new Background(); background.setColor(color); background.setCapability(Background.ALLOW_COLOR_WRITE); background.setApplicationBounds(worldBounds); scene.addChild(background); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new TowerScene(this)); return scene; }
From source file:ExBackgroundImage.java
public Group buildScene() { // Get the current image ImageComponent2D image = imageComponents[currentImage]; // Turn off the example headlight setHeadlightEnable(false);// w ww. j a va2s . co m // Default to walk navigation setNavigationType(Walk); // Build the scene root Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create application bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the background color and its application bounds background = new Background(); background.setImage(image); background.setCapability(Background.ALLOW_IMAGE_WRITE); background.setApplicationBounds(worldBounds); scene.addChild(background); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new TowerScene(this)); return scene; }
From source file:ExDepthCue.java
public Group buildScene() { // Get the current color Color3f color = (Color3f) colors[currentColor].value; // Turn off the example headlight setHeadlightEnable(false);/*from w w w . j a v a2 s .co m*/ // Create the scene group Group scene = new Group(); // Create a switch group to hold the fog node. This enables // us to turn the fog node on and off via the GUI. fogSwitch = new Switch(); fogSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); // Create influencing bounds Bounds worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the fog color, density, and its influencing bounds fog = new LinearFog(); fog.setColor(color); // front and back distances set below fog.setCapability(Fog.ALLOW_COLOR_WRITE); fog.setCapability(Fog.ALLOW_INFLUENCING_BOUNDS_WRITE); fog.setInfluencingBounds(worldBounds); fogSwitch.addChild(fog); scene.addChild(fogSwitch); if (depthCueOnOff) fogSwitch.setWhichChild(0); // on else fogSwitch.setWhichChild(Switch.CHILD_NONE); // off // Set the background color and its application bounds // Usually, the background color should match the fog color // or the results look odd. background = new Background(); background.setColor(color); background.setApplicationBounds(worldBounds); background.setCapability(Background.ALLOW_COLOR_WRITE); scene.addChild(background); // Build foreground geometry Group content = buildIsoline(); scene.addChild(content); // Automatically compute good front and back distances for // fog to get good depth-cueing. To do this, first get the // dimensions of the bounds around the content. Then, // set the front distance to be at the center of the content // (or closer by a tad) and the back distance at the front // distance PLUS half the depth of the content's bounding box BoundingSphere sampleSphere = new BoundingSphere(); BoundingBox sampleBox = new BoundingBox(); Bounds bounds = content.getBounds(); double deltaDistance = 0.0; double centerZ = 0.0; if (bounds == null) { // No bounds available. Estimate the values knowing // that the above content is what it is. centerZ = 0.5; // 0.5 closer than true center deltaDistance = 2.0; } else if (bounds.getClass() == sampleSphere.getClass()) { BoundingSphere sphereBounds = (BoundingSphere) bounds; deltaDistance = Math.abs(sphereBounds.getRadius()); Point3d center = new Point3d(); sphereBounds.getCenter(center); centerZ = center.z + 0.5; // 0.5 closer than true center } else if (bounds.getClass() == sampleBox.getClass()) { BoundingBox boxBounds = (BoundingBox) bounds; Point3d p1 = new Point3d(); Point3d p2 = new Point3d(); boxBounds.getLower(p1); boxBounds.getUpper(p2); deltaDistance = p2.z - p1.z; if (deltaDistance < 0.0) deltaDistance *= -1.0; if (p1.z > p2.z) centerZ = p1.z - deltaDistance / 2.0; else centerZ = p2.z - deltaDistance / 2.0; centerZ += 0.5; // 0.5 closer than true center } else { System.err.println("Unknown bounds type"); } // Set front distance to the distance from the default // viewing position (0,0,10) to the center of the bounds. fog.setFrontDistance(10.0f - (float) centerZ); // Set back distance to the distance from the default // viewing position (0,0,10) to the back of the bounds. fog.setBackDistance(10.0f - (float) centerZ + (float) deltaDistance); return scene; }
From source file:ExBluePrint.java
public Group buildScene() { // Get the current image ImageComponent2D image = imageComponents[currentImage]; // Build the scene root Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create application bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the background color and its application bounds background = new Background(); background.setColor(White);// ww w . ja v a 2 s. com background.setImage(image); background.setCapability(Background.ALLOW_IMAGE_WRITE); background.setApplicationBounds(worldBounds); scene.addChild(background); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(buildGadget()); return scene; }