Kahless
Kahless

Reputation: 1253

How can I save and then load a Three.js scene

I have seen loaders for objects and other things but nothing for an entire scene. Is it possible to save and load three.js scenes?

Upvotes: 3

Views: 10192

Answers (2)

LrakWortep
LrakWortep

Reputation: 217

looks like scene exporter is deprecated. There is now a GLTFExporter

Upvotes: 3

Jos Dirksen
Jos Dirksen

Reputation: 1903

Yes you can use the THREE.SceneLoader for this:

To export use this:

var exporter = new THREE.SceneExporter();
var sceneJson = JSON.stringify(exporter.parse(scene));

To import use this:

var sceneLoader = new THREE.SceneLoader();
sceneLoader.parse(JSON.parse(json), function (e) {scene = e.scene;}, '.');

For an example see: https://github.com/josdirksen/learning-threejs/blob/master/chapter-08/04-load-save-json-scene.html

Source files for loader and exporters are here:

Upvotes: 7

Related Questions