Package com.irurueta.geometry.io
Class MaterialLoader
java.lang.Object
com.irurueta.geometry.io.MaterialLoader
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
MaterialLoaderOBJ
Abstract class defining the interface for classes in charge of loading
materials.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longMaximum allowed file size to keep cached in memory.static final booleanConstant defining whether textures must be validated by default.protected FileFile to be read.private longLimit of bytes to keep mapped in memory.protected MaterialLoaderListenerListener in charge of notifying when the decoding starts, ends or progress events.protected booleanBoolean indicating that this instance is locked because decoding is being done.protected AbstractFileReaderAndWriterInstance in charge of reading data from file.protected booleanIndicates if texture images must be validated to ensure that they are valid image files. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault Constructor.protectedMaterialLoader(MaterialLoaderListener listener) Constructor.protectedConstructor.protectedMaterialLoader(File f, MaterialLoaderListener listener) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes file provided to this loader.longReturns maximum allowed file size to keep cached in memory.Returns material listener of this instance.booleanhasFile()Indicates whether a material file to be loaded has already been set.booleanisLocked()Determines whether this instance is locked.abstract booleanisReady()Determines whether enough parameters have been set so that the loading process can start.booleanIndicates if textures must be validated to ensure that image files are valid files.load()Starts the loading process of provided file.voidSets material file to be loaded.voidsetFileSizeLimitToKeepInMemory(long fileSizeLimitToKeepInMemory) Sets maximum allowed file size to keep cached in memory.voidsetListener(MaterialLoaderListener listener) Sets material listener of this instance.protected voidsetLocked(boolean locked) Sets the lock value of this instance so that no parameters cannot be changed until this instance is unlocked.voidsetTextureValidationEnabled(boolean textureValidationEnabled) Specifies whether textures must be validated to ensure that image files are valid files.
-
Field Details
-
DEFAULT_FILE_SIZE_LIMIT_TO_KEEP_IN_MEMORY
public static final long DEFAULT_FILE_SIZE_LIMIT_TO_KEEP_IN_MEMORYMaximum 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_ENABLEDConstant defining whether textures must be validated by default.- See Also:
-
reader
Instance in charge of reading data from file. -
locked
protected boolean lockedBoolean indicating that this instance is locked because decoding is being done. -
listener
Listener in charge of notifying when the decoding starts, ends or progress events. -
file
File to be read. -
textureValidationEnabled
protected boolean textureValidationEnabledIndicates if texture images must be validated to ensure that they are valid image files. -
fileSizeLimitToKeepInMemory
private long fileSizeLimitToKeepInMemoryLimit 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
Constructor.- Parameters:
f- material file to be read.- Throws:
IOException- raised if provided file does not exist or an I/O exception occurs.
-
MaterialLoader
Constructor.- Parameters:
listener- material listener to notify start, end and progress events.
-
MaterialLoader
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
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
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
Closes file provided to this loader.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- 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
Returns material listener of this instance. A material listener notifies of start, end and progress change events.- Returns:
- material listener of this instance.
-
setListener
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
public abstract Set<Material> load() throws LockedException, NotReadyException, IOException, LoaderExceptionStarts 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.
-