Hi everyone,
Due to some requirements, I’ll have to download texture into local, then load the downloaded Blob to BABYLON.Texture()
function.
It seems that this works for .png
textures, but not working for .ktx2
textures.
In this playground you can see if I pass the texture url directly into BABYLON.Texture()
function, texture can be loaded successfully. However in this playground, once I download it to local, convert to Blob, pass URL generated using createObjectURL(blob)
in to Texture function, texture loading errors out.
The error message is Error while trying to load image: blob:https://playground.babylonjs.com/ed7528e6-418f-469f-8326-2b4be3866883 - Fallback texture was used
I also tried to pass the converted Blob directly into Texture function, still doesn’t work.
Wonder if anyone know how I can get this work?
Thanks!
1 Like
Hello! On both of your playgrounds, it seems not even the original URL is loading now D: It’s showing this:
Hello! I have updated both playground with a public example ktx2 texture! Please let me know if they load up or not!
Since this is a ktx2 texture you need to let the load know it is a.ktx2 file and its mime type. this way you can use the blob created - Load texture from memory | Babylon.js Playground (babylonjs.com)
There is no need to define the buffer, the data is provided in the blob itself.
3 Likes
Thanks for explaining it!
I wonder if I can check Response Header details using BABYLON.Tools.LoadFileAsync
?
So, technically you can already do that, though it’s not the most straight-forward way.
Babylon has the concept of a WebRequest, which is a proxy class that allows you (among other things) to add headers and modify a request before it is sent:
Load texture from memory | Babylon.js Playground (babylonjs.com)
Could be simpler, I agree
3 Likes
Thank you very much! It’s really helpful
1 Like