SpanglefishDMS Consulting | sitemap | log in
This is a free Spanglefish 1 website.

JavaFX 3D

The Project

I have been writing Java3D programs for many years but recently interest in J3D has waned. This is a great shame as it is very powerful software. Then I got an Android smart phone. This ran Java and OpenGL.
Porting J3D to Android, while possible, did not look easy. Instead I wrote an API to run J3D routines on OpenGL. This culminated in the OlympicRobot App.
Along came the Raspberry PI which could run Java, followed closely by JavaFX to replace Swing. While working on JavaFX, I discovered the early release of JavaFX8 3D.

The Raspberry PI

Wanting to run my J3D programs on the PI, I wrote an API for OpenGL. Next I ported my Android J3d API to the PI and started debugging. A lot of the programs run but I ran into an OpenGL problem with the depth buffer.
At this point JavaFX got my attention and I ported my library routines that use Swing to JavaFX. While downloading Java 8, I found JavaFX 3D. JavaFX 3D will become available on the PI.

The Story So Far

I have ported most of my J3D API and written some new code. I can now run most of my 3D library and have ported a lot of test programs. The 3D shapes, Cylinder, Cuboid, Cone, Sphere, Torus etc. work but some have strange artifacts on their surfaces. My animation routines run and Olympic Robot works. Textures look very strange, lighting is difficult, the curved shapes are not smooth and transparency (now called Opacity) does not work.

The Problems


JavaFX 3D is an early release so bits are missing and others don't work. The main object drawing class is TriangleMesh. It was easy to implement the J3D routines TriangleStripArray, TriangleFanArray and TriangleArray except it does not support Normals. Instead it has FaceSmoothingGroups. I have been unable to find good documentation of this option but have copied code from the class. The following images compare JavaFX3D with Java3D. The first is JavaFX low res. The second is JavaFX medium res. The third is Java3D low res.



Ambient Light

AmbientLight just does not work.
This is a known bug and has been fixed but not released yet.
This is what happens if you use it!!



Spot Light

I tried to create ambient light using a cube of spot lights. This was the result. Only the first three of the eight lights work and you can't turn any of them off or on.




I need to read more about this class. At the moment, it seems you can only set Diffuse and Specular colors in the JavaFX Material. Java3D and OpenGL allow Ambient, Emission, Diffuse and Specular as well as Shininess. This may explain some of the strange texture colors I am seeing. Then again it might not.



My parabola test program has a display problem. There are white artifacts on the surface. Most curves surfaces have this problem. I am not sure what causes them (they are not from the inside surface as just displaying the outside still has them).
As anti aliasing does not work (not yet available) so aliasing might be the cause.


Transparency (or Opacity as it is now called) does not work if transforms are used. This feature is well implemented in J3D and OpenGL and is needed for water textures, disapearing objects etc.


Textures do not seem to display as expected. I am not sure what is causing this. It could be that only PointLight works. It could be the Material. The color definition in Material seems to have more affect on the texture than with J3D or OpenGL.


Backgrounds seem to be defined using CSS styles. So a background might be defined as pane.setStyle("-fx-background-color: white;");. This is fine for a fixed colour but how about a computed color. The colour can be defined #1f2f3f; but the class Color does not produce a hex String. Color.hashCode() produces an integer and the colours can then be extracted
("-fx-background-color: rgb("+((i>>24)&0xff)+","+((i>>16)&0xff)+","+((i>>8)&0xff)+");");
Now this is a bit complicated.
("-fx-background-color: #"+Integer.toHexString(col.hashCode()+";");
Is a bit better.
How about the Background class? It does not seem to be for this!
Colours are used in lots of CSS styles. A small extension to Color to produce hex strings would be very useful.

The Successes

Static Objects



My animation routines seem to work but there are so many problems with the lighting and textures that it is not easy to see what is happening. It is not worth trying to display them yet.


JavaFX 3D has a long way to go. Porting programs that are known to work is difficult because of so many problems. Writing new programs would be almost impossible.
I am not sure why, when they started designing JavaFX 3D, they did not start with J3D and then brought it up to date. J3D has a lot of clever features that could be lost.


The Raspberry PI Foundation


Java 8 Downloads



Interests and links


WikanikoWork from Home
sitemap | cookie policy | privacy policy