/// <summary>
        /// Creates the instance of the MeshBasedBake class that holds the result of baking.
        /// </summary>
        /// <param name="sources">Mesh sources.</param>
        /// <param name="settings">A settings for the baking process.</param>
        /// <returns>The instance of the MeshBasedBake class that holds the result of baking.</returns>
        public static MeshBasedBake Bake(MeshFilter[] sources, MeshBasedBakeSettings settings)
        {
            var result = new MeshBasedBake(settings);

            int numberOfMeshes = sources.Length;

            for (int i = 0; i < numberOfMeshes; i++)
            {
                result.AddWorldMesh(WorldMesh.Create(sources[i]));
            }
            return(result);
        }
        private void AddWorldMesh(WorldMesh mesh)
        {
            int numberOfTriangles = mesh.triangleNormals.Length;

            for (int t = 0; t < numberOfTriangles; t++)
            {
                if (Vector3.Angle(settings.upwards, mesh.triangleNormals[t]) > settings.maxSlope)
                {
                    OmittedTriangles++;
                    continue;
                }

                int index = 3 * t;
                int initialNumberOfVertices = vertices.Count;
                int a = FindOrAddVertex(mesh.vertices[mesh.triangles[index]]);
                int b = FindOrAddVertex(mesh.vertices[mesh.triangles[index + 1]]);
                int c = FindOrAddVertex(mesh.vertices[mesh.triangles[index + 2]]);

                if (IsValidTriangle(a, b, c) && !IsDuplicateTriangle(a, b, c))
                {
                    triangles.Add(a);
                    triangles.Add(b);
                    triangles.Add(c);
                }
                else
                {
                    OmittedTriangles++;
                    if (c >= initialNumberOfVertices)
                    {
                        vertices.RemoveAt(c);
                    }
                    if (b >= initialNumberOfVertices)
                    {
                        vertices.RemoveAt(b);
                    }
                    if (a >= initialNumberOfVertices)
                    {
                        vertices.RemoveAt(a);
                    }
                }
            }
        }