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 (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.

8 Responses to Experiments in 3D in JavaFX 2.0

  1. Jasper Potts says:

    Thanks for the cool blog. It looks like you are doing something very similar to what we were doing for the 3D Rubix Cube and 3D Bar Chart demos from JavaOne 2011. Basically polygons plus custom lighting. Interested how performance is for you, for us calculating world space coordinates for lighting etc was the performance killer. We are working on blogging the code for what we did as well. Would be cool if we can contribute and merge our efforts.

    We have used JBullet and PhysX engines with JavaFX. PhysX has way better performance but requires some native code.

  2. Alexander K says:

    Wow! That’s really cool! You did a great job!

  3. Johnny Y says:

    Great work Jim!
    I’m very impressed that you wrangled JavaFX LinearGradient into doing smooth shading based on vertex normals!

  4. Pingback: Java desktop links of the week, December 12 | Jonathan Giles

  5. Pingback: JavaFX links of the week, December 12 // JavaFX News, Demos and Insight // FX Experience

  6. Great Work!!

    Would be cool to have 3D on javafx, my app could use that.

  7. Dan Howard says:

    Very cool. Did you know David Brakeen developed a 3D engine entirely using the 2D apis. No extra dependencies! see http://www.brackeen.com/javagamebook/ and grab chapter 12 and build it.

    It’s amazingly fast.

  8. Anonymous says:

    Nice,
    I am working through the exact same issues with my effort. If you get a chance post your code, I think it would be worthwhile to merge efforts as mentioned by a previous poster.

    Thanks

    Mark

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.