|
FXCanvas3DImage | |||||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||||
FXCanvas3DImage provides the Java 3D™ scene by a BufferedImage object.
See:
Description
| Packages | |
|---|---|
| com.interactivemesh.j3d.community.gui | GUI components which Java 3D renders into. |
FXCanvas3DImage provides the Java 3D™ scene by a BufferedImage object.
This API is a derived work of the Java 3D utility class JCanvas3D and includes the Java™ class FXCanvas3DImage and the Java interface FXCanvas3DImageRepainter.
The following two objectives determine the current approach of the FXCanvas3DImage 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 JavaFX 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 FXCanvas3DImage the Java 3D renderer thread isn't blocked.
Java 3D's off-screen rendering implementation requires that a JPanel component is added to the JavaFX Scene for receiving user events and for enabling resp. disabling the 3D rendering loop in correspondence to the component's visibility. Therefore, the class FXCanvas3DImage is designed as a subclass of JPanel without any individual rendering. The size of the FXCanvas3DImage instance determines the size of the 3D rendering image.
The following sample 'FXCanvas3DImagePainter' of the corresponding JavaFX SwingComponent has the interface FXCanvas3DImageRepainter implemented. This allows a FXCanvas3DImage object to call 'repaintFXCanvas3DImage()' from its 'postSwap()' method. The repaint request is handled by a FX.deferAction() - an equivalent to SwingUtilities.invokeLater() - and will be executed on the EDT. The assigned function calls firstly 'copyOffScreenBuffer()' while the Java 3D renderer thread is waiting and secondly image drawing related operations. This completes the cycle of 3D off-screen rendering and image drawing.
JavaFX class FXCanvas3DImagePainter.fx
import java.awt.BorderLayout;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import javafx.ext.swing.SwingComponent;
import com.interactivemesh.j3d.community.gui.FXCanvas3DImage;
import com.interactivemesh.j3d.community.gui.FXCanvas3DImageRepainter;
public class FXCanvas3DImagePainter extends SwingComponent, FXCanvas3DImageRepainter {
// Container for FXCanvas3DImage
var container: JPanel;
// FXCanvas3DImage instance
var fxCanvas3DImage: FXCanvas3DImage;
// Image of 3D rendering
var canvas3DImage: BufferedImage;
// Create SwingComponent - called at construction time
override protected function createJComponent(): JPanel {
container = new JPanel(new BorderLayout());
}
// Called from Main
package function initFXCanvas3D(fxC3DImage: FXCanvas3DImage): Void {
fxCanvas3DImage = fxC3DImage;
fxCanvas3DImage.setRepainter(this);
container.add(fxCanvas3DImage.getParent(), BorderLayout.CENTER);
fxCanvas3DImage.setSize(this.layoutBounds.width, this.layoutBounds.height);
}
//
// Interface FXCanvas3DImageRepainter
//
// Called from FXCanvas3DImage
override public function onFXCanvas3DImageResized(): Void {
// Resizing operations: update 'canvas3DImage' etc.
...
}
// Called from FXCanvas3DImage
override public function repaintFXCanvas3DImage() {
/*
JavaFX API :
A deferAction represents an action that should be executed
at a later time of the system's choosing.
In systems based on event dispatch, such as Swing, execution of a
deferAction generally means putting it on the event queue for later processing.
*/
FX.deferAction(
function(): Void {
// Now we are in the JavaFX painting loop and on the EDT
// Copy renderImage into paintImage and notify J3D-Renderer thread
fxCanvas3DImage.copyOffScreenBuffer();
// Drawing of the 'canvas3DImage' object
...
}
)
}
}
Version: 1.0
Date: 2009/05/27
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, Java 3D, and JavaFX are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.
|
FXCanvas3DImage | |||||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||||