LS.ResourcesManager Class
Static class that contains all the resources loaded, parsed and ready to use. It also contains the parsers and methods in charge of processing them
Constructor
LS.ResourcesManager
()
Item Index
Methods
- cancelOnceLoaded
- cleanFullpath
- getBasename
- getExtension
- getFilename
- getFolder
- getFullURL
- getMesh
- getNoCache
- getProtocol
- getResource
- getResourcesData
- getResourceType
- getTexture
- getURLasFile
- isLoading
- isLoading
- load
- loadResources
- onceLoaded
- processFinalResource
- processResource
- registerFileSystem
- registerResource
- registerResourcePostProcessor
- registerResourcePreProcessor
- removeExtension
- renameResource
- replaceExtension
- reset
- resourceModified
- resourceSaved
- setPath
- setProxy
- unregisterResource
Methods
cancelOnceLoaded
-
fullpath
-
index
Cancels the binding of a onceLoaded
Parameters:
-
fullpath
Stringfullpath of the resource you want to cancel the binding
-
index
Numberthe index of the callback to cancel (as it was returned by onceLoaded)
cleanFullpath
-
fullpath
Cleans resource name (removing double slashes to avoid problems) It is slow, so use it only in changes, not in getters
Parameters:
-
fullpath
String
Returns:
fullpath cleaned
getBasename
-
fullpath
Returns the filename without the folder or the extension
Parameters:
-
fullpath
String
Returns:
filename extension
getExtension
-
fullpath
-
complex_extension
Returns the filename extension from an url
Parameters:
-
fullpath
Stringurl or filename
-
complex_extension
Boolean[optional] returns the extension from the first dot, otherwise only the part from last dot
Returns:
filename extension
getFilename
-
fullpath
Returns the filename from a full path
Parameters:
-
fullpath
String
Returns:
filename extension
getFolder
-
fullpath
Returns the folder from a fullpath
Parameters:
-
fullpath
String
Returns:
folder name
getFullURL
-
url
-
options
transform a url to a full url taking into account proxy, virtual file systems and external_repository used only when requesting a resource to be loaded
Parameters:
-
url
String -
options
Object
Returns:
full url
getMesh
-
filename
returns a mesh resource if it is loaded
Parameters:
-
filename
String
Returns:
getNoCache
-
force
Returns a string to append to any url that should use the browser cache (when updating server info)
Parameters:
-
force
Booleanforce to return a nocache string ignoring the default configuration
Returns:
a string to attach to a url so the file wont be cached
getProtocol
-
url
Returns the url protocol (http, https) or empty string if no protocol was found
Parameters:
-
url
String
Returns:
protocol
getResource
-
url
-
constructor
Returns the resource if it has been loaded, if you want to force to load it, use load
Parameters:
-
url
Stringwhere the resource is located (if its a relative url it depends on the path attribute)
-
constructor
Function[optional] allows to specify the class expected for this resource, if the resource doesnt match, it returns null
Returns:
the resource
getResourcesData
-
resource_names
-
allow_files
Returns an object containig all the resources and its data (used to export resources)
Parameters:
-
resource_names
Arrayan array containing the resources names
-
allow_files
Bool[optional] used to allow to retrieve the data in File or Blob, otherwise only String and ArrayBuffer is supported
Returns:
object with name:data
getResourceType
-
resource
Returns the resource type ("Mesh","Texture","Material","SceneNode",...) of a given resource
Parameters:
-
resource
Returns:
the type in string format
getTexture
-
filename
returns a texture resource if it is loaded
Parameters:
-
filename
Stringcould be a texture itself in which case returns the same texture
Returns:
getURLasFile
-
filename
Used to load files and get them as File (or Blob)
Parameters:
-
filename
String
Returns:
the file
isLoading
()
Boolean
forces to try to reload again resources not found
Returns:
isLoading
()
Boolean
Tells if it is loading resources (or an specific resource)
Returns:
load
-
url
-
[options={}]
-
[on_complete=null]
-
[force_load=false]
-
[on_error=null]
Loads a generic resource, the type will be infered from the extension, if it is json or wbin it will be processed Do not use to load regular files (txts, csv, etc), instead use the LS.Network methods
Parameters:
-
url
Stringwhere the resource is located (if its a relative url it depends on the path attribute)
-
[options={}]
Object optionaloptions to apply to the loaded resource when processing it { force: to force a reload }
-
[on_complete=null]
Function optionalcallback when the resource is loaded and cached, params: callback( resource, url ) //( url, resource, options )
-
[force_load=false]
Boolean optionalif true it will load the resource, even if it already exists
-
[on_error=null]
Function optionalcallback in case the file wasnt found
loadResources
-
resources
-
[options={}]
Loads all the resources in the Object (it uses an object to store not only the filename but also the type)
Parameters:
-
resources
Object | Arraycontains all the resources, associated with its type
-
[options={}]
Object optionaloptions to apply to the loaded resources
Returns:
the actual amount of resources being loaded (this differs fromt he resources passed because some could be already in memory)
onceLoaded
-
fullpath
-
callback
Binds a callback for when a resource is loaded (in case you need to do something special)
Parameters:
-
fullpath
Stringof the resource you want to get the notification once is loaded
-
callback
Functionthe function to call, it will be called as callback( fullpath, resource )
Returns:
(number) index of the position in the array, use this index to cancel the event
processFinalResource
-
url
-
the
-
[options={}]
-
on_complete
Takes a resource instance, and adds some extra properties and register it
Parameters:
-
url
Stringwhere the resource is located (if its a relative url it depends on the path attribute)
-
the
resource class
-
[options={}]
Object optionaloptions to apply to the loaded resource
-
on_complete
Functiononce the resource is ready
processResource
-
url
-
data
-
[options={}]
-
on_complete
Takes some resource data and transforms it to a resource (and Object ready to be used by the engine) and REGISTERs it in the ResourcesManager. In most cases the process involves parsing and uploading to the GPU It is called for every single resource that comes from an external source (URL) right after being loaded
Parameters:
-
url
Stringwhere the resource is located (if its a relative url it depends on the path attribute)
-
data
the data of the resource (could be string, arraybuffer, image... )
-
[options={}]
Object optionaloptions to apply to the loaded resource
-
on_complete
Functiononce the resource is ready
registerFileSystem
-
name
-
url
Allows to associate a resource path like "vfs:myfile.png" to an url according to the value before the ":". This way we can have alias for different folders where the assets are stored. P.e: "e","http://domain.com" -> will transform "e:myfile.png" in "http://domain.com/myfile.png"
Parameters:
-
name
Stringthe filesystem name (the string before the colons in the path)
-
url
Stringthe url to attach before
registerResource
-
filename
-
resource
Stores the resource inside the manager containers. This way it will be retrieveble by anybody who needs it.
Parameters:
-
filename
Stringfullpath
-
resource
Object
registerResourcePostProcessor
-
resource_type
-
callback
Some resources require to be post-processed right after being parsed to validate, extend, register (meshes need to have the AABB computed...) This job could be done inside the parser but it is better to do it separatedly so it can be reused among different parsers.
Parameters:
-
resource_type
Stringthe name of the class of the resource
-
callback
Functionthe function to call once the data has been processed
registerResourcePreProcessor
-
fileformats
-
callback
-
data_type
-
resource_type
Resources need to be parsed once the data has been received, some formats could be parsed using native functions (like images) others require to pass the data through a series of functions (extract raw content, parse it, upload it to the GPU... Registering a resource preprocessor the data will be converted once it is in memory
Parameters:
-
fileformats
Stringthe extension of the formats that this function will parse
-
callback
Functionthe function to call once the data must be processed, if the process is async it must return true
-
data_type
String -
resource_type
String
removeExtension
-
fullpath
-
complex_extension
Returns the url without the extension
Parameters:
-
fullpath
Stringurl or filename
-
complex_extension
Boolean[optional] removes the extension from the first dot, otherwise only the part from last dot
Returns:
url without extension
renameResource
-
old_name
-
new_name
-
[skip_event=false]
Changes the name of a resource and sends an event to all components to change it accordingly
Parameters:
-
old_name
String -
new_name
String -
[skip_event=false]
Boolean optionalignore sending an event to all components to rename the resource
Returns:
if the file was found
replaceExtension
-
fullpath
-
extension
Replaces the extension of a filename
Parameters:
-
fullpath
Stringurl or filename
-
extension
String
Returns:
url with the new extension
reset
()
Resets all the resources cached, so it frees the memory
resourceModified
-
resource
Marks the resource as modified, used in editor to know when a resource data should be updated
Parameters:
-
resource
Object
resourceSaved
-
resource
Unmarks the resource as modified
Parameters:
-
resource
Object
setPath
-
url
Set the base path where all the resources will be fetched (unless they have absolute URL) By default it will use the website home address
Parameters:
-
url
String
setProxy
-
proxy_url
Set a proxy url where all non-local resources will be requested, allows to fetch assets to other servers. request will be in this form: proxy_url + "/" + url_with_protocol: -> http://myproxy.com/google.com/images/...
Parameters:
-
proxy_url
String
unregisterResource
-
filename
removes the resources from all the containers
Parameters:
-
filename
String
Returns:
true is removed, false if not found