public ObjectViewer(URL url) { setLayout(new BorderLayout()); Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add("Center", canvas3D); BoundingSphere bounds = new BoundingSphere(new Point3d(), 1000); BranchGroup root = new BranchGroup(); BranchGroup scene = createSceneGraph(url); scene.setBoundsAutoCompute(true); System.out.println(scene.getBounds()); BoundingSphere sceneBounds = new BoundingSphere(scene.getBounds()); SimpleUniverse univ = new SimpleUniverse(canvas3D); ViewingPlatform view = univ.getViewingPlatform(); view.setNominalViewingTransform(); Transform3D t = new Transform3D(); TransformGroup viewTransform = view.getViewPlatformTransform(); t.set(new Vector3d(0, 0, 3 * sceneBounds.getRadius())); viewTransform.setTransform(t); BranchGroup lights = new BranchGroup(); Light light = new AmbientLight(); light.setInfluencingBounds(bounds); lights.addChild(light); light = new DirectionalLight(); light.setInfluencingBounds(bounds); lights.addChild(light); root.addChild(lights); TransformGroup tg = new TransformGroup(); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tg.addChild(scene); root.addChild(tg); MouseRotate mouse = new MouseRotate(); mouse.setTransformGroup(tg); mouse.setSchedulingBounds(bounds); root.addChild(mouse); MouseZoom mousezoom = new MouseZoom(); mousezoom.setTransformGroup(tg); mousezoom.setSchedulingBounds(bounds); root.addChild(mousezoom); Background background = new Background(1, 1, 1); background.setApplicationBounds(bounds); root.addChild(background); root.compile(); univ.addBranchGraph(root); }
private TransformGroup makeText(Vector3d vertex, String text) // Create a Text2D object at the specified vertex { Text2D message = new Text2D(text, white, "SansSerif", 36, Font.BOLD); // 36 point bold Sans Serif TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(vertex); tg.setTransform(t3d); tg.addChild(message); return tg; } // end of getTG()
public void processStimulus(Enumeration criteria) { posVector.set( (float) targetHistogram.neutronNumber - ((float) targetMaxNeutron / 2.0f), (float) targetHistogram.abundance[step] - targetHistogram.normalizationFactor, (float) -targetHistogram.protonNumber + ((float) targetMaxProton / 2.0f)); ca = targetHistogram.fillingAppearance.getColoringAttributes(); targetColorRamp.getColor( targetHistogram.abundance[step] - targetHistogram.normalizationFactor, histColor); ca.setColor(histColor); step++; if (step >= targetHistogram.abundance.length) { step = 0; } targetT3D.set(posVector); targetTG.setTransform(targetT3D); this.wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_CLICKED)); }
/** Setup the basic scene which consists of a quad and a viewpoint */ private void setupSceneGraph() { // View group Viewpoint vp = new Viewpoint(); Vector3f trans = new Vector3f(0, 0, 1); Matrix4f mat = new Matrix4f(); mat.setIdentity(); mat.setTranslation(trans); TransformGroup tx = new TransformGroup(); tx.addChild(vp); tx.setTransform(mat); Group scene_root = new Group(); scene_root.addChild(tx); // Flat panel that has the viewable object as the demo float[] coord = {0, 0, -1, 0.25f, 0, -1, 0, 0.25f, -1}; float[] normal = {0, 0, 1, 0, 0, 1, 0, 0, 1}; TriangleArray geom = new TriangleArray(); geom.setValidVertexCount(3); geom.setVertices(TriangleArray.COORDINATE_3, coord); geom.setNormals(normal); Material material = new Material(); material.setDiffuseColor(new float[] {0, 0, 1}); material.setEmissiveColor(new float[] {0, 0, 1}); material.setSpecularColor(new float[] {1, 1, 1}); material.setTransparency(0.5f); Appearance app = new Appearance(); app.setMaterial(material); Shape3D shape = new Shape3D(); shape.setGeometry(geom); shape.setAppearance(app); TransformGroup tg = new TransformGroup(); Matrix4f transform = new Matrix4f(); transform.setIdentity(); transform.setTranslation(new Vector3f(0.15f, 0, -1)); tg.setTransform(transform); Shape3D backShape = new Shape3D(); Material material2 = new Material(); material2.setDiffuseColor(new float[] {1, 0, 0}); material2.setEmissiveColor(new float[] {1, 0, 0}); material2.setSpecularColor(new float[] {1, 1, 1}); Appearance app2 = new Appearance(); app2.setMaterial(material2); backShape.setGeometry(geom); backShape.setAppearance(app2); tg.addChild(backShape); scene_root.addChild(tg); scene_root.addChild(shape); SimpleScene scene = new SimpleScene(); scene.setRenderedGeometry(scene_root); scene.setActiveView(vp); // Then the basic layer and viewport at the top: SimpleViewport view = new SimpleViewport(); view.setDimensions(0, 0, 500, 500); view.setScene(scene); SimpleLayer layer = new SimpleLayer(); layer.setViewport(view); Layer[] layers = {layer}; displayManager.setLayers(layers, 1); }