feature: use KTX2 texture format to significantly improve load times#30
feature: use KTX2 texture format to significantly improve load times#30dastarruer merged 8 commits intomasterfrom
Conversation
📝 WalkthroughWalkthroughThis PR converts the globe's normal map workflow from PNG to KTX2 by adding build-time PNG→KTX2 encoding, bundling the Three.js basis transcoder, switching the component to load KTX2, and adjusting related material/mesh properties. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
e47a1ec to
16b8a0e
Compare
16b8a0e to
ee4665b
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/.gitignore`:
- Around line 25-26: The current .gitignore rule '*.ktx2' is too broad; restrict
it to only generated build outputs by replacing that line with a scoped pattern
that targets generated artifacts (e.g., change the '*.ktx2' entry to a
build-only pattern such as '**/build/**/*.ktx2' or 'app/**/build/**/*.ktx2') so
checked-in KTX2 assets aren't accidentally ignored; update the '*.ktx2' entry
accordingly in the .gitignore.
In `@app/src/lib/components/globe/Globe.svelte`:
- Around line 17-25: The load chain using
useKtx2(...).loadAsync('/normal-map.ktx2') currently has no rejection handling
so failures leave isLoaded false and the globe stuck in wireframe; add a .catch
handler (or convert to async/await with try/catch) on the promise returned by
loadAsync in Globe.svelte to handle errors from useKtx2/loadAsync, set isLoaded
= true or to a safe fallback state, optionally clear or set normalMap to null,
set numSegments to a reasonable default, and log the error so failures don’t
leave the component indefinitely in the loading/wireframe state; reference the
useKtx2 call, the loadAsync promise, and the isLoaded/normalMap/numSegments
variables when implementing this change.
In `@app/vite.config.ts`:
- Around line 27-40: The build currently invokes execFileSync('toktx', ...) (the
toktx call that produces normal-map.ktx2) which makes vite build fail when the
external toktx binary isn't present; instead, change the build step around that
execFileSync call to either (A) guard it: detect availability of toktx (e.g.,
try spawnSync/which or wrap execFileSync in try/catch) and fall back to a
checked-in normal-map.ktx2 or a JS-based encoder, or (B) replace the external
dependency by adding a reproducible/npm-provided encoder and invoke its binary
from node_modules/.bin (so npm install provisions it) or commit normal-map.ktx2;
ensure the code references the same artifact name (normal-map.ktx2) and that
vite build no longer assumes an unmanaged toktx binary.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5f4d1d1c-bb8b-42b4-a667-cec77c6fd449
⛔ Files ignored due to path filters (2)
app/package-lock.jsonis excluded by!**/package-lock.jsonapp/static/normal-map.pngis excluded by!**/*.png
📒 Files selected for processing (5)
app/.gitignoreapp/package.jsonapp/src/lib/components/globe/Globe.svelteapp/vite.config.tsdevenv.nix
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/vite.config.ts`:
- Line 55: The success log currently prints the literal "${output}" because it's
using single quotes; update the console.log call (console.log('ktx2 successfully
created ${output}')) to actually interpolate the output variable by using a
template string or concatenation, e.g. change to console.log(`ktx2 successfully
created ${output}`) or console.log('ktx2 successfully created ' + output) so the
generated file path is shown.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8932c627-e9de-4dda-8ba6-491822c38305
⛔ Files ignored due to path filters (1)
app/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
app/package.jsonapp/vite.config.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/vite.config.ts`:
- Around line 27-59: The code is using an undocumented imageDecoder option with
encodeToKTX2; remove the entire imageDecoder async callback (and its sharp-based
pixel decoding) and instead pass the raw pngBuffer directly to
encodeToKTX2(pngBuffer, options). Keep the existing encoder option keys
(isUASTC, qualityLevel, isNormalMap, generateMipmap, isKTX2File,
needSupercompression) but ensure they match the ktx2-encoder v0.5.1 API; update
or remove unused sharp-related code/imports and only handle the resulting
ktx2Buffer/writeFileSync logic unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: d72ca498-3b57-4a84-8616-3c8fffdc9eb7
📒 Files selected for processing (1)
app/vite.config.ts
Closes #28.
Screenshot
Benchmarks
Before
2026-03-31.16-23-35.mp4
After
2026-03-31.16-24-15.mp4
Summary
vite-plugin-static-copyvite plugin to copy necessary transcoder files at buildtime.pngtextures to.ktx2textures at build time..ktx2every single time. Secondly, it would unnecessarily bloat the size of the git tree with two versions of the same data that already exist.Summary by CodeRabbit
New Features
Chores