List of usage examples for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ
int ALLOW_TRANSFORM_READ
To view the source code for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ.
Click Source Link
From source file:AlternateAppearanceScopeTest.java
BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Create influencing bounds worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent Transform3D t = new Transform3D(); // move the object upwards t.set(new Vector3f(0.0f, 0.1f, 0.0f)); // Shrink the object t.setScale(0.8);// www . ja va2 s . c om TransformGroup trans = new TransformGroup(t); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); otherApp = new Appearance(); altMat = new Material(); altMat.setCapability(Material.ALLOW_COMPONENT_WRITE); altMat.setDiffuseColor(new Color3f(0.0f, 1.0f, 0.0f)); otherApp.setMaterial(altMat); altApp = new AlternateAppearance(); altApp.setAppearance(otherApp); altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_WRITE); altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_READ); altApp.setInfluencingBounds(worldBounds); objRoot.addChild(altApp); // Build foreground geometry into two groups. We'll // create three directional lights below, one each with // scope to cover the first geometry group only, the // second geometry group only, or both geometry groups. Appearance app1 = new Appearance(); mat1 = new Material(); mat1.setCapability(Material.ALLOW_COMPONENT_WRITE); mat1.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f)); app1.setMaterial(mat1); content1 = new SphereGroup(0.05f, // radius of spheres 0.4f, // x spacing 0.2f, // y spacing 3, // number of spheres in X 5, // number of spheres in Y app1, // appearance true); // alt app override = true trans.addChild(content1); shapes1 = ((SphereGroup) content1).getShapes(); content2 = new SphereGroup(0.05f, // radius of spheres .4f, // x spacing 0.2f, // y spacing 2, // number of spheres in X 5, // number of spheres in Y app1, // appearance true); // alt app override = true trans.addChild(content2); shapes2 = ((SphereGroup) content2).getShapes(); // Add lights DirectionalLight light1 = null; light1 = new DirectionalLight(); light1.setEnable(true); light1.setColor(new Color3f(0.2f, 0.2f, 0.2f)); light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light1.setInfluencingBounds(worldBounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(); light2.setEnable(true); light2.setColor(new Color3f(0.2f, 0.2f, 0.2f)); light2.setDirection(new Vector3f(-1.0f, 0.0f, 1.0f)); light2.setInfluencingBounds(worldBounds); objRoot.addChild(light2); // Add an ambient light to dimly illuminate the rest of // the shapes in the scene to help illustrate that the // directional lights are being scoped... otherwise it looks // like we're just removing shapes from the scene AmbientLight ambient = new AmbientLight(); ambient.setEnable(true); ambient.setColor(new Color3f(1.0f, 1.0f, 1.0f)); ambient.setInfluencingBounds(worldBounds); objRoot.addChild(ambient); objRoot.addChild(trans); return objRoot; }
From source file:NodesTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); double labelScale = 20; // create the top level Switch Node // we will use the Switch Node to switch the // other Nodes on and off. // 1: Switch/*from ww w .jav a2 s .c o m*/ Switch switchGroup = new Switch(); switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE); switchGroup.addChild(createLabel("1. Switch Label", labelScale)); // 2: BranchGroup BranchGroup branchGroup = new BranchGroup(); branchGroup.addChild(createLabel("2. BranchGroup", labelScale)); switchGroup.addChild(branchGroup); // 3: OrderedGroup, OrderedGroup orderedGroup = new OrderedGroup(); orderedGroup.addChild(createLabel("3. OrderedGroup", labelScale)); orderedGroup.addChild(createLabel("Child 1", labelScale)); orderedGroup.addChild(createLabel("Child 2", labelScale)); switchGroup.addChild(orderedGroup); // 4: SharedGroup, SharedGroup sharedGroup1 = new SharedGroup(); sharedGroup1.addChild(createLabel("4. Shared Group 1", labelScale)); switchGroup.addChild(new Link(sharedGroup1)); // 5: Primitive, BranchGroup primitiveGroup = new BranchGroup(); primitiveGroup.addChild(createLabel("5. Primitive", labelScale)); primitiveGroup.addChild(new Sphere(2)); switchGroup.addChild(primitiveGroup); // 6: TransformGroup TransformGroup transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); 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, transformGroup, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(createApplicationBounds()); transformGroup.addChild(rotator); transformGroup.addChild(new ColorCube(2)); transformGroup.addChild(createLabel("6. TransformGroup", labelScale)); switchGroup.addChild(transformGroup); // 7: add another copy of the shared group switchGroup.addChild(new Link(sharedGroup1)); // create a SwitchValueInterpolator to // cycle through the child nodes in the Switch Node Alpha switchAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 10000, 0, 0, 0, 0, 0); SwitchValueInterpolator switchInterpolator = new SwitchValueInterpolator(switchAlpha, switchGroup); switchInterpolator.setSchedulingBounds(createApplicationBounds()); switchInterpolator.setEnable(true); // WARNING: do not add the SwitchValueInterpolator to the Switch Node! objRoot.addChild(switchInterpolator); // finally add the Switch Node objRoot.addChild(switchGroup); return objRoot; }
From source file:PickCollisionTest.java
protected void addSphere(BranchGroup bg, double x, double y, double z, Vector3d incVector, String name) { Appearance app = new Appearance(); TransformGroup sphereTg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, y, z)); sphereTg.setTransform(t3d);/*from www .j a va2s .c o m*/ sphereTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); sphereTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); sphereTg.addChild(new Sphere(1, app)); bg.addChild(sphereTg); recursiveSetUserData(sphereTg, name); // create the collision behaviour CollisionBehavior collisionBehavior = new CollisionBehavior(bg, sphereTg, app, new Vector3d(x, y, z), incVector); collisionBehavior.setSchedulingBounds(getApplicationBounds()); bg.addChild(collisionBehavior); }
From source file:LightTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // create the 4 lights - the actual creation // and UI managment is delegated to an object // that "shadows" (no pun intended) the functionality // of the particular light createLight(new AmbientLightObject(), objRoot); createLight(new PointLightObject(), objRoot); createLight(new DirectionalLightObject(), objRoot); createLight(new SpotLightObject(), objRoot); // rotate some of the spheres in the scene TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); 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(getApplicationBounds()); objTrans.addChild(rotator);/*from www. ja v a 2 s.com*/ // create a large sphere in the center of the // scene and the floor as staionary objects objRoot.addChild(createSphere(0, 0, 0, 2)); objRoot.addChild(createFloor()); // create a smaller sphere at the corners of a cube final int nCubeSize = 3; objTrans.addChild(createSphere(nCubeSize, nCubeSize, nCubeSize, 1)); objTrans.addChild(createSphere(nCubeSize, nCubeSize, -nCubeSize, 1)); objTrans.addChild(createSphere(nCubeSize, -nCubeSize, nCubeSize, 1)); objTrans.addChild(createSphere(nCubeSize, -nCubeSize, -nCubeSize, 1)); objTrans.addChild(createSphere(-nCubeSize, nCubeSize, nCubeSize, 1)); objTrans.addChild(createSphere(-nCubeSize, nCubeSize, -nCubeSize, 1)); objTrans.addChild(createSphere(-nCubeSize, -nCubeSize, nCubeSize, 1)); objTrans.addChild(createSphere(-nCubeSize, -nCubeSize, -nCubeSize, 1)); // add some small spheres here and there to // make things interesting objRoot.addChild(createSphere(-6, -6, 2, 1)); objRoot.addChild(createSphere(8, -5, 3, 1)); objRoot.addChild(createSphere(6, 7, -1, 1)); objRoot.addChild(createSphere(-5, 6, -3.5f, 0.5f)); objRoot.addChild(objTrans); return objRoot; }
From source file:CustomAlphaTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); ColorCube cube = new ColorCube(2); objTrans.addChild(cube);/*from w w w . ja v a 2s .com*/ FileAlpha fileAlpha = null; try { fileAlpha = new FileAlpha(new URL(getWorkingDirectory(), "values.xls"), this); } catch (Exception e) { e.toString(); } PositionInterpolator posInterpolator = new PositionInterpolator(fileAlpha, objTrans, new Transform3D(), -6, 6); posInterpolator.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(posInterpolator); objRoot.addChild(objTrans); return objRoot; }
From source file:VrmlPickingTest.java
private TransformGroup createMouseBehaviorsGroup() { TransformGroup examineGroup = new TransformGroup(); examineGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); examineGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Bounds behaviorBounds = getApplicationBounds(); MouseRotate mr = new MouseRotate(examineGroup); mr.setSchedulingBounds(behaviorBounds); examineGroup.addChild(mr);/* w w w. j ava2 s .com*/ MouseTranslate mt = new MouseTranslate(examineGroup); mt.setSchedulingBounds(behaviorBounds); examineGroup.addChild(mt); MouseZoom mz = new MouseZoom(examineGroup); mz.setSchedulingBounds(behaviorBounds); examineGroup.addChild(mz); return examineGroup; }
From source file:ScenegraphTest.java
private TransformGroup addLimb(Group parentGroup, String szName, double radius, double length, double rotMin, double rotMax) { // create the rotator TransformGroup tgJoint = new TransformGroup(); tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // add a rotator if necessary if (rotMin != rotMax) { Transform3D xAxis = new Transform3D(); xAxis.rotX(Math.PI / 2.0); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, tgJoint, xAxis, (float) rotMin, (float) rotMax); rotator.setSchedulingBounds(createApplicationBounds()); tgJoint.addChild(rotator);/* ww w . ja v a 2 s.c o m*/ } // create a cylinder using length and radius tgJoint.addChild(createLimb(radius, length)); // create the joint (the *next* TG should // be offset by the length of this limb) TransformGroup tgOffset = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(0, length, 0)); tgOffset.setTransform(t3d); tgJoint.addChild(tgOffset); parentGroup.addChild(tgJoint); // return the offset TG, so any child TG's will be added // in the correct position. return tgOffset; }
From source file:DoorApp.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup doorTG = new TransformGroup(); doorTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); doorTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); OpenBehavior openObject = new OpenBehavior(doorTG); CloseBehavior closeObject = new CloseBehavior(doorTG); //prepare the behavior objects openObject.setBehaviorObjectPartner(closeObject); closeObject.setBehaviorObjectPartner(openObject); // set scheduling bounds for behavior objects BoundingSphere bounds = new BoundingSphere(); openObject.setSchedulingBounds(bounds); closeObject.setSchedulingBounds(bounds); // assemble scene graph objRoot.addChild(openObject);/*from w w w. j av a 2s. com*/ objRoot.addChild(closeObject); objRoot.addChild(doorTG); doorTG.addChild(new ColorCube(0.4)); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:Human1.java
void createHuman() { Human_body = new TransformGroup(); // center the body tmpVector.set(0.0f, -1.5f, 0.0f);/* w ww .j a va 2 s . co m*/ tmpTrans.set(tmpVector); Human_body.setTransform(tmpTrans); // Set up an appearance to make the body with red ambient, // black emmissive, red diffuse and white specular coloring Material material = new Material(red, black, red, white, 64); Appearance appearance = new Appearance(); appearance.setMaterial(material); // offset and place the cylinder for the body tmpTG = new TransformGroup(); // offset the shape tmpVector.set(0.0f, 1.5f, 0.0f); tmpTrans.set(tmpVector); tmpTG.setTransform(tmpTrans); tmpCyl = new Cylinder(0.75f, 3.0f, appearance); tmpTG.addChild(tmpCyl); // add the shape to the body Human_body.addChild(tmpTG); // create the r_shoulder TransformGroup Human_r_shoulder = new TransformGroup(); Human_r_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Human_r_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // translate from the waist tmpVector.set(-0.95f, 2.9f, -0.2f); tmpTrans.set(tmpVector); Human_r_shoulder.setTransform(tmpTrans); // place the sphere for the r_shoulder tmpSphere = new Sphere(0.22f, appearance); Human_r_shoulder.addChild(tmpSphere); // offset and place the cylinder for the r_shoulder tmpTG = new TransformGroup(); // offset the shape tmpVector.set(0.0f, -0.5f, 0.0f); tmpTrans.set(tmpVector); tmpTG.setTransform(tmpTrans); tmpCyl = new Cylinder(0.2f, 1.0f, appearance); tmpTG.addChild(tmpCyl); // add the shape to the r_shoulder Human_r_shoulder.addChild(tmpTG); // add the shoulder to the body group Human_body.addChild(Human_r_shoulder); // create the r_elbow TransformGroup Human_r_elbow = new TransformGroup(); Human_r_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Human_r_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tmpVector.set(0.0f, -1.054f, 0.0f); tmpTrans.set(tmpVector); Human_r_elbow.setTransform(tmpTrans); // place the sphere for the r_elbow tmpSphere = new Sphere(0.22f, appearance); Human_r_elbow.addChild(tmpSphere); // offset and place the cylinder for the r_shoulder tmpTG = new TransformGroup(); // offset the shape tmpVector.set(0.0f, -0.5f, 0.0f); tmpTrans.set(tmpVector); tmpTG.setTransform(tmpTrans); tmpCyl = new Cylinder(0.2f, 1.0f, appearance); tmpTG.addChild(tmpCyl); // add the shape to the r_shoulder Human_r_elbow.addChild(tmpTG); // add the elbow to the shoulder group Human_r_shoulder.addChild(Human_r_elbow); // create the l_shoulder TransformGroup Human_l_shoulder = new TransformGroup(); Human_l_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Human_l_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tmpVector.set(0.95f, 2.9f, -0.2f); tmpTrans.set(tmpVector); Human_l_shoulder.setTransform(tmpTrans); // place the sphere for the l_shoulder tmpSphere = new Sphere(0.22f, appearance); Human_l_shoulder.addChild(tmpSphere); // offset and place the cylinder for the l_shoulder tmpTG = new TransformGroup(); // offset the shape tmpVector.set(0.0f, -0.5f, 0.0f); tmpTrans.set(tmpVector); tmpTG.setTransform(tmpTrans); tmpCyl = new Cylinder(0.2f, 1.0f, appearance); tmpTG.addChild(tmpCyl); // add the shape to the l_shoulder Human_l_shoulder.addChild(tmpTG); // add the shoulder to the body group Human_body.addChild(Human_l_shoulder); // create the r_elbow TransformGroup Human_l_elbow = new TransformGroup(); Human_l_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Human_l_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tmpVector.set(0.0f, -1.054f, 0.0f); tmpTrans.set(tmpVector); Human_l_elbow.setTransform(tmpTrans); // place the sphere for the l_elbow tmpSphere = new Sphere(0.22f, appearance); Human_l_elbow.addChild(tmpSphere); // offset and place the cylinder for the l_elbow tmpTG = new TransformGroup(); // offset the shape tmpVector.set(0.0f, -0.5f, 0.0f); tmpTrans.set(tmpVector); tmpTG.setTransform(tmpTrans); tmpCyl = new Cylinder(0.2f, 1.0f, appearance); tmpTG.addChild(tmpCyl); // add the shape to the l_elbow Human_l_elbow.addChild(tmpTG); // add the shoulder to the body group Human_l_shoulder.addChild(Human_l_elbow); // create the skullbase TransformGroup Human_skullbase = new TransformGroup(); tmpVector.set(0.0f, 3.632f, 0.0f); tmpTrans.set(tmpVector); Human_skullbase.setTransform(tmpTrans); // offset and place the sphere for the skull tmpSphere = new Sphere(0.5f, appearance); // add the shape to the l_shoulder Human_skullbase.addChild(tmpSphere); // add the shoulder to the body group Human_body.addChild(Human_skullbase); }
From source file:BehaviorTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // create a TransformGroup to rotate the hand TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create a RotationInterpolator behavior to rotate the hand Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); m_RotationInterpolator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); m_RotationInterpolator.setSchedulingBounds(createApplicationBounds()); objTrans.addChild(m_RotationInterpolator); // create an Appearance and Material Appearance app = new Appearance(); TextureLoader tex = new TextureLoader("earth.jpg", this); app.setTexture(tex.getTexture());//from ww w . j a v a 2 s .co m Sphere sphere = new Sphere(3, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, 32, app); // connect the scenegraph objTrans.addChild(sphere); objRoot.addChild(objTrans); m_FpsBehavior = new FpsBehavior(); m_FpsBehavior.setSchedulingBounds(getApplicationBounds()); objRoot.addChild(m_FpsBehavior); m_BoundsBehavior = new BoundsBehavior(sphere); m_BoundsBehavior.setSchedulingBounds(getApplicationBounds()); m_BoundsBehavior.addBehaviorToParentGroup(objTrans); m_StretchBehavior = new StretchBehavior((GeometryArray) sphere.getShape().getGeometry()); m_StretchBehavior.setSchedulingBounds(getApplicationBounds()); objRoot.addChild(m_StretchBehavior); m_StretchBehavior.setEnable(false); m_SizeBehavior = new ObjectSizeBehavior((GeometryArray) sphere.getShape().getGeometry()); m_SizeBehavior.setSchedulingBounds(getApplicationBounds()); objRoot.addChild(m_SizeBehavior); m_SizeBehavior.setEnable(false); m_ExplodeBehavior = new ExplodeBehavior(sphere.getShape(), 10000, 20, this); m_ExplodeBehavior.setSchedulingBounds(getApplicationBounds()); objRoot.addChild(m_ExplodeBehavior); return objRoot; }