List of usage examples for javax.media.j3d Light ALLOW_STATE_WRITE
int ALLOW_STATE_WRITE
To view the source code for javax.media.j3d Light ALLOW_STATE_WRITE.
Click Source Link
From source file:ExLightScope.java
public Group buildScene() { // Turn off the example headlight setHeadlightEnable(false);//from ww w . ja v a 2 s .c om // Build the scene group Group scene = new Group(); // 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. content1 = new SphereGroup(0.25f, // radius of spheres 1.5f, // x spacing 0.75f, // y spacing 3, // number of spheres in X 5, // number of spheres in Y null); // appearance scene.addChild(content1); content2 = new SphereGroup(0.25f, // radius of spheres 1.5f, // x spacing 0.75f, // y spacing 2, // number of spheres in X 5, // number of spheres in Y null); // appearance scene.addChild(content2); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Add three directional lights whose scopes are set // to cover one, the other, or both of the shape groups // above. Also set the lights' color and aim direction. // Light #1 with content1 scope light1 = new DirectionalLight(); light1.setEnable(light1OnOff); light1.setColor(Red); light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light1.setInfluencingBounds(worldBounds); light1.addScope(content1); light1.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(light1); // Light #2 with content2 scope light2 = new DirectionalLight(); light2.setEnable(light2OnOff); light2.setColor(Blue); light2.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light2.setInfluencingBounds(worldBounds); light2.addScope(content2); light2.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(light2); // Light #3 with universal scope (the default) light3 = new DirectionalLight(); light3.setEnable(light3OnOff); light3.setColor(White); light3.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light3.setInfluencingBounds(worldBounds); light3.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(light3); // 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(White); ambient.setInfluencingBounds(worldBounds); scene.addChild(ambient); // END EXAMPLE TOPIC return scene; }
From source file:EnvironmentExplorer.java
void setupLights() { lightGroup = new Group(); // Set up the ambient light lightAmbient = new AmbientLight(darkGrey); lightAmbient.setInfluencingBounds(infiniteBounds); lightAmbient.setCapability(Light.ALLOW_STATE_WRITE); lightAmbient.setEnable(true);//from w w w . j a v a2s .co m lightGroup.addChild(lightAmbient); // Set up the directional light Vector3f lightDirection = new Vector3f(0.65f, -0.65f, -0.40f); lightDirectional = new DirectionalLight(white, lightDirection); lightDirectional.setInfluencingBounds(infiniteBounds); lightDirectional.setEnable(true); lightDirectional.setCapability(Light.ALLOW_STATE_WRITE); lightGroup.addChild(lightDirectional); // Set up the point light Point3f lightPosition = new Point3f(-1.0f, 1.0f, 0.6f); lightPoint = new PointLight(white, lightPosition, attenuation); lightPoint.setInfluencingBounds(infiniteBounds); lightPoint.setEnable(false); lightPoint.setCapability(Light.ALLOW_STATE_WRITE); lightPoint.setCapability(PointLight.ALLOW_ATTENUATION_WRITE); lightGroup.addChild(lightPoint); // Set up the spot light // Point the light back at the origin lightSpot = new SpotLight(white, lightPosition, attenuation, lightDirection, (float) Math.toRadians(spotSpreadAngle), spotConcentration); lightSpot.setInfluencingBounds(infiniteBounds); lightSpot.setEnable(false); lightSpot.setCapability(Light.ALLOW_STATE_WRITE); lightSpot.setCapability(PointLight.ALLOW_ATTENUATION_WRITE); lightSpot.setCapability(SpotLight.ALLOW_CONCENTRATION_WRITE); lightSpot.setCapability(SpotLight.ALLOW_SPREAD_ANGLE_WRITE); lightGroup.addChild(lightSpot); }
From source file:ExSound.java
public Group buildScene() { // Get the initial sound volume float vol = ((Float) volumes[currentVolume].value).floatValue(); // Turn off the example headlight setHeadlightEnable(false);/*from w w w . j av a 2s .com*/ // Default to walk navigation setNavigationType(Walk); // Build the scene group Group scene = new Group(); // // Preload the sounds // if (debug) System.err.println(" sounds..."); String path = getCurrentDirectory(); MediaContainer backgroundMedia = new MediaContainer(path + "canon.wav"); backgroundMedia.setCacheEnable(true); MediaContainer pointMedia = new MediaContainer(path + "willow1.wav"); pointMedia.setCacheEnable(true); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Background sound backgroundSound = new BackgroundSound(); backgroundSound.setEnable(backgroundSoundOnOff); backgroundSound.setLoop(Sound.INFINITE_LOOPS); backgroundSound.setSoundData(backgroundMedia); backgroundSound.setInitialGain(vol); backgroundSound.setSchedulingBounds(worldBounds); backgroundSound.setCapability(Sound.ALLOW_ENABLE_WRITE); backgroundSound.setCapability(Sound.ALLOW_INITIAL_GAIN_WRITE); scene.addChild(backgroundSound); // Create a distance gain array for the point sound Point2f[] distanceGain = { new Point2f(9.0f, 1.0f), // Full volume new Point2f(10.0f, 0.5f), // Half volume new Point2f(20.0f, 0.25f), // Quarter volume new Point2f(30.0f, 0.0f), // Zero volume }; // Point sound pointSound = new PointSound(); pointSound.setEnable(pointSoundOnOff); pointSound.setPosition(new Point3f(pointX, soundHeight, 0.0f)); pointSound.setLoop(Sound.INFINITE_LOOPS); pointSound.setSoundData(pointMedia); pointSound.setInitialGain(vol); pointSound.setDistanceGain(distanceGain); pointSound.setSchedulingBounds(worldBounds); pointSound.setCapability(Sound.ALLOW_ENABLE_WRITE); pointSound.setCapability(Sound.ALLOW_INITIAL_GAIN_WRITE); scene.addChild(pointSound); // END EXAMPLE TOPIC // Build a few lights, one per sound. We'll turn them // on when the associated sound is on. ambientLight = new AmbientLight(); ambientLight.setEnable(backgroundSoundOnOff); ambientLight.setColor(Gray); ambientLight.setInfluencingBounds(worldBounds); ambientLight.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(ambientLight); pointLight = new PointLight(); pointLight.setEnable(pointSoundOnOff); pointLight.setColor(White); pointLight.setPosition(0.0f, soundHeight, 0.0f); pointLight.setInfluencingBounds(worldBounds); pointLight.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(pointLight); // Add a basic ambient light for when all sounds (and // their lights) are off so that the world isn't dark AmbientLight amb = new AmbientLight(); amb.setEnable(true); amb.setColor(Gray); amb.setInfluencingBounds(worldBounds); amb.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(amb); // Build foreground geometry scene.addChild(buildForeground()); return scene; }
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 ww w .j av 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:LightTest.java
protected int[] getCapabilities() { int[] caps = new int[8]; int nIndex = 0; caps[nIndex++] = Light.ALLOW_COLOR_READ; caps[nIndex++] = Light.ALLOW_COLOR_WRITE; caps[nIndex++] = Light.ALLOW_INFLUENCING_BOUNDS_READ; caps[nIndex++] = Light.ALLOW_INFLUENCING_BOUNDS_WRITE; caps[nIndex++] = Light.ALLOW_SCOPE_READ; caps[nIndex++] = Light.ALLOW_SCOPE_WRITE; caps[nIndex++] = Light.ALLOW_STATE_READ; caps[nIndex++] = Light.ALLOW_STATE_WRITE; return caps;/*from w w w . ja v a 2 s. com*/ }
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 . java 2s . com */ 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:AppearanceExplorer.java
Group setupLights() { Group group = new Group(); // set up the BoundingSphere for all the lights BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0); // Set up the ambient light AmbientLight lightAmbient = new AmbientLight(medGrey); lightAmbient.setInfluencingBounds(bounds); lightAmbient.setCapability(Light.ALLOW_STATE_WRITE); group.addChild(lightAmbient);/*from w ww . j a v a 2 s. c om*/ lightSwitch = new Switch(); lightSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); group.addChild(lightSwitch); // Set up the directional light Vector3f lightDirection1 = new Vector3f(0.0f, 0.0f, -1.0f); DirectionalLight lightDirectional1 = new DirectionalLight(white, lightDirection1); lightDirectional1.setInfluencingBounds(bounds); lightDirectional1.setCapability(Light.ALLOW_STATE_WRITE); lightSwitch.addChild(lightDirectional1); Point3f lightPos1 = new Point3f(-4.0f, 8.0f, 16.0f); Point3f lightAttenuation1 = new Point3f(1.0f, 0.0f, 0.0f); PointLight pointLight1 = new PointLight(brightWhite, lightPos1, lightAttenuation1); pointLight1.setInfluencingBounds(bounds); lightSwitch.addChild(pointLight1); Point3f lightPos2 = new Point3f(-16.0f, 8.0f, 4.0f); //Point3f lightPos = new Point3f(-4.0f, 2.0f, 1.0f); Point3f lightAttenuation2 = new Point3f(1.0f, 0.0f, 0.0f); PointLight pointLight2 = new PointLight(white, lightPos2, lightAttenuation2); pointLight2.setInfluencingBounds(bounds); lightSwitch.addChild(pointLight2); return group; }