1 line
34 KiB
Plaintext
1 line
34 KiB
Plaintext
|
|
{"version":3,"file":"BasisTextureLoader.cjs","sources":["../../src/loaders/BasisTextureLoader.js"],"sourcesContent":["import {\n CompressedTexture,\n FileLoader,\n LinearFilter,\n LinearMipmapLinearFilter,\n Loader,\n RGBAFormat,\n RGBA_ASTC_4x4_Format,\n RGBA_BPTC_Format,\n RGBA_ETC2_EAC_Format,\n RGBA_PVRTC_4BPPV1_Format,\n RGBA_S3TC_DXT5_Format,\n RGB_ETC1_Format,\n RGB_ETC2_Format,\n RGB_PVRTC_4BPPV1_Format,\n RGB_S3TC_DXT1_Format,\n UnsignedByteType,\n} from 'three'\n\n/**\n * Loader for Basis Universal GPU Texture Codec.\n *\n * Basis Universal is a \"supercompressed\" GPU texture and texture video\n * compression system that outputs a highly compressed intermediate file format\n * (.basis) that can be quickly transcoded to a wide variety of GPU texture\n * compression formats.\n *\n * This loader parallelizes the transcoding process across a configurable number\n * of web workers, before transferring the transcoded compressed texture back\n * to the main thread.\n */\n\nconst _taskCache = new WeakMap()\n\nconst BasisTextureLoader = /* @__PURE__ */ (() => {\n class BasisTextureLoader extends Loader {\n /* CONSTANTS */\n\n static BasisFormat = {\n ETC1S: 0,\n UASTC_4x4: 1,\n }\n\n static TranscoderFormat = {\n ETC1: 0,\n ETC2: 1,\n BC1: 2,\n BC3: 3,\n BC4: 4,\n BC5: 5,\n BC7_M6_OPAQUE_ONLY: 6,\n BC7_M5: 7,\n PVRTC1_4_RGB: 8,\n PVRTC1_4_RGBA: 9,\n ASTC_4x4: 10,\n ATC_RGB: 11,\n ATC_RGBA_INTERPOLATED_ALPHA: 12,\n RGBA32: 13,\n RGB565: 14,\n BGR565: 15,\n RGBA4444: 16,\n }\n\n static EngineFormat = {\n RGBAFormat: RGBAFormat,\n RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format,\n RGBA_BPTC_Format: RGBA_BPTC_Format,\n RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format,\n RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format,\n RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format,\n RGB_ETC1_Format: RGB_ETC1_Format,\n RGB_ETC2_Format: RGB_ETC2_Format,\n RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format,\n RGB_S3TC_DXT1_Format: RGB_S3TC_DXT1_Format,\n }\n\n /* WEB WORKER */\n\n static BasisWorker = function () {\n let config\n let transcoderPending\n let BasisModule\n\n const EngineFormat = _EngineFormat\n const TranscoderFormat = _TranscoderFormat\n const BasisFormat = _BasisFormat\n\n onmessage = function (e) {\n const message = e.data\n\n switch (message.type) {\n case 'init':\n config = message.config\n init(message.transcoderBinary)\n break\n\n case 'transcode':\n transcoderPending.then(() => {\n try {\n const { width, height, hasAlpha, mipmaps, format } = message.taskConfig.lowLevel\n ? transcodeLowLevel(message.taskConfig)\n : transcode(message.buffers[0])\n\n const buffers = []\n\n for (let i = 0; i < mipmaps.length; ++i) {\n buffers.push(mipmaps[i].data.buffer)\n }\n\n self.postMessage(\n { type: 'transcode', id: message.id, width, height, hasAlpha, mipmaps, format },\n buffers,\n )\n } catch (error) {\n console.error(error)\n\n self.postMessage({ type: 'error', id: message.id, error: error.message })\n }\n })\n break\n }\n }\n\n function init(wasmBinary) {\n transcoderPending = new Promise((resolve) => {\n BasisModule = { wasmBinary, onRuntimeInitialized: resolve }\n BASIS(BasisModule)\n }).then(() => {\n BasisModule.initializeBasis()\n })\n }\n\n function transcodeLowLevel(taskConfig) {\n const { basisFormat, width, height, hasAlpha } = taskConfig\n\n const { transcoderFormat, engineFormat } = getTranscoderFormat(basisFormat, width, height, hasAlpha)\n\n const blockByteLength = BasisModu
|