List of usage examples for javax.media.j3d BoundingSphere BoundingSphere
public BoundingSphere(Point3d center, double radius)
From source file:RedGreenGriffin.java
public BranchGroup createSceneGraph(int i) { System.out.println("Creating scene for: " + URLString); // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); try {// w w w .ja va 2s .c om Transform3D myTransform3D = new Transform3D(); myTransform3D.setTranslation(new Vector3f(+0.0f, -0.15f, -3.6f)); TransformGroup objTrans = new TransformGroup(myTransform3D); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D t = new Transform3D(); TransformGroup tg = new TransformGroup(t); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.addChild(tg); URL url = new URL(URLString); ObjectFile f = new ObjectFile(); f.setFlags(ObjectFile.RESIZE | ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY); System.out.println("About to load"); Scene s = f.load(url); Transform3D myTrans = new Transform3D(); myTrans.setTranslation(new Vector3f(eyeOffset, -eyeOffset, 0F)); TransformGroup mytg = new TransformGroup(myTrans); //mytg.addChild(s.getSceneGroup()); tg.addChild(mytg); Transform3D myTrans2 = new Transform3D(); myTrans2.setTranslation(new Vector3f(-eyeOffset, +eyeOffset, 0F)); TransformGroup mytg2 = new TransformGroup(myTrans2); //mytg2.addChild(s.getSceneGroup()); Hashtable table = s.getNamedObjects(); for (Enumeration e = table.keys(); e.hasMoreElements();) { Object key = e.nextElement(); System.out.println(key); Object obj = table.get(key); System.out.println(obj.getClass().getName()); Shape3D shape = (Shape3D) obj; //shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); Appearance ap = new Appearance(); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f red = new Color3f(0.7f, .0f, .15f); Color3f green = new Color3f(0f, .7f, .15f); ap.setMaterial(new Material(green, black, green, black, 1.0f)); Appearance ap2 = new Appearance(); ap2.setMaterial(new Material(red, black, red, black, 1.0f)); float transparencyValue = 0.5f; TransparencyAttributes t_attr = new TransparencyAttributes(TransparencyAttributes.BLENDED, transparencyValue, TransparencyAttributes.BLEND_SRC_ALPHA, TransparencyAttributes.BLEND_ONE); ap2.setTransparencyAttributes(t_attr); ap2.setRenderingAttributes(new RenderingAttributes()); ap.setTransparencyAttributes(t_attr); ap.setRenderingAttributes(new RenderingAttributes()); // bg.addChild(ap); shape.setAppearance(ap); mytg2.addChild(new Shape3D(shape.getGeometry(), ap2)); mytg.addChild(new Shape3D(shape.getGeometry(), ap)); } tg.addChild(mytg2); System.out.println("Finished Loading"); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Color3f light1Color = new Color3f(.9f, 0.9f, 0.9f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objTrans.addChild(light1); // Set up the ambient light Color3f ambientColor = new Color3f(1.0f, .4f, 0.3f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objTrans.addChild(ambientLightNode); MouseRotate behavior = new MouseRotate(); behavior.setTransformGroup(tg); objTrans.addChild(behavior); // Create the translate behavior node MouseTranslate behavior3 = new MouseTranslate(); behavior3.setTransformGroup(tg); objTrans.addChild(behavior3); behavior3.setSchedulingBounds(bounds); KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(tg); keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0)); objTrans.addChild(keyNavBeh); behavior.setSchedulingBounds(bounds); objRoot.addChild(objTrans); } catch (Throwable t) { System.out.println("Error: " + t); } return objRoot; }
From source file:Gouraud.java
/** * Erstellt den Szenegraphen//from w w w . j av a 2 s. c o m * * @return BranchGroup */ public BranchGroup macheSzene() { BranchGroup objWurzel = new BranchGroup(); // Transformation, 2 Rotationen: Transform3D drehung = new Transform3D(); Transform3D drehung2 = new Transform3D(); drehung.rotX(Math.PI / 4.0d); drehung2.rotY(Math.PI / 5.0d); drehung.mul(drehung2); TransformGroup objDreh = new TransformGroup(drehung); //Loader ObjectFile file = new ObjectFile(ObjectFile.RESIZE); Scene scene = null; try { // Laden der Obj Datei mittels jar scene = file.load(ClassLoader.getSystemResource("teapot.obj")); } catch (Exception e) { System.err.println(e); System.exit(1); } objDreh.addChild(scene.getSceneGroup()); DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f), new Vector3f(-1.0f, -1.0f, -1.0f)); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d)); objDreh.addChild(d_Licht); objWurzel.addChild(objDreh); return objWurzel; }
From source file:KeyNavigatorApp.java
public BranchGroup createSceneGraph(SimpleUniverse su) { // Create the root of the branch graph TransformGroup vpTrans = null;/*from w ww . j a va 2s . c o m*/ BranchGroup objRoot = new BranchGroup(); Vector3f translate = new Vector3f(); Transform3D T3D = new Transform3D(); TransformGroup TG = null; objRoot.addChild(createLand()); SharedGroup share = new SharedGroup(); share.addChild(createPyramid()); float[][] position = { { 0.0f, 0.0f, -3.0f }, { 6.0f, 0.0f, 0.0f }, { 6.0f, 0.0f, 6.0f }, { 3.0f, 0.0f, -10.0f }, { 13.0f, 0.0f, -30.0f }, { -13.0f, 0.0f, 30.0f }, { -13.0f, 0.0f, 23.0f }, { 13.0f, 0.0f, 3.0f } }; for (int i = 0; i < position.length; i++) { translate.set(position[i]); T3D.setTranslation(translate); TG = new TransformGroup(T3D); TG.addChild(new Link(share)); objRoot.addChild(TG); } vpTrans = su.getViewingPlatform().getViewPlatformTransform(); translate.set(0.0f, 0.3f, 0.0f); T3D.setTranslation(translate); vpTrans.setTransform(T3D); KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans); keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0)); objRoot.addChild(keyNavBeh); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:ExDirectionalLight.java
public Group buildScene() { // Get the current color and direction Color3f color = (Color3f) colors[currentColor].value; Vector3f dir = (Vector3f) directions[currentDirection].value; // Turn off the example headlight setHeadlightEnable(false);/* w w 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 DirectionalLight(); light.setEnable(lightOnOff); light.setColor(color); light.setDirection(dir); light.setCapability(DirectionalLight.ALLOW_STATE_WRITE); light.setCapability(DirectionalLight.ALLOW_COLOR_WRITE); light.setCapability(DirectionalLight.ALLOW_DIRECTION_WRITE); light.setInfluencingBounds(worldBounds); scene.addChild(light); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new SphereGroup()); // Add anotation arrows pointing in +-X, +-Y, +-Z to // illustrate aim direction scene.addChild(buildArrows()); return scene; }
From source file:ExPointLight.java
public Group buildScene() { // Get the current color, position, and attenuation Color3f color = (Color3f) colors[currentColor].value; Point3f pos = (Point3f) positions[currentPosition].value; Point3f atten = (Point3f) attenuations[currentAttenuation].value; // Turn off the example headlight setHeadlightEnable(false);//from w w w .j av a 2 s. c o m // Build the scene root 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 PointLight(); light.setEnable(lightOnOff); light.setColor(color); light.setPosition(pos); light.setAttenuation(atten); light.setCapability(PointLight.ALLOW_STATE_WRITE); light.setCapability(PointLight.ALLOW_COLOR_WRITE); light.setCapability(PointLight.ALLOW_POSITION_WRITE); light.setCapability(PointLight.ALLOW_ATTENUATION_WRITE); light.setInfluencingBounds(worldBounds); scene.addChild(light); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new SphereGroup()); // Add arrows in a fan to show light ray directions scene.addChild(buildArrows()); return scene; }
From source file:HelloUniverse.java
public void init() { // These are the string arguments given to the VirtualInputDevice // constructor. These are settable parameters. Look in the // VirtualInputDevice constructor for a complete list. String[] args = new String[10]; args[0] = "printvalues"; args[1] = "true"; args[2] = "yscreeninitloc"; args[3] = "50"; args[4] = null;// w w w. j a va 2 s .co m InputDevice device = new VirtualInputDevice(args); // now create the HelloUniverse Canvas setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); u = new SimpleUniverse(c); // The InputDevice must be initialized before registering it // with the PhysicalEnvironment object. device.initialize(); // Register the VirtualInputDevice with Java 3D u.getViewer().getPhysicalEnvironment().addInputDevice(device); TransformGroup viewTrans = u.getViewingPlatform().getViewPlatformTransform(); SensorBehavior s = new SensorBehavior(viewTrans, device.getSensor(0)); s.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Float.MAX_VALUE)); scene.addChild(s); u.addBranchGraph(scene); }
From source file:ExLightScope.java
public Group buildScene() { // Turn off the example headlight setHeadlightEnable(false);/* ww w. j a v a 2s .co m*/ // 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:ExBackgroundColor.java
public Group buildScene() { // Get the current color Color3f color = (Color3f) colors[currentColor].value; // Turn off the example headlight setHeadlightEnable(false);// w w w .j a va 2 s .com // Default to walk navigation setNavigationType(Walk); // Create the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create application bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the background color and its application bounds background = new Background(); background.setColor(color); background.setCapability(Background.ALLOW_COLOR_WRITE); background.setApplicationBounds(worldBounds); scene.addChild(background); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new TowerScene(this)); return scene; }
From source file:ExBackgroundImage.java
public Group buildScene() { // Get the current image ImageComponent2D image = imageComponents[currentImage]; // Turn off the example headlight setHeadlightEnable(false);/* w w w . j a v a 2 s . co m*/ // Default to walk navigation setNavigationType(Walk); // Build the scene root Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create application bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the background color and its application bounds background = new Background(); background.setImage(image); background.setCapability(Background.ALLOW_IMAGE_WRITE); background.setApplicationBounds(worldBounds); scene.addChild(background); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new TowerScene(this)); return scene; }
From source file:LOD.java
public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); u = new SimpleUniverse(c); // only add zoom mouse behavior to viewingPlatform ViewingPlatform viewingPlatform = u.getViewingPlatform(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. viewingPlatform.setNominalViewingTransform(); // add orbit behavior to the ViewingPlatform, but disable rotate // and translate OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ZOOM | OrbitBehavior.DISABLE_ROTATE | OrbitBehavior.DISABLE_TRANSLATE); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds);/* w ww . ja v a2 s. c om*/ viewingPlatform.setViewPlatformBehavior(orbit); u.addBranchGraph(scene); }