List of usage examples for javax.media.j3d Group addChild
public void addChild(Node child)
From source file:ExRaster.java
public Group buildScene() { // Turn on the headlight setHeadlightEnable(true);/*ww w.ja v a2 s . c om*/ // 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:ExExponentialFog.java
public Group buildScene() { // Get the current color Color3f color = (Color3f) colors[currentColor].value; float density = ((Float) densities[currentDensity].value).floatValue(); // Turn off the example headlight setHeadlightEnable(false);//from w w w.j a v a 2 s .com // Default to walk navigation setNavigationType(Walk); // Create the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere 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 ExponentialFog(); fog.setColor(color); fog.setDensity(density); fog.setCapability(Fog.ALLOW_COLOR_WRITE); fog.setCapability(ExponentialFog.ALLOW_DENSITY_WRITE); fog.setInfluencingBounds(worldBounds); scene.addChild(fog); // END EXAMPLE TOPIC // 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 scene.addChild(new ColumnScene(this)); return scene; }
From source file:SplineInterpolatorTest.java
public Group createLodLand(Group g) { Switch switchNode = new Switch(); switchNode.setCapability(Switch.ALLOW_SWITCH_WRITE); Group hiResGroup = createLand(switchNode); createEnvirons(switchNode);/*from ww w. j a va 2 s .co m*/ // create a DistanceLOD that will select the child of // the Switch node based on distance. Here we are selecting // child 0 (high res) if we are closer than 180 units to // 0,0,0 and child 1 (low res) otherwise. float[] distanceArray = { 180 }; DistanceLOD distanceLod = new DistanceLOD(distanceArray); distanceLod.setSchedulingBounds(getApplicationBounds()); distanceLod.addSwitch(switchNode); g.addChild(distanceLod); g.addChild(switchNode); return hiResGroup; }
From source file:ExLinearFog.java
public Group buildScene() { // Get the current color Color3f color = (Color3f) colors[currentColor].value; float front = ((Float) fronts[currentFront].value).floatValue(); float back = ((Float) backs[currentBack].value).floatValue(); // Turn off the example headlight setHeadlightEnable(false);/* w w w . j a v a 2 s. co m*/ // Default to walk navigation setNavigationType(Walk); // Create the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the fog color, front & back distances, and // its influencing bounds fog = new LinearFog(); fog.setColor(color); fog.setFrontDistance(front); fog.setBackDistance(back); fog.setCapability(Fog.ALLOW_COLOR_WRITE); fog.setCapability(LinearFog.ALLOW_DISTANCE_WRITE); fog.setInfluencingBounds(worldBounds); scene.addChild(fog); // END EXAMPLE TOPIC // 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 scene.addChild(new ColumnScene(this)); return scene; }
From source file:ExLinearFog.java
private Group buildColumns(SharedGroup column) { Group group = new Group(); // Place columns float x = -ColumnSideOffset; float y = -1.6f; float z = ColumnDepthSpacing; float xSpacing = 2.0f * ColumnSideOffset; float zSpacing = -ColumnDepthSpacing; // BEGIN EXAMPLE TOPIC Vector3f trans = new Vector3f(); Transform3D tr = new Transform3D(); TransformGroup tg;//from ww w.ja v a2 s . com for (int i = 0; i < NumberOfColumns; i++) { // Left link trans.set(x, y, z); tr.set(trans); tg = new TransformGroup(tr); tg.addChild(new Link(column)); group.addChild(tg); // Right link trans.set(x + xSpacing, y, z); tr.set(trans); tg = new TransformGroup(tr); tg.addChild(new Link(column)); group.addChild(tg); z += zSpacing; } // END EXAMPLE TOPIC return group; }
From source file:ExClip.java
public Group buildScene() { // Get the current color Color3f color = (Color3f) colors[currentColor].value; float front = ((Float) fronts[currentFront].value).floatValue(); float back = ((Float) backs[currentBack].value).floatValue(); // Turn off the example headlight setHeadlightEnable(false);//from w w w.j a va 2 s.c o m // Default to walk navigation setNavigationType(Walk); // Create the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the fog color, front & back distances, and // its influencing bounds fog = new LinearFog(); fog.setColor(color); fog.setFrontDistance(front); fog.setBackDistance(back); fog.setCapability(Fog.ALLOW_COLOR_WRITE); fog.setCapability(LinearFog.ALLOW_DISTANCE_WRITE); fog.setInfluencingBounds(worldBounds); scene.addChild(fog); // Add a clip node with it's clip distance (back // distance) set to the fog's back distance. This // insures that shapes are clipped off, and not drawn, // from the fog back (maximum density) onwards into // the distance. clip = new Clip(); clip.setBackDistance(back); clip.setCapability(Clip.ALLOW_BACK_DISTANCE_WRITE); clip.setApplicationBounds(worldBounds); scene.addChild(clip); // END EXAMPLE TOPIC // 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 scene.addChild(new ColumnScene(this)); 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);/* w w w . jav a 2 s .c o m*/ 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; }
From source file:ExSpotLight.java
public Group buildScene() { // Get the current color, position, attenuation, // spread angle, and concentration Color3f color = (Color3f) colors[currentColor].value; Point3f pos = (Point3f) positions[currentPosition].value; Vector3f dir = (Vector3f) directions[currentDirection].value; Point3f atten = (Point3f) attenuations[currentAttenuation].value; float spread = ((Double) spreads[currentSpread].value).floatValue(); float concen = ((Double) concentrations[currentConcentration].value).floatValue(); // Turn off the example headlight setHeadlightEnable(false);/*from ww w .ja v a2 s. c o m*/ // Build the scene root Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the light color and its influencing bounds light = new SpotLight(); light.setEnable(lightOnOff); light.setColor(color); light.setPosition(pos); light.setAttenuation(atten); light.setDirection(dir); light.setSpreadAngle(spread); light.setConcentration(concen); light.setCapability(SpotLight.ALLOW_STATE_WRITE); light.setCapability(SpotLight.ALLOW_COLOR_WRITE); light.setCapability(SpotLight.ALLOW_POSITION_WRITE); light.setCapability(SpotLight.ALLOW_ATTENUATION_WRITE); light.setCapability(SpotLight.ALLOW_DIRECTION_WRITE); light.setCapability(SpotLight.ALLOW_SPREAD_ANGLE_WRITE); light.setCapability(SpotLight.ALLOW_CONCENTRATION_WRITE); light.setInfluencingBounds(worldBounds); scene.addChild(light); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new SphereGroup()); // Add annotation arrows in a fan to show light ray directions, // positions, and the spread angle scene.addChild(buildArrows()); return scene; }
From source file:SplineInterpolatorTest.java
public Group createBuildings(Group g) { m_BuildingAppearance = new Appearance(); BranchGroup bg = new BranchGroup(); Texture tex = new TextureLoader("boston.gif", this).getTexture(); BufferedImage image = ((ImageComponent2D) tex.getImage(0)).getImage(); final int nMaxBuildings = 120; for (int n = 0; n < nMaxBuildings; n++) { Cuboid building = new Cuboid(this, bg, ComplexObject.GEOMETRY | ComplexObject.TEXTURE); float posX = (int) Utils.getRandomNumber(0, LAND_WIDTH); float posZ = (int) Utils.getRandomNumber(0, LAND_LENGTH); if (isLocationWater(image, posX, posZ) == false) { building.createObject(m_BuildingAppearance, new Vector3d(posX, 0, posZ), new Vector3d(Utils.getRandomNumber(3, 2), Utils.getRandomNumber(8, 7), Utils.getRandomNumber(3, 2)), "house.gif", null, null); }/*from w w w . jav a 2s .c o m*/ } g.addChild(bg); return bg; }
From source file:ExBluePrint.java
private Group buildGadget() { if (debug)/*from w w w . j a v a2s . co m*/ 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; }