Jump to content

Loading a local scene in 3.3+ without XMLHttpRequest


Recommended Posts

As of this PR, it's no longer possible to load a scene from a local file:

const sceneFile = new File('foo.babylon')
const scene = await SceneLoader.LoadAsync('file:', sceneFile, engine)

The only workaround I have found, which doesn't involve the inefficient conversion into a "data:" string, is this:

import XMLHttpRequest from 'xmlhttprequest'
global.XMLHttpRequest = XMLHttpRequest.XMLHttpRequest
// ...
const scene = await SceneLoader.LoadAsync('', 'file:foo.babylon', engine)

It works, but I dislike having an extra dependency - "xmlhttprequest" - for no good reason.

I've combed through the code, and looks like there's no alternative path. There's a handy utility called "LoadFile", but the only way to reach it without copy-pasting a ton of code is really convoluted, involving the "FilesInput.FilesToLoad" global.

What's the rationale behind that PR? And would you mind adding the in-memory file support back?

Edit: On the other hand, it appears I don't need to shim "FileReader" anymore with this new approach. Hmm. Either way, documenting the correct way to go about this would be greatly appreciated. Having a shimless way to load a local scene would be even better :D E.g. by just passing a Buffer. But I can live without that.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...