FXCanvas3DMV


FXCanvas3DMV
API Specification 1.1

FXCanvas3DMV enables JavaFX™ to draw Multiple Views into Virtual Universes.

See:
          Description

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

 

FXCanvas3DMV enables JavaFX™ to draw Multiple Views into Virtual Universes.

This API is a derived work of the Java 3D™ utility class JCanvas3D and includes the Java™ classes FXCanvas3DMV and FXCanvas3DMVControl as well as the Java interface FXCanvas3DMVRepainter.

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

Each FXCanvas3DMV object provides two off-screen buffers to ensure that the threads of both loops can independently access the common image data. These two buffers consist of a BufferedImage which Java 3D is rendering into and a BufferedImage which JavaFX is drawing.

A FXCanvas3DMVControl object controls repainting and resizing of the FXCanvas3DMV objects with the help of a Lock with two Conditions. As soon as Java 3D has finished rendering into all attached and active FXCanvas3DMV objects for a single frame the FXCanvas3DMVControl object requests JavaFX to copy the image data and to repaint all corresponding SwingComponent objects in a single loop.

Only for the period of time it takes to copy the image data from one buffer into the other buffer the loops interrupt their regular tasks controlled by one of the two Lock's Conditions. The other Condition guarantees that during resizing of a FXCanvas3DMV panel the Java 3D renderer thread isn't blocked.

The following JavaFX sample class 'FXVirtualUniverse.fx' has the interface FXCanvas3DMVRepainter implemented. FXCanvas3DMVControl's repaint request by calling the interface method 'repaintFXCanvas3D()' is handled by a FX.deferAction() - an equivalent to SwingUtilities.invokeLater() - and will be executed on the EDT. The assigned function calls in return 'copyBuffersAndRepaint()' on the FXCanvas3DMVControl object for image data copying while the Java 3D renderer thread is waiting and for repainting of each FXCanvas3DMV panel. This completes the cycle of 3D off-screen rendering and image drawing.

The JavaFX sample class 'FXCanvas3DComp.fx' provides the corresponding JavaFX SwingComponent for a FXCanvas3DMV object.

JavaFX class FXVirtualUniverse.fx

import javafx.async.JavaTaskBase;
import javafx.async.RunnableFuture;
import com.interactivemesh.j3d.community.gui.FXCanvas3DMV;
import com.interactivemesh.j3d.community.gui.FXCanvas3DMVControl;
import com.interactivemesh.j3d.community.gui.FXCanvas3DMVRepainter;

package class FXVirtualUniverse extends JavaTaskBase, FXCanvas3DMVRepainter {
    
    package var universe: TuxInTheBoxUniverse;

    package var fxCanvas3DMVControl: FXCanvas3DMVControl;

    // Implemented in Main, called here from 'onDone'
    package var initUniverse: function(universe: TuxInTheBoxUniverse): Void;

    package function getFXCanvas3DMV(index: Integer): FXCanvas3DMV {
        universe.getFXCanvas3DMV(index);
    }

    //
    // Implementation of JavaTaskBase
    //
    // Create RunnableFuture: TuxInTheBoxUniverse
    // Called in function 'start()'
    protected override function create(): RunnableFuture {
        universe = new TuxInTheBoxUniverse();
        return universe;
    }
    // Called from TuxInTheBoxMain.fx
    // Initializes the 3D scene : calls run() on RunnableFuture 'universe'
    protected override function start(): Void {        
        // Nothing to do
        super.start();
    }
    // Callback: Finish init
    override var onDone = function(): Void {
        initUniverse(universe);
    };

    //
    // Interface FXCanvas3DMVRepainter
    //
    // Called from FXCanvas3DMVControl
    override function repaintFXCanvas3DMV() {

        FX.deferAction(
            function(): Void {

                // Now we are in the JavaFX painting loop and on the EDT

                // Copy renderImages into paintImages and notify J3D-Renderer thread
                // Call repaint on all fxCanvas3DMVs
                fxCanvas3DMVControl.copyBuffersAndRepaint();

            }
        );
    }
}

JavaFX class FXCanvas3DComp.fx

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javafx.ext.swing.SwingComponent;
import com.interactivemesh.j3d.community.gui.FXCanvas3DMV;

package class FXCanvas3DComp extends SwingComponent {

    // Container for FXCanvas3DMV's parent
    var container: JPanel;

    // FXCanvas3DMV instance
    var fxCanvas3DMV: FXCanvas3DMV;

     // Create SwingComponent - called at construction time
    override protected function createJComponent(): JPanel{    
        container = new JPanel(new BorderLayout());
    }

    // Typically called from Main.fx
    package function initFXCanvas3D(canvas: FXCanvas3DMV) {
        fxCanvas3DMV = canvas;

        fxCanvas3DMV.setRepainter(this);

        container.add(fxCanvas3DMV.getParent(), BorderLayout.CENTER);
    }
}

Version: 1.1
Date: 2009/11/10

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.



FXCanvas3DMV