List of usage examples for javax.media.j3d BoundingLeaf BoundingLeaf
public BoundingLeaf(Bounds region)
From source file:SimpleLOD.java
/** * Build the view branch of the scene graph. In this case a key navigation * utility object is created and associated with the view transform so that * the view can be changed via the keyboard. * /*from ww w. j a va 2 s . c o m*/ * @return BranchGroup that is the root of the view branch */ protected BranchGroup buildViewBranch(Canvas3D c) { BranchGroup viewBranch = new BranchGroup(); Transform3D viewXfm = new Transform3D(); viewXfm.set(new Vector3f(0.0f, 0.0f, 10.0f)); TransformGroup viewXfmGroup = new TransformGroup(viewXfm); viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); BoundingSphere movingBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); BoundingLeaf boundLeaf = new BoundingLeaf(movingBounds); ViewPlatform myViewPlatform = new ViewPlatform(); viewXfmGroup.addChild(boundLeaf); PhysicalBody myBody = new PhysicalBody(); PhysicalEnvironment myEnvironment = new PhysicalEnvironment(); viewXfmGroup.addChild(myViewPlatform); viewBranch.addChild(viewXfmGroup); View myView = new View(); myView.addCanvas3D(c); myView.attachViewPlatform(myViewPlatform); myView.setPhysicalBody(myBody); myView.setPhysicalEnvironment(myEnvironment); KeyNavigatorBehavior keyNav = new KeyNavigatorBehavior(viewXfmGroup); keyNav.setSchedulingBounds(movingBounds); viewBranch.addChild(keyNav); return viewBranch; }
From source file:SimpleSounds.java
/** * Build the view branch of the scene graph. In this case a key navigation * utility object is created and associated with the view transform so that * the view can be changed via the keyboard. * //from ww w . j ava 2s . c o m * @return BranchGroup that is the root of the view branch */ protected BranchGroup buildViewBranch(Canvas3D c) { BranchGroup viewBranch = new BranchGroup(); Transform3D viewXfm = new Transform3D(); viewXfm.set(new Vector3f(0.0f, 0.0f, 30.0f)); TransformGroup viewXfmGroup = new TransformGroup(viewXfm); viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); ViewPlatform myViewPlatform = new ViewPlatform(); BoundingSphere movingBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); BoundingLeaf boundLeaf = new BoundingLeaf(movingBounds); PhysicalBody myBody = new PhysicalBody(); PhysicalEnvironment myEnvironment = new PhysicalEnvironment(); viewXfmGroup.addChild(myViewPlatform); viewBranch.addChild(viewXfmGroup); View myView = new View(); myView.addCanvas3D(c); myView.attachViewPlatform(myViewPlatform); myView.setPhysicalBody(myBody); myView.setPhysicalEnvironment(myEnvironment); KeyNavigatorBehavior keyNav = new KeyNavigatorBehavior(viewXfmGroup); keyNav.setSchedulingBounds(movingBounds); viewBranch.addChild(keyNav); //Create a sounds mixer to use our sounds with //and initialise it JavaSoundMixer myMixer = new JavaSoundMixer(myEnvironment); myMixer.initialize(); return viewBranch; }
From source file:Drag.java
/** * Create the scenegraph for this program. */// w w w .ja v a2s. c om public BranchGroup createSceneGraph() { // Define colors Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f red = new Color3f(0.80f, 0.20f, 0.2f); Color3f ambientRed = new Color3f(0.2f, 0.05f, 0.0f); Color3f ambient = new Color3f(0.2f, 0.2f, 0.2f); Color3f diffuse = new Color3f(0.7f, 0.7f, 0.7f); Color3f specular = new Color3f(0.7f, 0.7f, 0.7f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); // Create the branch group BranchGroup branchGroup = 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); objScale.setTransform(t3d); branchGroup.addChild(objScale); // Create the bounding leaf node BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); BoundingLeaf boundingLeaf = new BoundingLeaf(bounds); objScale.addChild(boundingLeaf); // Set up the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // Create the ambient light AmbientLight ambLight = new AmbientLight(white); ambLight.setInfluencingBounds(bounds); objScale.addChild(ambLight); // Create the directional light Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight dirLight = new DirectionalLight(white, dir); dirLight.setInfluencingBounds(bounds); objScale.addChild(dirLight); // Create the red appearance node Material redMaterial = new Material(ambientRed, black, red, specular, 75.0f); redMaterial.setLightingEnable(true); Appearance redAppearance = new Appearance(); redAppearance.setMaterial(redMaterial); // Create the white appearance node Material whiteMaterial = new Material(ambient, black, diffuse, specular, 75.0f); whiteMaterial.setLightingEnable(true); Appearance whiteAppearance = new Appearance(); whiteAppearance.setMaterial(whiteMaterial); // Create the transform node TransformGroup transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transformGroup.addChild(new Cube(redAppearance).getChild()); // transformGroup.addChild(new Corners(whiteAppearance).getChild()); objScale.addChild(transformGroup); // Create the drag behavior node MouseRotate behavior = new MouseRotate(); behavior.setTransformGroup(transformGroup); transformGroup.addChild(behavior); behavior.setSchedulingBounds(bounds); // Create the zoom behavior node MouseZoom behavior2 = new MouseZoom(); behavior2.setTransformGroup(transformGroup); transformGroup.addChild(behavior2); behavior2.setSchedulingBounds(bounds); // Create the zoom behavior node MouseTranslate behavior3 = new MouseTranslate(); behavior3.setTransformGroup(transformGroup); transformGroup.addChild(behavior3); behavior3.setSchedulingBounds(bounds); // Let Java 3D perform optimizations on this scene graph. branchGroup.compile(); return branchGroup; }
From source file:BackgroundApp.java
public BranchGroup createSceneGraph(SimpleUniverse su) { // Create the root of the branch graph BranchGroup objRootBG = new BranchGroup(); Vector3f translate = new Vector3f(); Transform3D T3D = new Transform3D(); translate.set(0.0f, -0.3f, 0.0f);//from w ww.j a va 2 s . co m T3D.setTranslation(translate); TransformGroup objRoot = new TransformGroup(T3D); objRootBG.addChild(objRoot); objRoot.addChild(createLand()); BoundingLeaf boundingLeaf = new BoundingLeaf(new BoundingSphere()); PlatformGeometry platformGeom = new PlatformGeometry(); platformGeom.addChild(boundingLeaf); platformGeom.compile(); su.getViewingPlatform().setPlatformGeometry(platformGeom); KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior( su.getViewingPlatform().getViewPlatformTransform()); keyNavBeh.setSchedulingBoundingLeaf(boundingLeaf); objRootBG.addChild(keyNavBeh); Background background = new Background(); background.setApplicationBounds(new BoundingSphere(new Point3d(), 1000.0)); background.setGeometry(createBackGraph()); objRoot.addChild(background); AmbientLight ambientLight = new AmbientLight(); ambientLight.setInfluencingBounds(new BoundingSphere()); objRootBG.addChild(ambientLight); return objRootBG; }
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);/*w ww. j ava 2 s .c o m*/ // 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:AlternateAppearanceBoundsTest.java
BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Create an alternate appearance 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);//from w ww. java2s.com altApp = new AlternateAppearance(); altApp.setAppearance(otherApp); altApp.setCapability(AlternateAppearance.ALLOW_BOUNDS_WRITE); altApp.setCapability(AlternateAppearance.ALLOW_INFLUENCING_BOUNDS_WRITE); altApp.setInfluencingBounds(worldBounds); objRoot.addChild(altApp); // Build foreground geometry 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.15f, // x spacing 0.15f, // y spacing 5, // number of spheres in X 5, // number of spheres in Y app1, // appearance true); // alt app override = true objRoot.addChild(content1); shapes1 = ((SphereGroup) content1).getShapes(); // Add lights 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); light1.setCapability(DirectionalLight.ALLOW_INFLUENCING_BOUNDS_WRITE); light1.setCapability(DirectionalLight.ALLOW_BOUNDS_WRITE); objRoot.addChild(light1); // 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); // Define a bounding leaf leafBounds = new BoundingLeaf(allBounds[currentBounds]); leafBounds.setCapability(BoundingLeaf.ALLOW_REGION_WRITE); objRoot.addChild(leafBounds); if (boundingLeafOn) { altApp.setInfluencingBoundingLeaf(leafBounds); } else { altApp.setInfluencingBounds(allBounds[currentBounds]); } return objRoot; }
From source file:FourByFour.java
/** * Create the scenegraph for the 3D view. */// w w w.j a va2s .c o m public BranchGroup createScene3D() { // Define colors Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f red = new Color3f(0.80f, 0.20f, 0.2f); Color3f ambient = new Color3f(0.25f, 0.25f, 0.25f); Color3f diffuse = new Color3f(0.7f, 0.7f, 0.7f); Color3f specular = new Color3f(0.9f, 0.9f, 0.9f); Color3f ambientRed = new Color3f(0.2f, 0.05f, 0.0f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); // Create the branch group BranchGroup branchGroup = new BranchGroup(); // Create the bounding leaf node BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0); BoundingLeaf boundingLeaf = new BoundingLeaf(bounds); branchGroup.addChild(boundingLeaf); // Create the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); branchGroup.addChild(bg); // Create the ambient light AmbientLight ambLight = new AmbientLight(white); ambLight.setInfluencingBounds(bounds); branchGroup.addChild(ambLight); // Create the directional light Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight dirLight = new DirectionalLight(white, dir); dirLight.setInfluencingBounds(bounds); branchGroup.addChild(dirLight); // Create the pole appearance Material poleMaterial = new Material(ambient, black, diffuse, specular, 110.f); poleMaterial.setLightingEnable(true); Appearance poleAppearance = new Appearance(); poleAppearance.setMaterial(poleMaterial); // Create the transform group node TransformGroup transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); branchGroup.addChild(transformGroup); // Create the poles Poles poles = new Poles(poleAppearance); transformGroup.addChild(poles.getChild()); // Add the position markers to the transform group transformGroup.addChild(positions.getChild()); // Let the positions object know about the transform group positions.setTransformGroup(transformGroup); // Create the mouse pick and drag behavior node PickDragBehavior behavior = new PickDragBehavior(canvas2D, canvas3D, positions, branchGroup, transformGroup); behavior.setSchedulingBounds(bounds); transformGroup.addChild(behavior); return branchGroup; }