pex-loaders
v1.2.1
Published
Resource loader for PEX.
Readme
pex-loaders
Resource loader for PEX.
Installation
npm install pex-loadersUsage
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/",
},
});
};API
Modules
Typedefs
pex-loaders
- pex-loaders
- .loadBasis(urlOrArrayBuffer, [options]) ⇒ Promise.<object>
- .loadDraco(urlOrArrayBuffer, [options]) ⇒ Promise.<object>
- .loadExr(ctx, urlOrArrayBuffer, [options], [texture]) ⇒ Promise.<ctx.texture2D>
- .loadHdr(ctx, urlOrArrayBuffer, [texture]) ⇒ Promise.<ctx.texture2D>
- .loadKtx2(urlOrArrayBuffer, [options]) ⇒ Promise.<object>
- .loadUltraHdr(ctx, urlOrArrayBuffer, [texture]) ⇒ Promise.<ctx.texture2D>
pex-loaders.loadBasis(urlOrArrayBuffer, [options]) ⇒ Promise.<object>
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 |
pex-loaders.loadDraco(urlOrArrayBuffer, [options]) ⇒ Promise.<object>
Load a draco file or array buffer as a texture
Kind: static method of pex-loaders
| Param | Type | | ---------------- | ----------------------------------------------- | | urlOrArrayBuffer | string | ArrayBuffer | | [options] | DracoOptions |
pex-loaders.loadExr(ctx, urlOrArrayBuffer, [options], [texture]) ⇒ Promise.<ctx.texture2D>
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. |
pex-loaders.loadHdr(ctx, urlOrArrayBuffer, [texture]) ⇒ Promise.<ctx.texture2D>
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. |
pex-loaders.loadKtx2(urlOrArrayBuffer, [options]) ⇒ Promise.<object>
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 |
pex-loaders.loadUltraHdr(ctx, urlOrArrayBuffer, [texture]) ⇒ Promise.<ctx.texture2D>
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. |
BasisOptions
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 } |
DracoOptions
Kind: global typedef Properties
| Name | Type | Default | | ----------------- | ------------------- | ----------------------------------------------------------- | | [transcoderPath] | string | "'assets/decoders/draco/'" | | [transcodeConfig] | object | {} | | [workerLimit] | number | 4 | | [workerConfig] | object | {} |
ExrOptions
Kind: global typedef Properties
| Name | Type | Default | Description | | ------ | ------------------- | ----------------- | ------------------------------------------------ | | [type] | number | 1015 | Float or Half Float WebGL type. (1015 for Float) |
Ktx2Options
Kind: global typedef Properties
| Name | Type | Default | | -------------- | ------------------------------------------ | --------------- | | [basisOptions] | BasisOptions | {} |
License
MIT. See license file.
