Class: ResourceLoader

pc.ResourceLoader

Load resource data, potentially from remote sources. Caches resource on load to prevent multiple requests. Add ResourceHandlers to handle different types of resources.

Constructor

new ResourceLoader(app)

Parameters:
Name Type Description
app pc.Application The application
Source:

Methods

addHandler(type, handler)

Add a handler for a resource type. Handler should support: load(url, callback) and open(url, data). Handlers can optionally support patch(asset, assets) to handle dependencies on other assets
Parameters:
Name Type Description
type String The name of the type that the handler will load
handler pc.ResourceHandler An instance of a resource handler supporting load() and open().
Source:
Example
var loader = new ResourceLoader();
loader.addHandler("json", new pc.JsonHandler());

destroy()

Destroys the resource loader.
Source:

(private) destroy()

Destroys the registry, and releases its resources. Does not unload bundle assets as these should be unloaded by the pc.AssetRegistry.
Source:

(private) disableRetry()

Disables retrying of failed requests when loading assets.
Source:

(private) enableRetry()

Enables retrying of failed requests when loading assets.
Source:

getFromCache(url, type) → {*}

Check cache for resource from a URL. If present, return the cached value.
Parameters:
Name Type Description
url String The URL of the resource to get from the cache.
type String The type of the resource.
Source:
Returns:
The resource loaded from the cache.
Type
*

load(url, type, callback, assetopt)

Make a request for a resource from a remote URL. Parse the returned data using the handler for the specified type. When loaded and parsed, use the callback to return an instance of the resource.
Parameters:
Name Type Attributes Description
url String The URL of the resource to load.
type String The type of resource expected.
callback function The callback used when the resource is loaded or an error occurs.
asset pc.Asset <optional>
Optional asset that is passed into handler Passed (err, resource) where err is null if there are no errors.
Source:
Example
app.loader.load("../path/to/texture.png", "texture", function (err, texture) {
    // use texture here
});

open(type, data) → {*}

Convert raw resource data into a resource instance. e.g. take 3D model format JSON and return a pc.Model.
Parameters:
Name Type Description
type String The type of resource.
data * The raw resource data.
Source:
Returns:
The parsed resource data.
Type
*

patch(asset, assets)

Perform any operations on a resource, that requires a dependency on its asset data or any other asset data.
Parameters:
Name Type Description
asset pc.Asset The asset to patch.
assets pc.AssetRegistry The asset registry.
Source: