List of usage examples for javax.media.j3d ImageComponent2D ImageComponent2D
public ImageComponent2D(int format, RenderedImage image)
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 w w. ja v a 2s. co 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: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);/* www. j a v a 2 s . c om*/ 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);/* w ww . j ava 2s .com*/ 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);/* www.j a v a2s.c o m*/ initJava3d(); }
From source file:BooksDemo.java
public void createScene() { BufferedImage image = new BufferedImage(xpanel.getWidth(), xpanel.getHeight(), BufferedImage.TYPE_INT_RGB); getContentPane().paint(image.getGraphics()); BufferedImage subImage = new BufferedImage(CANVAS3D_WIDTH, CANVAS3D_HEIGHT, BufferedImage.TYPE_INT_RGB); ((Graphics2D) subImage.getGraphics()).drawImage(image, null, -c3d.getX(), -c3d.getY()); Background bg = new Background(new ImageComponent2D(ImageComponent2D.FORMAT_RGB, subImage)); BoundingSphere bounds = new BoundingSphere(); bounds.setRadius(100.0);/* ww w . j a v a 2 s . c om*/ bg.setApplicationBounds(bounds); BranchGroup objRoot = new BranchGroup(); objRoot.addChild(bg); TransformGroup objTg = new TransformGroup(); objTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D yAxis = new Transform3D(); rotor1Alpha = new Alpha(1, 400); rotator1 = new RotationInterpolator(rotor1Alpha, objTg, yAxis, (float) Math.PI * 1.0f, (float) Math.PI * 2.0f); rotator1.setSchedulingBounds(bounds); textures.put("pages_top", createTexture("pages_top.jpg")); textures.put("pages", createTexture("amazon.jpg")); textures.put("amazon", createTexture("amazon.jpg")); textures.put("cover1", createTexture("cover1.jpg")); textures.put("cover2", createTexture("cover2.jpg")); textures.put("cover3", createTexture("cover3.jpg")); book = new com.sun.j3d.utils.geometry.Box(0.5f, 0.7f, 0.15f, com.sun.j3d.utils.geometry.Box.GENERATE_TEXTURE_COORDS, new Appearance()); book.getShape(book.TOP).setAppearance((Appearance) textures.get("pages_top")); book.getShape(book.RIGHT).setAppearance((Appearance) textures.get("pages")); book.getShape(book.LEFT).setAppearance((Appearance) textures.get("amazon")); book.getShape(book.FRONT).setAppearance((Appearance) textures.get("cover1")); book.getShape(book.BACK).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); book.getShape(book.FRONT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); // book.getShape(book.LEFT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); // book.getShape(book.RIGHT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); objTg.addChild(book); objTg.addChild(rotator1); Transform3D spin = new Transform3D(); Transform3D tempspin = new Transform3D(); spin.rotX(Math.PI / 8.0d); tempspin.rotY(Math.PI / 7.0d); spin.mul(tempspin); TransformGroup objTrans = new TransformGroup(spin); objTrans.addChild(objTg); objRoot.addChild(objTrans); SimpleUniverse u = new SimpleUniverse(c3d); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(objRoot); View view = u.getViewer().getView(); view.setSceneAntialiasingEnable(true); }
From source file:MultiTextureTest.java
public Texture createLightMap() { int width = 128; int height = 128; BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); int[] rgbArray = new int[width * height]; int index, index2; int rgbInc = 256 / (width / 2 - 20); int rgbValue = 0; int k = width / 2 - 5; int i, j, rgb; rgb = 0xff;/*from w w w. j a va 2s . com*/ rgbValue = rgb | (rgb << 8) | (rgb << 16) | (rgb << 24); for (i = width / 2 - 1, j = 0; j < 10; j++, i--) { rgbArray[i] = rgbValue; } for (; i > 8; i--, rgb -= rgbInc) { rgbValue = rgb | (rgb << 8) | (rgb << 16) | (rgb << 24); rgbArray[i] = rgbValue; } for (; i >= 0; i--) { rgbArray[i] = rgbValue; } for (i = 0; i < width / 2; i++) { rgbValue = rgbArray[i]; index = i; index2 = (width - i - 1); for (j = 0; j < height; j++) { rgbArray[index] = rgbArray[index2] = rgbValue; index += width; index2 += width; } } bimage.setRGB(0, 0, width, height, rgbArray, 0, width); ImageComponent2D grayImage = new ImageComponent2D(ImageComponent.FORMAT_RGB, bimage); lightTex = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, width, height); lightTex.setImage(0, grayImage); return lightTex; }
From source file:PrintFromButton.java
public void print(boolean toWait) { if (!toWait)// w w w . j av a 2 s . com printing = true; BufferedImage bImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage); buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ); this.setOffScreenBuffer(buffer); this.renderOffScreenBuffer(); if (toWait) { this.waitForOffScreenRendering(); drawOffScreenBuffer(); } }
From source file:PrintFromButton.java
void drawOffScreenBuffer() { BufferedImage bImage = this.getOffScreenBuffer().getImage(); ImageComponent2D newImageComponent = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage); drawRaster.setImage(newImageComponent); }
From source file:ReadRaster.java
public void processStimulus(Enumeration criteria) { synchronized (readRaster) { bImage = readRaster.getImage().getImage(); }// w w w.ja v a 2 s . co m newImageComponent = new ImageComponent2D(ImageComponent.FORMAT_RGB, bImage); drawRaster.setImage(newImageComponent); super.processStimulus(criteria); }
From source file:SwingTest.java
/** * Initialize an offscreen Canvas3D.//from ww w . j a va2 s. c o m */ protected Canvas3D createOffscreenCanvas3D() { offScreenCanvas3D = createCanvas3D(true); offScreenCanvas3D.getScreen3D().setSize(offScreenWidth, offScreenHeight); offScreenCanvas3D.getScreen3D().setPhysicalScreenHeight(0.0254 / 90 * offScreenHeight); offScreenCanvas3D.getScreen3D().setPhysicalScreenWidth(0.0254 / 90 * offScreenWidth); RenderedImage renderedImage = new BufferedImage(offScreenWidth, offScreenHeight, BufferedImage.TYPE_3BYTE_BGR); imageComponent = new ImageComponent2D(ImageComponent.FORMAT_RGB8, renderedImage); imageComponent.setCapability(ImageComponent2D.ALLOW_IMAGE_READ); offScreenCanvas3D.setOffScreenBuffer(imageComponent); return offScreenCanvas3D; }