Babylon FilesInput -- for plain text files?

I’m wondering if “BABYLON.FilesInput” can be used to load plain text files or is it just restricted to .babylon and a few other extensions. I tried out a vanilla version of it and my console is telling me that the file I dragged and dropped is not a .babylon file. I have paired down array that includes just basic transform attributes and I want users to be able to save out a text file and load it back in. This is the code that I tried:

var filesInput = new BABYLON.FilesInput(engine, null, scene, null, null, null, function () {
}, null, null);
filesInput.onProcessFileCallback = (function(file, name, extension) {
        return true;

I copy-pasted the code you provided into a Playground, and I’m actually getting the output from the callback. There’s a different function throwing errors because it’s expecting a scene file and trying to reload from that (still working back to try to figure out how to prevent that :slight_smile: ), but your callback seems to getting called. Does that match what you’re seeing, or have I misunderstood the issue?

EDIT: If you don’t want to use FilesInput to reload the scene, I think the easiest thing to do to get rid of the error will be to just override the FilesInput.reload() function. This is essentially the same code you pasted above, but with the addition of replacing reload() with a no-op. I’ve made a Playground, in case that’s helpful.

I worked with yours a bit and finally just pasted the whole thing into my playground.:

I still get a console warning:
babylon.js:16 BJS - [15:18:13]: Please provide a valid .babylon file.

Must be some difference in the playground environments, maybe… your url is:

mine is:

Hmm. When I follow the link to your Playground, I actually don’t get that error anymore.

Did you try refreshing your Playground? I’ve noticed is that the FilesInput callbacks from this code seem to stick around even after clicking “Run” to reset the Playground. For clarity, here’s what I did:

  • Click on your playground link.
  • Press F12 to open the console, then clear the console.
  • Drag and drop an example file into the canvas.
  • In the console, I only see 1 message reading, “done: object foo.txt txt”
  • Clear the console again.
  • Delete line 37 and press Run.
  • Clear the console again, just for fun.
  • Drag and drop the same example file into the canvas.

At the end of this process, my console shows one error message of the kind you describe, and two messages reading “done: object foo.txt txt.” I think this is because the FilesInput object is sticking around between playground runs, so both the one with the default reload() method and the one with the no-op are handling the drag-and-drop. If this is the issue, just refreshing the tab that contains your playground should remove the error message. Does that work?

Yes I started to get different results in different tabs, that explains it. As long as I can cleanly load a text file I’m good to go… thanks so much