Class MaterialLoaderOBJ

java.lang.Object
com.irurueta.geometry.io.MaterialLoader
com.irurueta.geometry.io.MaterialLoaderOBJ
All Implemented Interfaces:
Closeable, AutoCloseable

public class MaterialLoaderOBJ extends MaterialLoader
MaterialLoader implementation for OBJ files, which is capable of reading its associated MTL file.
  • Field Details

    • MAX_COLOR_VALUE

      public static final short MAX_COLOR_VALUE
      Maximum allowed color value.
      See Also:
    • materials

      private final Set<Material> materials
      Set of materials loaded in MTL file.
    • currentMaterial

      private MaterialOBJ currentMaterial
      Current material being loaded.
    • textureCounter

      private int textureCounter
      Number of textures that have been found in MTL file.
  • Constructor Details

    • MaterialLoaderOBJ

      public MaterialLoaderOBJ()
      Default Constructor.
    • MaterialLoaderOBJ

      public MaterialLoaderOBJ(File f) throws IOException
      Constructor.
      Parameters:
      f - material file to be read.
      Throws:
      IOException - raised if provided file does not exist or an I/O exception occurs.
    • MaterialLoaderOBJ

      public MaterialLoaderOBJ(MaterialLoaderListener listener)
      Constructor.
      Parameters:
      listener - material listener to notify start, end and progress events.
    • MaterialLoaderOBJ

      public MaterialLoaderOBJ(File f, MaterialLoaderListener listener) throws IOException
      Constructor.
      Parameters:
      f - material file to be read.
      listener - material listener to notify start, end and progress events.
      Throws:
      IOException - raised if provided file does not exist or an I/O exception occurs.
  • Method Details

    • isReady

      public boolean isReady()
      Indicates if material loader is ready to be used because a file has already been provided.
      Specified by:
      isReady in class MaterialLoader
      Returns:
      true if material loader is ready, false otherwise.
    • load

      Starts the loading process of provided file. This method returns a set containing all the materials that have been loaded.
      Specified by:
      load in class MaterialLoader
      Returns:
      a set containing all the materials that have been loaded.
      Throws:
      LockedException - raised if this instance is already locked.
      NotReadyException - raised if this instance is not yet ready.
      IOException - if an I/O error occurs.
      LoaderException - if file is corrupted or cannot be interpreted.
    • parseLine

      private void parseLine(String line) throws LoaderException
      Parses a line in an MTL file.
      Parameters:
      line - line being parsed.
      Throws:
      LoaderException - if line cannot be interpreted.
    • areMaterialsAvailable

      public boolean areMaterialsAvailable()
      Indicates if any material has been loaded already.
      Returns:
      true if materials have been loaded, false otherwise.
    • getMaterials

      public Set<Material> getMaterials()
      Returns set of materials that have been read.
      Returns:
      set of materials that have been read.
    • getMaterialByName

      public MaterialOBJ getMaterialByName(String name)
      Gets a material by its name, or null if material is not found.
      Parameters:
      name - name of material to be found.
      Returns:
      a material having provided name or null if none is found.
    • containsMaterial

      public boolean containsMaterial(String name)
      Indicates if material having provided name has been loaded or not.
      Parameters:
      name - name to search material by.
      Returns:
      true if material having provided name exists, false otherwise.
    • getMaterialByTextureMapName

      public Material getMaterialByTextureMapName(String name)
      Returns material by texture name.
      Parameters:
      name - name of texture.
      Returns:
      texture that has been found or null if none has been found.