List of usage examples for javax.media.j3d Group addChild
public void addChild(Node child)
From source file:ExAppearance.java
public Group buildScene() { // Turn off the example headlight setHeadlightEnable(false);//from www. j a v a2 s . c om // Build the scene group Group objRoot = new Group(); // 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); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objRoot.addChild(aLgt); objRoot.addChild(lgt1); // Add a background Background background = new Background(); background.setColor(new Color3f(0.0f, 0.5f, 1.0f)); background.setApplicationBounds(bounds); objRoot.addChild(background); // 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.9; for (int j = 0; j < 3; j++) { double xpos = (double) (j - 1) * 2.1; objRoot.addChild(createObject(app[i][j], 1.0, xpos, ypos)); } } return objRoot; }
From source file:ExLightBounds.java
public Group buildScene() { // Get the current bounding leaf position Point3f pos = (Point3f) positions[currentPosition].value; // Turn off the example headlight setHeadlightEnable(false);/*from ww w . ja va2 s .com*/ // Build the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create a bounding leaf we'll use or not use depending // upon menu selections. Put it within a transform group // so that we can move the leaf about. leafTransformGroup = new TransformGroup(); leafTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D tr = new Transform3D(); tr.setTranslation(new Vector3f(pos)); leafTransformGroup.setTransform(tr); leafBounds = new BoundingLeaf(worldBounds); leafBounds.setCapability(BoundingLeaf.ALLOW_REGION_WRITE); leafTransformGroup.addChild(leafBounds); scene.addChild(leafTransformGroup); // Add a directional light whose bounds we'll modify // Set its color and aim direction light = new DirectionalLight(); light.setEnable(true); light.setColor(White); light.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light.setCapability(DirectionalLight.ALLOW_INFLUENCING_BOUNDS_WRITE); // Set the bounds to be either from the leaf or from // explicit bounds, depending upon the menu initial state if (boundingLeafOnOff) // Use bounding leaf light.setInfluencingBoundingLeaf(leafBounds); else // Use bounds on the light light.setInfluencingBounds(worldBounds); // Set the scope list to include nothing initially. // This defaults to "universal scope" which covers // everything. scene.addChild(light); // Add an ambient light to dimly illuminate the rest of // the shapes in the scene to help illustrate that the // directional light is being bounded... otherwise it looks // like we're just removing shapes from the scene AmbientLight ambient = new AmbientLight(); ambient.setEnable(true); ambient.setColor(White); ambient.setInfluencingBounds(worldBounds); scene.addChild(ambient); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new SphereGroup()); return scene; }
From source file:ExHenge.java
public Group buildRing(SharedGroup sg) { Group g = new Group(); g.addChild(new Link(sg)); // 0 degrees TransformGroup tg = new TransformGroup(); Transform3D tr = new Transform3D(); tr.rotY(0.785); // 45 degrees tg.setTransform(tr);/*from w ww .j a va 2s .c o m*/ tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(-0.785); // -45 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(1.571); // 90 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(-1.571); // -90 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(2.356); // 135 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(-2.356); // -135 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(Math.PI); // 180 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); return g; }
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 ww . j a va 2 s . c om // 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:AppearanceExplorer.java
Group setupLights() { Group group = new Group(); // set up the BoundingSphere for all the lights BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0); // Set up the ambient light AmbientLight lightAmbient = new AmbientLight(medGrey); lightAmbient.setInfluencingBounds(bounds); lightAmbient.setCapability(Light.ALLOW_STATE_WRITE); group.addChild(lightAmbient); lightSwitch = new Switch(); lightSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); group.addChild(lightSwitch);// w w w. j av a2 s . c om // Set up the directional light Vector3f lightDirection1 = new Vector3f(0.0f, 0.0f, -1.0f); DirectionalLight lightDirectional1 = new DirectionalLight(white, lightDirection1); lightDirectional1.setInfluencingBounds(bounds); lightDirectional1.setCapability(Light.ALLOW_STATE_WRITE); lightSwitch.addChild(lightDirectional1); Point3f lightPos1 = new Point3f(-4.0f, 8.0f, 16.0f); Point3f lightAttenuation1 = new Point3f(1.0f, 0.0f, 0.0f); PointLight pointLight1 = new PointLight(brightWhite, lightPos1, lightAttenuation1); pointLight1.setInfluencingBounds(bounds); lightSwitch.addChild(pointLight1); Point3f lightPos2 = new Point3f(-16.0f, 8.0f, 4.0f); //Point3f lightPos = new Point3f(-4.0f, 2.0f, 1.0f); Point3f lightAttenuation2 = new Point3f(1.0f, 0.0f, 0.0f); PointLight pointLight2 = new PointLight(white, lightPos2, lightAttenuation2); pointLight2.setInfluencingBounds(bounds); lightSwitch.addChild(pointLight2); return group; }
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);/*from w ww . jav a2 s .c om*/ // 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:ExDirectionalLight.java
public Group buildScene() { // Get the current color and direction Color3f color = (Color3f) colors[currentColor].value; Vector3f dir = (Vector3f) directions[currentDirection].value; // Turn off the example headlight setHeadlightEnable(false);//from www. j ava 2 s . com // Build 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 light color and its influencing bounds light = new DirectionalLight(); light.setEnable(lightOnOff); light.setColor(color); light.setDirection(dir); light.setCapability(DirectionalLight.ALLOW_STATE_WRITE); light.setCapability(DirectionalLight.ALLOW_COLOR_WRITE); light.setCapability(DirectionalLight.ALLOW_DIRECTION_WRITE); light.setInfluencingBounds(worldBounds); scene.addChild(light); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new SphereGroup()); // Add anotation arrows pointing in +-X, +-Y, +-Z to // illustrate aim direction scene.addChild(buildArrows()); 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);//from ww w . j a v a 2 s .c o 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:SplineInterpolatorTest.java
public Group createHelicopter(Group g) { BranchGroup bg = new BranchGroup(); Helicopter heli = new Helicopter(this, bg, ComplexObject.GEOMETRY | ComplexObject.SOUND); heli.createObject(new Appearance(), new Vector3d(Utils.getRandomNumber(0, LAND_WIDTH), Utils.getRandomNumber(15, 5), Utils.getRandomNumber(0, LAND_LENGTH)), new Vector3d(10, 10, 10), null, "heli.wav", null); g.addChild(bg); return bg;/*from ww w. j av a 2 s. c o m*/ }
From source file:ExPointLight.java
public Group buildScene() { // Get the current color, position, and attenuation Color3f color = (Color3f) colors[currentColor].value; Point3f pos = (Point3f) positions[currentPosition].value; Point3f atten = (Point3f) attenuations[currentAttenuation].value; // Turn off the example headlight setHeadlightEnable(false);/*w ww .ja v a 2s .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 PointLight(); light.setEnable(lightOnOff); light.setColor(color); light.setPosition(pos); light.setAttenuation(atten); light.setCapability(PointLight.ALLOW_STATE_WRITE); light.setCapability(PointLight.ALLOW_COLOR_WRITE); light.setCapability(PointLight.ALLOW_POSITION_WRITE); light.setCapability(PointLight.ALLOW_ATTENUATION_WRITE); light.setInfluencingBounds(worldBounds); scene.addChild(light); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new SphereGroup()); // Add arrows in a fan to show light ray directions scene.addChild(buildArrows()); return scene; }