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

1 line
7.6 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"PVRLoader.cjs","sources":["../../src/loaders/PVRLoader.js"],"sourcesContent":["import {\n CompressedTextureLoader,\n RGBA_PVRTC_2BPPV1_Format,\n RGBA_PVRTC_4BPPV1_Format,\n RGB_PVRTC_2BPPV1_Format,\n RGB_PVRTC_4BPPV1_Format,\n} from 'three'\n\n/*\n *\t PVR v2 (legacy) parser\n * TODO : Add Support for PVR v3 format\n * TODO : implement loadMipmaps option\n */\n\nclass PVRLoader extends CompressedTextureLoader {\n constructor(manager) {\n super(manager)\n }\n\n parse(buffer, loadMipmaps) {\n const headerLengthInt = 13\n const header = new Uint32Array(buffer, 0, headerLengthInt)\n\n const pvrDatas = {\n buffer: buffer,\n header: header,\n loadMipmaps: loadMipmaps,\n }\n\n if (header[0] === 0x03525650) {\n // PVR v3\n\n return _parseV3(pvrDatas)\n } else if (header[11] === 0x21525650) {\n // PVR v2\n\n return _parseV2(pvrDatas)\n } else {\n console.error('THREE.PVRLoader: Unknown PVR format.')\n }\n }\n}\n\nfunction _parseV3(pvrDatas) {\n const header = pvrDatas.header\n let bpp, format\n\n const metaLen = header[12],\n pixelFormat = header[2],\n height = header[6],\n width = header[7],\n // numSurfs = header[ 9 ],\n numFaces = header[10],\n numMipmaps = header[11]\n\n switch (pixelFormat) {\n case 0: // PVRTC 2bpp RGB\n bpp = 2\n format = RGB_PVRTC_2BPPV1_Format\n break\n\n case 1: // PVRTC 2bpp RGBA\n bpp = 2\n format = RGBA_PVRTC_2BPPV1_Format\n break\n\n case 2: // PVRTC 4bpp RGB\n bpp = 4\n format = RGB_PVRTC_4BPPV1_Format\n break\n\n case 3: // PVRTC 4bpp RGBA\n bpp = 4\n format = RGBA_PVRTC_4BPPV1_Format\n break\n\n default:\n console.error('THREE.PVRLoader: Unsupported PVR format:', pixelFormat)\n }\n\n pvrDatas.dataPtr = 52 + metaLen\n pvrDatas.bpp = bpp\n pvrDatas.format = format\n pvrDatas.width = width\n pvrDatas.height = height\n pvrDatas.numSurfaces = numFaces\n pvrDatas.numMipmaps = numMipmaps\n pvrDatas.isCubemap = numFaces === 6\n\n return _extract(pvrDatas)\n}\n\nfunction _parseV2(pvrDatas) {\n const header = pvrDatas.header\n\n const headerLength = header[0],\n height = header[1],\n width = header[2],\n numMipmaps = header[3],\n flags = header[4],\n // dataLength = header[ 5 ],\n // bpp = header[ 6 ],\n // bitmaskRed = header[ 7 ],\n // bitmaskGreen = header[ 8 ],\n // bitmaskBlue = header[ 9 ],\n bitmaskAlpha = header[10],\n // pvrTag = header[ 11 ],\n numSurfs = header[12]\n\n const TYPE_MASK = 0xff\n const PVRTC_2 = 24,\n PVRTC_4 = 25\n\n const formatFlags = flags & TYPE_MASK\n\n let bpp, format\n const _hasAlpha = bitmaskAlpha > 0\n\n if (formatFlags === PVRTC_4) {\n format = _hasAlpha ? RGBA_PVRTC_4BPPV1_Format : RGB_PVRTC_4BPPV1_Format\n bpp = 4\n } else if (formatFlags === PVRTC_2) {\n format = _hasAlpha ? RGBA_PVRTC_2BPPV1_Format : RGB_PVRTC_2BPPV1_Format\n bpp = 2\n } else {\n console.error('THREE.PVRLoader: Unknown PVR format:', formatFlags)\n }\n\n pvrDatas.dataPtr = headerLength\n pvrDatas.bpp = bpp\n pvrDatas.format = format\n pvrDatas.width = width\n pvrDatas.height = height\n pvrDatas.numSurfaces = numSurfs\n pvrDatas.numMipmaps = numMipmaps + 1\n\n // guess cubemap type seems tricky in v2\n // it juste a pvr containing 6 surface (no explicit cubemap type)\n pvrDatas.isCubemap = numSurfs === 6\n\n return _extract(pvrDatas)\n}\n\nfunction _extract(pvrDatas) {\n const pvr = {\n mipmaps: [],\n width: pvrDatas.width,\n height: pvrDatas.height,\n format: pvrDatas.format,\n mipmapCount: pvrDatas.numMipmaps,\n isCubemap: pvrDatas.isCubemap,\n }\n\n const buffer = pvrDatas.buffer\n\n let dataOffset = pvrDatas.dataPtr,\n dataSize = 0,\n blockSize = 0,\n blockWidth = 0,\n blockHeight = 0,\n widthBlocks = 0,\n heightBlocks = 0\n\n const bpp = pvrDatas.bpp,\n numSurfs = pvrDatas.numSurfaces\n\n if (bpp === 2) {\n blockWidth = 8\n blockHeight = 4\n } else {\n bloc