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
- getResource
- getResourcesData
- getResourceType
- getTexture
- getURLasFile
- isLoading
- isLoading
- load
- loadResources
- onceLoaded
- processFinalResource
- processResource
- registerFileSystem
- registerResource
- registerResourcePostProcessor
- registerResourcePreProcessor
- removeExtension
- renameResource
- reset
- resourceModified
- resourceSaved
- setPath
- setProxy
- unregisterResource
Methods
cancelOnceLoaded
-
fullpath -
index
Cancels the binding of a onceLoaded
Parameters:
-
fullpathStringfullpath of the resource you want to cancel the binding
-
indexNumberthe 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:
-
fullpathString
Returns:
fullpath cleaned
getBasename
-
fullpath
Returns the filename without the folder or the extension
Parameters:
-
fullpathString
Returns:
filename extension
getExtension
-
fullpath -
complex_extension
Returns the filename extension from an url
Parameters:
-
fullpathStringurl or filename
-
complex_extensionBoolean[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:
-
fullpathString
Returns:
filename extension
getFolder
-
fullpath
Returns the folder from a fullpath
Parameters:
-
fullpathString
Returns:
folder name
getFullURL
-
url -
options
transform a url to a full url taking into account proxy, virtual file systems and local_repository
Parameters:
-
urlString -
optionsObject
Returns:
full url
getMesh
-
filename
returns a mesh resource if it is loaded
Parameters:
-
filenameString
Returns:
getNoCache
-
force
Returns a string to append to any url that should use the browser cache (when updating server info)
Parameters:
-
forceBooleanforce to return a nocache string ignoring the default configuration
Returns:
a string to attach to a url so the file wont be cached
getResource
-
url -
constructor
Returns the resource if it has been loaded, if you want to force to load it, use load
Parameters:
-
urlStringwhere the resource is located (if its a relative url it depends on the path attribute)
-
constructorFunction[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_namesArrayan array containing the resources names
-
allow_filesBool[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:
-
filenameStringcould 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:
-
filenameString
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]
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:
-
urlStringwhere 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
-
[on_complete=null]Function optionalcallback when the resource is loaded and cached, params: callback( resource, url ) //( url, resource, options )
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:
-
resourcesObjectcontains 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:
-
fullpathStringof the resource you want to get the notification once is loaded
-
callbackFunctionthe 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:
-
urlStringwhere the resource is located (if its a relative url it depends on the path attribute)
-
theresource class
-
[options={}]Object optionaloptions to apply to the loaded resource
-
on_completeFunctiononce 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:
-
urlStringwhere the resource is located (if its a relative url it depends on the path attribute)
-
datathe data of the resource (could be string, arraybuffer, image... )
-
[options={}]Object optionaloptions to apply to the loaded resource
-
on_completeFunctiononce 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:
-
nameStringthe filesystem name (the string before the colons in the path)
-
urlStringthe 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:
-
filenameStringfullpath
-
resourceObject
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_typeStringthe name of the class of the resource
-
callbackFunctionthe 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:
-
fileformatsStringthe extension of the formats that this function will parse
-
callbackFunctionthe function to call once the data must be processed, if the process is async it must return true
-
data_typeString -
resource_typeString
removeExtension
-
fullpath -
complex_extension
Returns the url without the extension
Parameters:
-
fullpathStringurl or filename
-
complex_extensionBoolean[optional] removes the extension from the first dot, otherwise only the part from last dot
Returns:
url without extension
renameResource
-
old -
newname -
[skip_event=false]
Changes the name of a resource and sends an event to all components to change it accordingly
Parameters:
-
oldString -
newnameString -
[skip_event=false]Boolean optionalignore sending an event to all components to rename the resource
Returns:
if the file was found
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:
-
resourceObject
resourceSaved
-
resource
Unmarks the resource as modified
Parameters:
-
resourceObject
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:
-
urlString
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_urlString
unregisterResource
-
filename
removes the resources from all the containers
Parameters:
-
filenameString
Returns:
true is removed, false if not found
