JavaFX™ 3D FXML Models


System requirements: JRE/JavaFX 8 [Java SE Downloads].

FXML


"FXML is a scriptable, XML-based markup language for constructing Java object graphs. It provides a convenient alternative to constructing such graphs in procedural code, and is ideally suited to defining the user interface of a JavaFX application, since the hierarchical structure of an XML document closely parallels the structure of the JavaFX scene graph." Quote from [Introduction to FXML].

FXML is also suited to constructing a pure 3D (sub-)scene graph or simply one 3D model consisting of following JavaFX 8 node types:

  • javafx.scene.Group
  • javafx.scene.shape.Box
  • javafx.scene.shape.Cylinder
  • javafx.scene.shape.MeshView
  • javafx.scene.shape.Sphere
  • javafx.scene.AmbientLight
  • javafx.scene.PointLight
  • javafx.scene.ParallelCamera
  • javafx.scene.PerspectiveCamera

Sample file: pyramid.fxml

<?xml version="1.0" encoding="utf-8"?>

<?import javafx.scene.paint.Color?>
<?import javafx.scene.paint.PhongMaterial?>
<?import javafx.scene.shape.MeshView?>
<?import javafx.scene.shape.TriangleMesh?>

<MeshView id="Pyramid">
  <material>
    <PhongMaterial>>
      <diffuseColor>
        <Color red="0.3" green="0.6" blue="0.9" opacity="1.0"/>
      </diffuseColor>
    </PhongMaterial>
  </material>
  <mesh>
    <TriangleMesh>
      <points>0.0 1.0 1.0 1.0 1.0 0.0 0.0 1.0 -1.0 -1.0 1.0 0.0 0.0 -1.0 0.0</points>
      <texCoords>0.0 0.0</texCoords>
      <faces>0 0 4 0 1 0 1 0 4 0 2 0 2 0 4 0 3 0 3 0 4 0 0 0 0 0 1 0 2 0 0 0 2 0 3 0</faces>
      <faceSmoothingGroups>1 2 4 8 16 16</faceSmoothingGroups>
    </TriangleMesh>
  </mesh>
</MeshView> 

FXMLLoader


"The FXMLLoader class is responsible for actually loading an FXML source file and returning the resulting object graph." Quote from [Introduction to FXML].

For more details see the 'javafx.fxml' package in the JavaFX 8 API.

Loading pyramid.fxml:

try {
  FXMLLoader fxmlLoader = new FXMLLoader();
  fxmlLoader.setLocation(this.getClass().getResource("resources/pyramid.fxml"));
  MeshView pyramidModel = fxmlLoader.<MeshView>load();
  // ...
}
catch (IOException e) {
  // exception handling
}
                

FxmlModelImporterJFX


FxmlModelImporterJFX is an importer for 3D FXML files released by InteractiveMesh as a member of the [JavaFX 3D Model Importers] set. It loads 3D scenes and models faster due to focusing on 3D related object types, requires less temporary memory, and provides access to:

  • location data of texture images
  • location data of included XML files
  • named Nodes
  • named PhongMaterials
  • viewpoints generated from cameras

FXMLLoader and FxmlModelImporterJFX are available in the JavaFX 3D application [ModelBrowserJFX] for loading 3D FXML files.

The ModelBrowserJFX also provides an FXML exporter. Each 3D scene graph loaded by one of the 3D model importers can be saved as an FXML file readable by FXMLLoader and FxmlModelImporterJFX.

FxmlModelImporterJFX imports following object types from FXML files:

  • javafx.scene.Group
  • javafx.scene.shape.Box
  • javafx.scene.shape.Cylinder
  • javafx.scene.shape.MeshView
  • javafx.scene.shape.Sphere
  • javafx.scene.AmbientLight
  • javafx.scene.PointLight
  • javafx.scene.ParallelCamera
  • javafx.scene.PerspectiveCamera
  • javafx.geometry.Point3D
  • javafx.scene.image.Image
  • javafx.scene.paint.Color
  • javafx.scene.paint.PhongMaterial
  • javafx.scene.shape.TriangleMesh
  • javafx.scene.transform.Affine
  • javafx.scene.transform.Rotate
  • javafx.scene.transform.Scale
  • javafx.scene.transform.Translate
  • java.lang.Boolean
  • java.lang.Double
  • java.lang.Float
  • java.lang.Integer
  • java.lang.String

and supports these FXML features:

  • <fx:include source="mySubScene.fxml"> : including of a root node of another FXML file
  • <fx:reference source="myPhongMaterial"> : reference to an existing sharable element

FXML 3D Models


These 3D models are derived works from the original models released by InteractiveMesh and can be used freely according to the attached license.


Image

CylinderHead

CylinderHead.fxml, 2.5 MB / 0.6MB compressed

FXMLLoader return type: TriangleMesh

1 TriangleMesh, 67,252 triangles

BoundsInLocal (rounded) :
  minX:-75.0, minY:-144.376, minZ:-74.983
  maxX:93.0, maxY:0.0, maxZ:74.983


Original model 'Cylinder head' (C) Copyright Open CASCADE Technology. Open CASCADE Technology Public License

CylinderHead-fxml-b87.zip includes fxml-file and license. [download]


Image

Duck

Duck.fxml, 0.2 MB / 0.07 MB compressed

FXMLLoader return type: MeshView

1 MeshView, 4,212 triangles, 1 image

BoundsInLocal (rounded) :
  minX:-0.693, minY:-1.640, minZ:-0.539
  maxX:0.962, maxY:-0.099, maxZ:0.613


Original model 'Duck' (C) Copyright 2006 Sony Computer Entertainment Inc.. Distributed under the terms of the SCEA Shared Source License.

Duck-fxml-b94.zip includes fxml-file, image, and license. [download]


Image

Scooter

Scooter.fxml, 1.3 MB / 0.3 MB compressed

FXMLLoader return type: Group

46 MeshViews, 36,026 triangles; shared PhongMaterials

BoundsInLocal (rounded) :
  minX:-0.312, minY:-0.795, minZ:-0.553
  maxX:0.312, maxY:0.0, maxZ:0.553


Original model 'Scooter' (C) Copyright Andrew Kator & Jennifer Legaz. Creative Commons Attribution 3.0 United States License.

Scooter-fxml-b87.zip includes fxml-file and license. [download]


Image

TuxRotation

TuxRotation.fxml, 0.5 MB / 0.1 MB compressed

FXMLLoader return type: Group

7 x 10 MeshViews, 7 x 13,744 triangles; shared PhongMaterials and TriangleMeshes

BoundsInLocal (rounded) :
  minX:-1.457, minY:-1.457, minZ:-1.457
  maxX:1.457, maxY:0.818, maxZ:1.457


Original model 'Tux.lwo / duke.dev.java.net' (C) Copyright Sun Microsystems, Inc.. Berkeley Software Distribution (BSD) License.

TuxRotation-fxml-b87.zip includes fxml-file and license. [download]