summit/frontend/node_modules/three-stdlib/loaders/DDSLoader.cjs.map

1 line
10 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"DDSLoader.cjs","sources":["../../src/loaders/DDSLoader.js"],"sourcesContent":["import {\n CompressedTextureLoader,\n RGBAFormat,\n RGBA_S3TC_DXT3_Format,\n RGBA_S3TC_DXT5_Format,\n RGB_ETC1_Format,\n RGB_S3TC_DXT1_Format,\n} from 'three'\n\nclass DDSLoader extends CompressedTextureLoader {\n constructor(manager) {\n super(manager)\n }\n\n parse(buffer, loadMipmaps) {\n const dds = { mipmaps: [], width: 0, height: 0, format: null, mipmapCount: 1 }\n\n // Adapted from @toji's DDS utils\n // https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js\n\n // All values and structures referenced from:\n // http://msdn.microsoft.com/en-us/library/bb943991.aspx/\n\n const DDS_MAGIC = 0x20534444\n\n // let DDSD_CAPS = 0x1;\n // let DDSD_HEIGHT = 0x2;\n // let DDSD_WIDTH = 0x4;\n // let DDSD_PITCH = 0x8;\n // let DDSD_PIXELFORMAT = 0x1000;\n const DDSD_MIPMAPCOUNT = 0x20000\n // let DDSD_LINEARSIZE = 0x80000;\n // let DDSD_DEPTH = 0x800000;\n\n // let DDSCAPS_COMPLEX = 0x8;\n // let DDSCAPS_MIPMAP = 0x400000;\n // let DDSCAPS_TEXTURE = 0x1000;\n\n const DDSCAPS2_CUBEMAP = 0x200\n const DDSCAPS2_CUBEMAP_POSITIVEX = 0x400\n const DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800\n const DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000\n const DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000\n const DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000\n const DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000\n // let DDSCAPS2_VOLUME = 0x200000;\n\n // let DDPF_ALPHAPIXELS = 0x1;\n // let DDPF_ALPHA = 0x2;\n const DDPF_FOURCC = 0x4\n // let DDPF_RGB = 0x40;\n // let DDPF_YUV = 0x200;\n // let DDPF_LUMINANCE = 0x20000;\n\n function fourCCToInt32(value) {\n return (\n value.charCodeAt(0) + (value.charCodeAt(1) << 8) + (value.charCodeAt(2) << 16) + (value.charCodeAt(3) << 24)\n )\n }\n\n function int32ToFourCC(value) {\n return String.fromCharCode(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >> 24) & 0xff)\n }\n\n function loadARGBMip(buffer, dataOffset, width, height) {\n const dataLength = width * height * 4\n const srcBuffer = new Uint8Array(buffer, dataOffset, dataLength)\n const byteArray = new Uint8Array(dataLength)\n let dst = 0\n let src = 0\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const b = srcBuffer[src]\n src++\n const g = srcBuffer[src]\n src++\n const r = srcBuffer[src]\n src++\n const a = srcBuffer[src]\n src++\n byteArray[dst] = r\n dst++ //r\n byteArray[dst] = g\n dst++ //g\n byteArray[dst] = b\n dst++ //b\n byteArray[dst] = a\n dst++ //a\n }\n }\n\n return byteArray\n }\n\n const FOURCC_DXT1 = fourCCToInt32('DXT1')\n const FOURCC_DXT3 = fourCCToInt32('DXT3')\n const FOURCC_DXT5 = fourCCToInt32('DXT5')\n const FOURCC_ETC1 = fourCCToInt32('ETC1')\n\n const headerLengthInt = 31 // The header length in 32 bit ints\n\n // Offsets into the header array\n\n const off_magic = 0\n\n const off_size = 1\n const off_flags = 2\n const off_height = 3\n const off_width = 4\n\n const off_mipmapCount = 7\n\n const off_pfFlags = 20\n const off_pfFourCC = 21\n const off_RGBBitCount = 22\n const off_RBitMask = 23\n const off_GBitMask = 24\n const off_BBitMask = 25\n const off_ABitMask = 26\n\n // let off_caps = 27;\n const off_caps2 = 28\n // let off_caps3 = 29;\n // let off_caps4 = 30;\n\n // Parse header\n\n const header = new Int32Array(buffer, 0, headerLengthInt)\n\n if (header[off_magic] !== DDS_MAGIC) {\n console.error('THREE.DDSLoader.parse: Invalid magic number in DDS header.')\n return dds\n }\n\n if (!header[off_pfFlags] & DDPF_FOURCC) {\n console.error('THREE.DDSLoader.parse: Unsupported format, must contain a FourCC code.')\n return dds\n }\n\n let blockBytes\n\n