How do I load scene data directly?

Hi, beginner here, I’m working on a project that needs to be able to run in a local file. I need to be able to load a mesh from blender and I wanted to know if there is a function I can run, and just supply the object from the babylon file, and have it load into the scene. Ive looked through the code, and, other than realizing I’m not as good at javascript as I thoght I was, I didnt find anything. Please help, thanks in advanced!

hello and welcome!

I guess the Viewer is what you need: Babylon.js Viewer | Babylon.js Documentation

Thanks, but i need to be able to load the model data into a scene. Is there a function to just use scene data? like where I can be able to just run BABYLON.something.function({content of babylon file})? Thanks!

what do you mean by scene data? Not the url I guess, how your scene data is stored?

The content of the babylon file I exported from blender.

but how do you store it? In a file, in a arrayBuffer?

in an object, I think. It’s stored like: {“producer”:“Blender”, …}

Edit: I think I know what you mean. It’s stored in an array of positions, normals, and indices.
Like this:{…“positions”:[…], “normals”:[…], “indices”:[…]}

Ok so if you have a JSON object containing your file, you can recreate a file like that:

let blob = new Blob([yourDataFile]);
let file = new File([blob], 'myscene.babylon');

BABYLON.SceneLoader.LoadAsync('file:', file, scene).then((scene) => {
// Use your scene here

My question then would be: how do you get the object? Are you loading it?

Thanks for the help! I’ll try that! And the way I’m getting the object is I’m exporting it from blender, and I plan on just copying and pasting the JSON code into a separate JS file that defines all of the meshes and stuff in the scene.

why not simply loading the scene files? like with SceneLoader.LoadAsync(url) …?

I need to have my project able to be loaded as a local file. I thought you cant load any outside files with Javascript on a local file?

edit:Yeah, I just tried it, if I try to just load a babylon file with LoadAsync, it tells me it cant load the file because its not http.

edit2:it says “Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///untitled.babylon. (Reason: CORS request not http)”

I tried making the file object and stuff, it keeps giving me this error:
Uncaught (in promise) TypeError: _this._engine.scenes is undefined

Well I guess you missed one info: you cannot run js code locally without millions of issues. You have to host your code in a web server and then from there it will be straightforward to load your scenes as I mentioned before

Ok, well thanks for the help!