« Return to Thread: Java 3D meets JavaFX !

Re: Java 3D meets JavaFX !

by java3d-interest :: Rate this Message:

Reply to Author | View in Thread

Hi,

thanks a lot to all of you for testing the samples and sending your feedback. Below I describe how Java 3D can provide 3D rendering in JavaFX 1.1 applications and applets. For more details see also the source code and the apidoc which are now available for download: http://interactivemesh.org/testspace/j3dmeetsjfx.html.


[b]FXCanvas3D enables JavaFX to draw the Virtual Universe.[/b]

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

1. Java 3D renders offscreen into a lightweight component which is added via a resizable JavaFX SwingComponent to a JavaFX Scene.
2. The Java 3D rendering loop runs in parallel to the JavaFX painting loop with synchronized minimal overlapping.

The Java class [b]FXCanvas3D[/b] and the Java interface [b]FXCanvas3DRepainter[/b] are the sources of this API.

Since Java 3D 1.5 lightweight 3D rendering is available through JCanvas3D as a subclass  of JPanel. JCanvas3D is designed for the Swing painting loop but doesn't interact very well with JavaFX resp. vice versa (see posts above).

The implementation of FXCanvas3D is a derived work (not a subclass) of JCanvas3D and is available under its license conditions (BSD).

A [b]Double Offscreen Buffer[/b] and a controlling [b]Lock with two Conditions[/b] 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 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 Condition. The other Condition guarantees that during resizing of a FXCanvas3D panel the Java 3D renderer thread isn't blocked.

The web page samples provide an implementation of the corresponding SwingComponent named as FXCanvas3DComp. This JavaFX class has the interface  FXCanvas3DRepainter implemented and allows a FXCanvas3D object to call 'repaintFXCanvas3D()' from its 'postSwap()' method. The repaint request is handled by a [b]FX.deferAction() [/b]- 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 'repaint()' on the FXCanvas3D object.

This completes the cycle of 3D offscreen rendering and image drawing. The duration of one cyle on a multi-core system can be estimated at [i]( max(Java 3D loop, JavaFX loop) + image copying + thread handling ) ms[/i]. The cost of the extra BufferedImage in comparison to JCanvas3D is about [i]( image.width x image.height x 4 ) bytes[/i] of CPU memory.

[b]Notes[/b]

To initiate the Java 3D engine, the 3D scene, and the FXCanvas3D object asynchronously per 'async operation' (see reference) seems to be reliable and effective. Both samples are implemented in this way.

The JavaFX loop is not yet synchronized with the monitor's vertical refresh. Therefore, visual artifacts might appear on the display. The JVM argument '-Dcom.sun.scenario.animation.vsync=true' may solve this (JavaFX bugs RT-1088/1198).

The samples' JavaFX script coding should not be considered as best practice. I'm really missing my beloved BoxLayout.

[b]References[/b]

Deploy A Rich Internet Application Developed With JavaFX Technology, Cindy Castillo
http://javafx.com/docs/tutorials/deployment

JavaFX Async operations, James Clarke
http://blogs.sun.com/clarkeman/entry/javafx_async_operations

Using Java Objects Within JavaFX Programs, Michael Heinrichs
http://java.sun.com/developer/technicalArticles/scripting/javafx/javafx_and_java

August
[Message sent by forum member 'interactivemesh' (interactivemesh)]

http://forums.java.net/jive/thread.jspa?messageID=331982

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...

 « Return to Thread: Java 3D meets JavaFX !