简体   繁体   中英

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?

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM