Commit e6ac9dd
authored
fix: enable export of scenes with KTX2 compressed textures (#5142)
* fix: enable export of scenes with KTX2 compressed textures
Call setTextureUtils() on GLTFExporter to decompress CompressedTexture
instances before serialization. The decompress wrapper preserves the
original texture's flipY to prevent orientation issues during export.
Fixes #5010.
* fix: enable export of scenes with KTX2 compressed textures
Replace Three.js's decompress() with a custom implementation that
renders compressed textures to a WebGLRenderTarget instead of the
renderer's main canvas. This avoids corrupting model-viewer's shared
renderer state, which caused the model to disappear after export.
The custom decompressTexture() function:
- Uses an off-screen WebGLRenderTarget (no canvas corruption)
- Saves and restores renderer toneMapping state
- Handles sRGB color space conversion in the shader
- Preserves the original texture's flipY property
Also strengthen the KTX2 export test to verify the scene remains
intact (materials, dimensions) after export, before re-importing.
* fix: simplify KTX2 export using Three.js native decompress with isolated context
Replace custom decompressTexture() (shaders, render targets, pixel readback)
with Three.js's built-in decompress() from WebGLTextureUtils, passing no
renderer so Three creates and disposes a temporary WebGL context. This avoids
corrupting model-viewer's shared canvas without maintaining custom GPU code.
---------
Co-authored-by: Douglas Holm <161740744+MyrqvistDouglas@users.noreply.github.com>1 parent 6fa0f87 commit e6ac9dd
2 files changed
Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
289 | 290 | | |
290 | 291 | | |
291 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
292 | 300 | | |
293 | 301 | | |
294 | 302 | | |
| |||
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
78 | 109 | | |
79 | 110 | | |
80 | 111 | | |
| |||
0 commit comments