Skip to content

fix: decompress KTX2 textures when generating USDZ for Quick Look - #5228

Open
Frank3K wants to merge 2 commits into
google:masterfrom
Frank3K:fix/usdz-ktx2-textures
Open

Frank3K wants to merge 2 commits into
google:masterfrom
Frank3K:fix/usdz-ktx2-textures

Conversation

@Frank3K

@Frank3K Frank3K commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Problem

When a model uses KTX2 textures (KHR_texture_basisu) and no ios-src is set, generating the USDZ for Quick Look fails with:

THREE.USDZExporter: setTextureUtils() must be called to process compressed textures.

prepareUSDZ() rejects, and on iOS tapping the AR button silently does nothing.

Repro (4.4.0): https://jsfiddle.net/ps5mcLf9/. It loads shared-assets/models/BarramundiFish.mixed.glb and calls prepareUSDZ(). It also works on desktop. Astronaut.glb is included as a working comparison.

Fix

Give USDZExporter a decompress implementation built on three's WebGLTextureUtils:

  • One shared WebGL context: a single dedicated WebGLRenderer is created only when a compressed texture is found. All textures in the export use it, and it is disposed in the existing finally block. Otherwise decompress would create and destroy a context for every texture.
  • Size cap: textures are decompressed at ar-usdz-max-texture-size instead of full resolution. This limits peak memory on mobile devices.
  • Unchanged for other models: models without compressed textures never create the extra context.

Tests

Added a test to ar-spec.ts. It exports BarramundiFish.mixed.glb (2048×2048 KTX2 textures) with ar-usdz-max-texture-size="256". It then checks that the USDZ contains PNG textures that are 256×256 and contain real image data.

three's USDZExporter can only write compressed textures (e.g. KTX2 via
KHR_texture_basisu) after texture utils have been set; otherwise it throws
"setTextureUtils() must be called to process compressed textures" and
activating AR on iOS silently does nothing.

Provide a decompress implementation based on WebGLTextureUtils. A single
dedicated WebGL context is shared for all textures and disposed after the
export, and textures are decompressed at ar-usdz-max-texture-size to limit
peak memory on mobile devices.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant