List of usage examples for javax.media.j3d BranchGroup addChild
public void addChild(Node child)
From source file:AvatarTest.java
public static void main(String[] args) { AvatarTest avatarTest = new AvatarTest(); // Create a simple scene and attach it to the virtual universe SimpleUniverse u = new SimpleUniverse(); PhysicalEnvironment physicalEnv = u.getViewer().getPhysicalEnvironment(); TransformGroup tg = u.getViewer().getViewingPlatform().getViewPlatformTransform(); Transform3D t3d = new Transform3D(); t3d.set(new Vector3f(0, 0.5f, 0)); tg.setTransform(t3d);/*from ww w . j a va2s . c om*/ CarSteering keys = new CarSteering(tg); keys.setSchedulingBounds(avatarTest.getBoundingSphere()); u.getViewer().setAvatar(avatarTest.createAvatar()); if (physicalEnv != null) { JavaSoundMixer javaSoundMixer = new JavaSoundMixer(physicalEnv); if (javaSoundMixer == null) System.out.println("Unable to create AudioDevice."); javaSoundMixer.initialize(); } // Add everthing to the scene graph - it will now be displayed. BranchGroup scene = avatarTest.createSceneGraph(); scene.addChild(keys); // Java3dTree j3dTree = new Java3dTree(); // j3dTree.recursiveApplyCapability(scene); u.addBranchGraph(scene); //j3dTree.updateNodes(u); u.getViewingPlatform().getViewPlatform().setActivationRadius(2); }
From source file:HelloWorld.java
private static BranchGroup createSceneGraph() { // Make a scene graph branch BranchGroup branch = new BranchGroup(); // Make a changeable 3D transform TransformGroup trans = new TransformGroup(); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); branch.addChild(trans); // Make a shape ColorCube demo = new ColorCube(0.4); trans.addChild(demo);/*from w w w. j ava 2 s .com*/ // Make a behavor to spin the shape Alpha spinAlpha = new Alpha(-1, 4000); RotationInterpolator spinner = new RotationInterpolator(spinAlpha, trans); spinner.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0)); trans.addChild(spinner); return branch; }
From source file:Hello3d.java
public Hello3d() { SimpleUniverse universe = new SimpleUniverse(); BranchGroup group = new BranchGroup(); group.addChild(new ColorCube(0.3)); universe.getViewingPlatform().setNominalViewingTransform(); universe.addBranchGraph(group);//from ww w. j av a2 s. c o m }
From source file:HelloJava3Da.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); objRoot.addChild(new ColorCube(0.4)); return objRoot; }
From source file:CanvasDemo.java
public CanvasDemo() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas = new Canvas3D(config); add("North", new Label("This is the top")); add("Center", canvas); add("South", new Label("This is the bottom")); BranchGroup contents = new BranchGroup(); contents.addChild(new ColorCube(0.3)); SimpleUniverse universe = new SimpleUniverse(canvas); universe.getViewingPlatform().setNominalViewingTransform(); universe.addBranchGraph(contents);//from w w w . ja va 2 s . co m }
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 . ja va2s. co 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:Ball.java
public Ball() { // Create the universe SimpleUniverse universe = new SimpleUniverse(); // Create a structure to contain objects BranchGroup group = new BranchGroup(); // Create a ball and add it to the group of objects Sphere sphere = new Sphere(0.5f); group.addChild(sphere); // Create a red light that shines for 100m from the origin Color3f light1Color = new Color3f(1.8f, 0.1f, 0.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);/*from w w w . j a v a 2 s . c om*/ // look towards the ball universe.getViewingPlatform().setNominalViewingTransform(); // add the group of objects to the Universe universe.addBranchGraph(group); }
From source file:SimpleLOD.java
/** * Build the content branch for the scene graph This creates three * cylinders, each with a different resolution. These are then used with a * LOD node to implement a crude level of detail. * /*from ww w .j ava 2 s .c o m*/ * @return BranchGroup that is the root of the content */ protected BranchGroup buildContentBranch() { //Create the appearance Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 1.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, 1.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Make the switch node that is to used with the LOD //and make it writable Switch LODswitch = new Switch(); LODswitch.setCapability(Switch.ALLOW_SWITCH_WRITE); //Add the three cylinders LODswitch.addChild(new Cylinder(1.0f, 1.0f, Cylinder.GENERATE_NORMALS, 10, 10, app)); LODswitch.addChild(new Cylinder(1.0f, 1.0f, Cylinder.GENERATE_NORMALS, 5, 5, app)); LODswitch.addChild(new Cylinder(1.0f, 1.0f, Cylinder.GENERATE_NORMALS, 3, 3, app)); //Define the distances for the LOD float[] LODdistances = { 5.0f, 10.0f, 15.0f }; DistanceLOD myLOD = new DistanceLOD(LODdistances, new Point3f(0.0f, 0.0f, 0.0f)); myLOD.setSchedulingBounds(bounds); //Add the switch to the LOD myLOD.addSwitch(LODswitch); BranchGroup contentBranch = new BranchGroup(); contentBranch.addChild(myLOD); addLights(contentBranch); contentBranch.addChild(LODswitch); return contentBranch; }
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 w ww . j av a 2 s . c o m*/ 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:SimpleBillboard.java
/** * Build the content branch for the scene graph. This creates two cubes and * uses a billboard node to keep one face of one of the cubes facing the * viewer./*from ww w .jav a 2 s. c om*/ * * @return BranchGroup that is the root of the content */ protected BranchGroup buildContentBranch() { //Create the appearance Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 1.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, 1.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Make the cubes Box leftCube = new Box(1.0f, 1.0f, 1.0f, app); ColorCube rightCube = new ColorCube(); //Create the transformgroup used for the billboard TransformGroup billBoardGroup = new TransformGroup(); //Set the access rights to the group billBoardGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); //Add the cube to the group billBoardGroup.addChild(rightCube); //Create and activate the billboard Billboard myBillboard = new Billboard(billBoardGroup, Billboard.ROTATE_ABOUT_AXIS, new Vector3f(0.0f, 1.0f, 0.0f)); myBillboard.setSchedulingBounds(bounds); BranchGroup contentBranch = new BranchGroup(); contentBranch.addChild(myBillboard); addLights(contentBranch); //Position the cubes TransformGroup bothGroup = new TransformGroup(); Transform3D leftGroupXfm = new Transform3D(); leftGroupXfm.set(new Vector3d(-1.5, 0.0, 0.0)); TransformGroup leftGroup = new TransformGroup(leftGroupXfm); Transform3D rightGroupXfm = new Transform3D(); rightGroupXfm.set(new Vector3d(1.5, 0.0, 0.0)); TransformGroup rightGroup = new TransformGroup(rightGroupXfm); //Put it all together bothGroup.addChild(leftGroup); leftGroup.addChild(leftCube); bothGroup.addChild(rightGroup); rightGroup.addChild(billBoardGroup); contentBranch.addChild(bothGroup); return contentBranch; }