`CubeTexture.CreateFromPrefilteredData` does not work with URL that contains URI params


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() : "";

That’s a great solution :slight_smile:

Want to submit a PR?

Sure, I’ll give it a try. I have not done this before and don’t know anything about the PR conventions etc. in BJS, but I’ll find out :wink:

1 Like

Let us know! Otherwise I can do it

At the moment the workaround might be to use the forcedExtension param.

FYI, a colleague of mine created the PR which has already been merged & is live with version 5.26.0 :tada:


This has to be my favorite part of working with an open source project :slight_smile:
Thank your friend for the PR!

1 Like