Texture parsing issues with "file:..." in the name of the texture

Hello!

When I try to parse a texture whose name starts with “file:…” it all goes wrong:

  • In PG there is an error stating that local resources are not allowed. (look in the console)
  • In a real project it seemingly loads correctly but eventually I find out that scene._pendingData never gets empty, which leads to other problems e.g. not being able to gltf-export the scene.

I’m thinking that the name shouldn’t influence the way the texture is being loaded.

Hello! Are you able to share a minimal repro of your local project?

I assume you mean in a local project? The browser blocks access to file: for security reasons (which make a lot of sense - you could load files from my file system by sending me a playground).

What you can do is use a blob instead or serve/host the file using a webserver (which would be the best variant). In general, Babylon should support the file schema, if the browser supports it. if it doesn’t work we would be happy to try a working reproduction and see what is wrong, but my personal recommendation would be to never use the file protocol, or to use it as little as possible.

1 Like

Thanks for the replies.
I guess I’m being not clear enough about the problem.
I’m talking about any project, not necessarily a local one. Specifically I’ve encountered the issue in our production server when users are not able to export bjs scenes to gltf.

Notice that I’m only providing a name of the texture for parsing, and bjs thinks (I assume “incorrectly thinks”) that this texture should be loaded from a local drive. Seems like this somehow fools the engine. Correct me if I’m wrong.

Meanwhile I’ll prepare a reproduction repository.

1 Like

We have many places where we are checking if the provided URL has a protocol in it (like file or blob, for example), but I am not sure we are actually parsing the name. Would be great to see a reproducion.

Sorry let me correct that. The parse function actually uses the name as URL:

                        if (parsedTexture.name && parsedTexture.name.indexOf("://") > 0) {
                            url = parsedTexture.name;
                        } else {
                            url = rootUrl + parsedTexture.name;
                        }

You can override this behavior by providing a url and setting the flag that uses it to true (Texture.UseSerializedUrlIfAny)

“file:” in the parsed texture name | Babylon.js Playground (babylonjs.com)

1 Like

Thanks!
This explains everything!