|
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 (javafx-jira.kenai.com) 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 (ardor3d.com). |
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 code.google.com/p/jfx3d, 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.