using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class CombineMeshNode : MeshProcessor { public List Source = new List(); public override void Execute(ProceduralMeshData m) { List vertices = new List(); List indices = new List(); List normals = new List(); List tangents = new List(); List> uvs = new List>(); //combine foreach (var meshData in Source) { if (meshData != null) { //append all indices foreach (var submeshIndices in meshData.Indices) { var newIndices = new int[submeshIndices.Length]; //offset indices for (int i = 0; i < newIndices.Length; ++i) { newIndices[i] = submeshIndices[i] + vertices.Count; } indices.Add(newIndices); } vertices.AddRange(meshData.Vertices); normals.AddRange(meshData.Normals); if (meshData.Tangents != null) { tangents.AddRange(meshData.Tangents); } while (uvs.Count < meshData.Uvs.Count){ uvs.Add(new List()); } for (int i = 0; i < meshData.Uvs.Count; ++i) { uvs[i].AddRange(meshData.Uvs[i]); } } } m.Vertices = vertices.ToArray(); m.Indices = indices; m.Normals = normals.ToArray(); m.Tangents = tangents.Count == 0 ? null : tangents.ToArray(); m.Uvs = uvs; } }