List of usage examples for javax.media.j3d TransformGroup ALLOW_TRANSFORM_WRITE
int ALLOW_TRANSFORM_WRITE
To view the source code for javax.media.j3d TransformGroup ALLOW_TRANSFORM_WRITE.
Click Source Link
From source file:ExLightBounds.java
public Group buildScene() { // Get the current bounding leaf position Point3f pos = (Point3f) positions[currentPosition].value; // Turn off the example headlight setHeadlightEnable(false);//from w w w. j a va 2 s . c om // Build the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create a bounding leaf we'll use or not use depending // upon menu selections. Put it within a transform group // so that we can move the leaf about. leafTransformGroup = new TransformGroup(); leafTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D tr = new Transform3D(); tr.setTranslation(new Vector3f(pos)); leafTransformGroup.setTransform(tr); leafBounds = new BoundingLeaf(worldBounds); leafBounds.setCapability(BoundingLeaf.ALLOW_REGION_WRITE); leafTransformGroup.addChild(leafBounds); scene.addChild(leafTransformGroup); // Add a directional light whose bounds we'll modify // Set its color and aim direction light = new DirectionalLight(); light.setEnable(true); light.setColor(White); light.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light.setCapability(DirectionalLight.ALLOW_INFLUENCING_BOUNDS_WRITE); // Set the bounds to be either from the leaf or from // explicit bounds, depending upon the menu initial state if (boundingLeafOnOff) // Use bounding leaf light.setInfluencingBoundingLeaf(leafBounds); else // Use bounds on the light light.setInfluencingBounds(worldBounds); // Set the scope list to include nothing initially. // This defaults to "universal scope" which covers // everything. scene.addChild(light); // Add an ambient light to dimly illuminate the rest of // the shapes in the scene to help illustrate that the // directional light is being bounded... otherwise it looks // like we're just removing shapes from the scene AmbientLight ambient = new AmbientLight(); ambient.setEnable(true); ambient.setColor(White); ambient.setInfluencingBounds(worldBounds); scene.addChild(ambient); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new SphereGroup()); return scene; }
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);/*from www . jav a2 s . co m*/ 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 .ja va 2 s . co 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: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);// w w w . j a va2 s . c o m Shape3D twist = new Twist(); objSpin.addChild(twist); 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:RasterTest.java
protected BranchGroup createSceneBranchGroup() { // create some simple geometry (a rotating ColorCube) // and a Shape3D object for the Raster containing the Image BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D yAxis = new Transform3D(); yAxis.rotX(0.6);//from w w w. j a va 2s .c om 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); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); // wrap the Raster in a Shape3D Shape3D shape = new Shape3D(m_RenderRaster); objRoot.addChild(shape); objTrans.addChild(new ColorCube(1.0)); objRoot.addChild(objTrans); 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 w w w . j a va 2 s . co 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);//ww w . j a v a 2 s .c om // 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:SimpleGame.java
/** * This builds the gun geometry. It uses box and cylinder primitives and * sets up a transform group so that we can rotate the gun. *//*w w w . j a v a2 s . co m*/ protected BranchGroup buildGun() { BranchGroup theGun = new BranchGroup(); Appearance gunApp = new Appearance(); Color3f ambientColour = new Color3f(0.5f, 0.5f, 0.5f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(0.5f, 0.5f, 0.5f); float shininess = 20.0f; gunApp.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); TransformGroup init = new TransformGroup(); TransformGroup barrel = new TransformGroup(); Transform3D gunXfm = new Transform3D(); Transform3D barrelXfm = new Transform3D(); barrelXfm.set(new Vector3d(0.0, -2.0, 0.0)); barrel.setTransform(barrelXfm); Matrix3d gunXfmMat = new Matrix3d(); gunXfmMat.rotX(Math.PI / 2); gunXfm.set(gunXfmMat, new Vector3d(0.0, 0.0, 0.0), 1.0); init.setTransform(gunXfm); gunXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); gunXfmGrp.addChild(new Box(1.0f, 1.0f, 0.5f, gunApp)); barrel.addChild(new Cylinder(0.3f, 4.0f, gunApp)); gunXfmGrp.addChild(barrel); theGun.addChild(init); init.addChild(gunXfmGrp); return theGun; }
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);//ww w . ja va 2 s .c o m 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:GearTest.java
public BranchGroup createSceneGraph(int toothCount) { // 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);//from w w w . j a va 2 s. com 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 Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); objScale.addChild(bgNode); // Set up the global lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f); Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f); Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objScale.addChild(ambientLightNode); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objScale.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objScale.addChild(light2); // 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); objScale.addChild(objTrans); // Create an Appearance. Appearance look = new Appearance(); Color3f objColor = new Color3f(0.5f, 0.5f, 0.6f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); look.setMaterial(new Material(objColor, black, objColor, white, 100.0f)); // Create a gear, add it to the scene graph. // SpurGear gear = new SpurGear(toothCount, 1.0f, 0.2f, SpurGear gear = new SpurGearThinBody(toothCount, 1.0f, 0.2f, 0.05f, 0.05f, 0.3f, 0.28f, look); objTrans.addChild(gear); // Create a new Behavior object that will rotate the object and // add it into the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 8000, 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); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }