API Reference

Class List

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.

Summary

Methods

addHandlerAdd a handler for a resource type.
destroyDestroys the resource loader.
getFromCacheCheck cache for resource from a URL.
loadMake a request for a resource from a remote URL.
openConvert raw resource data into a resource instance.
patchPerform any operations on a resource, that requires a dependency on its asset data or any other asset data.

Details

Constructor

ResourceLoader()

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

var loader = new ResourceLoader();
loader.addHandler("json", new pc.JsonHandler());

Parameters

typeStringThe name of the type that the handler will load
handlerpc.ResourceHandlerAn instance of a resource handler supporting load() and open().

destroy()

Destroys the resource loader.

getFromCache(url, type)

Check cache for resource from a URL. If present, return the cached value.

Parameters

urlStringThe URL of the resource to get from the cache.
typeStringThe type of the resource.

Returns

* The resource loaded from the cache.

load(url, type, callback, [asset])

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.

app.loader.load("../path/to/texture.png", "texture", function (err, texture) {
    // use texture here
});

Parameters

urlStringThe URL of the resource to load.
typeStringThe type of resource expected.
callbackfunctionThe callback used when the resource is loaded or an error occurs.
assetpc.AssetOptional asset that is passed into handler Passed (err, resource) where err is null if there are no errors.

open(type, data)

Convert raw resource data into a resource instance. e.g. take 3D model format JSON and return a pc.Model.

Parameters

typeStringThe type of resource.
data*The raw resource data.

Returns

* The parsed resource data.

patch(asset, assets)

Perform any operations on a resource, that requires a dependency on its asset data or any other asset data.

Parameters

assetpc.AssetThe asset to patch.
assetspc.AssetRegistryThe asset registry.