25 lines
733 B
C#
25 lines
733 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class MeshCombiner : MonoBehaviour
|
|
{
|
|
[SerializeField] private List<MeshFilter> sourceMeshFilters;
|
|
[SerializeField] private MeshFilter targetMeshFilter;
|
|
|
|
[ContextMenu("Combine Meshes")]
|
|
private void CombineMeshes()
|
|
{
|
|
var combine = new CombineInstance[sourceMeshFilters.Count];
|
|
|
|
for (var i = 0; i < sourceMeshFilters.Count; i++)
|
|
{
|
|
combine[i].mesh = sourceMeshFilters[i].sharedMesh;
|
|
combine[i].transform = sourceMeshFilters[i].transform.localToWorldMatrix;
|
|
}
|
|
|
|
var mesh = new Mesh();
|
|
mesh.CombineMeshes(combine);
|
|
targetMeshFilter.mesh = mesh;
|
|
}
|
|
} |