JCanvas3DOB


JCanvas3DOB
API Specification 1.0

JCanvas3DOB provides fast and fully synchronized lightweight Java 3D™ rendering.

See:
          Description

Packages
com.interactivemesh.j3d.community.gui GUI components which Java 3D renders into.

 

JCanvas3DOB provides fast and fully synchronized lightweight Java 3D™ rendering.

This API (J Canvas3D DOB) is a derived work of the Java 3D utility class JCanvas3D and includes the abstract class JCanvas3DOBAbstract and the class JCanvas3DOB as a standard implementation. Subclassing one of these classes allows mixing of 2D and 3D rendering as well as adding arbitrary operations.

The following two objectives determine the current approach of the JCanvas3DOB API:

A Double Off-screen Buffer and a controlling Lock with two Conditions were introduced to ensure that the threads of both loops access the common image data deadlock-free. These two buffers consist of a BufferedImage which Java 3D is rendering into and a BufferedImage which Swing is drawing. Both images have an identical format type. Only for the period of time it takes to copy integer values from the first into the second image the loops interrupt their regular tasks controlled by one of the two Lock's Conditions. The other Condition guarantees that during resizing of a JCanvas3DOB panel the Java 3D renderer thread isn't blocked.

Painting of the 3D rendering is based on the java.awt.Graphics' 'drawImage()' method which flips the image vertically on the fly while drawing. This allows to choose off-screen buffers in 'yUp' mode. In consequence the memory for an image is saved as well as the time to copy it within the ImageComponent2D object which Java 3D is directly rendering into. This results in a faster running Java 3D rendering loop.

JCanvas3DOBAbstract provides specific callback methods for adding individual 2D paintings or arbitrary operations on the 3D image data. The following code shows the standard implementation JCanvas3DOB:

public class JCanvas3DOB extends JCanvas3DOBAbstract {
        
    public JCanvas3DOB() {
        this(null, null);
    }

    public JCanvas3DOB(GraphicsDevice device) {
        this(null, device);
    }

    public JCanvas3DOB(GraphicsConfigTemplate3D template) {
        this(template, null);
    }

    public JCanvas3DOB(GraphicsConfigTemplate3D template, GraphicsDevice device) {       
        super(template, device);
    }
   
    /**
     * Creates new off-screen buffers of the given size. This method is called 
     * internally whenever this panel is added to a parent or is resized. 
     * 
     * Subclasses should call and/or override this method according to its
     * individual needs. In case of overriding calling
     * super.createOffScreenBuffer(canvasWidth, canvasHeight)
     * has to be the last thing to do.
     *      
     * A JCanvas3DOB object calls super.createOffScreenBuffer(canvasWidth, canvasHeight)
     * with the given size.   
     * 
     * @param width the width of the off-screen buffers to create
     * @param height the height of the off-screen buffers to create
     */
    @Override
    protected void createOffScreenBuffer(int width, int height) {
        super.createOffScreenBuffer(width, height);       
    }
    
    /**
     * Callback used to allow an overriding subclass to execute individual code
     * when new off-screen buffers were created. 
     * 
     * This method is called internally by the event-dispatching thread (EDT)
     * and should not be called by applications. 
     * 
     * A JCanvas3DOB object provides an empty implementation.   
     */
    @Override
    protected void offScreenBufferCreated () {       
    }
    
    /**
     * Callback used to allow an overriding subclass to execute individual code
     * when the off-screen buffers were copied.
     * 
     * This method is called internally by the event-dispatching thread (EDT)
     * and should not be called by applications. 
     * 
     * A JCanvas3DOB object provides an empty implementation.   
     */
    @Override
    protected void offScreenBufferCopied() {        
    }

    /**
     * Flips and paints the result of the 3D rendering.
     */
    @Override
    public void paintComponent(Graphics g) {
        
        super.paintComponent(g); // paint background
                
        // Draw & flip offscreen buffer        
        if (isReadyForDrawing()) {
            g.drawImage(paintImage,
                    // destination in g2d: flip lowerY and upperY 
                    // dx1    dy1          dx2         dy2
                        0, imageHeight, imageWidth, 0,    
                    // source: the bottom part of the scene image
                    // sx1    sy1          sx2         sy2
                        0, 0,           imageWidth, imageHeight, null);
        }                
    }
}    

Version: 1.0
Date: 2009/03/09

Author:
August Lammersdorf, InteractiveMesh e.K.
Kolomanstrasse 2a, 85737 Ismaning
Germany / Munich Area
www.InteractiveMesh.com/org

License:

Redistribution and use are permitted according to the following license notice.

com.sun.j3d.exp.swing.JCanvas3D.java

Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Neither the name of Sun Microsystems, Inc. or the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.

This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

You acknowledge that this software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility.

Revision: 1.10
Date: 2007/04/11 02:08:56
State: Exp

Trademarks:

Java and Java 3D are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.



JCanvas3DOB