Example usage for javax.media.j3d Canvas3D Canvas3D

List of usage examples for javax.media.j3d Canvas3D Canvas3D

Introduction

In this page you can find the example usage for javax.media.j3d Canvas3D Canvas3D.

Prototype

public Canvas3D(GraphicsConfiguration graphicsConfiguration, boolean offScreen) 

Source Link

Document

Constructs and initializes a new Canvas3D object that Java 3D can render into.

Usage

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);//from   w ww .  ja  v a 2s . co 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:SwingTest.java

/**
 * Create a Canvas3D.//from   www  . j a  v  a  2 s. c  o m
 * 
 * @param offscreen
 *            true to specify an offscreen canvas
 */
protected Canvas3D createCanvas3D(boolean offscreen) {
    GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D();
    gc3D.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED);
    GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();

    Canvas3D c3d = new Canvas3D(gd[0].getBestConfiguration(gc3D), offscreen);
    c3d.setSize(500, 500);

    return c3d;
}

From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java

public void newOffScreen(int w, int h) {
    if (w * h == 0) {
        logger.error("bad window size");
        return;/*from   w  w w.j  a  va2s .c  o m*/
    }
    im = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    imC = new ImageComponent2D(ImageComponent2D.FORMAT_RGB, im, true, false);
    imC.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);
    offScreenCanvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration(), true) {
        @Override
        public void postRender() {
            int stdEffectiveWidth = effectiveWidth;
            int stdEffectiveHeight = effectiveHeight;
            effectiveWidth = offScreenCanvas.getWidth();
            effectiveHeight = offScreenCanvas.getHeight();
            J3DGraphics2D vGraphics = super.getGraphics2D();
            vGraphics.setFont(new Font("sans-serif", Font.PLAIN, 10));
            vGraphics.setColor(Color.YELLOW);
            offScreenLocToWin = new LocalToWindow(objScene, offScreenCanvas);
            offScreenLocToWin.update();
            fireProjectionChanged(new ProjectionEvent(this, offScreenLocToWin));
            draw2D(vGraphics, offScreenLocToWin, effectiveWidth, effectiveHeight);
            vGraphics.flush(false);
            effectiveWidth = stdEffectiveWidth;
            effectiveHeight = stdEffectiveHeight;
            offScreenRenderDone = true;
        }
    };
    offScreenView = offScreenCanvas.getView();
    offScreen = offScreenCanvas.getScreen3D();
    offScreenCanvas.setOffScreenLocation(0, 0);
    offScreenCanvas.setOffScreenBuffer(imC);
    offScreen.setSize(w, h);
    double width = 0.0254 / 90.0 * w;
    double height = 0.0254 / 90.0 * h;
    offScreen.setPhysicalScreenWidth(width);
    offScreen.setPhysicalScreenHeight(height);
    universe.getViewer().getView().addCanvas3D(offScreenCanvas);
    if (offScreenView != null)
        if (perspective)
            offScreenView.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
        else
            offScreenView.setProjectionPolicy(View.PARALLEL_PROJECTION);
}