Repro
const baseUrl = 'https://raw.githubusercontent.com/CombeeMike/babylonjs-test-files/main';
✅ Works as expected
CubeTexture.CreateFromPrefilteredData(`${baseUrl}/studio.env`, scene);
🔥 Throws unhandled exception
CubeTexture.CreateFromPrefilteredData(`${baseUrl}/studio.env?raw=true`, scene);
The culprit
I briefly looked at the code and identified the culprit within engine.cubeTexture.js
:
// ...
ThinEngine.prototype.createCubeTextureBase = function (rootUrl, /* ... */) {
// ...
// Line 132 ff (at the moment of writing...):
var lastDot = rootUrl.lastIndexOf(".");
var extension = forcedExtension ? forcedExtension : lastDot > -1 ? rootUrl.substring(lastDot).toLowerCase() : "";
// -> Results in ".env?raw=true"
// -> 🔥 The following loop cannot find an appropriate loader for the extension
// -> 🔥 `this._cascadeLoadImgs` is called with an empty `files` arrow which later results in the throw
// ...
}
// ...
Possible solution
Make this “extension extraction” a bit more “generous” by ignoring URI params.
E.g. something like this:
var rootUrlWithoutUriParams = rootUrl.split('?')[0]
var lastDot = rootUrlWithoutUriParams.lastIndexOf(".");
var extension = forcedExtension ? forcedExtension : lastDot > -1 ? rootUrlWithoutUriParams.substring(lastDot).toLowerCase() : "";