Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export and then import a scene with Three JS?

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?

like image 978
Ruslan Popov Avatar asked Jul 07 '13 22:07

Ruslan Popov


People also ask

How do I save a scene in three js?

On this page, you'll see a single Three. js scene. If you hit the p key, the current state will be saved as a new image, which you can then download normally.

How do you export data from js file to another?

Implementation of Export in JavaScript Using the keyword “export” we can export anything like a variable, function, or class to any other file. What we have to do is, simply write the “export” keyword prior to that variable, function, class, or anything we want to export.

What is JavaScript import and export?

With the help of ES6, we can create modules in JavaScript. In a module, there can be classes, functions, variables, and objects as well. To make all these available in another file, we can use export and import. The export and import are the keywords used for exporting and importing one or more members in a module.


1 Answers

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

like image 64
Dan.Judex Avatar answered Oct 21 '22 04:10

Dan.Judex