Export/import from and to file

Hello how can i easy export and import scene to and from file .obj or .glb??

Hi @MrPeter ,

We have a detailed documentation page for that:

and

i will try… and it will export scene with all meshes in there?

With the limitation stated in the document :slight_smile:

I have this code

importScene() {
    console.log('Importujem scenu');
    BABYLON.SceneLoader.Append(
      'C:\\Users\\Uzivatel\\Downloads\\',
      'test1.glb',
      this.scene,
      function (scene) {
        // do something with the scene
      }
    );


This errors are shown, can you help me?

It is recommended to host your file on a local server in order to load it. Remote server that supports CORS will also work! I have to admit I don’t remember how well the support for the file:// protocol works, but it does work well for http requests.
I always recommend “http-server”, which is a wonderful NPM package that will allow you to serve any directory as a local website.

npx http-server --cors

in the directory with the model will allow you to load it from localhost:8080

Okey so i installed http-server and then what, where should i copy my file? :smiley:

http-server will serve files in any directory you choose. run it wherever you want, and it will serve those files.

If you have a bit of difficulties with that, we have a wonderful tutorial that might be helpful - Playground to Production - Fruit Fallin' | Babylon.js Documentation

2 Likes

I used github pages like server but it doesnt work for now… maybe bad export.
One more question. So it is not possible to export file and then import it from file input from my pc? Without server side?

i am using angular framework how should i import exporter? Because i have this errors in terminal.

what version of dependencies are you using?
can you add “babylonjs-gltf2interface” to your dependencies?

i used just this npm i @babylonjs/serializers, where should i add it? I think it was there

It should be included in the package when you install it.

What typescript version are you using? Also, just to be sure (as there was an issue with the types in previous versions) can you try updating your dependencies to 5.0.3 and see if it compiles correctly?

Can just help me with this? Babylon .obj export :smiley: next step will be try repair dependecy, because i think it will work with this error.

the great(est) @carolhmj just answered :slight_smile:

1 Like

Hello, why i have this error do you know?


I have this code for exxport
image

I wanted reply you, can you check the error i posted?

That seems like a versioning issue (using loaders and core not in the same version). It’s very hard to say without you reproducing this. If you want to share a project or a deployed version (with sourcemaps / maximized version of the framework) it would be possible to check that.