Imported Meshes
Load 3D models created in external applications:
// Load a single model (glTF or GLB format - recommended)
BABYLON.SceneLoader.ImportMesh(
"", // Names of meshes to import (empty = all)
"./models/", // Path to models
"character.glb", // Filename
scene, // Scene to import into
(meshes, particleSystems, skeletons, animationGroups) => {
// Successfully imported
const character = meshes[0];
character.scaling = new BABYLON.Vector3(0.1, 0.1, 0.1);
// Play animations if available
if (animationGroups.length > 0) {
animationGroups[0].start(true); // true = loop
}
}
);
// Asynchronous loading with await
async function loadModel() {
const result = await BABYLON.SceneLoader.ImportMeshAsync(
"", "./models/", "scene.gltf", scene
);
// Process imported meshes
for (const mesh of result.meshes) {
mesh.checkCollisions = true;
}
// Handle animations
if (result.animationGroups.length > 0) {
const idleAnim = result.animationGroups.find(g => g.name === "Idle");
if (idleAnim) idleAnim.start(true);
}
}
// Load a complete scene (replaces current scene)
BABYLON.SceneLoader.Load("./models/", "environment.glb", engine, (newScene) => {
// newScene is now the active scene
newScene.createDefaultCameraOrLight(true, true, true);
});