ContainerHandler
Loads files that contain multiple resources. For example glTF files can contain textures, models and animations.
For glTF files, the asset options object can be used to pass load time callbacks for handling the various resources at different stages of loading. The table below lists the resource types and the corresponding supported process functions.
resource | preprocess | process | processAsync | postprocess |
---|---|---|---|---|
global | √ | √ | ||
node | √ | √ | √ | |
light | √ | √ | √ | |
camera | √ | √ | √ | |
animation | √ | √ | ||
material | √ | √ | √ | |
image | √ | √ | √ | |
texture | √ | √ | √ | |
buffer | √ | √ | √ | |
bufferView | √ | √ | √ |
Additional options that can be passed for glTF files: [options.morphPreserveData] - When true, the morph target keeps its data passed using the options, allowing the clone operation. [options.morphPreferHighPrecision] - When true, high precision storage for morph targets should be preferred. This is faster to create and allows higher precision, but takes more memory and might be slower to render. Defaults to false. [options.skipMeshes] - When true, the meshes from the container are not created. This can be useful if you only need access to textures or animations and similar.
For example, to receive a texture preprocess callback:
const containerAsset = new pc.Asset(filename, 'container', { url: url, filename: filename }, null, {
texture: {
preprocess: (gltfTexture) => {
console.log("texture preprocess");
}
}
});
Summary
Properties
handlerType | Type of the resource the handler handles. |
Methods
load | |
open | |
patch |
Details
Properties
Methods
load(url, callback, [asset])
Parameters
url | string, object | Either the URL of the resource to load or a structure containing the load and original URL. |
url.load | string | The URL to be used for loading the resource. |
url.original | string | The original URL to be used for identifying the resource format. This is necessary when loading, for example from blob. |
callback | ResourceHandlerCallback | The callback used when the resource is loaded or an error occurs. |
asset | Asset | Optional asset that is passed by ResourceLoader. |
open(url, data, [asset])
Parameters
url | string | The URL of the resource to open. |
data | * | The raw resource data passed by callback from ResourceHandler#load. |
asset | Asset | Optional asset that is passed by ResourceLoader. |
Returns
*The parsed resource data.
patch(asset, assets)
Parameters
asset | Asset | The asset to patch. |
assets | AssetRegistry | The asset registry. |