API Docs for:
Show:

LS.ResourcesManager Class

Module: LS

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

()

Methods

cancelOnceLoaded

(
  • fullpath
  • index
)

Cancels the binding of a onceLoaded

Parameters:

  • fullpath String

    fullpath of the resource you want to cancel the binding

  • index Number

    the index of the callback to cancel (as it was returned by onceLoaded)

cleanFullpath

(
  • fullpath
)
String

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:

String:

fullpath cleaned

getBasename

(
  • fullpath
)
String

Returns the filename without the folder or the extension

Parameters:

  • fullpath String

Returns:

String:

filename extension

getExtension

(
  • fullpath
  • complex_extension
)
String

Returns the filename extension from an url

Parameters:

  • fullpath String

    url or filename

  • complex_extension Boolean

    [optional] returns the extension from the first dot, otherwise only the part from last dot

Returns:

String:

filename extension

getFilename

(
  • fullpath
)
String

Returns the filename from a full path

Parameters:

  • fullpath String

Returns:

String:

filename extension

getFolder

(
  • fullpath
)
String

Returns the folder from a fullpath

Parameters:

  • fullpath String

Returns:

String:

folder name

getFullURL

(
  • url
  • options
)
String

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:

String:

full url

getMesh

(
  • filename
)
Mesh

returns a mesh resource if it is loaded

Parameters:

  • filename String

Returns:

Mesh:

getNoCache

(
  • force
)
String

Returns a string to append to any url that should use the browser cache (when updating server info)

Parameters:

  • force Boolean

    force to return a nocache string ignoring the default configuration

Returns:

String:

a string to attach to a url so the file wont be cached

getProtocol

(
  • url
)
String

Returns the url protocol (http, https) or empty string if no protocol was found

Parameters:

  • url String

Returns:

String:

protocol

getResource

(
  • url
  • constructor
)

Returns the resource if it has been loaded, if you want to force to load it, use load

Parameters:

  • url String

    where 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
)
Object

Returns an object containig all the resources and its data (used to export resources)

Parameters:

  • resource_names Array

    an 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:

object with name:data

getResourceType

(
  • resource
)
String

Returns the resource type ("Mesh","Texture","Material","SceneNode",...) of a given resource

Parameters:

  • resource

Returns:

String:

the type in string format

getTexture

(
  • filename
)
Texture

returns a texture resource if it is loaded

Parameters:

  • filename String

    could be a texture itself in which case returns the same texture

Returns:

Texture:

getURLasFile

(
  • filename
)
File

Used to load files and get them as File (or Blob)

Parameters:

  • filename String

Returns:

File:

the file

isLoading

() Boolean

forces to try to reload again resources not found

Returns:

Boolean:

isLoading

() Boolean

Tells if it is loading resources (or an specific resource)

Returns:

Boolean:

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 String

    where the resource is located (if its a relative url it depends on the path attribute)

  • [options={}] Object optional

    options to apply to the loaded resource when processing it { force: to force a reload }

  • [on_complete=null] Function optional

    callback when the resource is loaded and cached, params: callback( resource, url ) //( url, resource, options )

  • [force_load=false] Boolean optional

    if true it will load the resource, even if it already exists

  • [on_error=null] Function optional

    callback in case the file wasnt found

loadResources

(
  • resources
  • [options={}]
)
Number

Loads all the resources in the Object (it uses an object to store not only the filename but also the type)

Parameters:

  • resources Object | Array

    contains all the resources, associated with its type

  • [options={}] Object optional

    options to apply to the loaded resources

Returns:

Number:

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 String

    of the resource you want to get the notification once is loaded

  • callback Function

    the 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 String

    where the resource is located (if its a relative url it depends on the path attribute)

  • the

    resource class

  • [options={}] Object optional

    options to apply to the loaded resource

  • on_complete Function

    once 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 String

    where 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 optional

    options to apply to the loaded resource

  • on_complete Function

    once 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 String

    the filesystem name (the string before the colons in the path)

  • url String

    the 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 String

    fullpath

  • 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 String

    the name of the class of the resource

  • callback Function

    the 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 String

    the extension of the formats that this function will parse

  • callback Function

    the 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
)
String

Returns the url without the extension

Parameters:

  • fullpath String

    url or filename

  • complex_extension Boolean

    [optional] removes the extension from the first dot, otherwise only the part from last dot

Returns:

String:

url without extension

renameResource

(
  • old_name
  • new_name
  • [skip_event=false]
)
Boolean

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 optional

    ignore sending an event to all components to rename the resource

Returns:

Boolean:

if the file was found

replaceExtension

(
  • fullpath
  • extension
)
String

Replaces the extension of a filename

Parameters:

  • fullpath String

    url or filename

  • extension String

Returns:

String:

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
)
Boolean

removes the resources from all the containers

Parameters:

  • filename String

Returns:

Boolean:

true is removed, false if not found