List of usage examples for javax.media.j3d BoundingSphere BoundingSphere
public BoundingSphere(Point3d center, double radius)
From source file:SimpleGeometry.java
public BranchGroup createSceneGraph() { // 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);/*w w w . j a va 2s . c o m*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // 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 a simple shape leaf node, add it to the scene graph. objTrans.addChild(new ColorCube()); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. 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); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:PlatformTest.java
public PlatformTest() { m_KeyHashtable = new Hashtable(); m_Bounds = new BoundingSphere(new Point3d(0, 0, 0), 100); // get the graphics configuration for the graphics device GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); // create the first canvas, this is the top-down view Canvas3D c = new Canvas3D(config); c.setSize(m_kWidth, m_kHeight);//from w w w . j ava 2 s. c o m add(c); // create the second canvas, this is used for "Jim's" Viewer Canvas3D c2 = new Canvas3D(config); c2.setSize(m_kWidth, m_kHeight); add(c2); // create the third canvas, this is used for "Dan's" Viewer Canvas3D c3 = new Canvas3D(config); c3.setSize(m_kWidth, m_kHeight); add(c3); // Create the simple environment BranchGroup scene = createSceneGraph(); // create the first Viewer, this is a static top-down view // create a ViewingPlatform with 2 TransformGroups above the // ViewPlatform ViewingPlatform vp = new ViewingPlatform(2); // create the Viewer and attach to the first canvas Viewer viewer = new Viewer(c); // rotate and position the first Viewer above the environment Transform3D t3d = new Transform3D(); t3d.rotX(Math.PI / 2.0); t3d.setTranslation(new Vector3d(0, 0, -40)); t3d.invert(); MultiTransformGroup mtg = vp.getMultiTransformGroup(); mtg.getTransformGroup(0).setTransform(t3d); // create a SimpleUniverse from the ViewingPlatform and Viewer SimpleUniverse u = new SimpleUniverse(vp, viewer); // add the geometry to the scenegraph u.addBranchGraph(scene); // add two more Viewers to the scenegraph u.getLocale().addBranchGraph(createViewer(c2, "Jim", new Color3f(0.1f, 1.0f, 1.0f), -5, 8)); u.getLocale().addBranchGraph(createViewer(c3, "Dan", new Color3f(1.0f, 0.1f, 0.1f), 2, -8)); }
From source file:LOD.java
private void createLights(BranchGroup graphRoot) { // Create a bounds for the light source influence BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the global, ambient light Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds);//from ww w . java 2 s. c om graphRoot.addChild(aLgt); // Set up the directional (infinite) light source Color3f lColor1 = new Color3f(0.9f, 0.9f, 0.9f); Vector3f lDir1 = new Vector3f(1.0f, 1.0f, -1.0f); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); graphRoot.addChild(lgt1); }
From source file:ReadRaster.java
public BranchGroup createSceneGraph(BufferedImage bImage, Raster readRaster) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Raster shape. Add it to the root of the subgraph ImageComponent2D drawImageComponent = new ImageComponent2D(ImageComponent.FORMAT_RGB, bImage); Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, bImage.getWidth(), bImage.getHeight(), drawImageComponent, null); Shape3D shape = new Shape3D(drawRaster); drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE); objRoot.addChild(shape);/* w ww. j a v a 2s .c o m*/ // Ceate the transform greup 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); TransformGroup cubeScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(-0.5, 0.5, 0.0)); cubeScale.setTransform(t3d); cubeScale.addChild(objTrans); objRoot.addChild(cubeScale); // Create a simple shape leaf node, add it to the scene graph. objTrans.addChild(new ColorCube(0.3)); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); myRotationInterpolator rotator = new myRotationInterpolator(drawRaster, readRaster, 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); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:ImageComponentByReferenceTest.java
public BranchGroup createSceneGraph() { objRoot = new BranchGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(Group.ALLOW_CHILDREN_WRITE); objRoot.addChild(objTrans);/*www. j av a2s.com*/ BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); app.setCapability(Appearance.ALLOW_TEXTURE_WRITE); textureCube = new Box(0.4f, 0.4f, 0.4f, Box.GENERATE_TEXTURE_COORDS | Box.GENERATE_NORMALS, app); boxShape = textureCube.getShape(Box.FRONT); boxShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); objTrans.addChild(textureCube); checkBoard = new TiledImage(); TextureLoader texLoader = new TextureLoader(texImage, this); ImageComponent2D oneImage = texLoader.getImage(); bImage1 = oneImage.getImage(); int index = 0; image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, true); image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, true); image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, false); image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, false); createRaster(objRoot); image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, true); image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, true); image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, false); image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, false); texOne = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[2].getWidth(), image[2].getHeight()); texOne.setCapability(Texture.ALLOW_IMAGE_WRITE); texOne.setImage(0, image[2]); app.setTexture(texOne); texCheckBoard = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[4].getWidth(), image[4].getHeight()); texCheckBoard.setCapability(Texture.ALLOW_IMAGE_WRITE); objRoot.compile(); return objRoot; }
From source file:ExTransform.java
public Group buildScene() { // Turn on the headlight setHeadlightEnable(true);/*from w ww .j av a 2 s .co m*/ // Build the scene root switchGroup = new Switch(); switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE); // Create application bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent Transform3D t3d; Appearance app = new Appearance(); Material mat = new Material(); mat.setAmbientColor(0.2f, 0.8f, 0.4f); mat.setDiffuseColor(0.2f, 0.8f, 0.4f); mat.setSpecularColor(0.0f, 0.0f, 0.f); app.setMaterial(mat); // Build the 3D object: Box box = new Box(3.0f, 2.0f, 1.0f, app); // Build the shared object: sharedObject = new SharedGroup(); sharedObject.addChild(box); // Build 4 separate transforms: Transform3D id = new Transform3D(); TransformGroup idGroup = new TransformGroup(id); idGroup.addChild(new Link(sharedObject)); switchGroup.addChild(idGroup); Transform3D rot = new Transform3D(); rot.set(new AxisAngle4d(0., 1., 0., Math.PI / 4.)); TransformGroup rotGroup = new TransformGroup(rot); rotGroup.addChild(new Link(sharedObject)); switchGroup.addChild(rotGroup); Transform3D trans = new Transform3D(); trans.set(new Vector3d(2., 0., 0.)); TransformGroup transGroup = new TransformGroup(trans); transGroup.addChild(new Link(sharedObject)); switchGroup.addChild(transGroup); Transform3D scale = new Transform3D(); scale.set(2.0); TransformGroup scaleGroup = new TransformGroup(scale); scaleGroup.addChild(new Link(sharedObject)); switchGroup.addChild(scaleGroup); switchGroup.setWhichChild(options[currentSwitch].child); return switchGroup; }
From source file:AlternateAppearanceScopeTest.java
public void init() { Container contentPane = getContentPane(); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); contentPane.add("Center", c); BranchGroup scene = createSceneGraph(); // SimpleUniverse is a Convenience Utility class u = new SimpleUniverse(c); // add mouse behaviors to the viewingPlatform ViewingPlatform viewingPlatform = u.getViewingPlatform(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. viewingPlatform.setNominalViewingTransform(); OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds);/*from w ww.j av a 2 s. co m*/ viewingPlatform.setViewPlatformBehavior(orbit); u.addBranchGraph(scene); // Create GUI JPanel p = new JPanel(); BoxLayout boxlayout = new BoxLayout(p, BoxLayout.Y_AXIS); p.add(createScopingPanel()); p.add(createMaterialPanel()); p.setLayout(boxlayout); contentPane.add("South", p); }
From source file:LoaderTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // create a TransformGroup to flip the hand onto its end and enlarge it. TransformGroup objTrans1 = new TransformGroup(); Transform3D tr = new Transform3D(); objTrans1.getTransform(tr);//from w w w.ja v a2s .c o m tr.rotX(90.0 * Math.PI / 180.0); tr.setScale(10.0); objTrans1.setTransform(tr); // create a TransformGroup to rotate the hand TransformGroup objTrans2 = new TransformGroup(); objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // 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); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans2, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans2.addChild(rotator); // Set up the global lights Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objRoot.addChild(aLgt); objRoot.addChild(lgt1); // load the object file Scene scene = null; Shape3D shape = null; // read in the geometry information from the data file ObjectFile objFileloader = new ObjectFile(ObjectFile.RESIZE); try { scene = objFileloader.load("hand1.obj"); } catch (Exception e) { scene = null; System.err.println(e); } if (scene == null) System.exit(1); // retrieve the Shape3D object from the scene BranchGroup branchGroup = scene.getSceneGroup(); shape = (Shape3D) branchGroup.getChild(0); // create an Appearance and Material Appearance app = new Appearance(); Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); // assign the appearance to the Shape shape.setAppearance(app); // connect the scenegraph objTrans2.addChild(scene.getSceneGroup()); objTrans1.addChild(objTrans2); objRoot.addChild(objTrans1); return objRoot; }
From source file:ExAmbientLight.java
public Group buildScene() { // Get the current color Color3f color = (Color3f) colors[currentColor].value; // Turn off the example headlight setHeadlightEnable(false);/*ww w. j ava2s . c o m*/ // Build the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the light color and its influencing bounds light = new AmbientLight(); light.setEnable(lightOnOff); light.setColor(color); light.setCapability(AmbientLight.ALLOW_STATE_WRITE); light.setCapability(AmbientLight.ALLOW_COLOR_WRITE); light.setInfluencingBounds(worldBounds); scene.addChild(light); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new SphereGroup()); return scene; }
From source file:OrientedTest.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objScale = new TransformGroup(); Transform3D textMat = new Transform3D(); // Assuming uniform size chars, set scale to fit string in view textMat.setScale(1.2 / sl);//w ww . j ava 2 s. c o m objScale.setTransform(textMat); // 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); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(objTrans); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Appearance apText = new Appearance(); Material m = new Material(); m.setLightingEnable(true); apText.setMaterial(m); Appearance apEarth = new Appearance(); Material mm = new Material(); mm.setLightingEnable(true); apEarth.setMaterial(mm); Appearance apStone = new Appearance(); apStone.setMaterial(mm); // create 3D text Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion()); Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, 3.0f, 0.0f)); OrientedShape3D textShape = new OrientedShape3D(); textShape.setGeometry(txt); textShape.setAppearance(apText); textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f); objScale.addChild(textShape); // Create a simple shape leaf node, add it to the scene graph. Transform3D cubeMat = new Transform3D(); TransformGroup cubeTrans = new TransformGroup(cubeMat); cubeMat.set(new Vector3d(0.9, 0.0, -1.0)); cubeTrans.setTransform(cubeMat); cubeTrans.addChild(new ColorCube(0.3)); objTrans.addChild(cubeTrans); TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this); if (stoneTex != null) apStone.setTexture(stoneTex.getTexture()); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); apStone.setTextureAttributes(texAttr); Transform3D coneMat = new Transform3D(); TransformGroup coneTrans = new TransformGroup(coneMat); coneMat.set(new Vector3d(0.0, 0.0, 0.0)); coneTrans.setTransform(coneMat); coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone)); objTrans.addChild(coneTrans); TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this); if (earthTex != null) apEarth.setTexture(earthTex.getTexture()); apEarth.setTextureAttributes(texAttr); Transform3D cylinderMat = new Transform3D(); TransformGroup cylinderTrans = new TransformGroup(cylinderMat); cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0)); cylinderTrans.setTransform(cylinderMat); cylinderTrans.addChild( new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth)); objTrans.addChild(cylinderTrans); objTrans.addChild(objScale); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); objRoot.addChild(bgNode); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objRoot.addChild(light2); apText.setMaterial(mm); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }