...

/

Local Storage to Save and Load Scene

Local Storage to Save and Load Scene

Learn how to use local storage to save and load Three.js scenes in the browser.

Saving and loading in Three.js JSON format

We can use the Three.js JSON format for two different scenarios in Three.js. We can use it to save and load a single THREE.Object3D object (which means we can also use it to export a THREE.Scene object).

Example: Save/load JSON

To demonstrate saving and loading, we created a simple example based on THREE.TorusKnotGeometry. With this example, we can create a torus knot, and using the “save” button from the “save”/“load” menu, we can save the current geometry. For this example, we save using the HTML5 local storage API. This API allows us to easily store persistent information in the client’s browser and retrieve it at a later time (even after the browser has been shut down and restarted):

Press + to interact
Showing the loaded and the current mesh
Showing the loaded and the current mesh
...