/** * Generate Two Meshes (an upper and lower) cross section from a set of intersection * points and a plane normal. Intersection Points do not have to be in order. */ private static List <Triangle> CreateFrom(List <Vector3> intPoints, Vector3 planeNormal) { List <Triangle> tris; if (Triangulator.MonotoneChain(intPoints, planeNormal, out tris)) { return(tris); } return(null); }
/** * Generate Two Meshes (an upper and lower) cross section from a set of intersection * points and a plane normal. Intersection Points do not have to be in order. */ private static Mesh[] CreateFrom(List <Vector3> intPoints, Vector3 planeNormal) { Vector3[] newVertices; Vector2[] newUvs; int[] newIndices; if (Triangulator.MonotoneChain(intPoints, planeNormal, out newVertices, out newIndices, out newUvs)) { Mesh upperCrossSection = new Mesh(); // fill the mesh structure upperCrossSection.vertices = newVertices; upperCrossSection.uv = newUvs; upperCrossSection.triangles = newIndices; // consider computing this array externally instead upperCrossSection.RecalculateNormals(); // for the lower cross section, we need to flip the triangles so they are // facing the right way int indiceCount = newIndices.Length; int[] flippedIndices = new int[indiceCount]; for (int i = 0; i < indiceCount; i += 3) { flippedIndices[i] = newIndices[i]; flippedIndices[i + 1] = newIndices[i + 2]; flippedIndices[i + 2] = newIndices[i + 1]; } Mesh lowerCrossSection = new Mesh(); // fill the mesh structure lowerCrossSection.vertices = newVertices; lowerCrossSection.uv = newUvs; lowerCrossSection.triangles = flippedIndices; // consider computing this array externally instead lowerCrossSection.RecalculateNormals(); return(new Mesh[] { upperCrossSection, lowerCrossSection }); } return(null); }