Resource loader for PEX.
npm install pex-loaders








Resource loader for PEX.
``bash`
npm install pex-loaders
`js
import {
loadUltraHdr,
loadHdr,
loadExr,
loadDraco,
loadKtx2,
} from "pex-loaders";
import createContext from "pex-context";
const ctx = createContext();
const getEnvMap = async (ctx, url) => {
if (url.endsWith(".jpg")) return await loadUltraHdr(ctx, url);
if (url.endsWith(".hdr")) return await loadHdr(ctx, url);
if (url.endsWith(".exr")) return await loadExr(ctx, url);
throw new Error("Unsupported env map file type");
};
const loadDracoGeometry = async (urlOrArrayBuffer) => {
return await loadDraco(urlOrArrayBuffer, {
transcoderPath: "assets/decoders/draco/",
});
};
const loadKtxTexture = async (ctx, urlOrArrayBuffer) => {
return await loadKtx2(urlOrArrayBuffer, {
basisOptions: {
gl: ctx.gl,
transcoderPath: "assets/decoders/basis/",
},
});
};
``
- pex-loaders
- [.loadBasis(urlOrArrayBuffer, [options])](#module_pex-loaders.loadBasis) ⇒ Promise.<object>
- [.loadDraco(urlOrArrayBuffer, [options])](#module_pex-loaders.loadDraco) ⇒ Promise.<object>
- [.loadExr(ctx, urlOrArrayBuffer, [options], [texture])](#module_pex-loaders.loadExr) ⇒ Promise.<ctx.texture2D>
- [.loadHdr(ctx, urlOrArrayBuffer, [texture])](#module_pex-loaders.loadHdr) ⇒ Promise.<ctx.texture2D>
- [.loadKtx2(urlOrArrayBuffer, [options])](#module_pex-loaders.loadKtx2) ⇒ Promise.<object>
- [.loadUltraHdr(ctx, urlOrArrayBuffer, [texture])](#module_pex-loaders.loadUltraHdr) ⇒ Promise.<ctx.texture2D>
Load a basis file or array buffer as texture options
Kind: static method of pex-loaders
| Param | Type |
| ---------------- | ----------------------------------------------------------------------------------------- |
| urlOrArrayBuffer | string \| ArrayBuffer \| Array.<ArrayBuffer> |
| [options] | BasisOptions |
Load a draco file or array buffer as a texture
Kind: static method of pex-loaders
| Param | Type |
| ---------------- | ----------------------------------------------- |
| urlOrArrayBuffer | string \| ArrayBuffer |
| [options] | DracoOptions |
Load an EXR file or array buffer as a texture
Kind: static method of pex-loaders
| Param | Type | Description |
| ---------------- | ----------------------------------------------- | ---------------------------------------------------- |
| ctx | ctx | |
| urlOrArrayBuffer | string \| ArrayBuffer | |
| [options] | ExrOptions | |
| [texture] | ctx.texture2D | Optionally pass an already created texture resource. |
Load an HDR file or array buffer as a texture
Kind: static method of pex-loaders
| Param | Type | Description |
| ---------------- | ----------------------------------------------- | ---------------------------------------------------- |
| ctx | ctx | |
| urlOrArrayBuffer | string \| ArrayBuffer | |
| [texture] | ctx.texture2D | Optionally pass an already created texture resource. |
Load a ktx2 file or array buffer as texture options
- KTX: http://github.khronos.org/KTX-Specification/
- DFD: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html#basicdescriptor
Kind: static method of pex-loaders
| Param | Type |
| ---------------- | ----------------------------------------------- |
| urlOrArrayBuffer | string \| ArrayBuffer |
| [options] | Ktx2Options |
Load an Ultra HDR (aka gain map) file or array buffer as a texture
Kind: static method of pex-loaders
| Param | Type | Description |
| ---------------- | ----------------------------------------------- | ---------------------------------------------------- |
| ctx | ctx | |
| urlOrArrayBuffer | string \| ArrayBuffer | |
| [texture] | ctx.texture2D | Optionally pass an already created texture resource. |
Kind: global typedef
Properties
| Name | Type | Default |
| ----------------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| gl | WebGLRenderingContext \| WebGL2RenderingContext | |
| [transcoderPath] | string | "'assets/decoders/basis/'" |
| [transcodeConfig] | object | {} |
| [workerLimit] | number | 4 |
| [workerConfig] | object | { astcSupported, etc1Supported, etc2Supported, dxtSupported, bptcSupported, pvrtcSupported } |
Kind: global typedef
Properties
| Name | Type | Default |
| ----------------- | ------------------- | ----------------------------------------------------------- |
| [transcoderPath] | string | "'assets/decoders/draco/'" |
| [transcodeConfig] | object | {} |
| [workerLimit] | number | 4 |
| [workerConfig] | object | {} |
Kind: global typedef
Properties
| Name | Type | Default | Description |
| ------ | ------------------- | ----------------- | ------------------------------------------------ |
| [type] | number | 1015 | Float or Half Float WebGL type. (1015 for Float) |
Kind: global typedef
Properties
| Name | Type | Default |
| -------------- | ------------------------------------------ | --------------- |
| [basisOptions] | BasisOptions | {} |
MIT. See license file.