Closed catalin-enache closed 2 months ago
Just realised that the fix only works with gltf
having ktx2
textures but will make it crash if there are other kinds of textures. We need to also check for the file extension.
A quick finding would be something like:
const isKTX2 = json.images?.some((img) => img.uri?.split('.').pop() === 'ktx2'); // assuming all images are the same type
if (isKTX2 && this.options.ktx2Loader) {
this.textureLoader = this.options.ktx2Loader;
} else if (typeof createImageBitmap === 'undefined' || isSafari || (isFirefox && firefoxVersion < 98)) {
this.textureLoader = new TextureLoader(this.options.manager);
} else {
this.textureLoader = new ImageBitmapLoader(this.options.manager);
}
Does this also affect the upstream GLTFLoader
in three? We can consult there as well and backport progress.
Ah sorry, I was so sure that I created the issue in main ThreeJS
repo :) I realise now that I was raising it in the three-stdlib
repo. I'll report it there too. Thanks for feedback !
I just reported it in ThreeJs repo (https://github.com/mrdoob/three.js/issues/28258), I will close it here. Thank you !
It seems the issue was with the official gltf asset not declaring required extensions.
three
version: 0.164.1@types/three
version: 0.164.0three-stdlib
version: not usedProblem description:
Loading this GLTF asset https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/AnisotropyBarnLamp/glTF-KTX-BasisU which has external
ktx2
textures fails with error:THREE.GLTFLoader: Couldn't load texture
.This is raise by GLTFLoader at line 2658
Relevant code:
I'm doing all the required setup:
Suggested solution:
Looking through the code I found that
ktx2Loader
is not used inside theGLTFParser
even it is sent in options fromGLTFLoader
It seems to be fixed with a bit of a patch inside GLTFParser. If we change these lines from:
to:
the external
ktx2
textures will be loaded. I'm not sure if this is the right approach to fix it though.There is a sandbox that works when using suggested patch: https://codesandbox.io/p/sandbox/young-waterfall-22pkx4?file=%2Fsrc%2Findex.js%3A8%2C61 Please play with different imports (original/patched) (also note that it takes long to load the asset):![image](https://github.com/pmndrs/three-stdlib/assets/4470065/76b14796-4919-4ede-baf6-6acc40f911ba)