Code for Experiments in 3D in JavaFX 2.0

Finally and belatedly I have published code for 3D objects in JavaFX 2.

The code is available at

Please note the warning about undocumented code.

From what I have seen the 3D code in JavaFX 8 (early access)  looks promising but this can only be a start; I think that it will need a lot more mathematics to make it really useful (see previous post). I have seen the recent post about a .obj importer ( from – this should be good!?

Screenshot below shows all objects available at jfx3d.Image


JavaFX 3D Features in JDK 8

Had a quick look at the 3D api. I was surprised that I did not see any reference to Quaternions, Are these not essential for comprehensive 3D rotations and transforms? Most other 3D engines seem to have them.

I am considering trying to hook up the Bullet physics engine to JavaFX and exploring how difficult/painful this is going to be!


PS Posted here because of FXexperience database error on posting a comment!

Experiments in 3D in JavaFX 2.0

As a programming exercise I have started to play with the idea of adding 3D primitives and objects to JavaFX. I understand that JavaFX labs are working on this and it ‘might’ be a future release. From the comments and views on the bugs website ( I am not convinced that this will happen soon or at all. From my, limited, knowledge the amount of effort to make a  fully featured 3D scenegraph, would require considerable effort and resources, which I am not convinced that Oracle are prepared to commit. At the moment, and for the foreseeable future, I would recommend that anybody contemplating any serious 3D work should use an existing 3D scenegraph such as ardor3D (

My efforts (see screenshots below) have focussed on some of the basics of a 3D scenegraph:

  • Constructing triangles in 3D space, this is done by calculating a rotation matrix to map the required triangle to 2D space, constructing a JavaFX Polygon shape and transforming this back to the original location.
  • Creation of generic ‘Vector3D’ class for all 3D vector calculations.
  • Creation of a base ‘Mesh’ class.
  • Creation of 3D primitives (e.g. sphere, cube, pyramid, rod, cylinder, tube, torus – most of these courtesy of ardor3D) and bunny rabbit!
  • Smooth shading based on vertex normals using a JavaFX LinearGradient (yes, really!).
  • White diffuse lighting giving monochromatic color shading of meshes depending on material color (it is not possible to successfully blend shades/gradients in 3D); hoping to add specular lighting.

Yet to do:

  • Sort out specular lighting.
  • Material colors from .mtl files.
  • Triangle picking algorithm.
  • Tidy up code; add comments!
  • Publish code on google-code (blank website at, no code yet).
  • Add physics, probably JBullet.

Will not do:

  • Textures, I have absolutely no idea how to do this.

Jim Kay


 Screenshot  of .obj model

 Screenshot of teapot (model – copyright (c) 2008-2010 Ardor Labs, Inc.)

Screenshot of teapot showing mesh lines, triangle face normals and vertex normals.