/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/compressed-textures/dds/loadDDS.ts
67 строк
2 KB
Copilot
fix: compressed textures ignoring resolution from URL (e.g. `@0.75x`) (#11960)
16 мар 2026, 11:47
Не верифицирован
16 мар 2026, 11:47
fc5ec38
Код
Авторство
О чём код?
import { LoaderParserPriority } from '../../assets/loader/parsers/LoaderParser'; import { createTexture } from '../../assets/loader/parsers/textures/utils/createTexture'; import { checkExtension } from '../../assets/utils/checkExtension'; import { ExtensionType } from '../../extensions/Extensions'; import { CompressedSource } from '../../rendering/renderers/shared/texture/sources/CompressedSource'; import { getSupportedTextureFormats } from '../../rendering/renderers/shared/texture/utils/getSupportedTextureFormats'; import { getResolutionOfUrl } from '../../utils/network/getResolutionOfUrl'; import { parseDDS } from './parseDDS'; import type { Loader } from '../../assets/loader/Loader'; import type { LoaderParser } from '../../assets/loader/parsers/LoaderParser'; import type { ResolvedAsset } from '../../assets/types'; import type { TextureSourceOptions } from '../../rendering/renderers/shared/texture/sources/TextureSource'; import type { Texture } from '../../rendering/renderers/shared/texture/Texture'; /** * Loads DDS textures. * @category assets * @advanced */ export const loadDDS = { extension: { type: ExtensionType.LoadParser, priority: LoaderParserPriority.High, name: 'loadDDS', }, /** used for deprecation purposes */ name: 'loadDDS', id: 'dds', test(url: string): boolean { return checkExtension(url, ['.dds']); }, async load(url: string, asset: ResolvedAsset, loader: Loader): Promise<Texture | Texture[]> { const supportedTextures = await getSupportedTextureFormats(); const ddsResponse = await fetch(url); const ddsArrayBuffer = await ddsResponse.arrayBuffer(); const textureOptions = parseDDS(ddsArrayBuffer, supportedTextures); const compressedTextureSource = new CompressedSource({ ...textureOptions, resolution: asset.data?.resolution || getResolutionOfUrl(url), }); return createTexture(compressedTextureSource, loader, url); }, unload(texture: Texture | Texture[]): void { if (Array.isArray(texture)) { texture.forEach((t) => t.destroy(true)); } else { texture.destroy(true); } } } satisfies LoaderParser<Texture | Texture[], TextureSourceOptions>;