Class MaterialLoader

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

public abstract class MaterialLoader extends Object implements Closeable
Abstract class defining the interface for classes in charge of loading materials.
  • Field Details

    • DEFAULT_FILE_SIZE_LIMIT_TO_KEEP_IN_MEMORY

      public static final long DEFAULT_FILE_SIZE_LIMIT_TO_KEEP_IN_MEMORY
      Maximum allowed file size to keep cached in memory. Files exceeding this size will just be streamed.
      See Also:
    • DEFAULT_TEXTURE_VALIDATION_ENABLED

      public static final boolean DEFAULT_TEXTURE_VALIDATION_ENABLED
      Constant defining whether textures must be validated by default.
      See Also:
    • reader

      protected AbstractFileReaderAndWriter reader
      Instance in charge of reading data from file.
    • locked

      protected boolean locked
      Boolean indicating that this instance is locked because decoding is being done.
    • listener

      protected MaterialLoaderListener listener
      Listener in charge of notifying when the decoding starts, ends or progress events.
    • file

      protected File file
      File to be read.
    • textureValidationEnabled

      protected boolean textureValidationEnabled
      Indicates if texture images must be validated to ensure that they are valid image files.
    • fileSizeLimitToKeepInMemory

      private long fileSizeLimitToKeepInMemory
      Limit of bytes to keep mapped in memory. If provided file exceeds this value, then it is not mapped into memory.
  • Constructor Details

    • MaterialLoader

      protected MaterialLoader()
      Default Constructor.
    • MaterialLoader

      protected MaterialLoader(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.
    • MaterialLoader

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

      protected MaterialLoader(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

    • getFileSizeLimitToKeepInMemory

      public long getFileSizeLimitToKeepInMemory()
      Returns maximum allowed file size to keep cached in memory. Files exceeding this size will just be streamed.
      Returns:
      maximum allowed file size to keep cached in memory.
    • setFileSizeLimitToKeepInMemory

      public void setFileSizeLimitToKeepInMemory(long fileSizeLimitToKeepInMemory) throws LockedException
      Sets maximum allowed file size to keep cached in memory. Files exceeding this size will just be streamed.
      Parameters:
      fileSizeLimitToKeepInMemory - maximum allowed file size to keep cached in memory.
      Throws:
      LockedException - if this instance is already loading another file.
    • hasFile

      public boolean hasFile()
      Indicates whether a material file to be loaded has already been set.
      Returns:
      True if material file has already been provided, false otherwise.
    • setFile

      public void setFile(File f) throws LockedException, IOException
      Sets material file to be loaded.
      Parameters:
      f - material file to be loaded.
      Throws:
      LockedException - raised if this instance is loaded because a file is already being loaded.
      IOException - raised if provided file does not exist or if an I/O exception occurs.
    • close

      public void close() throws IOException
      Closes file provided to this loader.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error occurs.
    • isTextureValidationEnabled

      public boolean isTextureValidationEnabled()
      Indicates if textures must be validated to ensure that image files are valid files.
      Returns:
      true if textures must be validated, false otherwise.
    • setTextureValidationEnabled

      public void setTextureValidationEnabled(boolean textureValidationEnabled)
      Specifies whether textures must be validated to ensure that image files are valid files.
      Parameters:
      textureValidationEnabled - true if textures must be validated, false otherwise.
    • isLocked

      public boolean isLocked()
      Determines whether this instance is locked. A material loader remains locked while decoding of a file is being done. This instance will remain locked once the loading process starts until it finishes either successfully or not. While this instance remains locked no parameters can be changed, otherwise a LockedException will be raised.
      Returns:
      True if instance is locked, false otherwise.
    • setLocked

      protected void setLocked(boolean locked)
      Sets the lock value of this instance so that no parameters cannot be changed until this instance is unlocked.
      Parameters:
      locked - value that determines whether this instance is locked or not.
    • getListener

      public MaterialLoaderListener getListener()
      Returns material listener of this instance. A material listener notifies of start, end and progress change events.
      Returns:
      material listener of this instance.
    • setListener

      public void setListener(MaterialLoaderListener listener) throws LockedException
      Sets material listener of this instance. A material listener notifies of start, end and progress change events.
      Parameters:
      listener - material listener of this instance.
      Throws:
      LockedException - Raised if this instance is already locked.
    • isReady

      public abstract boolean isReady()
      Determines whether enough parameters have been set so that the loading process can start.
      Returns:
      True if this instance is ready to start loading a file, false otherwise.
    • load

      Starts the loading process of provided file. This method returns a set containing all the materials that have been loaded.
      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.