Example #1
0
    void TriangulateWaterShore(
        HexDirection direction, HexCell cell, HexCell neighbor, Vector3 center
        )
    {
        EdgeVertices e1 = new EdgeVertices(
            center + HexMetrics.GetFirstWaterCorner(direction),
            center + HexMetrics.GetSecondWaterCorner(direction)
            );

        water.AddTriangle(center, e1.v1, e1.v2);
        water.AddTriangle(center, e1.v2, e1.v3);
        water.AddTriangle(center, e1.v3, e1.v4);
        water.AddTriangle(center, e1.v4, e1.v5);

        Vector3 center2 = neighbor.Position;

        center2.y = center.y;
        EdgeVertices e2 = new EdgeVertices(
            center2 + HexMetrics.GetSecondSolidCorner(direction.Opposite()),
            center2 + HexMetrics.GetFirstSolidCorner(direction.Opposite())
            );

        waterShore.AddQuad(e1.v1, e1.v2, e2.v1, e2.v2);
        waterShore.AddQuad(e1.v2, e1.v3, e2.v2, e2.v3);
        waterShore.AddQuad(e1.v3, e1.v4, e2.v3, e2.v4);
        waterShore.AddQuad(e1.v4, e1.v5, e2.v4, e2.v5);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);

        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        if (nextNeighbor != null)
        {
            Vector3 v3 = nextNeighbor.Position + (nextNeighbor.IsUnderwater ?
                                                  HexMetrics.GetFirstWaterCorner(direction.Previous()) :
                                                  HexMetrics.GetFirstSolidCorner(direction.Previous()));
            v3.y = center.y;
            waterShore.AddTriangle(e1.v5, e2.v5, v3);
            waterShore.AddTriangleUV(
                new Vector2(0f, 0f),
                new Vector2(0f, 1f),
                new Vector2(0f, nextNeighbor.IsUnderwater ? 0f : 1f)
                );
        }
    }
Example #2
0
    //三角化填充河流周围
    void TriangulateAdjacentToRiver(
        HexDirection direction, HexCell cell, Vector3 center, EdgeVertices e
        )
    {
        if (cell.HasRoads)
        {
            TriangulateRoadAdjacentToRiver(direction, cell, center, e);
        }

        if (cell.HasRiverThroughEdge(direction.Next()))
        {
            if (cell.HasRiverThroughEdge(direction.Previous()))
            {
                center += HexMetrics.GetSolidEdgeMiddle(direction) *
                          (HexMetrics.innerToOuter * 0.5f);
            }
            else if (
                cell.HasRiverThroughEdge(direction.Previous2())
                )
            {
                center += HexMetrics.GetFirstSolidCorner(direction) * 0.25f;
            }
        }
        else if (
            cell.HasRiverThroughEdge(direction.Previous()) &&
            cell.HasRiverThroughEdge(direction.Next2())
            )
        {
            center += HexMetrics.GetSecondSolidCorner(direction) * 0.25f;
        }

        EdgeVertices m = new EdgeVertices(
            Vector3.Lerp(center, e.v1, 0.5f),
            Vector3.Lerp(center, e.v5, 0.5f)
            );

        TriangulateEdgeStrip(
            m, weights1, cell.Index,
            e, weights1, cell.Index
            );
        TriangulateEdgeFan(center, m, cell.Index);

        if (!cell.IsUnderwater && !cell.HasRoadThroughEdge(direction))
        {
            features.AddFeature(cell, (center + e.v1 + e.v5) * (1f / 3f));
        }
    }
Example #3
0
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3      center = cell.Position;
        EdgeVertices e      = new EdgeVertices(
            center + HexMetrics.GetFirstSolidCorner(direction),
            center + HexMetrics.GetSecondSolidCorner(direction)
            );

        if (cell.HasRiver)
        {
            if (cell.HasRiverThroughEdge(direction))
            {
                e.v3.y = cell.StreamBedY;
                if (cell.HasRiverBeginOrEnd)
                {
                    TriangulateWithRiverBeginOrEnd(direction, cell, center, e);
                }
                else
                {
                    TriangulateWithRiver(direction, cell, center, e);
                }
            }
            else
            {
                TriangulateAdjacentToRiver(direction, cell, center, e);
            }
        }
        else
        {
            TriangulateWithoutRiver(direction, cell, center, e);

            if (!cell.IsUnderwater && !cell.HasRoadThroughEdge(direction))
            {
                features.AddFeature(cell, (center + e.v1 + e.v5) * (1f / 3f));
            }
        }

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

        if (cell.IsUnderwater)
        {
            TriangulateWater(direction, cell, center);
        }
    }
Example #4
0
    void TriangulateWallStrip(HexDirection d, HexCell cell)
    {
        HexDirection castDir = d.Opposite();
        HexCell      n       = cell.GetNeighbor(castDir);

        if (CheckCellValid(n))
        {
            //limit to prevent infinite loops if something goes wrong
            for (int i = 0; i < 10; i++)
            {
                HexCell n2 = n.GetNeighbor(castDir);
                if (CheckCellValid(n2))
                {
                    n = n2;
                }
                else
                {
                    break;
                }
            }
            //n is final cell
            Vector3 offset = new Vector3(0, wallHeight, 0);

            EdgeVertices e1 = new EdgeVertices(
                cell.transform.localPosition + HexMetrics.GetFirstSolidCorner(castDir),
                n.transform.localPosition + HexMetrics.GetSecondSolidCorner(d)
                );

            EdgeVertices e2 = new EdgeVertices(
                e1.v1 + offset,
                e1.v2 + offset
                );
            wallMesh.AddQuad(e1, e2);

            EdgeVertices e3 = new EdgeVertices(
                offset + cell.transform.localPosition + HexMetrics.GetFirstCorner(castDir),
                offset + n.transform.localPosition + HexMetrics.GetSecondCorner(d)
                );
            wallMesh.AddQuad(e2, e3);

            EdgeVertices e4 = new EdgeVertices(
                offset + cell.transform.localPosition + HexMetrics.GetFirstCorner(castDir.Previous()),
                offset + n.transform.localPosition + HexMetrics.GetSecondCorner(d.Next())
                );
            wallMesh.AddQuad(e3, e4);
        }
    }
Example #5
0
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3 center = cell.Position;

        // 为了丰富cell的结构, 一条边,截成2段,新增两个边缘点
        EdgeVertices e = new EdgeVertices(
            center + HexMetrics.GetFirstSolidCorner(direction),
            center + HexMetrics.GetSecondSolidCorner(direction)
            );

        TriangulateEdgeFan(center, e, cell.color);

        if (direction <= HexDirection.SE)
        {
            TriangulateConnection(direction, cell, e);
        }
    }
Example #6
0
    /* creates the stage boundaries */
    void TriangulateOuterWallPanelCorner(HexDirection direction, HexCell cell, HexCell neighbor)
    {
        Vector3 offset   = new Vector3(0, wallHeight, 0);
        Vector3 endpoint = offset + cell.transform.localPosition + HexMetrics.GetSecondCorner(direction);

        EdgeVertices e1 = new EdgeVertices(
            cell.transform.localPosition + HexMetrics.GetSecondSolidCorner(direction),
            neighbor.transform.localPosition + HexMetrics.GetFirstSolidCorner(direction.Previous())
            );
        EdgeVertices e2 = new EdgeVertices(
            e1.v1 + offset,
            e1.v2 + offset
            );

        edgeMesh.AddQuad(e1, e2);
        edgeMesh.AddTriangle(e2.v1, endpoint, e2.v2);
    }
Example #7
0
    private void TriangulateWaterShore(HexDirection direction, HexObject cell, HexObject neighbour, Vector3 center1)
    {
        EdgeVertices e1 = new EdgeVertices(center1 + HexMetrics.GetFirstWaterCorner(direction), center1 + HexMetrics.GetSecondWaterCorner(direction));

        water.AddTriangle(center1, e1.v1, e1.v2);
        water.AddTriangle(center1, e1.v2, e1.v3);
        water.AddTriangle(center1, e1.v3, e1.v4);
        water.AddTriangle(center1, e1.v4, e1.v5);

        Vector3 center2 = neighbour.Position;

        center2.y = center1.y;
        EdgeVertices e2 = new EdgeVertices(center2 + HexMetrics.GetSecondSolidCorner(direction.Opposite()), center2 + HexMetrics.GetFirstSolidCorner(direction.Opposite()));

        if (cell.HasRiverThroughEdge(direction))
        {
            TriangulateEstuary(e1, e2, cell.IncomingRiver == direction);
        }
        else
        {
            waterShore.AddQuad(e1.v1, e1.v2, e2.v1, e2.v2);
            waterShore.AddQuad(e1.v2, e1.v3, e2.v2, e2.v3);
            waterShore.AddQuad(e1.v3, e1.v4, e2.v3, e2.v4);
            waterShore.AddQuad(e1.v4, e1.v5, e2.v4, e2.v5);
            waterShore.AddQuadUV(0f, 0f, 0f, 1f);
            waterShore.AddQuadUV(0f, 0f, 0f, 1f);
            waterShore.AddQuadUV(0f, 0f, 0f, 1f);
            waterShore.AddQuadUV(0f, 0f, 0f, 1f);
        }

        HexObject nextNeighbor = cell.GetNeighbour(direction.Next());

        if (nextNeighbor != null)
        {
            Vector3 v3 = nextNeighbor.Position + (nextNeighbor.IsUnderwater ? HexMetrics.GetFirstWaterCorner(direction.Previous()) : HexMetrics.GetFirstSolidCorner(direction.Previous()));
            v3.y = center1.y;
            waterShore.AddTriangle(
                e1.v5, e2.v5, v3
                );
            waterShore.AddTriangleUV(
                new Vector2(0f, 0f),
                new Vector2(0f, 1f),
                new Vector2(0f, nextNeighbor.IsUnderwater ? 0f : 1f)
                );
        }
    }
    void TriangulateWater(HexDirection direction, HexCell cell, Vector3 center)
    {
        //int diffStart = terrain.vertices.Count - terrain.terrainTypes.Count;
        center.y = cell.WaterSurfaceY;
        Vector3 c1 = center + HexMetrics.GetFirstSolidCorner(direction);
        Vector3 c2 = center + HexMetrics.GetSecondSolidCorner(direction);

        water.AddTriangle(center, c1, c2);

        if (direction <= HexDirection.SE)
        {
            HexCell neighbor = cell.GetNeighbor(direction);
            if (neighbor == null || !neighbor.IsUnderwater)
            {
                return;
            }

            Vector3 bridge = HexMetrics.GetBridge(direction);
            Vector3 e1     = c1 + bridge;
            Vector3 e2     = c2 + bridge;

            water.AddQuad(c1, c2, e1, e2);

            if (direction <= HexDirection.E)
            {
                HexCell nextNeighbor = cell.GetNeighbor(direction.Next());
                if (nextNeighbor == null || !nextNeighbor.IsUnderwater)
                {
                    return;
                }
                water.AddTriangle(
                    c2, e2, c2 + HexMetrics.GetBridge(direction.Next())
                    );
            }
        }

        /*int diffEnd = terrain.vertices.Count - terrain.terrainTypes.Count;
         * if (terrain.vertices.Count != terrain.terrainTypes.Count && diffStart != diffEnd) {
         *  Debug.Log("END TriangulateWater::");
         *  Debug.Log("terrain.vertices.Count::" + terrain.vertices.Count);
         *  Debug.Log("terrain.terrainTypes.Count::" + terrain.terrainTypes.Count);
         *  Debug.Log("diffStart::" + diffStart);
         *  Debug.Log("diffEnd::" + diffEnd);
         * }*/
    }
Example #9
0
    private void Triangulate(HexCell cell)
    {
        Vector3 center = cell.transform.localPosition;

        for (HexDirection direction = HexDirection.NE; direction <= HexDirection.NW; direction++)
        {
            Vector3 v1 = center + HexMetrics.GetFirstSolidCorner(direction);  //内六边形的第一个角坐标
            Vector3 v2 = center + HexMetrics.GetSecondSolidCorner(direction);

            EdgeVertices edge = new EdgeVertices(v1, v2);
            TriangulateEdgeFan(center, edge, cell.color);

            if (direction <= HexDirection.SE)
            {
                TriangulateConnection(direction, cell, center, edge);
            }
        }
    }
Example #10
0
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3 center = cell.transform.localPosition;
        Vector3 v1     = center + HexMetrics.GetFirstSolidCorner(direction);
        Vector3 v2     = center + HexMetrics.GetSecondSolidCorner(direction);

        AddTriangle(center, v1, v2);
        AddTriangleColor(cell.color);
        TriangulateConnection(direction, cell, v1, v2);
        if (direction == HexDirection.NE)
        {
            TriangulateConnection(direction, cell, v1, v2);
        }
        if (direction <= HexDirection.SE)
        {
            TriangulateConnection(direction, cell, v1, v2);
        }
    }
Example #11
0
    /// <summary>
    /// 根据方位将cell三角化
    /// </summary>
    private void Triangulate(HexDirection direction, HexCell cell)
    {
        // 内部三角形使单色...
        Vector3 center = cell.Position;

        EdgeVertices e = new EdgeVertices(
            center + HexMetrics.GetFirstSolidCorner(direction),
            center + HexMetrics.GetSecondSolidCorner(direction));

//        // 细分,一个三角形分为3个
        TriangulateEdgeFan(center, e, cell.Color);

        // ...剩下的四边形(梯形)使用混合
        if (direction <= HexDirection.SE)
        {
            TriangulateConnection(direction, cell, e);
        }
    }
Example #12
0
    private void TriangulateAdjacentToRiver(
        HexDirection direction, HexCell cell, Vector3 center, EdgeVertices e)
    {
        if (cell.HasRoads)
        {
            TriangulateRoadAdjacentToRiver(direction, cell, center, e);
        }

        if (cell.HasRiverThroughEdge(direction.Next()))
        {
            // Check whether we are on the inside of a curve.  This occurs when
            // both the previous and next direction contai a river. In this case teh center
            // will be moved towards the edge.
            if (cell.HasRiverThroughEdge(direction.Previous()))
            {
                center += HexMetrics.GetSolidEdgeMiddle(direction)
                          * (HexMetrics.innerToOuter * 0.5f);
                // Check whether this is a straight river, in that case move the center
                // towards the first corner.
            }
            else if (cell.HasRiverThroughEdge(direction.Previous2()))
            {
                center += HexMetrics.GetFirstSolidCorner(direction) * 0.25f;
            }
        }
        else if (
            cell.HasRiverThroughEdge(direction.Previous()) &&
            cell.HasRiverThroughEdge(direction.Next2()))
        {
            center += HexMetrics.GetSecondSolidCorner(direction) * 0.25f;
        }

        EdgeVertices m = new EdgeVertices(
            Vector3.Lerp(center, e.v1, 0.5f),
            Vector3.Lerp(center, e.v5, 0.5f));

        TriangulateEdgeStrip(m, cell.Color, e, cell.Color);
        TriangulateEdgeFan(center, m, cell.Color);

        if (!cell.IsUnderwater && !cell.HasRoadThroughEdge(direction))
        {
            features.AddFeature((center + e.v1 + e.v5) * (1f / 3f));
        }
    }
Example #13
0
    /// <summary>
    /// Recalculate single triangle of the cell based on its direction.
    /// </summary>
    /// <param name="direction">Direction of the triangle relative to cell center.</param>
    /// <param name="cell">Cell to recalculate triangle of.</param>
    void Triangulate(HexDirection direction, HexCell cell)
    {
        //	  -v3--v4-
        //	  \|    |/
        //	   v1--v2
        //		\  /
        //		 \/

        // 1) Add main triangle (center, v1, v2)
        Vector3 center = cell.transform.localPosition;
        Vector3 v1     = center + HexMetrics.GetFirstSolidCorner(direction);
        Vector3 v2     = center + HexMetrics.GetSecondSolidCorner(direction);

        AddTriangle(center, v1, v2);
        AddTriangleColor(cell.cellColor);

        // 2) Build a rectangular bridge. If is used so the bridge is built only once.
        // Also build two triangles left
        if (direction <= HexDirection.SE)
        {
            TriangulateConnection(direction, cell, v1, v2);
        }

        // Assign color to two last vertices from neighbor cell
        // Each vertex of hexagon is shared by three hexagons
        HexCell prevNeighbor = cell.GetNeighbor(direction.Previous()) ?? cell;
        HexCell neighbor     = cell.GetNeighbor(direction) ?? cell;
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next()) ?? cell;

        // 3) Fill the gaps left
//		AddTriangle(v1, center + HexMetrics.GetFirstCorner(direction), v3);
//		AddTriangleColor(
//			cell.cellColor,
//			(cell.cellColor + prevNeighbor.cellColor + neighbor.cellColor) / 3f,
//			bridgeColor
//		);
//
//		AddTriangle(v2, v4, center + HexMetrics.GetSecondCorner(direction));
//		AddTriangleColor(
//			cell.cellColor,
//			bridgeColor,
//			(cell.cellColor + prevNeighbor.cellColor + neighbor.cellColor) / 3f
//		);
    }
Example #14
0
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3      center = cell.Position;
        EdgeVertices e      = new EdgeVertices(
            center + HexMetrics.GetFirstSolidCorner(direction),
            center + HexMetrics.GetSecondSolidCorner(direction)
            );

        // 有河流
        if (cell.HasRiver)
        {
            // 指定方向边,有河流
            if (cell.HasRiverThroughEdge(direction))
            {
                // 边中点,下沉为河床
                e.v3.y = cell.StreamBedY;

                // 河流在这个cell结尾,或者 起源
                if (cell.HasRiverBeginOrEnd)
                {
                    TriangulateWithRiverBeginOrEnd(direction, cell, center, e);
                }
                else                 // 河流穿过了cell
                {
                    TriangulateWithRiver(direction, cell, center, e);
                }
            }
            else
            {
                TriangulateAdjacentToRiver(direction, cell, center, e);
            }
        }
        else         // 边缘没有河流,计算普通三角扇形结构
        {
            TriangulateEdgeFan(center, e, cell.Color);
        }

        // 计算桥连 和 三角混合区
        if (direction <= HexDirection.SE)
        {
            TriangulateConnection(direction, cell, e);
        }
    }
Example #15
0
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3 center = cell.transform.localPosition;
        Vector3 v1     = center + HexMetrics.GetFirstSolidCorner(direction, cell);
        Vector3 v2     = center + HexMetrics.GetSecondSolidCorner(direction, cell);

        //Fills in the top of the hex
        AddTriangle(center, v1, v2);
        AddTriangleColor(cell.color);

        //Add intermediate slopes
        //Don't bother with SW,W,NW because they would be duplicates
        if (direction == HexDirection.NE ||
            direction == HexDirection.E ||
            direction == HexDirection.SE)
        {
            TriangulateConnection(direction, cell, v1, v2);
        }
    }
    void TriangulateWaterShore(
        HexDirection direction, HexCell cell, HexCell neighbor, Vector3 center
        )
    {
        EdgeVertices e1 = new EdgeVertices(
            center + HexMetrics.GetFirstSolidCorner(direction),
            center + HexMetrics.GetSecondSolidCorner(direction)
            );

        water.AddTriangle(center, e1.v1, e1.v2);
        water.AddTriangle(center, e1.v2, e1.v3);
        water.AddTriangle(center, e1.v3, e1.v4);
        water.AddTriangle(center, e1.v4, e1.v5);

        Vector3      bridge = HexMetrics.GetBridge(direction);
        EdgeVertices e2     = new EdgeVertices(
            e1.v1 + bridge,
            e1.v5 + bridge
            );

        waterShore.AddQuad(e1.v1, e1.v2, e2.v1, e2.v2);
        waterShore.AddQuad(e1.v2, e1.v3, e2.v2, e2.v3);
        waterShore.AddQuad(e1.v3, e1.v4, e2.v3, e2.v4);
        waterShore.AddQuad(e1.v4, e1.v5, e2.v4, e2.v5);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);

        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        if (nextNeighbor != null)
        {
            waterShore.AddTriangle(
                e1.v5, e2.v5, e1.v5 + HexMetrics.GetBridge(direction.Next())
                );
            waterShore.AddTriangleUV(
                new Vector2(0f, 0f),
                new Vector2(0f, 1f),
                new Vector2(0f, nextNeighbor.IsUnderwater ? 0f : 1f)
                );
        }
    }
Example #17
0
    // Add a triangle using the hex metrics to get the vertex positions
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3 center = cell.transform.localPosition;
        Vector3 v1     = center + HexMetrics.GetFirstSolidCorner(direction);
        Vector3 v2     = center + HexMetrics.GetSecondSolidCorner(direction);

        AddTriangle(
            center,
            v1,
            v2
            );
        AddTriangleColor(cell.color);

        Vector3 bridge = HexMetrics.GetBridge(direction);
        Vector3 v3     = v1 + bridge;
        Vector3 v4     = v2 + bridge;

        AddQuad(v1, v2, v3, v4);

        //Blend colors from neighbors
        //Use current cell if no neighbor in direction
        HexCell prevNeighbor = cell.GetNeighbor(direction.Previous()) ?? cell;
        HexCell neighbor     = cell.GetNeighbor(direction) ?? cell;
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next()) ?? cell;

        Color bridgeColor = (cell.color + neighbor.color) * 0.5f;

        AddQuadColor(cell.color, bridgeColor);
        // Fill in gaps from creating bridge
        AddTriangle(v1, center + HexMetrics.GetFirstCorner(direction), v3);
        AddTriangleColor(
            cell.color,
            (cell.color + prevNeighbor.color + neighbor.color) / 3f,
            bridgeColor
            );
        //Add second bridge gap fill
        AddTriangle(v2, v4, center + HexMetrics.GetSecondCorner(direction));
        AddTriangleColor(
            cell.color,
            bridgeColor,
            (cell.color + neighbor.color + nextNeighbor.color) / 3f
            );
    }
Example #18
0
    /// <summary>
    /// 单个Cell,计算指定方向上的邻里Cell,连接三角形
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="cell"></param>
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3 center = cell.Position;

        // 截取指定方向的边
        EdgeVertices e = new EdgeVertices(
            center + HexMetrics.GetFirstSolidCorner(direction),
            center + HexMetrics.GetSecondSolidCorner(direction)
            );

        // 边截取之后的点,连接三角形
        TriangulateEdgeFan(center, e, cell.Color);

        // 混合区域连接:混合区域为共用区域,所以只需要处理一半的方向
        if (direction <= HexDirection.SE)
        {
            TriangulateConnection(direction, cell, e);
        }
    }
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3      center = cell.Position;
        EdgeVertices e      = new EdgeVertices(
            center + HexMetrics.GetFirstSolidCorner(direction),
            center + HexMetrics.GetSecondSolidCorner(direction)
            );

        if (cell.HasRiver)
        {
            if (cell.HasRiverThroughEdge(direction))
            {
                e.v3.y = cell.StreamBedY;
                if (cell.HasRiverBeginOrEnd)
                {
                    TriangulateWithRiverBeginOrEnd(direction, cell, center, e);
                }
                else
                {
                    TriangulateWithRiver(direction, cell, center, e);
                }
            }
            else
            {
                TriangulateAdjacentToRiver(direction, cell, center, e);
            }
        }
        else
        {
            //center
            TriangulateEdgeFan(center, e, (int)cell.TerrainType);
        }

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

        if (cell.IsUnderwater)
        {
            TriangulateWater(direction, cell, center);
        }
    }
Example #20
0
    void TriangulateAdjacentToRiver(
        HexDirection direction, HexCell cell, Vector3 center, EdgeVertices e
        )
    {
        if (cell.HasRoads)
        {
            TriangulateRoadAdjacentToRiver(direction, cell, center, e);
        }

        if (cell.HasRiverThroughEdge(direction.Next()))
        {
            if (cell.HasRiverThroughEdge(direction.Previous()))
            {
                center += HexMetrics.GetSolidEdgeMiddle(direction) *
                          (HexMetrics.innerToOuter * 0.5f);
            }
            else if (
                cell.HasRiverThroughEdge(direction.Previous2())
                )
            {
                center += HexMetrics.GetFirstSolidCorner(direction) * 0.25f;
            }
        }
        else if (
            cell.HasRiverThroughEdge(direction.Previous()) &&
            cell.HasRiverThroughEdge(direction.Next2())
            )
        {
            center += HexMetrics.GetSecondSolidCorner(direction) * 0.25f;
        }

        EdgeVertices m = new EdgeVertices(
            Vector3.Lerp(center, e.v1, 0.5f),
            Vector3.Lerp(center, e.v5, 0.5f)
            );

        TriangulateEdgeStrip(
            m, color1, cell.TerrainTypeIndex,
            e, color1, cell.TerrainTypeIndex
            );
        TriangulateEdgeFan(center, e, cell.TerrainTypeIndex);
    }
Example #21
0
    /// <summary>
    /// 填充河道细胞中其他没有河道的顶面部分
    /// 在此函数中处理河流和道路共存的情况
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="cell"></param>
    /// <param name="center"></param>
    /// <param name="e"></param>
    void TriangulateAdjacentToRiver(HexDirection direction, HexCell cell, Vector3 center, EdgeVertices e)
    {
        if (cell.HasRoads)
        {
            TriangulateRoadAdjacentToRiver(direction, cell, center, e);
        }

        if (cell.HasRiverThroughEdge(direction.Next()))
        {
            if (cell.HasRiverThroughEdge(direction.Previous()))
            {
                //当前方向的前一个方向和后一个方向上都有河道
                //就是河道的流入和流出之间相差一个方向单位
                center += HexMetrics.GetSoliEdgeMiddle(direction) * (HexMetrics.innerToOuter * 0.5f);
            }
            else if (cell.HasRiverThroughEdge(direction.Previous2()))
            {
                //当前方向的前一个方向和后两个方向上都有河道
                //就是笔直的河道,这是靠近前一个方向上的
                center += HexMetrics.GetFirstSolidCorner(direction) * 0.25f;
            }
        }
        else if (cell.HasRiverThroughEdge(direction.Previous()) && cell.HasRiverThroughEdge(direction.Next2()))
        {
            //当前方向的后一个方向和前两个方向上都有河道
            //就是笔直的河道,这是靠近后一个方向上的
            center += HexMetrics.GetSecondSolidCorner(direction) * 0.25f;
        }

        EdgeVertices m = new EdgeVertices(
            Vector3.Lerp(center, e.v1, 0.5f),
            Vector3.Lerp(center, e.v5, 0.5f)
            );

        TriangulateEdgeStrip(m, cell.Color, e, cell.Color);
        TriangulateEdgeFan(center, m, cell.Color);

        if (!cell.IsUnderwater && !cell.HasRoadThroughEdge(direction))
        {
            features.AddFeature(cell, (center + e.v1 + e.v5) * (1f / 3f));
        }
    }
Example #22
0
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3 center = cell.transform.localPosition;
        Vector3 v1     = center + HexMetrics.GetFirstSolidCorner(direction);
        Vector3 v2     = center + HexMetrics.GetSecondSolidCorner(direction);

        //Add base trinagle
        AddTriangle(center, v1, v2);
        AddTriangleColor();

        //Vector3 v3 = center + HexMetrics.GetFirstCorner(direction);
        //Vector3 v4 = center + HexMetrics.GetSecondCorner(direction);

        //Add triangle border
        //AddQuad(v1, v2, v3, v4);
        //AddQuadColor(Color.black);

        //Add particles
        AddParticles(center, direction, cell);
    }
Example #23
0
    /*** Unused? ***/

    /* creates the stage boundaries */
    void TriangulateOuterWallPanel(HexDirection direction, HexCell cell)
    {
        Vector3      center = cell.transform.localPosition;
        Vector3      offset = new Vector3(0, wallHeight, 0);
        EdgeVertices e1     = new EdgeVertices(
            center + HexMetrics.GetFirstSolidCorner(direction),
            center + HexMetrics.GetSecondSolidCorner(direction)
            );
        EdgeVertices e2 = new EdgeVertices(
            e1.v1 + offset,
            e1.v2 + offset
            );
        EdgeVertices e3 = new EdgeVertices(
            center + offset + HexMetrics.GetFirstCorner(direction),
            center + offset + HexMetrics.GetSecondCorner(direction)
            );

        wallMesh.AddQuad(e1, e2);
        wallMesh.AddQuad(e2, e3);
    }
Example #24
0
    private void Triangulate(HexCell cell)
    {
        Vector3 center = cell.transform.localPosition;

        for (int i = 0; i < 6; i++)
        {
            HexDirection dir = (HexDirection)i;
            Vector3      v1  = center + HexMetrics.GetFirstSolidCorner(dir);
            Vector3      v2  = center + HexMetrics.GetSecondSolidCorner(dir);

            //Vector3 bridge = HexMetrics.GetBridge(dir);

            AddTriangle(center, v1, v2);
            AddTriangleColor(cell.color);

            if (dir <= HexDirection.SE)
            {
                TriangulateConnection(dir, cell, v1, v2);
            }
        }
    }
    public void TriangulateAdjacentToRiver(HexDirection dir, HexCell cell, Vector3 center, EdgeVertices edges)
    {
        if (cell.HasRoads)
        {
            TriangulateRoadsAdjacentToRiver(dir, cell, center, edges);
        }


        if (cell.HasRiverThroughEdge(dir.Next()))
        {
            if (cell.HasRiverThroughEdge(dir.Previous()))
            {
                center += HexMetrics.GetSolidEdgeMiddle(dir) * (HexMetrics.InnerToOuter * 0.5f);
            }
            else if (cell.HasRiverThroughEdge(dir.Previous2()))
            {
                center += HexMetrics.GetFirstSolidCorner(dir) * 0.23f;
            }
        }
        else if (cell.HasRiverThroughEdge(dir.Previous()) && cell.HasRiverThroughEdge(dir.Next2()))
        {
            center += HexMetrics.GetSecondSolidCorner(dir) * 0.25f;
        }


        EdgeVertices modifiedEdges = new EdgeVertices(Vector3.Lerp(center, edges.v1, 0.5f), Vector3.Lerp(center, edges.v5, 0.5f));

        Color color = Weights1; // cell.Color;

        TriangulateEdgeStrip(modifiedEdges, color, cell.TerrainTypeIndex, edges, color, cell.CellIndex);
        TriangulateEdgeFan(center, modifiedEdges, color, cell.CellIndex);


        if (!cell.IsUnderwater && !cell.HasRoadThroughEdge(dir))
        {
            // centred in triangle
            Vector3 position = (center + edges.v1 + edges.v5) * (1f / 3f);
            FeatureManager.AddFeature(cell, position);
        }
    }
Example #26
0
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3 center = cell.transform.localPosition;
        Vector3 v1     = center + HexMetrics.GetFirstSolidCorner(direction);
        Vector3 v2     = center + HexMetrics.GetSecondSolidCorner(direction);

        AddTriangle(center, v1, v2);
        AddTriangleColor(cell.color);

        if (direction <= HexDirection.SE)
        {
            TriangulateConnection(direction, cell, v1, v2);
        }
        //Vector3 bridge = HexMetrics.GetBridge(direction);
        //Vector3 v3 = v1 + bridge;//center + HexMetrics.GetFirstCorner(direction);
        //Vector3 v4 = v2 + bridge;//center + HexMetrics.GetSecondCorner(direction);

        //AddQuad(v1, v2, v3, v4);

        //HexCell prevNeighbor = cell.GetNeighbour(direction.Previous()) ?? cell;
        //HexCell neighbor = cell.GetNeighbour(direction) ?? cell;
        //HexCell nextNeighbor = cell.GetNeighbour(direction.Next()) ?? cell;

        //Color bridgeColor = (cell.color + neighbor.color) * 0.5f;
        //AddQuadColor(cell.color, bridgeColor);

        //AddTriangle(v1, center + HexMetrics.GetFirstCorner(direction), v3);
        //AddTriangleColor(
        //    cell.color,
        //    (cell.color + prevNeighbor.color + neighbor.color) / 3f,
        //    bridgeColor
        //);

        //AddTriangle(v2, v4, center + HexMetrics.GetSecondCorner(direction));
        //AddTriangleColor(
        //    cell.color,
        //    bridgeColor,
        //    (cell.color + neighbor.color + nextNeighbor.color) / 3f
        //);
    }
Example #27
0
    /// <summary>
    /// 六边形中,创个指定方向的三角形
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="cell"></param>
    void Triangulate(HexDirection direction, HexCell cell)
    {
        #region 创建纯色内核区域
        Vector3 center = cell.transform.localPosition;
        Vector3 v1     = center + HexMetrics.GetFirstSolidCorner(direction);
        Vector3 v2     = center + HexMetrics.GetSecondSolidCorner(direction);

        // 连接三个顶点
        AddTriangle(center, v1, v2);

        // 添加颜色:六角形颜色
        AddTriangleColor(cell.color);
        #endregion

        #region 创建混合区
        // 混合区域是公共的,所以只需要处理一半的方向就可以
        if (direction <= HexDirection.SE)
        {
            TriangulateConnection(direction, cell, v1, v2);
        }
        #endregion
    }
Example #28
0
    void TriangulateConnection(
        HexDirection direction, HexCell cell, Vector3 v1, Vector3 v2)
    {
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }                                 //Don't make bridges to nowhere

        //Vector3 bridge = HexMetrics.GetFirstBridgeCorner(direction, neighbor);//HexMetrics.GetBridge(direction, cell);
        //Vector3 bridge2 = HexMetrics.GetSecondBridgeCorner(direction, neighbor);//HexMetrics.GetBridge(direction.Opposite(), neighbor);
        Vector3 bridge  = (neighbor.transform.localPosition) + HexMetrics.GetSecondSolidCorner(direction.Opposite(), neighbor);
        Vector3 bridge2 = (neighbor.transform.localPosition) + HexMetrics.GetFirstSolidCorner(direction.Opposite(), neighbor);
        //bridge = (bridge + bridge2) / 2;
        Vector3 v3 = bridge;  //v1 + bridge;
        Vector3 v4 = bridge2; // v2 + bridge2;

        v3.y = v4.y = neighbor.Height * HexMetrics.heightStep;

        AddQuad(v1, v2, v3, v4);
        AddQuadColor(cell.color, neighbor.color);

        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        //Three cells share one triangular connection, so we only need two, <=E = NE and E
        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            bridge  = (nextNeighbor.transform.localPosition) + HexMetrics.GetFirstSolidCorner(direction.Previous(), nextNeighbor);
            bridge2 = (neighbor.transform.localPosition) + HexMetrics.GetFirstSolidCorner(direction.Opposite(), neighbor);
            //bridge = (bridge + bridge2) / 2;
            Vector3 v5 = bridge;//v2 + bridge;
            v4 = bridge2;
            //v4 += bridge;
            v5.y = nextNeighbor.Height * HexMetrics.heightStep;
            AddTriangle(v2, v4, v5);
            AddTriangleColor(cell.color, neighbor.color, nextNeighbor.color);
        }
    }
Example #29
0
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3 center = cell.transform.localPosition;
        Vector3 v1     = center + HexMetrics.GetFirstSolidCorner(direction);
        Vector3 v2     = center + HexMetrics.GetSecondSolidCorner(direction);

        AddTriangle(center, v1, v2);
        AddTriangleColor(cell.color);

        Vector3 bridge = HexMetrics.GetBridge(direction);
        Vector3 v3     = v1 + bridge;
        Vector3 v4     = v2 + bridge;

        AddQuad(v1, v2, v3, v4);

        HexCell prevNeighbor = cell.GetNeighbor(direction.Previous()) ?? cell;
        HexCell neighbor     = cell.GetNeighbor(direction) ?? cell;
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next()) ?? cell;

        Color bridgeColor = (cell.color + neighbor.color) * 0.5f;

        AddQuadColor(cell.color, bridgeColor);

        //填充间隙
        AddTriangle(v1, center + HexMetrics.GetFirstCorner(direction), v3);
        AddTriangleColor(
            cell.color,
            (cell.color + prevNeighbor.color + neighbor.color) / 3f,
            bridgeColor
            );

        AddTriangle(v2, v4, center + HexMetrics.GetSecondCorner(direction));
        AddTriangleColor(
            cell.color,
            bridgeColor,
            (cell.color + neighbor.color + nextNeighbor.color) / 3f
            );
    }
Example #30
0
    void Triangulate(HexDirection direction, HexCell cell)
    {
        //纯色区域三角化使用单一颜色
        Vector3 center = cell.transform.localPosition;
        Vector3 v1     = center + HexMetrics.GetFirstSolidCorner(direction);
        Vector3 v2     = center + HexMetrics.GetSecondSolidCorner(direction);

        AddTriangle(center, v1, v2);
        AddTriangleColor(cell.color);
        //梯形混色区域
        Vector3 bridge = HexMetrics.GetBridge(direction);
        Vector3 v3     = v1 + bridge;
        Vector3 v4     = v2 + bridge;

        AddQuad(v1, v2, v3, v4);
        HexCell prevNeighbor = cell.GetNeighbor(direction.Previous()) ?? cell;
        HexCell neighbor     = cell.GetNeighbor(direction) ?? cell;
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next()) ?? cell;

        AddQuadColor(cell.color,
                     (cell.color + prevNeighbor.color + neighbor.color) * 0.5f);
        //补上被剔除的两个三角形(第一个三角形三个顶点的颜色分别是v1本色,2三个六边形混色,3桥色)
        Color bridgeColor = (cell.color + neighbor.color) * 0.5f;

//        AddQuadColor(cell.color, bridgeColor);
        AddTriangle(v1, center + HexMetrics.GetFirstCorner(direction), v3);
        AddExcludedTriangleColor(
            cell.color,
            (cell.color + prevNeighbor.color + neighbor.color) / 3f,
            bridgeColor);
        AddTriangle(v2, v4, center + HexMetrics.GetSecondCorner(direction));
        AddExcludedTriangleColor(
            cell.color,
            bridgeColor,
            (cell.color + neighbor.color + nextNeighbor.color) / 3f
            );
    }