List of usage examples for javax.media.j3d Raster Raster
public Raster(Point3f pos, int type, int clipMode, Point srcOffset, Dimension size, Point dstOffset, ImageComponent2D image, DepthComponent depthComponent)
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);//from w ww .jav a 2s . com // 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:PrintFromButton.java
public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); BufferedImage bImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage); buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ); Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, 200, 200, buffer, null);/* w w w. j av a2 s . c o m*/ drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE); // create the main scene graph BranchGroup scene = createSceneGraph(drawRaster); // create the on-screen canvas Canvas3D d = new Canvas3D(config, false); add("Center", d); // create a simple universe u = new SimpleUniverse(d); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); // create an off Screen Buffer c = new OffScreenCanvas3D(config, true, drawRaster); // set the offscreen to match the onscreen Screen3D sOn = d.getScreen3D(); Screen3D sOff = c.getScreen3D(); sOff.setSize(sOn.getSize()); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth()); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight()); // attach the same view to the offscreen canvas u.getViewer().getView().addCanvas3D(c); // create the gui Button b = new Button("Print"); b.addActionListener(this); Panel p = new Panel(); p.add(b); add("North", p); u.addBranchGraph(scene); }
From source file:OffScreenTest.java
public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); BufferedImage bImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage); buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ); Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, 200, 200, buffer, null);/*from w ww .j a v a 2 s . c o m*/ drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE); // create the main scene graph BranchGroup scene = createSceneGraph(drawRaster); // create the on-screen canvas OnScreenCanvas3D d = new OnScreenCanvas3D(config, false); add("Center", d); // create a simple universe u = new SimpleUniverse(d); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); // create an off Screen Canvas OffScreenCanvas3D c = new OffScreenCanvas3D(config, true, drawRaster); // set the offscreen to match the onscreen Screen3D sOn = d.getScreen3D(); Screen3D sOff = c.getScreen3D(); sOff.setSize(sOn.getSize()); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth()); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight()); // attach the same view to the offscreen canvas View v = u.getViewer().getView(); v.addCanvas3D(c); // tell onscreen about the offscreen so it knows to // render to the offscreen at postswap d.setOffScreenCanvas(c); u.addBranchGraph(scene); v.stopView(); // Make sure that image are render completely // before grab it in postSwap(). d.setImageReady(); v.startView(); }
From source file:RasterTest.java
public RasterTest() { // create the image to be rendered using a Raster BufferedImage bufferedImage = new BufferedImage(128, 128, BufferedImage.TYPE_INT_RGB); ImageComponent2D imageComponent2D = new ImageComponent2D(ImageComponent2D.FORMAT_RGB, bufferedImage); imageComponent2D.setCapability(ImageComponent.ALLOW_IMAGE_READ); imageComponent2D.setCapability(ImageComponent.ALLOW_SIZE_READ); // create the depth component to store the 3D depth values DepthComponentInt depthComponent = new DepthComponentInt(m_kWidth, m_kHeight); depthComponent.setCapability(DepthComponent.ALLOW_DATA_READ); // create the Raster for the image m_RenderRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), imageComponent2D, null); m_RenderRaster.setCapability(Raster.ALLOW_IMAGE_WRITE); m_RenderRaster.setCapability(Raster.ALLOW_SIZE_READ); // create the Raster for the depth components m_DepthRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_DEPTH, 0, 0, m_kWidth, m_kHeight, null, depthComponent);//from www.ja va2 s. c o m initJava3d(); }
From source file:ReadRaster.java
public void init() { int width = 128; int height = 128; ImageComponent2D readImageComponent = new ImageComponent2D(ImageComponent.FORMAT_RGB, width, height); Raster readRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, width, height, readImageComponent, null);// w w w.j av a2 s . c om setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new myCanvas3D(config, readRaster); add("Center", c); // Create a simple scene and attach it to the virtual universe BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); BranchGroup scene = createSceneGraph(bImage, readRaster); u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); }