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 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 it's 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 resource loader

getFromCache()

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

load(url, type, callback)

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. Handles multiple requests for

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. Passed (err, resource) where err is null if there are no errors

open()

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

patch()

Perform any operations on a resource, that requires a dependency on it's asset data or any other asset data