List of usage examples for javax.media.j3d AlternateAppearance ALLOW_SCOPE_WRITE
int ALLOW_SCOPE_WRITE
To view the source code for javax.media.j3d AlternateAppearance ALLOW_SCOPE_WRITE.
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);//from ww w. j a v a2 s. c o 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; }