Save scene to database

Hello,

I am trying to save the scene into the database and read it from there.
The first thing I did was to use scene.toJSON() function and I saved this value.

But when I try to load this scene from the database I get nothing. Is it possible to have oposite to toJSON function that I could use in this case?

I did the test with ObjectLoader in the following way:
console.log(scene);
sceneJSON = scene.toJSON(); // here I have the json file

    //here i am trying to get to the scene again:
    var loader = new THREE.ObjectLoader();

    loader.load(sceneJSON,
        function ( json ) {
          console.log(json);

    });

But what I am getting for the last console.log is:

    three.js:40357 Uncaught TypeError: url.lastIndexOf is not a function
    at Object.extractUrlBase (three.js:40357)
    at ObjectLoader.load (three.js:40645)
    at saveSceneAs (index.js:710)
    at HTMLAnchorElement.onclick (VM5016 index.php:71)

Many thanks in advance!

Mirko

A complete round-trip usually looks like so:

const serializedScene = JSON.stringify( scene.toJSON() );
const scene = new THREE.ObjectLoader().parse( JSON.parse( serializedScene ) );

So you don’t use ObjectLoader.load().

1 Like

Yes! This is what i was looking for.

Thanks a lot mate!

1 Like