UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

55 lines (54 loc) 1.7 kB
import { ADDRESS_CLAMP_TO_EDGE, ADDRESS_REPEAT, TEXHINT_ASSET, pixelFormatLinearToGamma } from "../../../platform/graphics/constants.js"; import { Texture } from "../../../platform/graphics/texture.js"; import { Asset } from "../../asset/asset.js"; import { basisTranscode } from "../../handlers/basis.js"; import { TextureParser } from "./texture.js"; class BasisParser extends TextureParser { constructor(registry, device) { super(); this.device = device; this.maxRetries = 0; } load(url, callback, asset) { const device = this.device; const transcode = (data) => { const basisModuleFound = basisTranscode( device, url.load, data, callback, { isGGGR: (asset?.file?.variants?.basis?.opt & 8) !== 0 } ); if (!basisModuleFound) { callback(`Basis module not found. Asset [${asset.name}](${asset.getFileUrl()}) basis texture variant will not be loaded.`); } }; Asset.fetchArrayBuffer(url.load, (err, result) => { if (err) { callback(err); } else { transcode(result); } }, asset, this.maxRetries); } // our async transcode call provides the neat structure we need to create the texture instance open(url, data, device, textureOptions = {}) { const format = textureOptions.srgb ? pixelFormatLinearToGamma(data.format) : data.format; const texture = new Texture(device, { name: url, addressU: data.cubemap ? ADDRESS_CLAMP_TO_EDGE : ADDRESS_REPEAT, addressV: data.cubemap ? ADDRESS_CLAMP_TO_EDGE : ADDRESS_REPEAT, width: data.width, height: data.height, format, cubemap: data.cubemap, levels: data.levels, ...textureOptions }); texture.upload(); return texture; } } export { BasisParser };