List of usage examples for javax.media.j3d Group ALLOW_CHILDREN_EXTEND
int ALLOW_CHILDREN_EXTEND
To view the source code for javax.media.j3d Group ALLOW_CHILDREN_EXTEND.
Click Source Link
From source file:ExText.java
public Group buildScene() { // Get the current font attributes Font font = (Font) fonts[currentFont].value; String textString = (String) fonts[currentFont].name; // Turn on the example headlight setHeadlightEnable(true);//from w w w. j a va 2s .c o m // Build the scene group scene = new Group(); scene.setCapability(Group.ALLOW_CHILDREN_EXTEND); scene.setCapability(Group.ALLOW_CHILDREN_WRITE); // Build a branch group to hold the text shape // (this allows us to remove the text shape later, // change it, then put it back, all under menu control) textGroup = new BranchGroup(); textGroup.setCapability(BranchGroup.ALLOW_DETACH); scene.addChild(textGroup); // BEGIN EXAMPLE TOPIC // Create a font extrusion with a default extrusion shape extrusion = new FontExtrusion(); // Define a 3D font with a default extrusion path Font3D font3d = new Font3D(font, extrusion); // Build 3D text geometry using the 3D font Text3D tex = new Text3D(); tex.setFont3D(font3d); tex.setString(textString); tex.setAlignment(Text3D.ALIGN_CENTER); // Define a generic shaded appearance Appearance app = new Appearance(); Material mat = new Material(); mat.setLightingEnable(true); app.setMaterial(mat); // Assemble geometry and appearance into a shape // and add it to the scene shape = new Shape3D(tex, app); shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); textGroup.addChild(shape); // END EXAMPLE TOPIC return scene; }
From source file:edu.uci.ics.jung.visualization3d.VisualizationViewer.java
public BranchGroup createSceneGraph(final Canvas3D canvas) { objRoot = new BranchGroup(); objRoot.setCapability(Group.ALLOW_CHILDREN_EXTEND); objRoot.setCapability(Group.ALLOW_CHILDREN_WRITE); TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); // t3d.setScale(0.05); objScale.setTransform(t3d);/*from w w w . ja va 2 s .c om*/ objRoot.addChild(objScale); Transform3D tt = new Transform3D(); tt.setScale(.05); tt.setTranslation(new Vector3f(0, 0, -30.f)); objTrans = new TransformGroup(tt); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objTrans.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); objScale.addChild(objTrans); // objRoot.addChild(objTrans); // Create Colors, Materials, and Appearances. Appearance look = new Appearance(); Color3f objColor = new Color3f(0.7f, 0.7f, 0.7f); Color3f black = new Color3f(0.f, 0.f, 0.f); Color3f white = new Color3f(1.0f, 1.0f, 0.6f); Color3f gray = new Color3f(.2f, .2f, .2f); Color3f red = new Color3f(1.0f, 0, 0); Color3f yellow = new Color3f(1, 1, 0); Material objMaterial = new Material(objColor, black, objColor, white, 100.0f); Material blackMaterial = new Material(objColor, black, black, objColor, 10.0f); Material whiteMaterial = new Material(white, white, white, white, 100.0f); Material grayMaterial = new Material(gray, black, gray, gray, 100.0f); Material redMaterial = new Material(red, black, red, red, 100.0f); Material yellowMaterial = new Material(yellow, black, yellow, yellow, 100); look.setMaterial(new Material(objColor, black, objColor, white, 100.0f)); Appearance blackLook = new Appearance(); blackLook.setMaterial(blackMaterial); Appearance whiteLook = new Appearance(); whiteLook.setMaterial(whiteMaterial); Appearance grayLook = new Appearance(); grayLook.setMaterial(grayMaterial); grayLook.setCapability(Appearance.ALLOW_MATERIAL_READ); grayLook.setCapability(Appearance.ALLOW_MATERIAL_WRITE); final Appearance redLook = new Appearance(); redLook.setMaterial(redMaterial); // vertexLook = redLook; Appearance objLook = new Appearance(); objLook.setMaterial(objMaterial); grayLook = objLook; final Appearance yellowLook = new Appearance(); yellowLook.setMaterial(yellowMaterial); Bounds bounds = new BoundingSphere(new Point3d(), 300); MouseRotate behavior1 = new MouseRotate(); behavior1.setTransformGroup(objTrans); objTrans.addChild(behavior1); behavior1.setSchedulingBounds(bounds); MouseWheelZoom behavior2 = new MouseWheelZoom(); behavior2.setTransformGroup(objTrans); // behavior2.setFactor(10); objTrans.addChild(behavior2); behavior2.setSchedulingBounds(bounds); MouseTranslate behavior3 = new MouseTranslate(); behavior3.setTransformGroup(objTrans); objTrans.addChild(behavior3); behavior3.setSchedulingBounds(bounds); PickTranslateBehavior ptb = new PickTranslateBehavior(objRoot, canvas, bounds, PickTool.GEOMETRY); ptb.setSchedulingBounds(bounds); // objTrans.addChild(ptb); ptb.setupCallback(new PickingCallback() { public void transformChanged(int type, TransformGroup tg) { if (tg == null) return; Transform3D t3d = new Transform3D(); tg.getTransform(t3d); // System.err.println(tg+" transformChanged \n"+t3d); Point3f p1 = new Point3f(); V v = vertexMap.getKey(tg); // Transform3D lvw = new Transform3D(); // tg.getLocalToVworld(lvw); // System.err.println("lvw = \n"+lvw); // lvw.invert(); // System.err.println("invert lvw = \n"+lvw); Point3f p0 = layout.transform(v); // Transform3D vwip = new Transform3D(); // canvas.getVworldToImagePlate(vwip); // System.err.println("vwip=\n"+vwip); // t3d.mul(lvw); t3d.transform(p1); // scale.transform(p1); System.err.println( "change location for vertex " + v + ", transformGroup " + tg + " from " + p0 + " to " + p1); // p1.set(p1.getX()*2,p1.getY()*2,p1.getZ()*2); // layout.setLocation(v, p1); } }); PickSphereBehavior psb = new PickSphereBehavior(objRoot, canvas, bounds); PickVertexBehavior pvb = new PickVertexBehavior(objRoot, canvas, bounds, renderContext.getPickedVertexState()); objTrans.addChild(pvb); pvb.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { for (V v : graph.getVertices()) { VertexGroup<V> vg = vertexMap.get(v); Appearance look = redLook; if (renderContext.getPickedVertexState().isPicked(v)) { look = yellowLook; } Node node = vg.getShape(); if (node instanceof Primitive) { ((Primitive) node).setAppearance(look); } } } }); //Shine it with two colored lights. Color3f lColor1 = new Color3f(.5f, .5f, .5f); Color3f lColor2 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lDir2 = new Vector3f(-1.0f, 0.0f, -1.0f); DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2); AmbientLight ambient = new AmbientLight(lColor1); lgt2.setInfluencingBounds(bounds); ambient.setInfluencingBounds(bounds); objRoot.addChild(lgt2); objRoot.addChild(ambient); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); // VisRunner runner = new VisRunner((IterativeContext)elayout); // runner.relax(); return objRoot; }
From source file:J3dSwingFrame.java
/** * Create the basic universe and all of the supporting infrastructure that * is needed by a J3D application. The default setup just uses a single * local located at the origin.//from w w w . j av a2s. c o m */ public UniverseManager() { locale = new Locale(this); view_group = new BranchGroup(); view_group.setCapability(Group.ALLOW_CHILDREN_EXTEND); world_object_group = new BranchGroup(); world_object_group.setCapability(Group.ALLOW_CHILDREN_EXTEND); }
From source file:J3dSwingFrame.java
public Camera() { hud_group = new Group(); hud_group.setCapability(Group.ALLOW_CHILDREN_EXTEND); platform = new ViewPlatform(); location = new Transform3D(); root_tx_grp = new TransformGroup(); root_tx_grp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); root_tx_grp.setTransform(location);/*from w w w .ja v a 2 s.c o m*/ root_tx_grp.addChild(platform); root_tx_grp.addChild(hud_group); // now create the headlight headlight = new DirectionalLight(); headlight.setCapability(Light.ALLOW_STATE_WRITE); headlight.setColor(White); headlight.setInfluencingBounds(LIGHT_BOUNDS); root_tx_grp.addChild(headlight); body = new PhysicalBody(); env = new PhysicalEnvironment(); view = new View(); view.setBackClipDistance(BACK_CLIP_DISTANCE); view.setPhysicalBody(body); view.setPhysicalEnvironment(env); view.attachViewPlatform(platform); }
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);/*from w w w . jav a 2 s . c om*/ TransformGroup vpTrans = u.getViewingPlatform().getViewPlatformTransform(); KeyNavigatorBehavior keybehavior = new KeyNavigatorBehavior(vpTrans); keybehavior.setSchedulingBounds(bounds); scene.addChild(keybehavior); scene.setCapability(Group.ALLOW_CHILDREN_EXTEND); scene.compile(); u.addBranchGraph(scene); View view = u.getViewer().getView(); view.setBackClipDistance(100000); }
From source file:SwingTest.java
/** * Create the scene side of the scenegraph *//*from w ww.jav a 2 s .com*/ protected BranchGroup createSceneBranchGroup() { // create the root of the scene side scenegraph BranchGroup objRoot = new BranchGroup(); // create a TransformGroup to rotate the objects in the scene // set the capability bits on the TransformGroup so that it // can be modified at runtime TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create a spherical bounding volume BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // create a 4x4 transformation matrix Transform3D yAxis = new Transform3D(); // create an Alpha interpolator to automatically generate // modifications to the rotation component of the transformation matrix Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); // create a RotationInterpolator behavior to effect the TransformGroup rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); // set the scheduling bounds on the behavior rotator.setSchedulingBounds(bounds); // add the behavior to the scenegraph objTrans.addChild(rotator); // create the BranchGroup which contains the objects // we add/remove to and from the scenegraph sceneBranchGroup = new BranchGroup(); // allow the BranchGroup to have children added at runtime sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND); sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_READ); sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_WRITE); // add both the cube and the sphere to the scenegraph sceneBranchGroup.addChild(createCube()); sceneBranchGroup.addChild(createSphere()); // create the colors for the 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); // create the ambient light AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); // create the directional light DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); // add the lights to the scenegraph objRoot.addChild(aLgt); objRoot.addChild(lgt1); // wire the scenegraph together objTrans.addChild(sceneBranchGroup); objRoot.addChild(objTrans); // return the root of the scene side of the scenegraph return objRoot; }
From source file:ExText.java
/** * Builds the 3D universe by constructing a virtual universe (via * SimpleUniverse), a view platform (via SimpleUniverse), and a view (via * SimpleUniverse). A headlight is added and a set of behaviors initialized * to handle navigation types./*from w w w. j ava 2 s . c om*/ */ protected void buildUniverse() { // // Create a SimpleUniverse object, which builds: // // - a Locale using the given hi-res coordinate origin // // - a ViewingPlatform which in turn builds: // - a MultiTransformGroup with which to move the // the ViewPlatform about // // - a ViewPlatform to hold the view // // - a BranchGroup to hold avatar geometry (if any) // // - a BranchGroup to hold view platform // geometry (if any) // // - a Viewer which in turn builds: // - a PhysicalBody which characterizes the user's // viewing preferences and abilities // // - a PhysicalEnvironment which characterizes the // user's rendering hardware and software // // - a JavaSoundMixer which initializes sound // support within the 3D environment // // - a View which renders the scene into a Canvas3D // // All of these actions could be done explicitly, but // using the SimpleUniverse utilities simplifies the code. // if (debug) System.err.println("Building scene graph..."); SimpleUniverse universe = new SimpleUniverse(null, // Hi-res coordinate // for the origin - // use default 1, // Number of transforms in MultiTransformGroup exampleCanvas, // Canvas3D into which to draw null); // URL for user configuration file - use defaults // // Get the viewer and create an audio device so that // sound will be enabled in this content. // Viewer viewer = universe.getViewer(); viewer.createAudioDevice(); // // Get the viewing platform created by SimpleUniverse. // From that platform, get the inner-most TransformGroup // in the MultiTransformGroup. That inner-most group // contains the ViewPlatform. It is this inner-most // TransformGroup we need in order to: // // - add a "headlight" that always aims forward from // the viewer // // - change the viewing direction in a "walk" style // // The inner-most TransformGroup's transform will be // changed by the walk behavior (when enabled). // ViewingPlatform viewingPlatform = universe.getViewingPlatform(); exampleViewTransform = viewingPlatform.getViewPlatformTransform(); // // Create a "headlight" as a forward-facing directional light. // Set the light's bounds to huge. Since we want the light // on the viewer's "head", we need the light within the // TransformGroup containing the ViewPlatform. The // ViewingPlatform class creates a handy hook to do this // called "platform geometry". The PlatformGeometry class is // subclassed off of BranchGroup, and is intended to contain // a description of the 3D platform itself... PLUS a headlight! // So, to add the headlight, create a new PlatformGeometry group, // add the light to it, then add that platform geometry to the // ViewingPlatform. // BoundingSphere allBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100000.0); PlatformGeometry pg = new PlatformGeometry(); headlight = new DirectionalLight(); headlight.setColor(White); headlight.setDirection(new Vector3f(0.0f, 0.0f, -1.0f)); headlight.setInfluencingBounds(allBounds); headlight.setCapability(Light.ALLOW_STATE_WRITE); pg.addChild(headlight); viewingPlatform.setPlatformGeometry(pg); // // Create the 3D content BranchGroup, containing: // // - a TransformGroup who's transform the examine behavior // will change (when enabled). // // - 3D geometry to view // // Build the scene root BranchGroup sceneRoot = new BranchGroup(); // Build a transform that we can modify exampleSceneTransform = new TransformGroup(); exampleSceneTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); exampleSceneTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); exampleSceneTransform.setCapability(Group.ALLOW_CHILDREN_EXTEND); // // Build the scene, add it to the transform, and add // the transform to the scene root // if (debug) System.err.println(" scene..."); Group scene = this.buildScene(); exampleSceneTransform.addChild(scene); sceneRoot.addChild(exampleSceneTransform); // // Create a pair of behaviors to implement two navigation // types: // // - "examine": a style where mouse drags rotate about // the scene's origin as if it is an object under // examination. This is similar to the "Examine" // navigation type used by VRML browsers. // // - "walk": a style where mouse drags rotate about // the viewer's center as if the viewer is turning // about to look at a scene they are in. This is // similar to the "Walk" navigation type used by // VRML browsers. // // Aim the examine behavior at the scene's TransformGroup // and add the behavior to the scene root. // // Aim the walk behavior at the viewing platform's // TransformGroup and add the behavior to the scene root. // // Enable one (and only one!) of the two behaviors // depending upon the current navigation type. // examineBehavior = new ExamineViewerBehavior(exampleSceneTransform, // Transform // gorup // to // modify exampleFrame); // Parent frame for cusor changes examineBehavior.setSchedulingBounds(allBounds); sceneRoot.addChild(examineBehavior); walkBehavior = new WalkViewerBehavior(exampleViewTransform, // Transform // group to // modify exampleFrame); // Parent frame for cusor changes walkBehavior.setSchedulingBounds(allBounds); sceneRoot.addChild(walkBehavior); if (navigationType == Walk) { examineBehavior.setEnable(false); walkBehavior.setEnable(true); } else { examineBehavior.setEnable(true); walkBehavior.setEnable(false); } // // Compile the scene branch group and add it to the // SimpleUniverse. // if (shouldCompile) sceneRoot.compile(); universe.addBranchGraph(sceneRoot); reset(); }
From source file:Demo3D.java
/** * Create the subgraph #3//from www . j a v a 2 s. c om * * @return javax.media.j3d.BranchGroup brGr3 - the root of the subgraph #3 */ public BranchGroup mySubGraph3() { // Create the BranchGroup node brGr3, in other words the root of // the subgraph31 and subgraph32. brGr3 = new BranchGroup(); // To allow the detach/add process of the subgraph 32 from the // BranchGroup node brGr3. brGr3.setCapability(Group.ALLOW_CHILDREN_READ); brGr3.setCapability(Group.ALLOW_CHILDREN_WRITE); brGr3.setCapability(Group.ALLOW_CHILDREN_EXTEND); // A BoundingSphere instance as picking bound region. pickBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 5.0); // A BoundingSphere instance as general bounding region. boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Create and attach the subgraph31 with the tetrahedron // to the BranchGroup node brGr3. tetrahedron = new Tetrahedron(1.0f); sceneBuilder31 = new SceneBuilder31(tetrahedron.myTetrahedron()); brGr3.addChild(sceneBuilder31.mySubGraph31()); // Picking of the tetrahedron // Note:It's the instruction: // trGr31.setCapability(TransformGroup.ENABLE_PICK_REPORTING) // in the class SceneBuilder31 that determines if the // tetrahedron is pickable or not. // Pick and translate the tetrahedron parallel to the z-axis if the // mouse pointer is over it. pickZoomBehavior = new PickZoomBehavior(brGr3, canvas3D, pickBounds); // pickZoomBehavior.setEnable(ctrlDown); brGr3.addChild(pickZoomBehavior); // Pick and translate the tetrahedron in the (x-y)-plane if the // mouse pointer is over it. pickTransBehavior = new PickTranslateBehavior(brGr3, canvas3D, pickBounds); // pickTransBehavior.setEnable(ctrlDown); brGr3.addChild(pickTransBehavior); // Pick and rotate the tetrahedron if the mouse pointer is over it. pickRotBehavior = new PickRotateBehavior(brGr3, canvas3D, pickBounds); // pickRotBehavior.setEnable(ctrlDown); brGr3.addChild(pickRotBehavior); // Create the subgraph32 ===> the earth in double rotation. sceneBuilder32 = new SceneBuilder32(); brGr3.addChild(sceneBuilder32.mySubGraph32()); // Create an instance of the AddDetachEarthBehavior class to // allow the detach/add process of the subgraph32. addDetachEarthBehavior = new AddDetachEarthBehavior(this, sceneBuilder32); addDetachEarthBehavior.setSchedulingBounds(boundsGen); brGr3.addChild(addDetachEarthBehavior); // Compile the subgraph to optimize the performances. brGr3.compile(); // Return the final version of the BranchGroup node brGr3 return brGr3; }