# FxmlModelImporter (JavaFX 3D Model Importers)
Date: 2014-02-09

com.interactivemesh.jfx.importer.fxml

## Class FxmlModelImporter

- java.lang.Object
- - com.interactivemesh.jfx.importer.fxml.FxmlModelImporter

All Implemented Interfaces:
  Importer, ModelImporter

    public class FxmlModelImporter
    extends java.lang.Object
    implements ModelImporter

A JavaFX model importer for 3D FXML files.

For further details see the package page.

Import process

Prepare the importer (opt.) | Read the file | React (opt.) | Access the imported data | Clean up (recom'd)

- `setCreaseAngle(double)`

- `setOptions(EnumSet)`
- `setOptions(FxmlImportOption...)`

- `setResourceBasePath(String)`
- `setResourceBaseUrl(URL)`

- `read(File)`
- `read(String)`
- `read(URL)`

- `onFileImported()`

- `getImport()`

- `getImageFilePaths()`

- `getIncludedFxmlFilePaths()`

- `getNamedMaterials()`

- `getNamedNodes()`

- `getViewpoints()`

- `clear()`

- `close()`

Sample code

Following structure of the application-jar is assumed:

../app/MyApp.class
../app/resources/MyModel.fxml

    FxmlModelImporter fxmlImporter = new FxmlModelImporter();
    try {
        URL modelUrl = this.getClass().getResource("resources/MyModel.fxml");
        fxmlImporter.read(modelUrl);
    }
    catch (ImportException e) {
        // handle exception
    }
    Node[] rootNodes = fxmlImporter.getImport();

### Constructor Summary

Constructors
Constructor and Description
`FxmlModelImporter()` Creates a model importer for JavaFX 3D FXML files.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `clear()` Disposes of the imported data.
`void` `close()` Disposes of the imported data and closes the importer.
`double` `getCreaseAngle()` Gets the crease angle for normals generation measured in degrees.
`java.util.Map<javafx.scene.image.Image,FilePath>` `getImageFilePaths()` Gets the map which contains the FilePath objects for all imported texture images.
`javafx.scene.Node` `getImport()` Gets the root Node from the imported file.
`java.util.Map<javafx.scene.Node,FilePath>` `getIncludedFxmlFilePaths()` Gets the map which contains the FilePath objects for all included root nodes.
`java.util.Map<java.lang.String,javafx.scene.paint.PhongMaterial>` `getNamedMaterials()` Gets the map which contains all named and used PhongMaterial objects from the imported file.
`java.util.Map<java.lang.String,javafx.scene.Node>` `getNamedNodes()` Gets the map which contains all named (id property) Nodes from the imported file.
`java.util.EnumSet<FxmlImportOption>` `getOptions()` Gets a copy of the import options enum set.
`java.lang.String` `getResourceBasePath()` Gets the path where files associated with the imported 3D model file are located.
`java.net.URL` `getResourceBaseUrl()` Gets the URL where files associated with the imported 3D model file are located.
`Viewpoint[]` `getViewpoints()` Gets the viewpoints of the imported file.
`void` `onFileImported()` Method is invoked upon completion of import.
`void` `read(java.io.File file)` Imports a 3D model file passed as a File object.
`void` `read(java.lang.String filePath)` Imports a 3D model file with the passed file path.
`void` `read(java.net.URL url)` Imports a 3D model file from the passed location.
`void` `setCreaseAngle(double degrees)` Sets the crease angle for normals generation measured in degrees.
`void` `setOptions(java.util.EnumSet<FxmlImportOption> options)` Sets the import options.
`void` `setOptions(FxmlImportOption... options)` Sets the import options.
`void` `setResourceBasePath(java.lang.String path)` Sets the path where files associated with the imported 3D model file are located.
`void` `setResourceBaseUrl(java.net.URL url)` Sets the URL where files associated with the imported 3D model file are located.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### FxmlModelImporter

    public FxmlModelImporter()

Creates a model importer for JavaFX 3D FXML files.

### Method Detail

#### getResourceBasePath

    public java.lang.String getResourceBasePath()

Gets the path where files associated with the imported 3D model file are located. Default value: `null`.

Specified by:
  `getResourceBasePath` in interface `ModelImporter`
Returns:
  location of associated files

#### getResourceBaseUrl

    public java.net.URL getResourceBaseUrl()

Gets the URL where files associated with the imported 3D model file are located. Default value: `null`.

Specified by:
  `getResourceBaseUrl` in interface `ModelImporter`
Returns:
  location of associated files

#### setResourceBasePath

    public void setResourceBasePath(java.lang.String path)

Sets the path where files associated with the imported 3D model file are located. Only needs to be set if the base directory differs from that containing the imported 3D model file. Default value: `null`.

Specified by:
  `setResourceBasePath` in interface `ModelImporter`
Parameters:
  `path` - location of associated files

#### setResourceBaseUrl

    public void setResourceBaseUrl(java.net.URL url)

Sets the URL where files associated with the imported 3D model file are located. Only needs to be set if the base directory differs from that containing the imported 3D model file. Default value: `null`.

Specified by:
  `setResourceBaseUrl` in interface `ModelImporter`
Parameters:
  `url` - location of associated files

#### getCreaseAngle

    public double getCreaseAngle()

Gets the crease angle for normals generation measured in degrees.

Default value: 45

Specified by:
  `getCreaseAngle` in interface `Importer`
Returns:
  crease angle for normals generation

#### setCreaseAngle

    public void setCreaseAngle(double degrees)

Sets the crease angle for normals generation measured in degrees. The value will be clamped to [0, 180].

Normals are generated if the corresponding option `FxmlImportOption.NORMALS_GENERATION` is set.

Default value: 45

Specified by:
  `setCreaseAngle` in interface `Importer`
Parameters:
  `degrees` - crease angle for generating normals
See Also:
  `setOptions(FxmlImportOption...)`, `FxmlImportOption.GENERATE_NORMALS`

#### getOptions

    public java.util.EnumSet<FxmlImportOption> getOptions()

Gets a copy of the import options enum set. Default options: `FxmlImportOption.NONE`.

Returns:
  enum set of the import options

#### setOptions

    public void setOptions(FxmlImportOption... options)

Sets the import options. Currently set options are removed. Default options: `FxmlImportOption.NONE`.

Parameters:
  `options` - a sequence or an array of import options
Throws:
  `java.lang.IllegalArgumentException` - if options is `null`, its length is 0, or `FxmlImportOption.NONE` is not the sole element

#### setOptions

    public void setOptions(java.util.EnumSet<FxmlImportOption> options)

Sets the import options. Currently set options are removed. Default options: `FxmlImportOption.NONE`.

Parameters:
  `options` - enum set of import options
Throws:
  `java.lang.IllegalArgumentException` - if options is `null`, its size is 0, or `FxmlImportOption.NONE` is not the sole element

#### read

    public void read(java.io.File file)

Imports a 3D model file passed as a File object. The data of the last imported file will be disposed of. The imported data is available as soon as this method returns.

Specified by:
  `read` in interface `Importer`
Parameters:
  `file` - File object to import

#### read

    public void read(java.lang.String filePath)

Imports a 3D model file with the passed file path. The data of the last imported file will be disposed of. The imported data is available as soon as this method returns.

Specified by:
  `read` in interface `Importer`
Parameters:
  `filePath` - location of the file to import

#### read

    public void read(java.net.URL url)

Imports a 3D model file from the passed location. The data of the last imported file will be disposed of. The imported data is available as soon as this method returns.

Specified by:
  `read` in interface `Importer`
Parameters:
  `url` - location of the file to import

#### onFileImported

    public void onFileImported()

Method is invoked upon completion of import. This implementation doesn't do anything, but may be customized in subclasses.

Specified by:
  `onFileImported` in interface `Importer`

#### getImport

    public javafx.scene.Node getImport()

Gets the root Node from the imported file.

Specified by:
  `getImport` in interface `Importer`
Returns:
  imported root Node or `null` if no root Node is imported

#### getNamedNodes

    public java.util.Map<java.lang.String,javafx.scene.Node> getNamedNodes()

Gets the map which contains all named (id property) Nodes from the imported file.

Returns:
  named Nodes or `null` if no imported Node is named

#### getNamedMaterials

    public java.util.Map<java.lang.String,javafx.scene.paint.PhongMaterial> getNamedMaterials()

Gets the map which contains all named and used PhongMaterial objects from the imported file.

Specified by:
  `getNamedMaterials` in interface `ModelImporter`
Returns:
  named and used PhongMaterials or `null` if no material is named and used

#### getImageFilePaths

    public java.util.Map<javafx.scene.image.Image,FilePath> getImageFilePaths()

Gets the map which contains the FilePath objects for all imported texture images.

Specified by:
  `getImageFilePaths` in interface `ModelImporter`
Returns:
  paths of imported images or `null` if no image is imported
See Also:
  `FilePath`

#### getIncludedFxmlFilePaths

    public java.util.Map<javafx.scene.Node,FilePath> getIncludedFxmlFilePaths()

Gets the map which contains the FilePath objects for all included root nodes.

Returns:
  paths of included root nodes or `null` if no FXML file is included
See Also:
  `FilePath`

#### getViewpoints

    public Viewpoint[] getViewpoints()

Gets the viewpoints of the imported file.

Returns:
  imported viewpoints or `null` if no camera element is present in the imported file
See Also:
  `Viewpoint`

#### clear

    public void clear()

Disposes of the imported data. Imported data should be disposed of if the importer isn't used for some time. The importer doesn't run the garbage collector.

Specified by:
  `clear` in interface `Importer`

#### close

    public void close()

Disposes of the imported data and closes the importer. The importer should be closed if it isn't used again. The importer doesn't run the garbage collector.

Specified by:
  `close` in interface `Importer`

Copyright (C) 2013-2014 InteractiveMesh e.K.