如何保存然后加载Three.js场景

Kah*_*ess 3 javascript three.js

我见过用于物体和其他东西的装载机,但在整个场景中却看不到。是否可以保存和加载three.js场景?

小智 5

是的,您可以为此使用THREE.SceneLoader:

要导出,请使用以下命令:

var exporter = new THREE.SceneExporter();
var sceneJson = JSON.stringify(exporter.parse(scene));
Run Code Online (Sandbox Code Playgroud)

要导入,请使用以下命令:

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

有关示例,请参见:https : //github.com/josdirksen/learning-threejs/blob/master/chapter-08/04-load-save-json-scene.html

加载程序和导出程序的源文件在这里:

  • @Jos现在在哪里? (2认同)