List of usage examples for javax.media.j3d BranchGroup addChild
public void addChild(Node child)
From source file:PrintFromButton.java
public BranchGroup createSceneGraph(Raster drawRaster) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // spin object has composited transformation matrix Transform3D spin = new Transform3D(); Transform3D tempspin = new Transform3D(); spin.rotX(Math.PI / 4.0d);/*from w ww. ja va2s. co m*/ tempspin.rotY(Math.PI / 5.0d); spin.mul(tempspin); spin.setScale(0.7); spin.setTranslation(new Vector3d(-0.4, 0.3, 0.0)); TransformGroup objTrans = new TransformGroup(spin); objRoot.addChild(objTrans); // Create a simple shape leaf node, add it to the scene graph. // ColorCube is a Convenience Utility class objTrans.addChild(new ColorCube(0.4)); //Create a raster obj Shape3D shape = new Shape3D(drawRaster); objRoot.addChild(shape); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:SwingTest.java
/** * Create a BranchGroup that contains a Cube. The user data for the * BranchGroup is set so the BranchGroup can be identified. *///from ww w . j a va 2 s. co m protected BranchGroup createCube() { BranchGroup bg = new BranchGroup(); bg.setCapability(BranchGroup.ALLOW_DETACH); bg.addChild(new com.sun.j3d.utils.geometry.ColorCube()); bg.setUserData("Cube"); return bg; }
From source file:SimpleCombine.java
/** * This function builds the view branch of the scene graph. It creates a * branch group and then creates the necessary view elements to give a * useful view of our content./*from www. j a v a 2 s . co m*/ * * @param c * Canvas3D that will display the view * @return BranchGroup that is the root of the view elements */ protected BranchGroup buildViewBranch(Canvas3D c) { BranchGroup viewBranch = new BranchGroup(); Transform3D viewXfm = new Transform3D(); viewXfm.set(new Vector3f(0.0f, 0.0f, 7.0f)); TransformGroup viewXfmGroup = new TransformGroup(viewXfm); ViewPlatform myViewPlatform = new ViewPlatform(); PhysicalBody myBody = new PhysicalBody(); PhysicalEnvironment myEnvironment = new PhysicalEnvironment(); viewXfmGroup.addChild(myViewPlatform); viewBranch.addChild(viewXfmGroup); View myView = new View(); myView.addCanvas3D(c); myView.attachViewPlatform(myViewPlatform); myView.setPhysicalBody(myBody); myView.setPhysicalEnvironment(myEnvironment); return viewBranch; }
From source file:OffScreenTest.java
public BranchGroup createSceneGraph(Raster drawRaster) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // spin object has composited transformation matrix Transform3D spin = new Transform3D(); Transform3D tempspin = new Transform3D(); spin.rotX(Math.PI / 4.0d);//from w ww. j ava 2 s .c om tempspin.rotY(Math.PI / 5.0d); spin.mul(tempspin); spin.setScale(0.7); spin.setTranslation(new Vector3d(-0.4, 0.3, 0.0)); TransformGroup objTrans = new TransformGroup(spin); objRoot.addChild(objTrans); // Create a simple shape leaf node, add it to the scene graph. // ColorCube is a Convenience Utility class objTrans.addChild(new ColorCube(0.4)); //Create a raster Shape3D shape = new Shape3D(drawRaster); objRoot.addChild(shape); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:LOD.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); createLights(objRoot);//from ww w .ja v a2 s.co m // 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); objRoot.addChild(objTrans); // Create a switch to hold the different levels of detail Switch sw = new Switch(0); sw.setCapability(javax.media.j3d.Switch.ALLOW_SWITCH_READ); sw.setCapability(javax.media.j3d.Switch.ALLOW_SWITCH_WRITE); // Create several levels for the switch, with less detailed // spheres for the ones which will be used when the sphere is // further away sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 40)); sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 20)); sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 10)); sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 3)); // Add the switch to the main group objTrans.addChild(sw); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // set up the DistanceLOD behavior float[] distances = new float[3]; distances[0] = 5.0f; distances[1] = 10.0f; distances[2] = 25.0f; DistanceLOD lod = new DistanceLOD(distances); lod.addSwitch(sw); lod.setSchedulingBounds(bounds); objTrans.addChild(lod); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:ConicWorld.java
public BranchGroup createSceneGraph(Canvas3D c) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a bounds for the background and behaviors 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.2f); Background bg = new Background(bgColor); bg.setApplicationBounds(bounds);//w w 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; int numRows = 3, numCols = 5; Appearance[][] app = new Appearance[numRows][numCols]; for (row = 0; row < numRows; row++) for (col = 0; col < numCols; col++) app[row][col] = createAppearance(row * numCols + col); // Space between each row/column double xspace = 2.0 / ((double) numCols - 1.0); double yspace = 2.0 / ((double) numRows - 1.0); for (int i = 0; i < numRows; i++) { double ypos = ((double) i * yspace - 1.0) * 0.6; for (int j = 0; j < numCols; j++) { double xpos = xpos = ((double) j * xspace - 1.0) * 0.6; objRoot.addChild(createObject(i, j, app[i][j], 0.1, xpos, ypos)); } } // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:CompileTest.java
private BranchGroup createColorCubes() { BranchGroup bg = new BranchGroup(); final int kNumCubes = 1000; for (int n = 0; n < kNumCubes; n++) { ColorCube cube1 = new ColorCube(1.0); // switch off pickable attribute so we can compile cube1.setPickable(false);/*w ww.j a va 2 s .co m*/ bg.addChild(cube1); } bg.compile(); return bg; }
From source file:Text3DLoad.java
public BranchGroup createSceneGraph() { float sl = textString.length(); // 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(); // Assuming uniform size chars, set scale to fit string in view t3d.setScale(1.2 / sl);/* w ww . j av a2s . co 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); Font3D f3d; if (tessellation > 0.0) { f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), tessellation, new FontExtrusion()); } else { f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion()); } Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, -1.f, -1.f)); Shape3D sh = new Shape3D(); Appearance app = new Appearance(); Material mm = new Material(); mm.setLightingEnable(true); app.setMaterial(mm); sh.setGeometry(txt); sh.setAppearance(app); objTrans.addChild(sh); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); if (false) { 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(bounds); objTrans.addChild(rotator); } // 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.3f, 0.3f, 0.3f); 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, -1.0f); 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:SphereMotion.java
public BranchGroup createSceneGraph(SimpleUniverse u) { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Transform3D t;/*from ww w.java 2 s . c o m*/ // 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.4); objScale.setTransform(t3d); objRoot.addChild(objScale); // 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 Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // Create a Sphere object, generate one copy of the sphere, // and add it into the scene graph. Material m = new Material(objColor, eColor, objColor, sColor, 100.0f); Appearance a = new Appearance(); m.setLightingEnable(true); a.setMaterial(m); Sphere sph = new Sphere(1.0f, Sphere.GENERATE_NORMALS, 80, a); objScale.addChild(sph); // Create the transform group node for the each light and initialize // it to the identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add them to the root // of the subgraph. TransformGroup l1RotTrans = new TransformGroup(); l1RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objScale.addChild(l1RotTrans); TransformGroup l2RotTrans = new TransformGroup(); l2RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objScale.addChild(l2RotTrans); // Create transformations for the positional lights t = new Transform3D(); Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0); t.set(lPos1); TransformGroup l1Trans = new TransformGroup(t); l1RotTrans.addChild(l1Trans); t = new Transform3D(); Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0); t.set(lPos2); TransformGroup l2Trans = new TransformGroup(t); l2RotTrans.addChild(l2Trans); // Create Geometry for point lights ColoringAttributes caL1 = new ColoringAttributes(); ColoringAttributes caL2 = new ColoringAttributes(); caL1.setColor(lColor1); caL2.setColor(lColor2); Appearance appL1 = new Appearance(); Appearance appL2 = new Appearance(); appL1.setColoringAttributes(caL1); appL2.setColoringAttributes(caL2); l1Trans.addChild(new Sphere(0.05f, appL1)); l2Trans.addChild(new Sphere(0.05f, appL2)); // Create lights AmbientLight aLgt = new AmbientLight(alColor); Light lgt1 = null; Light lgt2 = null; Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f); Point3f atten = new Point3f(1.0f, 0.0f, 0.0f); Vector3f lDirect1 = new Vector3f(lPos1); Vector3f lDirect2 = new Vector3f(lPos2); lDirect1.negate(); lDirect2.negate(); switch (lightType) { case DIRECTIONAL_LIGHT: lgt1 = new DirectionalLight(lColor1, lDirect1); lgt2 = new DirectionalLight(lColor2, lDirect2); break; case POINT_LIGHT: lgt1 = new PointLight(lColor1, lPoint, atten); lgt2 = new PointLight(lColor2, lPoint, atten); break; case SPOT_LIGHT: lgt1 = new SpotLight(lColor1, lPoint, atten, lDirect1, 25.0f * (float) Math.PI / 180.0f, 10.0f); lgt2 = new SpotLight(lColor2, lPoint, atten, lDirect2, 25.0f * (float) Math.PI / 180.0f, 10.0f); break; } // Set the influencing bounds aLgt.setInfluencingBounds(bounds); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); // Add the lights into the scene graph objScale.addChild(aLgt); l1Trans.addChild(lgt1); l2Trans.addChild(lgt2); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into the // scene graph. Transform3D yAxis = new Transform3D(); Alpha rotor1Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator1 = new RotationInterpolator(rotor1Alpha, l1RotTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator1.setSchedulingBounds(bounds); l1RotTrans.addChild(rotator1); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into the // scene graph. Alpha rotor2Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 1000, 0, 0, 0, 0, 0); RotationInterpolator rotator2 = new RotationInterpolator(rotor2Alpha, l2RotTrans, yAxis, 0.0f, 0.0f); bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator2.setSchedulingBounds(bounds); l2RotTrans.addChild(rotator2); // Create a position interpolator and attach it to the view // platform TransformGroup vpTrans = u.getViewingPlatform().getViewPlatformTransform(); Transform3D axisOfTranslation = new Transform3D(); Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 0, 0, 5000, 0, 0); axisOfTranslation.rotY(-Math.PI / 2.0); PositionInterpolator translator = new PositionInterpolator(transAlpha, vpTrans, axisOfTranslation, 2.0f, 3.5f); translator.setSchedulingBounds(bounds); objScale.addChild(translator); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:SimpleKeyNav.java
/** * Add some lights to the scene graph//w w w . j a v a 2 s . c o m * * @param b * BranchGroup that the lights are added to */ protected void addLights(BranchGroup b) { // Create a bounds for the background and lights // Set up the global lights Color3f ambLightColour = new Color3f(0.5f, 0.5f, 0.5f); AmbientLight ambLight = new AmbientLight(ambLightColour); ambLight.setInfluencingBounds(bounds); Color3f dirLightColour = new Color3f(1.0f, 1.0f, 1.0f); Vector3f dirLightDir = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight dirLight = new DirectionalLight(dirLightColour, dirLightDir); dirLight.setInfluencingBounds(bounds); b.addChild(ambLight); b.addChild(dirLight); }