Exemplo n.º 1
0
    private void CreateStartVertex(Hex.HalfEdge edge)
    {
        Hex.HalfEdge prev;
        if (Region.Contains(edge.prev.polygon) && !Region.Contains(edge.prev.joins))
        {
            prev = edge.prev;
        }
        else
        {
            prev = edge.enters;
        }
        Vector3 left  = OffsetLineIntersection(prev.start.position, edge.start.position, edge.end.position, LineWidthExternal / 2.0f);
        Vector3 right = OffsetLineIntersection(prev.start.position, edge.start.position, edge.end.position, -LineWidthInternal / 2.0f);

        vertices.Add(left);
        vertices.Add(right);
        colors.Add(LineColor);
        colors.Add(LineColor);
    }
Exemplo n.º 2
0
    private void CreateEndVertex(Hex.HalfEdge edge)
    {
        Hex.HalfEdge next;
        if (Region.Contains(edge.next.polygon) && !Region.Contains(edge.next.joins))
        {
            next = edge.next;
        }
        else
        {
            next = edge.continues;
        }

        Vector3 left  = OffsetLineIntersection(edge.start.position, edge.end.position, next.end.position, LineWidthExternal / 2.0f);
        Vector3 right = OffsetLineIntersection(edge.start.position, edge.end.position, next.end.position, -LineWidthInternal / 2.0f);

        vertices.Add(left);
        vertices.Add(right);
        colors.Add(LineColor);
        colors.Add(LineColor);
    }
Exemplo n.º 3
0
    public void Apply()
    {
        vertices.Clear();
        triangles.Clear();
        colors.Clear();

        var lookup = new Dictionary <Hex.Vertex, int>();

        foreach (Hex.Polygon polygon in Chunk.Polygons)
        {
            for (int i = 0; i < 3; i++)
            {
                Hex.HalfEdge edge = polygon.GetBorder(i);
                if (Region.Contains(edge.polygon) && Region.Contains(edge.joins))
                {
                    int i1, i2;
                    if (!lookup.TryGetValue(edge.start, out i1))
                    {
                        i1 = vertices.Count;
                        CreateVertex(edge.start);
                        lookup[edge.start] = i1;
                    }
                    if (!lookup.TryGetValue(edge.end, out i2))
                    {
                        i2 = vertices.Count;
                        CreateVertex(edge.end);
                        lookup[edge.end] = i2;
                    }
                    CreateQuad(i1, i2, edge.side);
                }
            }
        }

        // Finalize mesh.
        mesh.Clear();
        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.colors    = colors.ToArray();
        mesh.RecalculateNormals();
    }