List of usage examples for javax.media.j3d Group ALLOW_CHILDREN_READ
int ALLOW_CHILDREN_READ
To view the source code for javax.media.j3d Group ALLOW_CHILDREN_READ.
Click Source Link
From source file:SwingTest.java
/** * Create the scene side of the scenegraph *//*from w ww . j a va2 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:Demo3D.java
/** * Create the subgraph #3// w ww. jav a 2s .c o m * * @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; }