pixi-textures
Compressed textures and retina support for pixi v5. Loader can choose textures depends on platform and rendering mode.
You can use previous version with PixiJS v4 - v4.x branch npm version 1.1.8
Supports DDS (S3TC DXT1-3-5, ATC, ATCA/ATC explicit, ATCI/ATC interpolated), PVR (PVRTC, ETC1, S3TC DXT1-3-5, PVRTC 2-4bpp RGB-RGBA), ASTC (all blocks size) 2D LDR preset
Supports advanced DXT compression crunch
Minimum demo
Pretty easy to hack parser into your loader.
let loader = ;loader;loader;
However if somehow pixi-compressed-textures was initialized after creation of loader, add a ImageParser to it:
loader;
Full example
If your app has no detection of supported formats it is not ready for production.
This example shows how to handle multiple resolutions and multiple image formats for single images and for atlases.
const app = resolution: windowdevicePixelRatio || 1 ;documentbody; // use empty array if you dont want to use detect featureconst extensions = PIXIcompressedTextures;const loader = apploader; loader;// use @2x texture if resolution is 2, use dds format if its windowsconst textureOptions1 = metadata: choice: '@2x.png' '.dds' '@2x.dds' ;// use dds format if its windows but dont care for retinaconst textureOptions2 = metadata: choice: '.dds' ;// while loading atlas, choose resolution for atlas and choose format for imageconst atlasOptions = metadata: choice: '@2x.json' '@1x.json' imageMetadata: choice: '.dds' ; loader // will be swapped to @1xб because @1x is always detected and we've specified it in atlasOptions // look up `detectExtensions` code, params and output ;
Fixing it in cache
To fix url names in cache your have to add one extra loader plugin: extensionFixer.
It should be added after all other image-related plugins.
That way in the example above, image will appear under name examples/assets/pixi-compressed-textures/building1.png
and not examples/assets/pixi-compressed-textures/building1.dds
.
loader;
Using crunch
To use crunch you have to manually add lib/crn_decomp.js
to your build.
We cant help you with adding it in webpack or browserify or angular, its your job.
Using BASIS
Basis format disabled by default and require transcoder. Transcoder may be got from: https://github.com/BinomialLLC/basis_universal/tree/master/webgl/transcoder
This lib can't include transcoder because transcoder use wasm and is heavy (greater then 300kb) at the moment.
For using BASIS, you can bind transcoder to load, it register .basis
to loader automatically.
Simple way:
;
Worker:
Because BASIS is synchronous then it transcode a RGB texture of 1024x1024 pixels ~30ms in main thread. Using it in Worker is the rightest way.
WorkedBASISLoader
uses workers for transcoding.
There are few API for it:
WorkedBASISLoader : Promise<void>
WorkedBASISLoader: Promise<void>`
Note: wasmSource is transferred to workers for faster initialisation.
You must call 1 or 2 before loading of .basis
files .
Ex:
apprenderertexture; // get supported extensionsconst ext = apprenderertexturecompressedExtensions;const WBL = PIXIcompressedTexturesWorkedBASISLoader;const pathToTranscoder = "/path/to/trancoder"; WBL;
Note about atlases
PIXI recognizes resolution of atlas by suffix (@1x, @2x, ... )
If you dont specify that, resolution of the atlas will be taken from "meta.scale" which in our example is 1 and 0.5 instead of 2 and 1. It will shrink everything!
Browserify / WebPack / Angular
If you use browserify or Webpack you can use pixi-textures like this:
Building
You will need to have node
Then you can install dependencies and build:
npm inpm run build
That will output the built distributables to ./dist
.