Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

pex-gl/pex-loaders

pex-loaders

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Resource loader for PEX.

Installation

npm install pex-loaders

Usage

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

pex-loaders

Typedefs

BasisOptions
DracoOptions
ExrOptions
Ktx2Options

pex-loaders

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

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.

About

Resource loader for PEX.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •