Exemplo n.º 1
0
    public void Triangulate()
    {
        hexMesh.Clear();
        vertices.Clear();
        triangles.Clear();

        Vector3 center = transform.localPosition;

        for (HexDirection direction = HexDirection.NE; direction <= HexDirection.NW; direction++)
        {
            AddTriangle(
                center,
                center + HexMetrics.GetFirstInnerCorner(direction),
                center + HexMetrics.GetSecondInnerCorner(direction)
                );
        }
        //for (HexDirection direction = HexDirection.NE; direction <= HexDirection.NW; direction++)
        //{
        //    AddQuad(
        //        HexMetrics.GetFirstInnerCorner(direction),
        //        HexMetrics.GetSecondInnerCorner(direction),
        //        HexMetrics.GetFirstCorner(direction),
        //        HexMetrics.GetSecondCorner(direction)
        //        );
        //}

        hexMesh.vertices  = vertices.ToArray();
        hexMesh.triangles = triangles.ToArray();
        SetCellColor(color);
        hexMesh.RecalculateNormals();

        meshCollider.sharedMesh = hexMesh;
    }
Exemplo n.º 2
0
    void Triangulate(HexDirection direction)
    {
        Vector3 center = transform.localPosition;

        AddTriangle(
            center,
            center + hexMetrics.GetFirstInnerCorner(direction),
            center + hexMetrics.GetSecondInnerCorner(direction)
            );
        var centerUV = new Vector3(0.5f, 0.5f);

        AddTriangleUV(
            centerUV, GetFirstUVCorner(direction), GetSecondUVCorner(direction)
            );
    }
Exemplo n.º 3
0
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3 center      = cell.Position;
        Vector3 v1          = center + HexMetrics.GetFirstInnerCorner(direction);
        Vector3 v2          = center + HexMetrics.GetSecondInnerCorner(direction);
        Vector3 v1OuterBump = center + HexMetrics.GetFirstBumpOuterCorner(direction);
        Vector3 v2OuterBump = center + HexMetrics.GetSecondBumpOuterCorner(direction);

        Vector3 indices;

        indices.x = indices.y = indices.z = cell.Index;

        terrain.AddTriangle(center, v1, v2);
        terrain.AddTriangleCellData(indices, weights1);

        terrain.AddQuad(v1, v2, v1OuterBump, v2OuterBump);
        if (cell.IsUnderwater)
        {
            terrain.AddQuadCellData(indices, weights1, weights1);
        }
        else
        {
            terrain.AddQuadCellData(indices, terrainColorBump, terrainColorBump);
        }

        if (direction <= HexDirection.SE)
        {
            TriangulateConnection(direction, cell, v1OuterBump, v2OuterBump);
        }

        if (cell.IsUnderwater)
        {
            TriangulateWater(direction, cell, center);
        }

        if (!cell.IsUnderwater)
        {
            features.AddFeature(cell, (center + v1 + v2) * (1f / 3f));
        }
    }