How to export and then import a scene with Three J

2019-04-21 08:18发布

问题:

I have a complex 3D scene builded with Three JS and a lot of Javascript code. I need to export this scene as one file and then use it on my site with a simple ThreeJS scene player.

I have tried ObjectExporter and SceneExporter. But still can not understand how to load this data back into ThreeJS environment.

What is the right way to do this?

回答1:

SceneExporter does not export the scene objects that are loaded through JSON ObjectExporter can't exports texture

link scripts

ObjectExporter.js
GeometryExporter.js
BufferGeometryExporter.js
MaterialExporter.js

function exportScene(save, type) {
    exporter = new THREE.ObjectExporter;
    var obj = exporter.parse(scene);
    var json = JSON.stringify(obj);
    log(json);
}

save json to file ext .json Library taken from https://github.com/mrdoob/three.js/tree/master/examples/js/exporters Loader taken from https://github.com/mrdoob/three.js/tree/master/editor default import in editor menu->file->import I'm working on that to add the ability to export texture