List of usage examples for javax.media.j3d BranchGroup addChild
public void addChild(Node child)
From source file:SimpleSwitch.java
/** * Add some lights so that we can illuminate the scene. This adds one * ambient light to bring up the overall lighting level and one directional * shape to show the shape of the objects in the scene. * /* w w w . j a v a 2 s .c om*/ * @param b * BranchGroup that the lights are to be added to. */ protected void addLights(BranchGroup b) { BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Color3f lightColour1 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir1 = new Vector3f(0.0f, -1.0f, 0.0f); Color3f lightColour2 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir2 = new Vector3f(0.0f, 1.0f, 0.0f); DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1); light1.setInfluencingBounds(bounds); DirectionalLight light2 = new DirectionalLight(lightColour2, lightDir2); light2.setInfluencingBounds(bounds); b.addChild(light1); b.addChild(light2); }
From source file:LineTypes.java
BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a TransformGroup to scale the scene down by 3.5x // TODO: move view platform instead of scene using orbit behavior TransformGroup objScale = new TransformGroup(); Transform3D scaleTrans = new Transform3D(); //scaleTrans.set(1 / 3.5f); // scale down by 3.5x objScale.setTransform(scaleTrans);/*from www . ja va 2 s. com*/ objRoot.addChild(objScale); // Create a TransformGroup and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // the mouse behaviors code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(objTrans); // Add the primitives to the scene objTrans.addChild(createLineTypes()); BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0); Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f)); bg.setApplicationBounds(bounds); objTrans.addChild(bg); // set up the mouse rotation behavior MouseRotate mr = new MouseRotate(); mr.setTransformGroup(objTrans); mr.setSchedulingBounds(bounds); mr.setFactor(0.007); objTrans.addChild(mr); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 1.0f); Vector3f light1Direction = new Vector3f(0.0f, -0.2f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); return objRoot; }
From source file:cgview.java
public BranchGroup createSceneGraph(CompressedGeometry cg) { // 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.7);//from w w w.ja v a 2s. c o 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. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(objTrans); // Add compressed geometry to the scene graph. CompressedGeometryHeader hdr = new CompressedGeometryHeader(); cg.getCompressedGeometryHeader(hdr); // There isn't really enough information in the compressed geometry // header to unamiguously determine the proper rendering attributes. // The bufferDataPresent field specifies whether or not normals are // bundled with vertices, but the compressed buffer can still contain // normals that should be lit. Assume that any surface geometry // should be lit and that lines and points should not unless the // header contains the NORMAL_IN_BUFFER bit. Material m = new Material(); if ((hdr.bufferType == hdr.TRIANGLE_BUFFER) || ((hdr.bufferDataPresent & hdr.NORMAL_IN_BUFFER) == 1)) m.setLightingEnable(true); else m.setLightingEnable(false); Appearance a = new Appearance(); a.setMaterial(m); objTrans.addChild(new Shape3D(cg, a)); // Create mouse behavior scheduling bounds. BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); objRoot.addChild(bgNode); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -0.9f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objRoot.addChild(light2); return objRoot; }
From source file:IntersectTest.java
public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); u = new SimpleUniverse(c); // Add picking behavior IntersectInfoBehavior behavior = new IntersectInfoBehavior(c, scene, 0.05f); behavior.setSchedulingBounds(bounds); scene.addChild(behavior); TransformGroup vpTrans = u.getViewingPlatform().getViewPlatformTransform(); KeyNavigatorBehavior keybehavior = new KeyNavigatorBehavior(vpTrans); keybehavior.setSchedulingBounds(bounds); scene.addChild(keybehavior);//from ww w. ja v a2 s . c o m scene.setCapability(Group.ALLOW_CHILDREN_EXTEND); scene.compile(); u.addBranchGraph(scene); View view = u.getViewer().getView(); view.setBackClipDistance(100000); }
From source file:HiResCoordTest.java
public void initJava3d() { super.initJava3d(); // create a second locale for the earth and attach it to the universe Locale locale = createLocaleEarth(m_Universe); BranchGroup sceneBranchGroup = createSceneBranchGroupEarth(); sceneBranchGroup.addChild(createBackground()); m_ViewPlatformArray[1] = createViewPlatform(); BranchGroup viewBranchGroup = createViewBranchGroup(getViewTransformGroupArray(1), m_ViewPlatformArray[1]); // getJ3dTree().recursiveApplyCapability(sceneBranchGroup); // getJ3dTree().recursiveApplyCapability(viewBranchGroup); locale.addBranchGraph(sceneBranchGroup); addViewBranchGroup(locale, viewBranchGroup); // create a third locale for the house on earth and attach it to the // universe//from w w w .jav a 2s . co m locale = createLocaleHouse(m_Universe); sceneBranchGroup = createSceneBranchGroupHouse(); sceneBranchGroup.addChild(createBackground()); m_ViewPlatformArray[2] = createViewPlatform(); viewBranchGroup = createViewBranchGroup(getViewTransformGroupArray(2), m_ViewPlatformArray[2]); // getJ3dTree().recursiveApplyCapability(sceneBranchGroup); // getJ3dTree().recursiveApplyCapability(viewBranchGroup); locale.addBranchGraph(sceneBranchGroup); addViewBranchGroup(locale, viewBranchGroup); onDoneInit(); }
From source file:FPSCounterDemo.java
BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create the TransformGroup node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at run time. Add it to // the root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans); // Create a simple Shape3D node; add it to the scene graph. objTrans.addChild(new ColorCube(0.4)); // Create a new Behavior object that will perform the // desired operation on the specified transform and add // it into the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, 4000); 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);// w w w .j a va2s . c om rotator.setSchedulingBounds(bounds); objRoot.addChild(rotator); // Create the Framecounter behavior fpsCounter.setSchedulingBounds(bounds); objRoot.addChild(fpsCounter); return objRoot; }
From source file:TexBug.java
BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Add the primitives to the scene setupAppearance();// w ww . jav a 2s .co m setupScene(); objRoot.addChild(scene); return objRoot; }
From source file:AppearanceTest.java
private BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a bounds for the background and lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background TextureLoader bgTexture = new TextureLoader(bgImage, this); Background bg = new Background(bgTexture.getImage()); bg.setApplicationBounds(bounds);//from ww w . ja v a2 s . c o m objRoot.addChild(bg); // 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); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objRoot.addChild(aLgt); objRoot.addChild(lgt1); // 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) * 0.6; for (int j = 0; j < 3; j++) { double xpos = (double) (j - 1) * 0.6; objRoot.addChild(createObject(app[i][j], 0.12, xpos, ypos)); } } // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:SimpleDirLight.java
/** * This creates some lights and adds them to the BranchGroup. * // w w w .j ava 2 s . c o m * @param b * BranchGroup that the lights are added to. */ protected void addLights(BranchGroup b) { // Create a bounds for the lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); //Set up the ambient light Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight ambientLight = new AmbientLight(ambientColour); ambientLight.setInfluencingBounds(bounds); //Set up the directional light Color3f lightColour = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight light = new DirectionalLight(lightColour, lightDir); light.setInfluencingBounds(bounds); //Add the lights to the BranchGroup b.addChild(ambientLight); b.addChild(light); }
From source file:MixedTest.java
public void initJava3d() { // m_Java3dTree = new com.tornadolabs.j3dtree.Java3dTree(); m_Universe = createVirtualUniverse(); Locale locale = createLocale(m_Universe); BranchGroup sceneBranchGroup = createSceneBranchGroup(); ViewPlatform vp = createViewPlatform(); BranchGroup viewBranchGroup = createViewBranchGroup(getViewTransformGroupArray(), vp); createView(vp);// w w w . j a v a 2 s. co m Background background = createBackground(); if (background != null) sceneBranchGroup.addChild(background); // m_Java3dTree.recursiveApplyCapability(sceneBranchGroup); // m_Java3dTree.recursiveApplyCapability(viewBranchGroup); locale.addBranchGraph(sceneBranchGroup); addViewBranchGroup(locale, viewBranchGroup); onDoneInit(); }