-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeshCombiner.cs
More file actions
31 lines (25 loc) · 986 Bytes
/
Copy pathMeshCombiner.cs
File metadata and controls
31 lines (25 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
}
// Create a new mesh and set its index format to UInt32
var mesh = new Mesh();
mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
// Combine the meshes with the UInt32 index format
mesh.CombineMeshes(combine);
// Set the combined mesh to the target MeshFilter
targetMeshFilter.mesh = mesh;
}
}