Mesh.CombineMeshes Manual     Reference     Scripting  
Scripting > Runtime Classes > Mesh
Mesh.CombineMeshes

function CombineMeshes (combine : CombineInstance[], mergeSubMeshes : bool = true, useMatrices : bool = true) : void

Description

Combines several meshes into this mesh.

Combining meshes is useful for performance optimization. If mergeSubMeshes is true, all the meshes will be combined to a single submesh. Otherwise each mesh will go into a different submesh. If all meshes share the same material, set this to true. If useMatrices is false, the transform matrices in CombineInstance structs will be ignored.

// Simple Mesh combiner, need to look after materials and subMeshes.
function Start () {
var renderers : Renderer[] = GetComponentsInChildren(Renderer);
var combine : CombineInstance[] = new CombineInstance[renderers.Length];
for (var i = 0; i < renderers.Length; i++)
{
combine[i].mesh = renderers[i].sharedMesh;
combine[i].transform = renderers[i].transform.localToWorldMatrix;
renderers[i].enabled = false;
}
renderer.mesh = new Mesh();
renderer.mesh.CombineMeshes (combine);
}