Mesh Operations
Combine and modify meshes:
// Merge multiple meshes into one for better performance
const merged = BABYLON.Mesh.MergeMeshes(
[box, sphere, cylinder], // Meshes to merge
true, // Dispose original meshes
true, // Allow different materials
undefined, // Use default world matrix
false, // Don't clone meshes
true // Allow different vertex colors
);
// Create instances for repeated objects with shared geometry
const boxInstance = box.createInstance("boxInstance");
boxInstance.position.x = 5;
// Create many instances efficiently
for (let i = 0; i < 100; i++) {
const instance = box.createInstance("box" + i);
instance.position = new BABYLON.Vector3(
Math.random() * 20 - 10,
Math.random() * 5,
Math.random() * 20 - 10
);
instance.rotation.y = Math.random() * Math.PI * 2;
}