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
| addHandler | Add a pc.ResourceHandler for a resource type. |
| clearCache | Remove resource from cache. |
| destroy | Destroys the resource loader. |
| getFromCache | Check cache for resource from a URL. |
| getHandler | Get a pc.ResourceHandler for a resource type. |
| load | Make a request for a resource from a remote URL. |
| open | Convert raw resource data into a resource instance. |
| patch | Perform any operations on a resource, that requires a dependency on its asset data or any other asset data. |
| removeHandler | Remove a pc.ResourceHandler for a resource type. |
Details
Constructor
Methods
addHandler(type, handler)
Add a pc.ResourceHandler for a resource type. Handler should support atleast load() and open(). Handlers can optionally support patch(asset, assets) to handle dependencies on other assets.
var loader = new ResourceLoader();
loader.addHandler("json", new pc.JsonHandler());
Parameters
| type | string | The name of the resource type that the handler will be registerd with. Can be: |
| handler | pc.ResourceHandler | An instance of a resource handler supporting atleast load() and open(). |
clearCache(url, type)
Remove resource from cache.
Parameters
| url | string | The URL of the resource. |
| type | string | The type of resource. |
destroy()
Destroys the resource loader.
getFromCache(url, type)
Check cache for resource from a URL. If present, return the cached value.
Parameters
| url | string | The URL of the resource to get from the cache. |
| type | string | The type of the resource. |
Returns
*The resource loaded from the cache.
getHandler(type)
Get a pc.ResourceHandler for a resource type.
Parameters
| type | string | The name of the resource type that the handler is registerd with. |
Returns
pc.ResourceHandlerThe registerd handler.
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
| url | string | The URL of the resource to load. |
| type | string | The type of resource expected. |
| callback | pc.callbacks.ResourceLoader | The callback used when the resource is loaded or an error occurs. |
| asset | pc.Asset | Optional 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
| type | string | The 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
| asset | pc.Asset | The asset to patch. |
| assets | pc.AssetRegistry | The asset registry. |
removeHandler(type)
Remove a pc.ResourceHandler for a resource type.
Parameters
| type | string | The name of the type that the handler will be removed. |