com.interactivemesh.jfx.importer.obj

## Class ObjModelImporter

- java.lang.Object
- - com.interactivemesh.jfx.importer.obj.ObjModelImporter

- All Implemented Interfaces:
    Importer, ModelImporter

      public class ObjModelImporter
      extends java.lang.Object
      implements ModelImporter

  A JavaFX importer for OBJ 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(ObjImportOption...)` `setResourceBasePath(String)` `setResourceBaseUrl(URL)` | `read(File)` `read(String)` `read(URL)` | `onFileImported()` | `getImport()` `getImageFilePaths()` `getNamedMaterials()` `getNamedMeshViews()` | `clear()` `close()`

  Sample code

  Following structure of the application-jar is assumed:

  ../app/MyApp.class
  ../app/resources/MyModel.obj

      ObjModelImporter objImporter = new ObjModelImporter();
      try {
          URL modelUrl = this.getClass().getResource("resources/MyModel.obj");
          objImporter.read(modelUrl);
      }
      catch (ImportException e) {
          // handle exception
      }
      MeshView[] meshViews = objImporter.getImport();

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ObjModelImporter()` Creates an OBJ model importer.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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.shape.MeshView[]` | `getImport()` Gets the array of MeshViews from the imported file.
    `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.shape.MeshView>` | `getNamedMeshViews()` Gets the map which contains all named (id property) MeshViews from the imported file.
    `java.util.EnumSet<ObjImportOption>` | `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.
    `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<ObjImportOption> options)` Sets the import options.
    `void` | `setOptions(ObjImportOption... 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

    - #### ObjModelImporter

          public ObjModelImporter()

      Creates an OBJ model importer.

  - ### 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 `ObjImportOption.NORMALS_GENERATION` is set or neither smoothing groups nor normals are given in the imported file.

      Default value: 45.

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

    - #### getOptions

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

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

    - #### setOptions

          public void setOptions(ObjImportOption... options)

      Sets the import options. Currently set options are removed. Default options: `ObjImportOption.NONE`.
      Parameters:
        `options` - a sequence or an array of import options
      Throws:
        `java.lang.IllegalArgumentException` - if options is `null`, its length is 0, or `ObjImportOption.NONE` is not the sole element

    - #### setOptions

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

      Sets the import options. Currently set options are removed. Default options: `ObjImportOption.NONE`.
      Parameters:
        `options` - enum set of import options
      Throws:
        `java.lang.IllegalArgumentException` - if options is `null`, its size is 0, or `ObjImportOption.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.shape.MeshView[] getImport()

      Gets the array of MeshViews from the imported file.
      Specified by:
        `getImport` in interface `Importer`
      Returns:
        imported MeshViews or `null` if no MeshViews are imported

    - #### getNamedMeshViews

          public java.util.Map<java.lang.String,javafx.scene.shape.MeshView> getNamedMeshViews()

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

      A MeshView's id is identical with the corresponding group name if exactly one material is assigned to all faces of this group. If more than one material is assigned to a group a MeshView for each material's faces is created and its id is named with the concatenation of the group and material names: groupName_materialName.

      Returns:
        named MeshViews or `null` if no imported MeshView 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`

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