using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace SplineMesh {
public class MeshUtility {
///
/// Returns a mesh with reserved triangles to turn back the face culling.
/// This is usefull when a mesh needs to have a negative scale.
///
///
///
public static int[] GetReversedTriangles(Mesh mesh) {
var res = mesh.triangles.ToArray();
var triangleCount = res.Length / 3;
for (var i = 0; i < triangleCount; i++) {
var tmp = res[i * 3];
res[i * 3] = res[i * 3 + 1];
res[i * 3 + 1] = tmp;
}
return res;
}
///
/// Returns a mesh similar to the given source plus given optionnal parameters.
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public static void Update(Mesh mesh,
Mesh source,
IEnumerable triangles = null,
IEnumerable vertices = null,
IEnumerable normals = null,
IEnumerable uv = null,
IEnumerable uv2 = null,
IEnumerable uv3 = null,
IEnumerable uv4 = null,
IEnumerable uv5 = null,
IEnumerable uv6 = null,
IEnumerable uv7 = null,
IEnumerable uv8 = null) {
mesh.hideFlags = source.hideFlags;
#if UNITY_2017_3_OR_NEWER
mesh.indexFormat = source.indexFormat;
#endif
mesh.triangles = new int[0];
mesh.vertices = vertices == null ? source.vertices : vertices.ToArray();
mesh.normals = normals == null ? source.normals : normals.ToArray();
mesh.uv = uv == null? source.uv : uv.ToArray();
mesh.uv2 = uv2 == null ? source.uv2 : uv2.ToArray();
mesh.uv3 = uv3 == null ? source.uv3 : uv3.ToArray();
mesh.uv4 = uv4 == null ? source.uv4 : uv4.ToArray();
#if UNITY_2018_2_OR_NEWER
mesh.uv5 = uv5 == null ? source.uv5 : uv5.ToArray();
mesh.uv6 = uv6 == null ? source.uv6 : uv6.ToArray();
mesh.uv7 = uv7 == null ? source.uv7 : uv7.ToArray();
mesh.uv8 = uv8 == null ? source.uv8 : uv8.ToArray();
#endif
mesh.triangles = triangles == null ? source.triangles : triangles.ToArray();
mesh.RecalculateBounds();
mesh.RecalculateTangents();
}
}
}