List of usage examples for javax.media.j3d BranchGroup addChild
public void addChild(Node child)
From source file:LitTwistApp.java
public BranchGroup createSceneGraph() { BranchGroup contentRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Add it to the root of the subgraph. TransformGroup objSpin = new TransformGroup(); objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); contentRoot.addChild(objSpin); Shape3D twist = new Twist(); objSpin.addChild(twist);// w ww . ja va 2 s.co m Alpha rotationAlpha = new Alpha(-1, 16000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin); // a bounding sphere specifies a region a behavior is active // create a sphere centered at the origin with radius of 1.5 BoundingSphere bounds = new BoundingSphere(); bounds.setRadius(1.5); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); DirectionalLight lightD = new DirectionalLight(); lightD.setInfluencingBounds(bounds); contentRoot.addChild(lightD); Background background = new Background(); background.setColor(1.0f, 1.0f, 1.0f); background.setApplicationBounds(bounds); contentRoot.addChild(background); // Let Java 3D perform optimizations on this scene graph. // contentRoot.compile(); return contentRoot; }
From source file:OrientedTest.java
public void init() { // the paths to the image files for an applet if (earthImage == null) { try {//from www . jav a2s. c o m earthImage = new java.net.URL(getCodeBase().toString() + "/earth.jpg"); } catch (java.net.MalformedURLException ex) { System.out.println(ex.getMessage()); System.exit(1); } } if (stoneImage == null) { try { stoneImage = new java.net.URL(getCodeBase().toString() + "/stone.jpg"); } catch (java.net.MalformedURLException ex) { System.out.println(ex.getMessage()); System.exit(1); } } 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, 4); // add mouse behaviors to ViewingPlatform ViewingPlatform viewingPlatform = u.getViewingPlatform(); // there is a special rotate behavior, so can't use the utility // method MouseRotateY rotate = new MouseRotateY(MouseRotateY.INVERT_INPUT); rotate.setTransformGroup(viewingPlatform.getMultiTransformGroup().getTransformGroup(0)); BranchGroup rotateBG = new BranchGroup(); rotateBG.addChild(rotate); viewingPlatform.addChild(rotateBG); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotate.setSchedulingBounds(bounds); MouseZoom zoom = new MouseZoom(c, MouseZoom.INVERT_INPUT); zoom.setTransformGroup(viewingPlatform.getMultiTransformGroup().getTransformGroup(1)); zoom.setSchedulingBounds(bounds); BranchGroup zoomBG = new BranchGroup(); zoomBG.addChild(zoom); viewingPlatform.addChild(zoomBG); MouseTranslate translate = new MouseTranslate(c, MouseTranslate.INVERT_INPUT); translate.setTransformGroup(viewingPlatform.getMultiTransformGroup().getTransformGroup(2)); translate.setSchedulingBounds(bounds); BranchGroup translateBG = new BranchGroup(); translateBG.addChild(translate); viewingPlatform.addChild(translateBG); // 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:HelloUniverse1.java
public 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); rotator.setSchedulingBounds(bounds); objRoot.addChild(rotator);/*from w ww . ja v a 2 s . c o m*/ // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:LOD.java
private void createLights(BranchGroup graphRoot) { // Create a bounds for the light source influence BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the global, ambient light Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds);/*from w w w .j a va 2s. com*/ graphRoot.addChild(aLgt); // Set up the directional (infinite) light source Color3f lColor1 = new Color3f(0.9f, 0.9f, 0.9f); Vector3f lDir1 = new Vector3f(1.0f, 1.0f, -1.0f); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); graphRoot.addChild(lgt1); }
From source file:TwistStripApp.java
public BranchGroup createSceneGraph() { BranchGroup contentRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Add it to the root of the subgraph. TransformGroup objSpin = new TransformGroup(); objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); contentRoot.addChild(objSpin); Shape3D twist = new Twist(); objSpin.addChild(twist);/* w ww. j av a 2 s. c o m*/ // Duplicate the twist strip geometry and set the // appearance of the new Shape3D object to line mode // without culling. // Add the POLYGON_FILLED and POLYGON_LINE strips // in the scene graph at the same point. // This will show the triangles of the original Mobius strip that // are clipped. The PolygonOffset is set to prevent stitching. PolygonAttributes polyAttrib = new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrib.setPolygonOffset(0.001f); Appearance polyAppear = new Appearance(); polyAppear.setPolygonAttributes(polyAttrib); objSpin.addChild(new Shape3D(twist.getGeometry(), polyAppear)); Alpha rotationAlpha = new Alpha(-1, 16000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin); // a bounding sphere specifies a region a behavior is active // create a sphere centered at the origin with radius of 1 BoundingSphere bounds = new BoundingSphere(); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); // make background white Background background = new Background(1.0f, 1.0f, 1.0f); background.setApplicationBounds(bounds); contentRoot.addChild(background); // Let Java 3D perform optimizations on this scene graph. contentRoot.compile(); return contentRoot; }
From source file:TextureMapping.java
/** * Erstellt den Szenegraphen//from w w w . ja v a2s . c om * * @return BranchGroup */ public BranchGroup macheSzene() { BranchGroup objWurzel = new BranchGroup(); // Transformation, 2 Rotationen: Transform3D drehung = new Transform3D(); Transform3D drehung2 = new Transform3D(); drehung.rotX(Math.PI / 4.0d); drehung2.rotY(Math.PI / 5.0d); drehung.mul(drehung2); TransformGroup objDreh = new TransformGroup(drehung); objDreh.addChild(new Box(0.5f, 0.5f, 0.5f, Box.GENERATE_TEXTURE_COORDS, makeAppearance())); objWurzel.addChild(objDreh); return objWurzel; }
From source file:AWTInteraction.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // 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. objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans); // Create a simple shape leaf node, add it to the scene graph. objTrans.addChild(new ColorCube(0.4)); // create the AWTInteractionBehavior AWTInteractionBehavior awtBehavior = new AWTInteractionBehavior(objTrans); rotateB.addActionListener(awtBehavior); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); awtBehavior.setSchedulingBounds(bounds); objRoot.addChild(awtBehavior);//from ww w . j a va 2s . co m return objRoot; }
From source file:ModelClipTest2.java
public BranchGroup createSceneGraph() { // 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);/*w w w .ja v a 2 s .c om*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // Create lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); //Shine it with two colored lights. Color3f lColor0 = new Color3f(1.0f, 1.0f, 1.0f); Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f); Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f); Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f); AmbientLight lgt0 = new AmbientLight(true, lColor2); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2); lgt0.setInfluencingBounds(bounds); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); objScale.addChild(lgt0); objScale.addChild(lgt1); objScale.addChild(lgt2); // Create a Transformgroup for the geometry TransformGroup objRot = new TransformGroup(); Transform3D t3d1 = new Transform3D(); AxisAngle4f rot1 = new AxisAngle4f(0.0f, 1.0f, 0.0f, 45.0f); t3d1.setRotation(rot1); objRot.setTransform(t3d1); objScale.addChild(objRot); //Create a cylinder PolygonAttributes attr = new PolygonAttributes(); attr.setCullFace(PolygonAttributes.CULL_NONE); Appearance ap = new Appearance(); Material mat = new Material(); mat.setLightingEnable(true); ap.setMaterial(mat); ap.setPolygonAttributes(attr); Cylinder CylinderObj = new Cylinder(0.5f, 2.2f, ap); objRot.addChild(CylinderObj); //Create a box Box BoxObj = new Box(0.8f, 0.8f, 0.8f, ap); objRot.addChild(BoxObj); // This Transformgroup is used by the mouse manipulators to // move the model clip planes. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRot.addChild(objTrans); // Create the rotate behavior node MouseRotate behavior = new MouseRotate(objTrans); objTrans.addChild(behavior); behavior.setSchedulingBounds(bounds); // Create the zoom behavior node MouseZoom behavior2 = new MouseZoom(objTrans); objTrans.addChild(behavior2); behavior2.setSchedulingBounds(bounds); //Create Model Clip ModelClip mc = new ModelClip(); boolean enables[] = { false, false, false, false, false, false }; Vector4d eqn = new Vector4d(0.0, 1.0, 1.0, 0.0); mc.setEnables(enables); mc.setPlane(1, eqn); mc.setEnable(1, true); mc.setInfluencingBounds(bounds); objTrans.addChild(mc); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:Licht.java
/** * Erstellt den Szenegraphen/*from w w w.j ava 2s . c o m*/ * * @return BranchGroup */ public BranchGroup macheSzene() { BranchGroup objWurzel = new BranchGroup(); // Transformation, 2 Rotationen: Transform3D drehung = new Transform3D(); Transform3D drehung2 = new Transform3D(); drehung.rotX(Math.PI / 4.0d); drehung2.rotY(Math.PI / 5.0d); drehung.mul(drehung2); TransformGroup objDreh = new TransformGroup(drehung); Sphere kugel = new Sphere(0.5f, Sphere.GENERATE_NORMALS, 50, makeAppearance()); objWurzel.addChild(kugel); objWurzel.addChild(objDreh); //directes Licht DirectionalLight d_Licht = new DirectionalLight(); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), Double.MAX_VALUE)); d_Licht.setColor(new Color3f(1.0f, 0.0f, 0.0f)); Vector3f dir = new Vector3f(1.0f, 2.0f, -1.0f); dir.normalize(); d_Licht.setDirection(dir); objWurzel.addChild(d_Licht); // ambient Licht AmbientLight a_licht = new AmbientLight(); a_licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0f, 0.0f, 0.0f), Double.MAX_VALUE)); a_licht.setColor(new Color3f(1.0f, 0.0f, 0.0f)); objWurzel.addChild(a_licht); return objWurzel; }
From source file:BackgroundApp.java
public BranchGroup createSceneGraph(SimpleUniverse su) { // Create the root of the branch graph BranchGroup objRootBG = new BranchGroup(); Vector3f translate = new Vector3f(); Transform3D T3D = new Transform3D(); translate.set(0.0f, -0.3f, 0.0f);// w w w. java2 s.c om T3D.setTranslation(translate); TransformGroup objRoot = new TransformGroup(T3D); objRootBG.addChild(objRoot); objRoot.addChild(createLand()); BoundingLeaf boundingLeaf = new BoundingLeaf(new BoundingSphere()); PlatformGeometry platformGeom = new PlatformGeometry(); platformGeom.addChild(boundingLeaf); platformGeom.compile(); su.getViewingPlatform().setPlatformGeometry(platformGeom); KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior( su.getViewingPlatform().getViewPlatformTransform()); keyNavBeh.setSchedulingBoundingLeaf(boundingLeaf); objRootBG.addChild(keyNavBeh); Background background = new Background(); background.setApplicationBounds(new BoundingSphere(new Point3d(), 1000.0)); background.setGeometry(createBackGraph()); objRoot.addChild(background); AmbientLight ambientLight = new AmbientLight(); ambientLight.setInfluencingBounds(new BoundingSphere()); objRootBG.addChild(ambientLight); return objRootBG; }