# SceneLoader class (legacy)

Source: https://doc.babylonjs.com/features/featuresDeepDive/importers/legacy

Once the plugin is referenced, the SceneLoader class can be used. It provides a few loading methods.

## SceneLoader.Append

Loads all Babylon assets from the file and appends them to the scene.

```javascript
BABYLON.AppendSceneAsync("duck.gltf", scene).then(function () {
  // do something with the scene
});
```

See an example here: [Playground: Append An Object](https://playground.babylonjs.com/#WGZLGJ#11155) - Simple example showing how append an object to your scene.

Loads all Babylon assets from a string and appends them to the scene.

```javascript
BABYLON.AppendSceneAsync("data:" + gltfString, scene).then(function () {
  // do something with the scene
});
```

See an example here: [Playground: Append Assets From A String](https://playground.babylonjs.com/#88CB6A#165) - Simple example showing how append objects from a string.

You can also load a .glb binary file from a data string as long as the binary data is base64 encoded:

```javascript
const base64_model_content = "data:;base64,BASE 64 ENCODED DATA...";
BABYLON.AppendSceneAsync(base64_model_content, scene).then(function () {
  // do something with the scene
});
```

Note that two mime types are allowed in the string data:

```javascript
const base64_model_content = "data:application/octet-stream;base64,-BASE 64 ENCODED DATA-";
const base64_model_content = "data:model/gltf-binary;base64,-BASE 64 ENCODED DATA-";
```

See an example here: [Playground: Load .glb From Binary Data](https://playground.babylonjs.com/#7F6S08#386) - Simple example showing how to load an object from a data string that is base64 encoded.

## LoadSceneAsync

Loads all Babylon assets from the file and creates a new scene.

```javascript
BABYLON.LoadSceneAsync("/assets/", "batman.obj", engine).then(function (scene) {
  // do something with the scene
});
```

## SceneLoader.ImportMesh

**Note:** Note: This function is deprecated. Use the `ImportMeshAsync` function instead.

Loads the meshes from the file and appends them to the scene.

```javascript
// The first parameter can be set to null to load all meshes and skeletons
BABYLON.SceneLoader.ImportMesh(["myMesh1", "myMesh2"], "./", "duck.gltf", scene, function (meshes, particleSystems, skeletons) {
  // do something with the meshes and skeletons
  // particleSystems are always null for glTF assets
});
```

See an example here: [Playground: Import Mesh](https://playground.babylonjs.com/#JUKXQD) - Simple example showing how to import an object into your scene.

### ImportMeshAsync

[Asynchronous](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous) version of the ImportMesh function. The result can be obtained by calling the returned [Promise](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Promises) or by using the [await](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await) keyword (note: to use the `await` keyword in the `createScene` function, it has to be marked as async in its definition).

```javascript
// The first parameter can be set to null to load all meshes and skeletons
const importPromise = BABYLON.ImportMeshAsync("./duck.gltf", scene, { meshNames: ["myMesh1", "myMesh2"] });
importPromise.then((result) => {
  //// Result has meshes, particleSystems, skeletons, animationGroups and transformNodes
});
```

See an example here: [Playground: Import Mesh Async with Promises](https://playground.babylonjs.com/#TVHK90#646) - Importing an object in your scene with async/await paradigm

or

```javascript
// The first parameter can be set to null to load all meshes and skeletons
const result = await BABYLON.ImportMeshAsync("./duck.gltf", scene, { meshNames: ["myMesh1", "myMesh2"] });
// Result has meshes, particleSystems, skeletons, animationGroups and transformNodes
```

See an example here: [Playground: Import Mesh Async with await](https://playground.babylonjs.com/#YAL1RN#307) - Importing an object in your scene with async/await paradigm

## LoadAssetContainerAsync

Loads all Babylon assets from the file and does not append them to the scene.

```javascript
BABYLON.LoadAssetContainerAsync("./duck.gltf", scene).then(function (container) {
  const meshes = container.meshes;
  const materials = container.materials;
  //...

  // Adds all elements to the scene
  container.addAllToScene();
});
```

See an example here: [Playground: Asset Container Load Example](https://playground.babylonjs.com/#JA1ND3#1053) - Simple example showing how to load assets into asset containers.

## ImportAnimationsAsync

Loads the animations from the file and merges them into the scene.
You can customize the import process using options and callbacks.

```javascript
BABYLON.ImportAnimationsAsync("./Elf_run.gltf", scene);
```

See an example here: [Playground: Importing Animations](https://playground.babylonjs.com/#UGD0Q0#315) - Simple example showing how to import animations into your scene.

## AppendSceneAsync

There are also `Async` versions of these functions that return promises:

```javascript
BABYLON.AppendSceneAsync("./duck.gltf", scene).then(function (scene) {
  // do something with the scene
});
```

See [How to Use Promises](https://doc.babylonjs.com/features/featuresDeepDive/events/promises) to learn more about using promises.

## Advanced Usage

Use the `onPluginActivatedObservable` to set properties and call methods specific to a particular loader.

```javascript
BABYLON.SceneLoader.OnPluginActivatedObservable.add(function (loader) {
  if (loader.name === "gltf") {
    // do something with the loader
    // loader.<option1> = <...>
    // loader.<option2> = <...>
  }
});
```

## Loading multiple assets

For assistance when loading multiple assets, the AssetsManager class can be used.
See [Load Files with Assets Manager](https://doc.babylonjs.com/features/featuresDeepDive/importers/assetManager).

## Direct loading base64 encoded models

Babylon.js supports directly loading models from base64-encoded [Data URLs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) without needing to create an object URL or download the file. When loading from a base64 data URL, the plugin is not automatically detected (with the exception of some glb formats). The `pluginExtension` parameter should be set when using base64 data URLs to ensure the correct plugin is used to load the model.

The format for a minimum base64 encoded model file is:

```javascript
data:;base64,<base64_encoded_file_contents>
```

The **;** before **base64** and the **,** following it are both required. See here for an example of loading an obj file in base64 encoding:
- [Playground: Load base64 model](https://playground.babylonjs.com/#58T0JY) - Example showing how to load a base64 encoded model using the data url syntax
