pmndrs / gltfjsx

🎮 Turns GLTFs into JSX components
https://gltf.pmnd.rs
MIT License
4.7k stars 309 forks source link

Add support for KTX2 loader #266

Open marwie opened 3 months ago

marwie commented 3 months ago

This PR adds support for KTX2 loader codegen since currently files with basisu compressed textures can not be loaded with gltfjsx codegen.

It also enables the draco option or meshopt option automatically if the mesh uses draco/meshopt compression.

Output Example: https://codesandbox.io/p/sandbox/example-gltfjsx-ktx-draco-zq868k?workspaceId=6fd5c640-33c5-4061-bc17-d4030f1a6650

Steps to reproduce: 1) Load compressed DamagedHelmet 2) Drop into https://gltf.pmnd.rs/ 3) Observe error

This PR might be actually better suited as an option for drei useGLTF to avoid creating KTX2 loaders for every model (as we do with this PR). It would also simplify codegen again. Let me know if you'd prefer this as a third bool argument (similar to draco and meshopt) and if so in what fashion (before the loader callback parameter or after) or if you prefer a different solution.

Currently the PR removes useGLTF.preload for files with KTX2 textures and doesnt handle the hasInstances case - happy to apply the necessary changes once it's clear what the preferred solution is :)

drcmda commented 2 months ago

yes i think this should be in drei/useGltf

marwie commented 2 months ago

Is that something you'll be adding or I should make a PR?