This commit is contained in:
2025-01-04 00:34:03 +01:00
parent 41829408dc
commit 0ca14bbc19
18111 changed files with 1871397 additions and 0 deletions

View File

@@ -0,0 +1,203 @@
"use strict";
var compressedTextures = require("@pixi/compressed-textures"), core = require("@pixi/core"), Basis = require("../Basis.js"), TranscoderWorker = require("../TranscoderWorker.js");
const _BasisParser = class _BasisParser2 {
/**
* Runs transcoding and populates imageArray. It will run the transcoding in a web worker
* if they are available.
* @private
*/
static async transcode(arrayBuffer) {
let resources;
return typeof Worker < "u" && _BasisParser2.TranscoderWorker.wasmSource ? resources = await _BasisParser2.transcodeAsync(arrayBuffer) : resources = _BasisParser2.transcodeSync(arrayBuffer), resources;
}
/**
* Finds a suitable worker for transcoding and sends a transcoding request
* @private
* @async
*/
static async transcodeAsync(arrayBuffer) {
!_BasisParser2.defaultRGBAFormat && !_BasisParser2.defaultRGBFormat && _BasisParser2.autoDetectFormats();
const workerPool = _BasisParser2.workerPool;
let leastLoad = 268435456, worker = null;
for (let i = 0, j = workerPool.length; i < j; i++)
workerPool[i].load < leastLoad && (worker = workerPool[i], leastLoad = worker.load);
worker || (worker = new TranscoderWorker.TranscoderWorker(), workerPool.push(worker)), await worker.initAsync();
const response = await worker.transcodeAsync(
new Uint8Array(arrayBuffer),
_BasisParser2.defaultRGBAFormat.basisFormat,
_BasisParser2.defaultRGBFormat.basisFormat
), basisFormat = response.basisFormat, imageArray = response.imageArray, fallbackMode = basisFormat > 12;
let imageResources;
if (fallbackMode)
imageResources = imageArray.map(
(image) => new core.BufferResource(
new Uint16Array(image.levelArray[0].levelBuffer.buffer),
{
width: image.width,
height: image.height
}
)
);
else {
const format = Basis.BASIS_FORMAT_TO_INTERNAL_FORMAT[response.basisFormat];
imageResources = new Array(imageArray.length);
for (let i = 0, j = imageArray.length; i < j; i++)
imageResources[i] = new compressedTextures.CompressedTextureResource(null, {
format,
width: imageArray[i].width,
height: imageArray[i].height,
levelBuffers: imageArray[i].levelArray,
levels: imageArray[i].levelArray.length
});
}
return imageResources.basisFormat = basisFormat, imageResources;
}
/**
* Runs transcoding on the main thread.
* @private
*/
static transcodeSync(arrayBuffer) {
!_BasisParser2.defaultRGBAFormat && !_BasisParser2.defaultRGBFormat && _BasisParser2.autoDetectFormats();
const BASIS = _BasisParser2.basisBinding, data = new Uint8Array(arrayBuffer), basisFile = new BASIS.BasisFile(data), imageCount = basisFile.getNumImages(), basisFormat = basisFile.getHasAlpha() ? _BasisParser2.defaultRGBAFormat.basisFormat : _BasisParser2.defaultRGBFormat.basisFormat, basisFallbackFormat = Basis.BASIS_FORMATS.cTFRGB565, imageResources = new Array(imageCount);
let fallbackMode = _BasisParser2.fallbackMode;
if (!basisFile.startTranscoding())
return console.error("Basis failed to start transcoding!"), basisFile.close(), basisFile.delete(), null;
for (let i = 0; i < imageCount; i++) {
const levels = fallbackMode ? 1 : basisFile.getNumLevels(i), width = basisFile.getImageWidth(i, 0), height = basisFile.getImageHeight(i, 0), alignedWidth = width + 3 & -4, alignedHeight = height + 3 & -4, imageLevels = new Array(levels);
for (let j = 0; j < levels; j++) {
const levelWidth = basisFile.getImageWidth(i, j), levelHeight = basisFile.getImageHeight(i, j), byteSize = basisFile.getImageTranscodedSizeInBytes(
i,
0,
fallbackMode ? basisFallbackFormat : basisFormat
);
if (imageLevels[j] = {
levelID: j,
levelBuffer: new Uint8Array(byteSize),
levelWidth,
levelHeight
}, !basisFile.transcodeImage(
imageLevels[j].levelBuffer,
i,
0,
fallbackMode ? basisFallbackFormat : basisFormat,
!1,
!1
))
if (fallbackMode) {
console.error(`Basis failed to transcode image ${i}, level 0!`);
break;
} else {
i = -1, fallbackMode = !0, console.warn(`Basis failed to transcode image ${i}, level 0 to a compressed texture format. Retrying to an uncompressed fallback format!`);
continue;
}
}
let imageResource;
fallbackMode ? imageResource = new core.BufferResource(
new Uint16Array(imageLevels[0].levelBuffer.buffer),
{ width, height }
) : imageResource = new compressedTextures.CompressedTextureResource(null, {
format: Basis.BASIS_FORMAT_TO_INTERNAL_FORMAT[basisFormat],
width: alignedWidth,
height: alignedHeight,
levelBuffers: imageLevels,
levels
}), imageResources[i] = imageResource;
}
basisFile.close(), basisFile.delete();
const transcodedResources = imageResources;
return transcodedResources.basisFormat = fallbackMode ? basisFallbackFormat : basisFormat, transcodedResources;
}
/**
* Detects the available compressed texture formats on the device.
* @param extensions - extensions provided by a WebGL context
* @ignore
*/
static autoDetectFormats(extensions) {
if (!extensions) {
const gl = core.settings.ADAPTER.createCanvas().getContext("webgl");
if (!gl) {
console.error("WebGL not available for BASIS transcoding. Silently failing.");
return;
}
extensions = {
bptc: gl.getExtension("EXT_texture_compression_bptc"),
astc: gl.getExtension("WEBGL_compressed_texture_astc"),
etc: gl.getExtension("WEBGL_compressed_texture_etc"),
s3tc: gl.getExtension("WEBGL_compressed_texture_s3tc"),
s3tc_sRGB: gl.getExtension("WEBGL_compressed_texture_s3tc_srgb"),
/* eslint-disable-line camelcase */
pvrtc: gl.getExtension("WEBGL_compressed_texture_pvrtc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),
etc1: gl.getExtension("WEBGL_compressed_texture_etc1"),
atc: gl.getExtension("WEBGL_compressed_texture_atc")
};
}
const supportedFormats = {};
for (const key in extensions) {
const extension = extensions[key];
extension && Object.assign(supportedFormats, Object.getPrototypeOf(extension));
}
for (let i = 0; i < 2; i++) {
const detectWithAlpha = !!i;
let internalFormat, basisFormat;
for (const id in supportedFormats)
if (internalFormat = supportedFormats[id], basisFormat = Basis.INTERNAL_FORMAT_TO_BASIS_FORMAT[internalFormat], basisFormat !== void 0 && (detectWithAlpha && Basis.BASIS_FORMATS_ALPHA[basisFormat] || !detectWithAlpha && !Basis.BASIS_FORMATS_ALPHA[basisFormat]))
break;
internalFormat ? _BasisParser2[detectWithAlpha ? "defaultRGBAFormat" : "defaultRGBFormat"] = {
textureFormat: internalFormat,
basisFormat
} : (_BasisParser2[detectWithAlpha ? "defaultRGBAFormat" : "defaultRGBFormat"] = {
textureFormat: core.TYPES.UNSIGNED_SHORT_5_6_5,
basisFormat: Basis.BASIS_FORMATS.cTFRGB565
}, _BasisParser2.fallbackMode = !0);
}
}
/**
* Binds the basis_universal transcoder to decompress *.basis files. You must initialize the transcoder library yourself.
* @example
* import { BasisParser } from '@pixi/basis';
*
* // BASIS() returns a Promise-like object
* globalThis.BASIS().then((basisLibrary) =>
* {
* // Initialize basis-library; otherwise, transcoded results maybe corrupt!
* basisLibrary.initializeBasis();
*
* // Bind BasisParser to the transcoder
* BasisParser.bindTranscoder(basisLibrary);
* });
* @param basisLibrary - the initialized transcoder library
* @private
*/
static bindTranscoder(basisLibrary) {
_BasisParser2.basisBinding = basisLibrary;
}
/**
* Loads the transcoder source code for use in {@link PIXI.BasisParser.TranscoderWorker}.
* @private
* @param jsURL - URL to the javascript basis transcoder
* @param wasmURL - URL to the wasm basis transcoder
*/
static loadTranscoder(jsURL, wasmURL) {
return _BasisParser2.TranscoderWorker.loadTranscoder(jsURL, wasmURL);
}
/**
* Set the transcoder source code directly
* @private
* @param jsSource - source for the javascript basis transcoder
* @param wasmSource - source for the wasm basis transcoder
*/
static setTranscoder(jsSource, wasmSource) {
_BasisParser2.TranscoderWorker.setTranscoder(jsSource, wasmSource);
}
static get TRANSCODER_WORKER_POOL_LIMIT() {
return this.workerPool.length || 1;
}
static set TRANSCODER_WORKER_POOL_LIMIT(limit) {
for (let i = this.workerPool.length; i < limit; i++)
this.workerPool[i] = new TranscoderWorker.TranscoderWorker(), this.workerPool[i].initAsync();
}
};
_BasisParser.fallbackMode = !1, _BasisParser.workerPool = [], _BasisParser.TranscoderWorker = TranscoderWorker.TranscoderWorker;
let BasisParser = _BasisParser;
exports.BasisParser = BasisParser;
//# sourceMappingURL=BasisParser.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,207 @@
import { CompressedTextureResource } from "@pixi/compressed-textures";
import { BufferResource, settings, TYPES } from "@pixi/core";
import { BASIS_FORMAT_TO_INTERNAL_FORMAT, BASIS_FORMATS, INTERNAL_FORMAT_TO_BASIS_FORMAT, BASIS_FORMATS_ALPHA } from "../Basis.mjs";
import { TranscoderWorker } from "../TranscoderWorker.mjs";
const _BasisParser = class _BasisParser2 {
/**
* Runs transcoding and populates imageArray. It will run the transcoding in a web worker
* if they are available.
* @private
*/
static async transcode(arrayBuffer) {
let resources;
return typeof Worker < "u" && _BasisParser2.TranscoderWorker.wasmSource ? resources = await _BasisParser2.transcodeAsync(arrayBuffer) : resources = _BasisParser2.transcodeSync(arrayBuffer), resources;
}
/**
* Finds a suitable worker for transcoding and sends a transcoding request
* @private
* @async
*/
static async transcodeAsync(arrayBuffer) {
!_BasisParser2.defaultRGBAFormat && !_BasisParser2.defaultRGBFormat && _BasisParser2.autoDetectFormats();
const workerPool = _BasisParser2.workerPool;
let leastLoad = 268435456, worker = null;
for (let i = 0, j = workerPool.length; i < j; i++)
workerPool[i].load < leastLoad && (worker = workerPool[i], leastLoad = worker.load);
worker || (worker = new TranscoderWorker(), workerPool.push(worker)), await worker.initAsync();
const response = await worker.transcodeAsync(
new Uint8Array(arrayBuffer),
_BasisParser2.defaultRGBAFormat.basisFormat,
_BasisParser2.defaultRGBFormat.basisFormat
), basisFormat = response.basisFormat, imageArray = response.imageArray, fallbackMode = basisFormat > 12;
let imageResources;
if (fallbackMode)
imageResources = imageArray.map(
(image) => new BufferResource(
new Uint16Array(image.levelArray[0].levelBuffer.buffer),
{
width: image.width,
height: image.height
}
)
);
else {
const format = BASIS_FORMAT_TO_INTERNAL_FORMAT[response.basisFormat];
imageResources = new Array(imageArray.length);
for (let i = 0, j = imageArray.length; i < j; i++)
imageResources[i] = new CompressedTextureResource(null, {
format,
width: imageArray[i].width,
height: imageArray[i].height,
levelBuffers: imageArray[i].levelArray,
levels: imageArray[i].levelArray.length
});
}
return imageResources.basisFormat = basisFormat, imageResources;
}
/**
* Runs transcoding on the main thread.
* @private
*/
static transcodeSync(arrayBuffer) {
!_BasisParser2.defaultRGBAFormat && !_BasisParser2.defaultRGBFormat && _BasisParser2.autoDetectFormats();
const BASIS = _BasisParser2.basisBinding, data = new Uint8Array(arrayBuffer), basisFile = new BASIS.BasisFile(data), imageCount = basisFile.getNumImages(), basisFormat = basisFile.getHasAlpha() ? _BasisParser2.defaultRGBAFormat.basisFormat : _BasisParser2.defaultRGBFormat.basisFormat, basisFallbackFormat = BASIS_FORMATS.cTFRGB565, imageResources = new Array(imageCount);
let fallbackMode = _BasisParser2.fallbackMode;
if (!basisFile.startTranscoding())
return console.error("Basis failed to start transcoding!"), basisFile.close(), basisFile.delete(), null;
for (let i = 0; i < imageCount; i++) {
const levels = fallbackMode ? 1 : basisFile.getNumLevels(i), width = basisFile.getImageWidth(i, 0), height = basisFile.getImageHeight(i, 0), alignedWidth = width + 3 & -4, alignedHeight = height + 3 & -4, imageLevels = new Array(levels);
for (let j = 0; j < levels; j++) {
const levelWidth = basisFile.getImageWidth(i, j), levelHeight = basisFile.getImageHeight(i, j), byteSize = basisFile.getImageTranscodedSizeInBytes(
i,
0,
fallbackMode ? basisFallbackFormat : basisFormat
);
if (imageLevels[j] = {
levelID: j,
levelBuffer: new Uint8Array(byteSize),
levelWidth,
levelHeight
}, !basisFile.transcodeImage(
imageLevels[j].levelBuffer,
i,
0,
fallbackMode ? basisFallbackFormat : basisFormat,
!1,
!1
))
if (fallbackMode) {
console.error(`Basis failed to transcode image ${i}, level 0!`);
break;
} else {
i = -1, fallbackMode = !0, console.warn(`Basis failed to transcode image ${i}, level 0 to a compressed texture format. Retrying to an uncompressed fallback format!`);
continue;
}
}
let imageResource;
fallbackMode ? imageResource = new BufferResource(
new Uint16Array(imageLevels[0].levelBuffer.buffer),
{ width, height }
) : imageResource = new CompressedTextureResource(null, {
format: BASIS_FORMAT_TO_INTERNAL_FORMAT[basisFormat],
width: alignedWidth,
height: alignedHeight,
levelBuffers: imageLevels,
levels
}), imageResources[i] = imageResource;
}
basisFile.close(), basisFile.delete();
const transcodedResources = imageResources;
return transcodedResources.basisFormat = fallbackMode ? basisFallbackFormat : basisFormat, transcodedResources;
}
/**
* Detects the available compressed texture formats on the device.
* @param extensions - extensions provided by a WebGL context
* @ignore
*/
static autoDetectFormats(extensions) {
if (!extensions) {
const gl = settings.ADAPTER.createCanvas().getContext("webgl");
if (!gl) {
console.error("WebGL not available for BASIS transcoding. Silently failing.");
return;
}
extensions = {
bptc: gl.getExtension("EXT_texture_compression_bptc"),
astc: gl.getExtension("WEBGL_compressed_texture_astc"),
etc: gl.getExtension("WEBGL_compressed_texture_etc"),
s3tc: gl.getExtension("WEBGL_compressed_texture_s3tc"),
s3tc_sRGB: gl.getExtension("WEBGL_compressed_texture_s3tc_srgb"),
/* eslint-disable-line camelcase */
pvrtc: gl.getExtension("WEBGL_compressed_texture_pvrtc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),
etc1: gl.getExtension("WEBGL_compressed_texture_etc1"),
atc: gl.getExtension("WEBGL_compressed_texture_atc")
};
}
const supportedFormats = {};
for (const key in extensions) {
const extension = extensions[key];
extension && Object.assign(supportedFormats, Object.getPrototypeOf(extension));
}
for (let i = 0; i < 2; i++) {
const detectWithAlpha = !!i;
let internalFormat, basisFormat;
for (const id in supportedFormats)
if (internalFormat = supportedFormats[id], basisFormat = INTERNAL_FORMAT_TO_BASIS_FORMAT[internalFormat], basisFormat !== void 0 && (detectWithAlpha && BASIS_FORMATS_ALPHA[basisFormat] || !detectWithAlpha && !BASIS_FORMATS_ALPHA[basisFormat]))
break;
internalFormat ? _BasisParser2[detectWithAlpha ? "defaultRGBAFormat" : "defaultRGBFormat"] = {
textureFormat: internalFormat,
basisFormat
} : (_BasisParser2[detectWithAlpha ? "defaultRGBAFormat" : "defaultRGBFormat"] = {
textureFormat: TYPES.UNSIGNED_SHORT_5_6_5,
basisFormat: BASIS_FORMATS.cTFRGB565
}, _BasisParser2.fallbackMode = !0);
}
}
/**
* Binds the basis_universal transcoder to decompress *.basis files. You must initialize the transcoder library yourself.
* @example
* import { BasisParser } from '@pixi/basis';
*
* // BASIS() returns a Promise-like object
* globalThis.BASIS().then((basisLibrary) =>
* {
* // Initialize basis-library; otherwise, transcoded results maybe corrupt!
* basisLibrary.initializeBasis();
*
* // Bind BasisParser to the transcoder
* BasisParser.bindTranscoder(basisLibrary);
* });
* @param basisLibrary - the initialized transcoder library
* @private
*/
static bindTranscoder(basisLibrary) {
_BasisParser2.basisBinding = basisLibrary;
}
/**
* Loads the transcoder source code for use in {@link PIXI.BasisParser.TranscoderWorker}.
* @private
* @param jsURL - URL to the javascript basis transcoder
* @param wasmURL - URL to the wasm basis transcoder
*/
static loadTranscoder(jsURL, wasmURL) {
return _BasisParser2.TranscoderWorker.loadTranscoder(jsURL, wasmURL);
}
/**
* Set the transcoder source code directly
* @private
* @param jsSource - source for the javascript basis transcoder
* @param wasmSource - source for the wasm basis transcoder
*/
static setTranscoder(jsSource, wasmSource) {
_BasisParser2.TranscoderWorker.setTranscoder(jsSource, wasmSource);
}
static get TRANSCODER_WORKER_POOL_LIMIT() {
return this.workerPool.length || 1;
}
static set TRANSCODER_WORKER_POOL_LIMIT(limit) {
for (let i = this.workerPool.length; i < limit; i++)
this.workerPool[i] = new TranscoderWorker(), this.workerPool[i].initAsync();
}
};
_BasisParser.fallbackMode = !1, _BasisParser.workerPool = [], _BasisParser.TranscoderWorker = TranscoderWorker;
let BasisParser = _BasisParser;
export {
BasisParser
};
//# sourceMappingURL=BasisParser.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,14 @@
"use strict";
var core = require("@pixi/core"), BasisParser = require("./BasisParser.js");
const detectBasis = {
extension: {
type: core.ExtensionType.DetectionParser,
priority: 3
},
test: async () => !!(BasisParser.BasisParser.basisBinding && BasisParser.BasisParser.TranscoderWorker.wasmSource),
add: async (formats) => [...formats, "basis"],
remove: async (formats) => formats.filter((f) => f !== "basis")
};
core.extensions.add(detectBasis);
exports.detectBasis = detectBasis;
//# sourceMappingURL=detectBasis.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"detectBasis.js","sources":["../../src/loader/detectBasis.ts"],"sourcesContent":["import { extensions, ExtensionType } from '@pixi/core';\nimport { BasisParser } from './BasisParser';\n\nimport type { FormatDetectionParser } from '@pixi/assets';\n\nexport const detectBasis = {\n extension: {\n type: ExtensionType.DetectionParser,\n priority: 3,\n },\n test: async (): Promise<boolean> => !!(BasisParser.basisBinding && BasisParser.TranscoderWorker.wasmSource),\n add: async (formats) => [...formats, 'basis'],\n remove: async (formats) => formats.filter((f) => f !== 'basis'),\n} as FormatDetectionParser;\n\nextensions.add(detectBasis);\n"],"names":["ExtensionType","BasisParser","extensions"],"mappings":";;AAKO,MAAM,cAAc;AAAA,EACvB,WAAW;AAAA,IACP,MAAMA,KAAc,cAAA;AAAA,IACpB,UAAU;AAAA,EACd;AAAA,EACA,MAAM,YAA8B,CAAC,EAAEC,YAAY,YAAA,gBAAgBA,wBAAY,iBAAiB;AAAA,EAChG,KAAK,OAAO,YAAY,CAAC,GAAG,SAAS,OAAO;AAAA,EAC5C,QAAQ,OAAO,YAAY,QAAQ,OAAO,CAAC,MAAM,MAAM,OAAO;AAClE;AAEAC,KAAAA,WAAW,IAAI,WAAW;;"}

View File

@@ -0,0 +1,16 @@
import { ExtensionType, extensions } from "@pixi/core";
import { BasisParser } from "./BasisParser.mjs";
const detectBasis = {
extension: {
type: ExtensionType.DetectionParser,
priority: 3
},
test: async () => !!(BasisParser.basisBinding && BasisParser.TranscoderWorker.wasmSource),
add: async (formats) => [...formats, "basis"],
remove: async (formats) => formats.filter((f) => f !== "basis")
};
extensions.add(detectBasis);
export {
detectBasis
};
//# sourceMappingURL=detectBasis.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"detectBasis.mjs","sources":["../../src/loader/detectBasis.ts"],"sourcesContent":["import { extensions, ExtensionType } from '@pixi/core';\nimport { BasisParser } from './BasisParser';\n\nimport type { FormatDetectionParser } from '@pixi/assets';\n\nexport const detectBasis = {\n extension: {\n type: ExtensionType.DetectionParser,\n priority: 3,\n },\n test: async (): Promise<boolean> => !!(BasisParser.basisBinding && BasisParser.TranscoderWorker.wasmSource),\n add: async (formats) => [...formats, 'basis'],\n remove: async (formats) => formats.filter((f) => f !== 'basis'),\n} as FormatDetectionParser;\n\nextensions.add(detectBasis);\n"],"names":[],"mappings":";;AAKO,MAAM,cAAc;AAAA,EACvB,WAAW;AAAA,IACP,MAAM,cAAc;AAAA,IACpB,UAAU;AAAA,EACd;AAAA,EACA,MAAM,YAA8B,CAAC,EAAE,YAAY,gBAAgB,YAAY,iBAAiB;AAAA,EAChG,KAAK,OAAO,YAAY,CAAC,GAAG,SAAS,OAAO;AAAA,EAC5C,QAAQ,OAAO,YAAY,QAAQ,OAAO,CAAC,MAAM,MAAM,OAAO;AAClE;AAEA,WAAW,IAAI,WAAW;"}

View File

@@ -0,0 +1,6 @@
"use strict";
var BasisParser = require("./BasisParser.js"), detectBasis = require("./detectBasis.js"), loadBasis = require("./loadBasis.js");
exports.BasisParser = BasisParser.BasisParser;
exports.detectBasis = detectBasis.detectBasis;
exports.loadBasis = loadBasis.loadBasis;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}

View File

@@ -0,0 +1,9 @@
import { BasisParser } from "./BasisParser.mjs";
import { detectBasis } from "./detectBasis.mjs";
import { loadBasis } from "./loadBasis.mjs";
export {
BasisParser,
detectBasis,
loadBasis
};
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}

View File

@@ -0,0 +1,32 @@
"use strict";
var assets = require("@pixi/assets"), compressedTextures = require("@pixi/compressed-textures"), core = require("@pixi/core"), Basis = require("../Basis.js"), TranscoderWorker = require("../TranscoderWorker.js"), BasisParser = require("./BasisParser.js");
const loadBasis = {
extension: {
type: core.ExtensionType.LoadParser,
priority: assets.LoaderParserPriority.High
},
name: "loadBasis",
test(url) {
return assets.checkExtension(url, ".basis");
},
async load(url, asset, loader) {
await TranscoderWorker.TranscoderWorker.onTranscoderInitialized;
const arrayBuffer = await (await core.settings.ADAPTER.fetch(url)).arrayBuffer(), resources = await BasisParser.BasisParser.transcode(arrayBuffer), type = Basis.BASIS_FORMAT_TO_TYPE[resources.basisFormat], format = resources.basisFormat !== Basis.BASIS_FORMATS.cTFRGBA32 ? core.FORMATS.RGB : core.FORMATS.RGBA, textures = resources.map((resource) => {
const base = new core.BaseTexture(resource, {
mipmap: resource instanceof compressedTextures.CompressedTextureResource && resource.levels > 1 ? core.MIPMAP_MODES.ON_MANUAL : core.MIPMAP_MODES.OFF,
alphaMode: core.ALPHA_MODES.NO_PREMULTIPLIED_ALPHA,
type,
format,
...asset.data
});
return assets.createTexture(base, loader, url);
});
return textures.length === 1 ? textures[0] : textures;
},
unload(texture) {
Array.isArray(texture) ? texture.forEach((t) => t.destroy(!0)) : texture.destroy(!0);
}
};
core.extensions.add(loadBasis);
exports.loadBasis = loadBasis;
//# sourceMappingURL=loadBasis.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"loadBasis.js","sources":["../../src/loader/loadBasis.ts"],"sourcesContent":["import { checkExtension, createTexture, LoaderParserPriority } from '@pixi/assets';\nimport { CompressedTextureResource } from '@pixi/compressed-textures';\nimport { ALPHA_MODES, BaseTexture, extensions, ExtensionType, FORMATS, MIPMAP_MODES, settings } from '@pixi/core';\nimport { BASIS_FORMAT_TO_TYPE, BASIS_FORMATS } from '../Basis';\nimport { TranscoderWorker } from '../TranscoderWorker';\nimport { BasisParser } from './BasisParser';\n\nimport type { Loader, LoaderParser, ResolvedAsset } from '@pixi/assets';\nimport type { IBaseTextureOptions, Texture, TYPES } from '@pixi/core';\n\n/** Load BASIS textures! */\nexport const loadBasis = {\n extension: {\n type: ExtensionType.LoadParser,\n priority: LoaderParserPriority.High,\n },\n\n name: 'loadBasis',\n\n test(url: string): boolean\n {\n return checkExtension(url, '.basis');\n },\n\n async load(url: string, asset: ResolvedAsset, loader: Loader): Promise<Texture | Texture[]>\n {\n await TranscoderWorker.onTranscoderInitialized;\n\n // get an array buffer...\n const response = await settings.ADAPTER.fetch(url);\n\n const arrayBuffer = await response.arrayBuffer();\n\n const resources = await BasisParser.transcode(arrayBuffer);\n\n const type: TYPES = BASIS_FORMAT_TO_TYPE[resources.basisFormat];\n const format: FORMATS = resources.basisFormat !== BASIS_FORMATS.cTFRGBA32 ? FORMATS.RGB : FORMATS.RGBA;\n\n const textures = resources.map((resource) =>\n {\n const base = new BaseTexture(resource, {\n mipmap: resource instanceof CompressedTextureResource && resource.levels > 1\n ? MIPMAP_MODES.ON_MANUAL\n : MIPMAP_MODES.OFF,\n alphaMode: ALPHA_MODES.NO_PREMULTIPLIED_ALPHA,\n type,\n format,\n ...asset.data,\n });\n\n return createTexture(base, loader, url);\n });\n\n return textures.length === 1 ? textures[0] : textures;\n },\n\n unload(texture): void\n {\n if (Array.isArray(texture))\n {\n texture.forEach((t) => t.destroy(true));\n }\n else\n {\n texture.destroy(true);\n }\n }\n\n} as LoaderParser<Texture | Texture[], IBaseTextureOptions>;\n\nextensions.add(loadBasis);\n"],"names":["ExtensionType","LoaderParserPriority","checkExtension","TranscoderWorker","settings","BasisParser","BASIS_FORMAT_TO_TYPE","BASIS_FORMATS","FORMATS","BaseTexture","CompressedTextureResource","MIPMAP_MODES","ALPHA_MODES","createTexture","extensions"],"mappings":";;AAWO,MAAM,YAAY;AAAA,EACrB,WAAW;AAAA,IACP,MAAMA,KAAc,cAAA;AAAA,IACpB,UAAUC,OAAqB,qBAAA;AAAA,EACnC;AAAA,EAEA,MAAM;AAAA,EAEN,KAAK,KACL;AACW,WAAAC,OAAA,eAAe,KAAK,QAAQ;AAAA,EACvC;AAAA,EAEA,MAAM,KAAK,KAAa,OAAsB,QAC9C;AACI,UAAMC,iBAAAA,iBAAiB;AAKvB,UAAM,cAAc,OAFH,MAAMC,KAAA,SAAS,QAAQ,MAAM,GAAG,GAEd,eAE7B,YAAY,MAAMC,YAAAA,YAAY,UAAU,WAAW,GAEnD,OAAcC,MAAAA,qBAAqB,UAAU,WAAW,GACxD,SAAkB,UAAU,gBAAgBC,MAAc,cAAA,YAAYC,KAAAA,QAAQ,MAAMA,KAAAA,QAAQ,MAE5F,WAAW,UAAU,IAAI,CAAC,aAChC;AACU,YAAA,OAAO,IAAIC,KAAA,YAAY,UAAU;AAAA,QACnC,QAAQ,oBAAoBC,mBAA6B,6BAAA,SAAS,SAAS,IACrEC,KAAA,aAAa,YACbA,KAAAA,aAAa;AAAA,QACnB,WAAWC,KAAY,YAAA;AAAA,QACvB;AAAA,QACA;AAAA,QACA,GAAG,MAAM;AAAA,MAAA,CACZ;AAEM,aAAAC,qBAAc,MAAM,QAAQ,GAAG;AAAA,IAAA,CACzC;AAED,WAAO,SAAS,WAAW,IAAI,SAAS,CAAC,IAAI;AAAA,EACjD;AAAA,EAEA,OAAO,SACP;AACQ,UAAM,QAAQ,OAAO,IAErB,QAAQ,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAI,CAAC,IAItC,QAAQ,QAAQ,EAAI;AAAA,EAE5B;AAEJ;AAEAC,KAAAA,WAAW,IAAI,SAAS;;"}

View File

@@ -0,0 +1,38 @@
import { LoaderParserPriority, checkExtension, createTexture } from "@pixi/assets";
import { CompressedTextureResource } from "@pixi/compressed-textures";
import { ExtensionType, settings, FORMATS, BaseTexture, MIPMAP_MODES, ALPHA_MODES, extensions } from "@pixi/core";
import { BASIS_FORMAT_TO_TYPE, BASIS_FORMATS } from "../Basis.mjs";
import { TranscoderWorker } from "../TranscoderWorker.mjs";
import { BasisParser } from "./BasisParser.mjs";
const loadBasis = {
extension: {
type: ExtensionType.LoadParser,
priority: LoaderParserPriority.High
},
name: "loadBasis",
test(url) {
return checkExtension(url, ".basis");
},
async load(url, asset, loader) {
await TranscoderWorker.onTranscoderInitialized;
const arrayBuffer = await (await settings.ADAPTER.fetch(url)).arrayBuffer(), resources = await BasisParser.transcode(arrayBuffer), type = BASIS_FORMAT_TO_TYPE[resources.basisFormat], format = resources.basisFormat !== BASIS_FORMATS.cTFRGBA32 ? FORMATS.RGB : FORMATS.RGBA, textures = resources.map((resource) => {
const base = new BaseTexture(resource, {
mipmap: resource instanceof CompressedTextureResource && resource.levels > 1 ? MIPMAP_MODES.ON_MANUAL : MIPMAP_MODES.OFF,
alphaMode: ALPHA_MODES.NO_PREMULTIPLIED_ALPHA,
type,
format,
...asset.data
});
return createTexture(base, loader, url);
});
return textures.length === 1 ? textures[0] : textures;
},
unload(texture) {
Array.isArray(texture) ? texture.forEach((t) => t.destroy(!0)) : texture.destroy(!0);
}
};
extensions.add(loadBasis);
export {
loadBasis
};
//# sourceMappingURL=loadBasis.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"loadBasis.mjs","sources":["../../src/loader/loadBasis.ts"],"sourcesContent":["import { checkExtension, createTexture, LoaderParserPriority } from '@pixi/assets';\nimport { CompressedTextureResource } from '@pixi/compressed-textures';\nimport { ALPHA_MODES, BaseTexture, extensions, ExtensionType, FORMATS, MIPMAP_MODES, settings } from '@pixi/core';\nimport { BASIS_FORMAT_TO_TYPE, BASIS_FORMATS } from '../Basis';\nimport { TranscoderWorker } from '../TranscoderWorker';\nimport { BasisParser } from './BasisParser';\n\nimport type { Loader, LoaderParser, ResolvedAsset } from '@pixi/assets';\nimport type { IBaseTextureOptions, Texture, TYPES } from '@pixi/core';\n\n/** Load BASIS textures! */\nexport const loadBasis = {\n extension: {\n type: ExtensionType.LoadParser,\n priority: LoaderParserPriority.High,\n },\n\n name: 'loadBasis',\n\n test(url: string): boolean\n {\n return checkExtension(url, '.basis');\n },\n\n async load(url: string, asset: ResolvedAsset, loader: Loader): Promise<Texture | Texture[]>\n {\n await TranscoderWorker.onTranscoderInitialized;\n\n // get an array buffer...\n const response = await settings.ADAPTER.fetch(url);\n\n const arrayBuffer = await response.arrayBuffer();\n\n const resources = await BasisParser.transcode(arrayBuffer);\n\n const type: TYPES = BASIS_FORMAT_TO_TYPE[resources.basisFormat];\n const format: FORMATS = resources.basisFormat !== BASIS_FORMATS.cTFRGBA32 ? FORMATS.RGB : FORMATS.RGBA;\n\n const textures = resources.map((resource) =>\n {\n const base = new BaseTexture(resource, {\n mipmap: resource instanceof CompressedTextureResource && resource.levels > 1\n ? MIPMAP_MODES.ON_MANUAL\n : MIPMAP_MODES.OFF,\n alphaMode: ALPHA_MODES.NO_PREMULTIPLIED_ALPHA,\n type,\n format,\n ...asset.data,\n });\n\n return createTexture(base, loader, url);\n });\n\n return textures.length === 1 ? textures[0] : textures;\n },\n\n unload(texture): void\n {\n if (Array.isArray(texture))\n {\n texture.forEach((t) => t.destroy(true));\n }\n else\n {\n texture.destroy(true);\n }\n }\n\n} as LoaderParser<Texture | Texture[], IBaseTextureOptions>;\n\nextensions.add(loadBasis);\n"],"names":[],"mappings":";;;;;;AAWO,MAAM,YAAY;AAAA,EACrB,WAAW;AAAA,IACP,MAAM,cAAc;AAAA,IACpB,UAAU,qBAAqB;AAAA,EACnC;AAAA,EAEA,MAAM;AAAA,EAEN,KAAK,KACL;AACW,WAAA,eAAe,KAAK,QAAQ;AAAA,EACvC;AAAA,EAEA,MAAM,KAAK,KAAa,OAAsB,QAC9C;AACI,UAAM,iBAAiB;AAKvB,UAAM,cAAc,OAFH,MAAM,SAAS,QAAQ,MAAM,GAAG,GAEd,eAE7B,YAAY,MAAM,YAAY,UAAU,WAAW,GAEnD,OAAc,qBAAqB,UAAU,WAAW,GACxD,SAAkB,UAAU,gBAAgB,cAAc,YAAY,QAAQ,MAAM,QAAQ,MAE5F,WAAW,UAAU,IAAI,CAAC,aAChC;AACU,YAAA,OAAO,IAAI,YAAY,UAAU;AAAA,QACnC,QAAQ,oBAAoB,6BAA6B,SAAS,SAAS,IACrE,aAAa,YACb,aAAa;AAAA,QACnB,WAAW,YAAY;AAAA,QACvB;AAAA,QACA;AAAA,QACA,GAAG,MAAM;AAAA,MAAA,CACZ;AAEM,aAAA,cAAc,MAAM,QAAQ,GAAG;AAAA,IAAA,CACzC;AAED,WAAO,SAAS,WAAW,IAAI,SAAS,CAAC,IAAI;AAAA,EACjD;AAAA,EAEA,OAAO,SACP;AACQ,UAAM,QAAQ,OAAO,IAErB,QAAQ,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAI,CAAC,IAItC,QAAQ,QAAQ,EAAI;AAAA,EAE5B;AAEJ;AAEA,WAAW,IAAI,SAAS;"}