Exemplo n.º 1
0
    private Vector3 GetNormalCenter(MPath path, List <Vector3> normals, List <Vector3> vertices)
    {
        var centerNormal = Vector3.zero;

        for (int i = 0; i < path.Count; i++)
        {
            centerNormal += normals[vertices.IndexOf(path.GetLocalPosition(i))];
        }
        return(centerNormal / (float)path.Count);
    }
Exemplo n.º 2
0
    public IEnumerator Cap(MPath path)
    {
        while (buildingGraph)
        {
            yield return(new WaitForSeconds(0.01f));
        }

        mesh = manifold.gameObject.GetComponent <MeshFilter> ().mesh;
        var vertices  = mesh.vertices.ToList();
        var normals   = mesh.normals.ToList();
        var triangles = mesh.triangles.ToList();
        var normal    = GetNormalCenter(path, normals, vertices);

        normals.Add(normal);

        var center = path.GetCenterPosition() + normal.normalized * 0.1f;

        vertices.Add(center);

        var newVertex = vertices.IndexOf(center);

        for (int i = 0; i < path.Count; i++)
        {
            int vertex     = vertices.IndexOf(path.GetLocalPosition(i));
            int nextVertex = vertices.IndexOf(path.GetLocalPosition(i + 1 < path.Count ? i + 1 : 0));

            triangles.Add(vertex);
            triangles.Add(nextVertex);
            triangles.Add(newVertex);
        }
        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.normals   = normals.ToArray();
        SetSwitchedManifold(manifold);

        manifold.gameObject.GetComponent <MeshCollider> ().sharedMesh = mesh;
    }