List of usage examples for javax.media.j3d BranchGroup addChild
public void addChild(Node child)
From source file:ImageComponentByReferenceTest.java
void createRaster(BranchGroup scene) { // Create raster geometries and shapes Vector3f trans = new Vector3f(); Transform3D tr = new Transform3D(); TransformGroup tg;//from w w w .j a v a 2s. c o m // Left raster = new javax.media.j3d.Raster(); raster.setCapability(javax.media.j3d.Raster.ALLOW_IMAGE_WRITE); raster.setCapability(javax.media.j3d.Raster.ALLOW_SIZE_WRITE); raster.setPosition(new Point3f(-0.9f, 0.75f, 0.0f)); raster.setType(javax.media.j3d.Raster.RASTER_COLOR); raster.setOffset(0, 0); raster.setSize(image[2].getWidth(), image[2].getHeight()); raster.setImage(image[2]); Shape3D sh = new Shape3D(raster, new Appearance()); scene.addChild(sh); }
From source file:SimpleGame.java
/** * This builds the ball that acts as the bullet for our gun. The ball is * created from a sphere primitive, and a transform group and interpolator * are added so that we can 'fire' the bullet. * /* w w w. j a v a 2s . co m*/ * @return BranchGroup that is the root of the ball branch. */ protected BranchGroup buildBall() { BranchGroup theBall = new BranchGroup(); Appearance ballApp = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); float shininess = 20.0f; ballApp.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); Sphere ball = new Sphere(0.2f, ballApp); TransformGroup ballMovXfmGrp = new TransformGroup(); ballMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); ballMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); ballMovXfmGrp.addChild(ball); theBall.addChild(ballMovXfmGrp); ballAlpha = new Alpha(1, 0, 0, 500, 0, 0); Transform3D axis = new Transform3D(); axis.rotY(Math.PI / 2); moveBall = new PositionInterpolator(ballAlpha, ballMovXfmGrp, axis, 0.0f, 50.0f); moveBall.setSchedulingBounds(bounds); theBall.addChild(moveBall); return theBall; }
From source file:SimpleCombine.java
/** * This defines the shapes used in the scene. The function uses the utility * geometries sphere, box, cone and cylinder to build a simple scene. This * demonstrates the use of transformations to group and position items. * //from w w w.j a v a2 s .c o m * @return Node that is the root of the shape hierarchy. */ protected Node buildShape() { //Create a root for the shapes in the scene BranchGroup theScene = new BranchGroup(); //Create an appearance for the ground Appearance groundApp = new Appearance(); Color3f groundColour = new Color3f(0.0f, 0.5f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(0.5f, 0.5f, 0.5f); float shininess = 10.0f; groundApp.setMaterial(new Material(groundColour, emissiveColour, groundColour, specularColour, shininess)); //Create a box that will be the ground Box ground = new Box(100.0f, 0.1f, 100.0f, groundApp); //Create a transform and a transform group that //will position the ground Transform3D grndXfm = new Transform3D(); grndXfm.set(new Vector3f(0.0f, -1.0f, 0.0f)); TransformGroup grndXfmGrp = new TransformGroup(grndXfm); //Add the ground shape to the group grndXfmGrp.addChild(ground); //Add the ground group to the scene group theScene.addChild(grndXfmGrp); //Create an appearance for the wall of the house Appearance wallApp = new Appearance(); Color3f wallColour = new Color3f(0.5f, 0.5f, 0.5f); wallApp.setMaterial(new Material(wallColour, emissiveColour, wallColour, specularColour, shininess)); //Create a cylinder that is the wall of the house Cylinder walls = new Cylinder(1.0f, 1.0f, Primitive.GENERATE_NORMALS, wallApp); //Create a group that will be the root of the house TransformGroup house = new TransformGroup(); //Add the walls to the house group house.addChild(walls); //Create an appearance for the roof Appearance roofApp = new Appearance(); Color3f roofColour = new Color3f(0.5f, 0.0f, 0.0f); roofApp.setMaterial(new Material(roofColour, emissiveColour, roofColour, specularColour, shininess)); //Create a cone that will be the roof Cone myRoof = new Cone(1.0f, 1.0f, Primitive.GENERATE_NORMALS, roofApp); //Create the transform and transform group that will position the //roof on the house Transform3D roofXfm = new Transform3D(); roofXfm.set(new Vector3f(0.0f, 1.0f, 0.0f)); TransformGroup roofXfmGrp = new TransformGroup(roofXfm); //Add the roof to the roof transform group roofXfmGrp.addChild(myRoof); //Add the roof group to the house house.addChild(roofXfmGrp); //Create an appearance for the tree trunks Appearance trunkApp = new Appearance(); Color3f trunkColour = new Color3f(0.2f, 0.2f, 0.0f); trunkApp.setMaterial(new Material(trunkColour, emissiveColour, trunkColour, specularColour, shininess)); //Create an appearance for the tree leaves Appearance leafApp = new Appearance(); Color3f leafColour = new Color3f(0.0f, 0.2f, 0.0f); leafApp.setMaterial(new Material(leafColour, emissiveColour, leafColour, specularColour, shininess)); //Create a transform and transform group for the tree Transform3D treeXfm = new Transform3D(); treeXfm.set(new Vector3f(-2.0f, 0.0f, 0.5f)); TransformGroup treeXfmGrp = new TransformGroup(treeXfm); //Create a cylinder for the tree trunk Cylinder myTrunk = new Cylinder(0.1f, 1.0f, trunkApp); //Add the trunk to the tree group treeXfmGrp.addChild(myTrunk); //Create a transform and transform group for the tree leaves Transform3D leafXfm = new Transform3D(); leafXfm.set(new Vector3f(0.0f, 1.0f, 0.0f)); TransformGroup leafXfmGrp = new TransformGroup(leafXfm); //Create the leaves Sphere myLeaf = new Sphere(0.5f, leafApp); //Add the leaves to the leaf group leafXfmGrp.addChild(myLeaf); //Add the leaf group to the tree group treeXfmGrp.addChild(leafXfmGrp); //Create another tree Transform3D tree1Xfm = new Transform3D(); tree1Xfm.set(new Vector3f(1.4f, 0.0f, -0.5f)); TransformGroup tree1XfmGrp = new TransformGroup(tree1Xfm); Cylinder myTrunk1 = new Cylinder(0.1f, 1.0f, trunkApp); tree1XfmGrp.addChild(myTrunk1); Transform3D leaf1Xfm = new Transform3D(); leaf1Xfm.set(new Vector3f(0.0f, 1.0f, 0.0f)); TransformGroup leaf1XfmGrp = new TransformGroup(leaf1Xfm); Sphere myLeaf1 = new Sphere(0.5f, leafApp); leaf1XfmGrp.addChild(myLeaf1); tree1XfmGrp.addChild(leaf1XfmGrp); //Create the final tree Transform3D tree2Xfm = new Transform3D(); tree2Xfm.set(new Vector3f(1.2f, 0.0f, 1.0f)); TransformGroup tree2XfmGrp = new TransformGroup(tree2Xfm); Cylinder myTrunk2 = new Cylinder(0.1f, 1.0f, trunkApp); tree2XfmGrp.addChild(myTrunk2); Transform3D leaf2Xfm = new Transform3D(); leaf2Xfm.set(new Vector3f(0.0f, 1.0f, 0.0f)); TransformGroup leaf2XfmGrp = new TransformGroup(leaf2Xfm); Sphere myLeaf2 = new Sphere(0.5f, leafApp); leaf2XfmGrp.addChild(myLeaf2); tree2XfmGrp.addChild(leaf2XfmGrp); //Put the scene together by adding all the groups //to the scene group theScene.addChild(house); theScene.addChild(treeXfmGrp); theScene.addChild(tree1XfmGrp); theScene.addChild(tree2XfmGrp); return theScene; }
From source file:BoundsTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // do NOT auto compute bounds for this node objRoot.setBoundsAutoCompute(false); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(createApplicationBounds()); objTrans.addChild(rotator);//from w w w .j a va2 s. c o m objTrans.addChild(createColorCubes()); objTrans.addChild(createPoints()); objRoot.addChild(objTrans); return objRoot; }
From source file:Text3DTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 4000, 0, 0, 0); TornadoRotation rotator = new TornadoRotation(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator);/* w ww .j a va 2s . co m*/ objTrans.addChild(createText3D(rotator, "setString", 1, 10.0f, 6.0f, Text3D.PATH_RIGHT)); objRoot.addChild(objTrans); return objRoot; }
From source file:RasterTest.java
protected BranchGroup createSceneBranchGroup() { // create some simple geometry (a rotating ColorCube) // and a Shape3D object for the Raster containing the Image BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D yAxis = new Transform3D(); yAxis.rotX(0.6);/* w w w . jav a 2 s . c o m*/ Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); // wrap the Raster in a Shape3D Shape3D shape = new Shape3D(m_RenderRaster); objRoot.addChild(shape); objTrans.addChild(new ColorCube(1.0)); objRoot.addChild(objTrans); return objRoot; }
From source file:AvatarTest.java
public void createBackground(Group bg) { // add the sky backdrop Background back = new Background(); back.setApplicationBounds(getBoundingSphere()); bg.addChild(back);//from w w w .j av a 2s .c om 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:PictureBall.java
public PictureBall() { // Create the universe SimpleUniverse universe = new SimpleUniverse(); // Create a structure to contain objects BranchGroup group = new BranchGroup(); // Set up colors Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(0.7f, .15f, .15f); // Set up the texture map TextureLoader loader = new TextureLoader("K:\\3d\\Arizona.jpg", "LUMINANCE", new Container()); Texture texture = loader.getTexture(); texture.setBoundaryModeS(Texture.WRAP); texture.setBoundaryModeT(Texture.WRAP); texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f)); // Set up the texture attributes //could be REPLACE, BLEND or DECAL instead of MODULATE TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); Appearance ap = new Appearance(); ap.setTexture(texture);/* w ww . j av a 2 s .co m*/ ap.setTextureAttributes(texAttr); //set up the material ap.setMaterial(new Material(red, black, red, black, 1.0f)); // Create a ball to demonstrate textures int primflags = Primitive.GENERATE_NORMALS + Primitive.GENERATE_TEXTURE_COORDS; Sphere sphere = new Sphere(0.5f, primflags, ap); group.addChild(sphere); // Create lights Color3f light1Color = new Color3f(1f, 1f, 1f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); group.addChild(light1); AmbientLight ambientLight = new AmbientLight(new Color3f(.5f, .5f, .5f)); ambientLight.setInfluencingBounds(bounds); group.addChild(ambientLight); // look towards the ball universe.getViewingPlatform().setNominalViewingTransform(); // add the group of objects to the Universe universe.addBranchGraph(group); }
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); return bg;// w w w . ja v a2 s . c o m }
From source file:TextureTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // add an Interpolator to rotate the scene objTrans.addChild(createInterpolator(objTrans)); // process the texture input files and add the geometry objTrans.addChild(createTextureGroup("ann.txt", -5, -5, -3, false)); objTrans.addChild(createTextureGroup("daniel.txt", -5, 5, 3, false)); objTrans.addChild(createTextureGroup("ann.txt", 5, 5, 3, false)); objTrans.addChild(createTextureGroup("daniel.txt", 5, -5, -3, false)); objRoot.addChild(objTrans); return objRoot; }