Getting Started - Chapter 2 - Combining Meshes

Combining Meshes Using Merge Meshes

This is a straight forwarded way of combining two or more meshes.

const combined = BABYLON.Mesh.MergeMeshes(Array_of_Meshes_to_Combine)

In our case this would be

const house = BABYLON.Mesh.MergeMeshes([box, roof])
Combining Meshes In Your Scene

house 5

The first thing we note is that the whole house is covered in only one of the materials used. Fortunately this can be corrected using the multiMultiMaterial parameter of MergeMeshes, unfortunately this is the final parameter of a long list. The code now looks like

const house = BABYLON.Mesh.MergeMeshes([box, roof], true, false, null, false, true);

At this stage it is important to note that the second parameter being true disposes of the original meshes and the last parameter being true allows the original material to be applied separately to the parts matching the original meshes.

Combining Meshes And Preserving Material Assignments

house 3

Before considering how to make multiple copies of our house we will first: find out the basics of exporting our models; how to import models made with Babylon.js or other software; and how to display your scene or models on your own website.

Further reading