API

Save Your Scene or Meshes

Any scene or mesh can be downloaded as a file to your computer. This is achieved with the scene serializer

Scene

Include the following code in your project to download your scene

import { SceneSerializer } from "@babylonjs/core/Misc/sceneSerializer";
import { Tools } from "@babylonjs/core/Misc/tools";
let objectUrl;
function doDownload(filename, scene) {
if (objectUrl) {
window.URL.revokeObjectURL(objectUrl);
}
const serializedScene = SceneSerializer.Serialize(scene);
const strScene = JSON.stringify(serializedScene);
if (filename.toLowerCase().lastIndexOf(".babylon") !== filename.length - 8 || filename.length < 9) {
filename += ".babylon";
}
const blob = new Blob([strScene], { type: "octet/stream" });
Tools.Download(blob, filename);
}

The following playground shows how to create a scene, use the serializer, convert it to a JSON file, and then offer it for download to your computer.
PG: Save Scene

Meshes

The following code shows the changes needed to download only a mesh to your computer.

import { SceneSerializer } from "@babylonjs/core/Misc/sceneSerializer";
import { Tools } from "@babylonjs/core/Misc/tools";
let objectUrl;
function doDownload(filename, mesh) {
if (objectUrl) {
window.URL.revokeObjectURL(objectUrl);
}
const serializedMesh = SceneSerializer.SerializeMesh(mesh);
const strMesh = JSON.stringify(serializedMesh);
if (filename.toLowerCase().lastIndexOf(".babylon") !== filename.length - 8 || filename.length < 9) {
filename += ".babylon";
}
const blob = new Blob([strMesh], { type: "octet/stream" });
Tools.Download(blob, filename);
}