コード例 #1
0
        public void CreateCornerTriangle(
            HexDirection direction,
            int elevation,
            Color color1,
            Color color2,
            Color color3
            )
        {
            Vector3 vertex5 = renderData.Vertex2 + HexMetrics.GetBridge(direction);

            vertex5.y = elevation * HexMetrics.elevationStep;

            Vector3[] edgeTriangleVertices = new Vector3[3] {
                renderData.Vertex2,
                renderData.Vertex4,
                vertex5
            };

            Color[] edgeTriangleColors = new Color[3] {
                color1,
                color2,
                color3
            };

            AddTriangle(
                edgeTriangleVertices,
                edgeTriangleColors
                );
        }
コード例 #2
0
    /// <summary>
    /// 创建混合区
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="cell"></param>
    /// <param name="v1"></param>
    /// <param name="v2"></param>
    void TriangulateConnection(HexDirection direction, HexCell cell, Vector3 v1, Vector3 v2)
    {
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }

        // 获取指定方向上的邻里桥
        Vector3 bridge = HexMetrics.GetBridge(direction);
        Vector3 v3     = v1 + bridge;
        Vector3 v4     = v2 + bridge;

        // 通过桥,创建矩形混合区域
        AddQuad(v1, v2, v3, v4);

        // 桥混合区,只是指定方向上的邻里颜色混合
        AddQuadColor(cell.color, neighbor.color);

        // 指定方向的下个方位的邻居
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        // 桥 和 相邻3色混合三角形区域
        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            AddTriangle(v2, v4, v2 + HexMetrics.GetBridge(direction.Next()));
            AddTriangleColor(cell.color, neighbor.color, nextNeighbor.color);
        }
    }
コード例 #3
0
ファイル: HexGridChunk.cs プロジェクト: RistoSK/Firekeeper
    private void TriangulateConnection(HexDirection direction, HexCell cell, EdgeVertices e1)
    {
        HexCell neighbor = cell.GetNeighbor(direction);

        // TODO: check if removing the null check breaks the logic, neighbor == null
        if (!neighbor)
        {
            return;
        }

        Vector3 bridge = HexMetrics.GetBridge(direction);

        EdgeVertices e2 = new EdgeVertices(
            e1.v1 + bridge,
            e1.v5 + bridge
            );

        TriangulateEdgeStrip(e1, cell.Color, e2, neighbor.Color, cell.HasWallThroughEdge(direction));
        //TriangulateEdgeStrip(e1, e2, cell.HasWallThroughEdge(direction));

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

        // TODO: check if removing the null check breaks the logic, nextNeighbor == null
        if (direction > HexDirection.East || !nextNeighbor)
        {
            return;
        }

        Vector3 v5 = e1.v5 + HexMetrics.GetBridge(direction.Next());

        TriangulateCorner(v5, nextNeighbor, e1.v5, cell, e2.v5, neighbor);
    }
コード例 #4
0
ファイル: HexMesh.cs プロジェクト: matrix09/Shader_CatLike
    void TriangulateConnection(
        HexDirection direction, HexCell cell, Vector3 v1, Vector3 v2
        )
    {
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }

        #region B : Rectangles

        Vector3 bridge = HexMetrics.GetBridge(direction);
        Vector3 v3     = v1 + bridge;
        Vector3 v4     = v2 + bridge;
        v3.y = v4.y = neighbor.Elevation * HexMetrics.ElevationStpe;
        TriangulateEageConnections(v1, v2, cell, v3, v4, neighbor);

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

        #region C : Triangles
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());
        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            Vector3 v5 = v2 + HexMetrics.GetBridge(direction.Next());
            v5.y = neighbor.Elevation * HexMetrics.ElevationStpe;
            AddTriangle(v2, v4, v5);
            AddTriangleColor(cell.color, neighbor.color, nextNeighbor.color);
        }
        #endregion
    }
コード例 #5
0
        public RenderData(
            HexDirection direction,
            Entity entity,
            int neighborElevation
            )
        {
            EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
            var           translation   = entityManager.GetComponentData <Translation>(entity);

            this.entity = entity;

            this.centerPosition = new Vector3(
                translation.Value.x,
                translation.Value.y,
                translation.Value.z
                );

            this.bridge  = HexMetrics.GetBridge(direction);
            this.vertex1 = centerPosition + HexMetrics.GetFirstSolidCorner(direction);
            this.vertex2 = centerPosition + HexMetrics.GetSecondSolidCorner(direction);
            this.vertex3 = vertex1 + bridge;
            this.vertex4 = vertex2 + bridge;

            vertex3.y = vertex4.y = neighborElevation * HexMetrics.elevationStep;
        }
コード例 #6
0
ファイル: HexMesh.cs プロジェクト: matrix09/Shader_CatLike
    void TriangulateConnection(HexDir dir, HexCell cell, Vector3 v1, Vector3 v2)
    {
        HexCell Neighbor = cell.GetHexNeighbour(dir);

        if (null == Neighbor)
        {
            return;
        }
        //add rectangle
        Vector3 v3 = v1 + HexMetrics.GetBridge(dir);
        Vector3 v4 = v2 + HexMetrics.GetBridge(dir);

        AddQuad(v1, v2, v3, v4);


        AddQuadColor(cell.color, Neighbor.color);

        HexCell nextNeighbor = cell.GetHexNeighbour(HexDirectionExtensions.GetNextDir(dir));

        if (null != nextNeighbor)
        {
            AddTriangle(v2, v4, v2 + HexMetrics.GetBridge(HexDirectionExtensions.GetNextDir(dir)));
            AddTriangleColor(cell.color, Neighbor.color, nextNeighbor.color);
        }
    }
コード例 #7
0
    void TriangulateConnection(
        HexDirection direction, HexCell cell, Vector3 v1, Vector3 v2
        )
    {
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }

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

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

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

        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            AddTriangle(v2, v4, v2 + HexMetrics.GetBridge(direction.Next()));
            AddTriangleColor(cell.Color, neighbor.Color, nextNeighbor.Color);
        }
    }
コード例 #8
0
ファイル: HexGridChunk.cs プロジェクト: CCSanders/hex-game
    //e1 = solid edge vertices
    void TriangulatePoliticalBorder(HexDirection direction, HexCell cell, EdgeVertices e1)
    {
        if (cell.IsNeighborFriendly(direction))
        {
            return;
        }

        Vector3      center = cell.Position;
        EdgeVertices e3     = new EdgeVertices(
            center + HexMetrics.GetFirstCorner(direction),
            center + HexMetrics.GetSecondCorner(direction)
            );

        politicalBorders.AddQuad(e1.v1, e1.v2, e3.v1, e3.v2);
        politicalBorders.AddQuad(e1.v2, e1.v3, e3.v2, e3.v3);
        politicalBorders.AddQuad(e1.v3, e1.v4, e3.v3, e3.v4);
        politicalBorders.AddQuad(e1.v4, e1.v5, e3.v4, e3.v5);

        politicalBorders.AddQuadUV(0f, 0f, 1f, 0f);
        politicalBorders.AddQuadUV(0f, 0f, 1f, 0f);
        politicalBorders.AddQuadUV(0f, 0f, 1f, 0f);
        politicalBorders.AddQuadUV(0f, 0f, 1f, 0f);

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

        if (cell.IsNeighborFriendly(direction.Next()))
        {
            Debug.Log("corner should be added");

            politicalBorders.AddTriangle(e3.v5, e1.v5 + HexMetrics.GetBridge(direction.Next()), e1.v5);
            politicalBorders.AddTriangleUV(new Vector2(0f, 0f), new Vector2(0f, 1f), new Vector2(0f, 1f));
        }
    }
コード例 #9
0
ファイル: HexGridChunk.cs プロジェクト: enatork/HexMap
    private void TriangulateWater(HexDirection direction, HexCell cell, Vector3 center)
    {
        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())
                );
        }
    }
コード例 #10
0
    void TriangulateConnection(HexCell cell, HexDirections direction, Vector3 v1, Vector3 v2)
    {
        HexCell neighbor = cell.GetNeighbors(direction);

        if (neighbor == null)
        {
            return;
        }

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

        v3.y = v4.y = neighbor.Elevation * HexMetrics.elevationStep;

        TriangulateConnectionTerrace(v1, v2, cell, v3, v4, neighbor);

        // Add triagles betwen bridges.
        HexCell nextNeighbor = cell.GetNeighbors(direction.Next());

        if (direction <= HexDirections.E && nextNeighbor != null)
        {
            Vector3 v5 = v2 + HexMetrics.GetBridge(direction.Next());
            v5.y = nextNeighbor.Elevation * HexMetrics.elevationStep;

            AddTriangle(v2, v4, v5);
            AddTriangleColor(cell.color, neighbor.color, nextNeighbor.color);
        }
    }
コード例 #11
0
ファイル: HexMesh.cs プロジェクト: bxck75/HexMap
    private void CreateBridge(
        HexDirection direction, HexCell cell, EdgeVertices edge)
    {
        var neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }

        var bridge = HexMetrics.GetBridge(direction);

        bridge.y = neighbor.Position.y - cell.Position.y;
        var e2 = new EdgeVertices(
            edge.v1 + bridge,
            edge.v4 + bridge
            );

        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            TriangulateEdgeTerraces(edge, cell, e2, neighbor);
        }
        else
        {
            TriangulateEdgeStrip(edge, cell.Color, e2, neighbor.Color);
        }

        CreateTriangleCorners(direction, cell, edge.v4, neighbor, e2.v4);
    }
コード例 #12
0
ファイル: HexMesh.cs プロジェクト: bxck75/HexMap
    private void CreateTriangleCorners(HexDirection direction, HexCell cell, Vector3 v2, HexCell neighbor, Vector3 v4)
    {
        var nextNeighbor = cell.GetNeighbor(direction.Next());

        if (nextNeighbor != null && direction <= HexDirection.E)
        {
            var v5 = v2 + HexMetrics.GetBridge(direction.Next());
            v5.y = nextNeighbor.Position.y;
            if (cell.Elevation <= neighbor.Elevation)
            {
                if (cell.Elevation <= nextNeighbor.Elevation)
                {
                    TriangulateCorner(v2, cell, v4, neighbor, v5, nextNeighbor);
                }
                else
                {
                    TriangulateCorner(v5, nextNeighbor, v2, cell, v4, neighbor);
                }
            }
            else if (neighbor.Elevation <= nextNeighbor.Elevation)
            {
                TriangulateCorner(v4, neighbor, v5, nextNeighbor, v2, cell);
            }
            else
            {
                TriangulateCorner(v5, nextNeighbor, v2, cell, v4, neighbor);
            }
        }
    }
コード例 #13
0
    private void TriangulateConnection(HexDirection direction, HexCell cell, Vector3 v1, Vector3 v2)
    {
        var neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }
        var bridge = HexMetrics.GetBridge(direction);
        var v3     = v1 + bridge;
        var v4     = v2 + bridge;

        v3.y = v4.y = neighbor.Elevation * HexMetrics.elevation;

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

        var nxtNeighbor = cell.GetNeighbor(direction.Next());

        if (direction <= HexDirection.E && nxtNeighbor != null)
        {
            Vector3 v5 = v2 + HexMetrics.GetBridge(direction.Next());
            v5.y = nxtNeighbor.Elevation * HexMetrics.elevation;
            AddTriangle(v2, v4, v5);
            AddTriangleColor(cell.color, neighbor.color, nxtNeighbor.color);
        }
    }
コード例 #14
0
    void Triangulate(HexDirection direction, HexCell cell)
    {
        Vector3 center = cell.transform.localPosition;
        Vector3 v1     = center + HexMetrics.GetFirstSolidCorner(direction);
        Vector3 v2     = center + HexMetrics.GetSecondSolidCorner(direction);
        Vector3 bridge = HexMetrics.GetBridge(direction);
        Vector3 v3     = v1 + bridge;
        Vector3 v4     = v2 + bridge;

        AddTriangle(center, v1, v2);
        AddTriangleColor(cell.color);
        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
            );
    }
コード例 #15
0
ファイル: HexMesh.cs プロジェクト: lee17017/HexField
    private void TriangulateConnection(HexCell cell, HexDirection direction, Vector3 v1, Vector3 v2)//Internal Bridges between hex cells and triangles
    {
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }
        Vector3 bridge = HexMetrics.GetBridge(direction);
        Vector3 v3     = v1 + bridge;
        Vector3 v4     = v2 + bridge;

        v3.y = v4.y = HexMetrics.elevationStep * neighbor.Elevation;

        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            TriangulateEdgeTerraces(v1, v2, v3, v4, cell, neighbor);
        }
        else
        {
            AddQuad(v1, v2, v3, v4);
            AddQuadColor(cell.color, neighbor.color);
        }
        //Triangle to the right of bridge:
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        if (direction <= HexDirection.E && nextNeighbor != null) //NE, E
        {
            Vector3 v5 = v2 + HexMetrics.GetBridge(direction.Next());
            v5.y = HexMetrics.elevationStep * nextNeighbor.Elevation;
            AddTriangle(v2, v4, v5);
            AddTriangleColor(cell.color, neighbor.color, nextNeighbor.color);
        }
    }
コード例 #16
0
    /// <summary>
    /// bei höhenunterschied werden die vertiecies mit filler triangles gefüllt
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="cell"></param>
    /// <param name="e1"></param>
    void TriangulateConnection(
        HexDirection direction, HexCell cell, EdgeVertices e1)
    {
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }

        Vector3 bridge = HexMetrics.GetBridge(direction);

        bridge.y = neighbor.Position.y - cell.Position.y;
        EdgeVertices e2 = new EdgeVertices(
            e1.v1 + bridge,
            e1.v4 + bridge);

        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            TriangulateEdgeTerraces(e1, cell, e2, neighbor);
        }
        else
        {
            TriangulateEdgeStrip(e1, cell.Color, e2, neighbor.Color);
        }

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

        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            Vector3 v5 = e1.v4 + HexMetrics.GetBridge(direction.Next());
            v5.y = nextNeighbor.Position.y;

            if (cell.Elevation <= neighbor.Elevation)
            {
                if (cell.Elevation <= nextNeighbor.Elevation)
                {
                    TriangulateCorner(
                        e1.v4, cell, e2.v4, neighbor, v5, nextNeighbor
                        );
                }
                else
                {
                    TriangulateCorner(
                        v5, nextNeighbor, e1.v4, cell, e2.v4, neighbor);
                }
            }
            else if (neighbor.Elevation <= nextNeighbor.Elevation)
            {
                TriangulateCorner(
                    e2.v4, neighbor, v5, nextNeighbor, e1.v4, cell);
            }
            else
            {
                TriangulateCorner(
                    v5, nextNeighbor, e1.v4, cell, e2.v4, neighbor);
            }
        }
    }
コード例 #17
0
ファイル: HexMesh.cs プロジェクト: sagarpatel2570/HexMap-PCG
    void TriangulateConnection(HexDirection direction, HexCell cell, Vector3 v1, Vector3 v2)
    {
        Vector3 bridge = HexMetrics.GetBridge(direction);
        Vector3 v3     = v1 + bridge;
        Vector3 v4     = v2 + bridge;

        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor != null)
        {
            v3.y = v4.y = neighbor.transform.localPosition.y;
        }

        if (direction <= HexDirection.SE)
        {
            AddQuad(v1, v2, v3, v4);
            AddQuadColor(
                room.region.regionColor,
                room.region.regionColor,
                room.region.regionColor,
                room.region.regionColor
                );
        }
        /// if the neifhfbour is wall we create wall
        if (cell.edgeTypes[(int)direction] == EdgeType.WALL)
        {
            AddConnectionWall(v1, v2, v3, v4, cell);
        }
        /// if the neihgbour is door we create door
        if (cell.edgeTypes[(int)direction] == EdgeType.DOOR)
        {
            GenerateDoor(v1, v2, v3, v4);
        }

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

        Vector3 v2Top = v2 + Vector3.up * HexMetrics.wallHeight;
        Vector3 v4Top = v4 + Vector3.up * HexMetrics.wallHeight;

        if (direction <= HexDirection.NW)
        {
            Vector3 v5 = v2 + HexMetrics.GetBridge(direction.Next());
            if (nextNeighbor != null)
            {
                v5.y = nextNeighbor.transform.localPosition.y;
            }
            if (direction <= HexDirection.E)
            {
                AddTriangle(v2, v4, v5);
                AddTriangleColor(room.region.regionColor);
            }
            /// create a triangle wall adjacent to wall
            if (cell.edgeTypes[(int)direction] == EdgeType.WALL || cell.edgeTypes[(int)direction] == EdgeType.DOOR)
            {
                AddConnectionWallTriangle(v2, v4, v5, cell);
            }
        }
    }
コード例 #18
0
    void GenBridge(HexCell cell, Direction dir, Vector3 v1, Vector3 v2, Vector3 ie1, Vector3 ie2)
    {
        if (cell.GetNeigbors(dir) == null)
        {
            return;
        }

        Vector3    bridge     = HexMetrics.GetBridge(cell, dir);
        BridgeType bridgeType = GetBridgeType(cell, dir);

        //生成两个六边形间的连接
        //只有slope类型的连接会生成梯度上升
        if (bridgeType == BridgeType.Slope)
        {
            GenSlopBridge(bridge, v1, v2);
        }
        else
        {
            GenFlatBridge(bridge, v1, v2);
        }
        //生成三个六边形的间的三角形
        if (dir != Direction.SE && cell.GetNeigbors(dir.Next()) != null)
        {
            Vector3 begin = v2;
            Vector3 left  = begin + HexMetrics.GetBridge(cell, dir);
            Vector3 right = begin + HexMetrics.GetBridge(cell, dir.Next());

            HexCell leftCell  = cell.GetNeigbors(dir);
            HexCell rightCell = cell.GetNeigbors(dir.Next());

            int beginLevel = cell.Elevation;
            int leftLevel  = leftCell.Elevation;
            int rightLevel = rightCell.Elevation;

            //这里需要将三个点按高度排序,传参又要符合特定顺序
            if (beginLevel < leftLevel)
            {
                if (beginLevel < rightLevel)
                {
                    GenCornerTriangle(begin, cell, left, leftCell, right, rightCell);
                }
                else
                {
                    GenCornerTriangle(right, rightCell, begin, cell, left, leftCell);
                }
            }
            else
            {
                if (leftLevel < rightLevel)
                {
                    GenCornerTriangle(left, leftCell, right, rightCell, begin, cell);
                }
                else
                {
                    GenCornerTriangle(right, rightCell, begin, cell, left, leftCell);
                }
            }
        }
    }
コード例 #19
0
ファイル: HexMesh.cs プロジェクト: JourneyHans/HexMap
    // 处理六边形连接处的网格
    void TriangulateConnection(HexDirection direction, HexCell cell, EdgeVertices e1)
    {
        // 1. 六边形之间连接的矩形
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }
        Vector3 bridge = HexMetrics.GetBridge(direction);

        bridge.y = neighbor.Position.y - cell.Position.y;
        EdgeVertices e2 = new EdgeVertices(
            e1.v1 + bridge,
            e1.v4 + bridge);

        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            // 如果是有坡度的,就插值计算阶梯的网格
            TriangulateEdgeTerraces(e1, cell, e2, neighbor);
        }
        else
        {
            // 否则,正常处理网格
            TriangulateEdgeStrip(e1, cell.Color, e2, neighbor.Color);
        }

        // 2. 剩下的三角形缝隙
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            Vector3 v5 = e1.v4 + HexMetrics.GetBridge(direction.Next());
            // 处理缝隙高度
            v5.y = nextNeighbor.Position.y;

            // 下面的算法是在处理三角形缝隙的网格渲染顺序
            // 从最低到最高绘制
            if (cell.Elevation <= neighbor.Elevation)
            {
                if (cell.Elevation <= nextNeighbor.Elevation)
                {
                    TriangulateCorner(e1.v4, cell, e2.v4, neighbor, v5, nextNeighbor);
                }
                else
                {
                    TriangulateCorner(v5, nextNeighbor, e1.v4, cell, e2.v4, neighbor);
                }
            }
            else if (neighbor.Elevation <= nextNeighbor.Elevation)
            {
                TriangulateCorner(e2.v4, neighbor, v5, nextNeighbor, e1.v4, cell);
            }
            else
            {
                TriangulateCorner(v5, nextNeighbor, e1.v4, cell, e2.v4, neighbor);
            }
        }
    }
コード例 #20
0
ファイル: HexGridChunk.cs プロジェクト: oguzunal/Anemoi
    void TriangulateConnection(HexDirection direction, HexCell cell, EdgeVertices e1)
    {
        HexCell neighbour = cell.GetNeighbour(direction);

        if (neighbour == null)
        {
            return;
        }

        Vector3 bridge = HexMetrics.GetBridge(direction);

        bridge.y = neighbour.Position.y - cell.Position.y;

        EdgeVertices e2 = new EdgeVertices(e1.v1 + bridge, e1.v5 + bridge);

        if (cell.HasRiverThroughEdge(direction))
        {
            e2.v3.y = neighbour.StreamBedY;
            TriangulateRiverQuad(e1.v2, e1.v4, e2.v2, e2.v4, cell.RiverSurfaceY, neighbour.RiverSurfaceY, .8f, cell.HasIncomingRiver && cell.IncomingRiver == direction);
        }

        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            TriangulateEdgeTerraces(e1, cell, e2, neighbour);
        }
        else
        {
            TriangulateEdgeStrip(e1, cell.Color, e2, neighbour.Color);
        }

        HexCell nextNeighbour = cell.GetNeighbour(direction.Next());

        if (direction <= HexDirection.E && nextNeighbour != null)
        {
            Vector3 v5 = e1.v5 + HexMetrics.GetBridge(direction.Next());
            v5.y = nextNeighbour.Position.y;

            if (cell.Elevation <= neighbour.Elevation)
            {
                if (cell.Elevation <= nextNeighbour.Elevation)
                {
                    TriangulateCorner(e1.v5, cell, e2.v5, neighbour, v5, nextNeighbour);
                }
                else
                {
                    TriangulateCorner(v5, nextNeighbour, e1.v5, cell, e2.v5, neighbour);
                }
            }
            else if (neighbour.Elevation <= nextNeighbour.Elevation)
            {
                TriangulateCorner(e2.v5, neighbour, v5, nextNeighbour, e1.v5, cell);
            }
            else
            {
                TriangulateCorner(v5, nextNeighbour, e1.v5, cell, e2.v5, neighbour);
            }
        }
    }
コード例 #21
0
    void TriangulateConnection(
        HexDirection direction, HexCell cell, Vector3 v1, Vector3 v2
        )
    {
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }

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

        // 桥连混合区,体现出邻居海拔
        v3.y = v4.y = neighbor.Elevation * HexMetrics.elevationStep;

        // 陡坡,转为梯田
        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            TriangulateEdgeTerraces(v1, v2, cell, v3, v4, neighbor);
        }
        else         // 平原 和 悬崖
        {
            AddQuad(v1, v2, v3, v4);
            AddQuadColor(cell.color, neighbor.color);
        }

        // 3色三角形混合区
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            Vector3 v5 = v2 + HexMetrics.GetBridge(direction.Next());
            v5.y = nextNeighbor.Elevation * HexMetrics.elevationStep;

            if (cell.Elevation <= neighbor.Elevation)
            {
                if (cell.Elevation <= nextNeighbor.Elevation)
                {
                    TriangulateCorner(v2, cell, v4, neighbor, v5, nextNeighbor);
                }
                else
                {
                    TriangulateCorner(v5, nextNeighbor, v2, cell, v4, neighbor);
                }
            }
            else if (neighbor.Elevation <= nextNeighbor.Elevation)
            {
                TriangulateCorner(v4, neighbor, v5, nextNeighbor, v2, cell);
            }
            else
            {
                TriangulateCorner(v5, nextNeighbor, v2, cell, v4, neighbor);
            }
        }
    }
コード例 #22
0
ファイル: HexGridChunk.cs プロジェクト: cmr624/unity-hex
    void TriangulateConnection(HexDirection direction, HexCell cell, EdgeVertices e1)
    {
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }
        Vector3 bridge = HexMetrics.GetBridge(direction);

        bridge.y = neighbor.Position.y - cell.Position.y;
        EdgeVertices e2 = new EdgeVertices(e1.v1 + bridge, e1.v5 + bridge);

        if (cell.HasRiverThroughEdge(direction))
        {
            e2.v3.y = neighbor.StreamBedY;
        }

        //terrace time!!
        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            TriangulateEdgeTerraces(e1, cell, e2, neighbor);
        }
        else
        {
            TriangulateEdgeStrip(e1, cell.Color, e2, neighbor.Color);
        }

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

        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            Vector3 v5 = e1.v5 + HexMetrics.GetBridge(direction.Next());
            v5.y = nextNeighbor.Position.y;
            if (cell.Elevation <= neighbor.Elevation)
            {
                if (cell.Elevation <= nextNeighbor.Elevation)
                {
                    TriangulateCorner(e1.v5, cell, e2.v5, neighbor, v5, nextNeighbor);
                }
                else
                {
                    TriangulateCorner(v5, nextNeighbor, e1.v5, cell, e2.v5, neighbor);
                }
            }
            else if (neighbor.Elevation <= nextNeighbor.Elevation)
            {
                TriangulateCorner(e2.v5, neighbor, v5, nextNeighbor, e1.v5, cell);
            }
            else
            {
                TriangulateCorner(v5, nextNeighbor, e1.v5, cell, e2.v5, neighbor);
            }
            //AddTriangle(v2, v4, v5);
            //AddTriangleColor(cell.color, neighbor.color, nextNeighbor.color);
        }
    }
コード例 #23
0
    void TriangulateConnections(HexDirection direction, HexCell cell, Vector3 vertex1, Vector3 vertex2)
    {
        HexCell currentNeighbor = cell.GetNeighbor(direction);

        if (!currentNeighbor)
        {
            return;
        }

        Vector3 bridge  = HexMetrics.GetBridge(direction);
        Vector3 vertex3 = vertex1 + bridge;
        Vector3 vertex4 = vertex2 + bridge;

        /*CREATING A SLOPE*/
        vertex3.y = vertex4.y = currentNeighbor.Elevation * HexMetrics.elevationStep;
        /*TERRACING ONLY ONE HEIGHT DIFFERENCE CONNECTIONS*/
        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            TriangulateEdgeTerraces(vertex1, vertex2, cell, vertex3, vertex4, currentNeighbor);
        }
        else
        {
            AddQuad(vertex1, vertex2, vertex3, vertex4);
            AddQuadColor(cell.color, currentNeighbor.color);
        }

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

        if (direction <= HexDirection.E && nextNeighbor)
        {
            /*SLOPE CONNECTIONS*/
            Vector3 vertex5 = vertex2 + HexMetrics.GetBridge(direction.Next());
            vertex5.y = nextNeighbor.Elevation * HexMetrics.elevationStep;
            //AddTriangle(vertex2, vertex4, vertex5);
            //AddTriangleColor(cell.color, currentNeighbor.color, nextNeighbor.color);
            if (cell.Elevation <= currentNeighbor.Elevation)
            {
                if (cell.Elevation <= nextNeighbor.Elevation)
                {
                    TriangulateCorner(vertex2, cell, vertex4, currentNeighbor, vertex5, nextNeighbor);
                }
                else
                {
                    TriangulateCorner(vertex5, nextNeighbor, vertex2, cell, vertex4, currentNeighbor);
                }
            }
            else if (currentNeighbor.Elevation <= nextNeighbor.Elevation)
            {
                TriangulateCorner(vertex4, currentNeighbor, vertex5, nextNeighbor, vertex2, cell);
            }
            else
            {
                TriangulateCorner(vertex5, nextNeighbor, vertex2, cell, vertex4, currentNeighbor);
            }
        }
    }
コード例 #24
0
ファイル: HexMesh.cs プロジェクト: zybzyb1/Hexagon
    /// <summary>
    /// 处理边缘三角形以及边缘混合
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="cell"></param>
    /// <param name="v1"></param>
    /// <param name="v2"></param>
    private void TriangulateConnection(HexDirection direction, HexCell cell, EdgeVertices e1)
    {
        // 如果没有邻居,就不画桥了
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }

        Vector3 bridge = HexMetrics.GetBridge(direction);

        bridge.y = neighbor.Position.y - cell.Position.y;
        EdgeVertices e2 = new EdgeVertices(e1.v1 + bridge, e1.v5 + bridge);

        // 边缘阶梯化 只有连接类型为斜坡时才加入阶梯
        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            TriangulateEdgeTerraces(e1, cell, e2, neighbor);
        }
        else
        {
            TriangulateEdgeStrip(e1, cell.Color, e2, neighbor.Color);
        }

        // 如果下一个方向有邻居,连接三角形
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            Vector3 v5 = e1.v5 + HexMetrics.GetBridge(direction.Next());
            // 改变连接三角形另一边的高度
            v5.y = nextNeighbor.Position.y;

            // 角部阶梯化
            if (cell.Elevation <= neighbor.Elevation)
            {
                if (cell.Elevation <= nextNeighbor.Elevation)
                {
                    TriangulateCorner(e1.v5, cell, e2.v5, neighbor, v5, nextNeighbor);
                }
                else
                {
                    TriangulateCorner(v5, nextNeighbor, e1.v5, cell, e2.v5, neighbor);
                }
            }
            else if (neighbor.Elevation < nextNeighbor.Elevation)
            {
                TriangulateCorner(e2.v5, neighbor, v5, nextNeighbor, e1.v5, cell);
            }
            else
            {
                TriangulateCorner(v5, nextNeighbor, e1.v5, cell, e2.v5, neighbor);
            }
        }
    }
コード例 #25
0
    /// <summary>
    /// Create a rectangular bridge from two triangles and complete triangle left.
    /// </summary>
    /// <param name="direction">Direction of the neighbor.</param>
    /// <param name="cell">Current cell.</param>
    /// <param name="v1">First vertex of solid color.</param>
    /// <param name="v2">Second vertex of solid color.</param>
    void TriangulateConnection(HexDirection direction, HexCell cell, Vector3 v1, Vector3 v2)
    {
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }

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

        v3.y = v4.y = neighbor.Elevation * HexMetrics.ElevationStep;

        // Only create terraces for slopes
        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            TriangulateEdgeTerraces(v1, v2, cell, v3, v4, neighbor);
        }
        else
        {
            AddQuad(v1, v2, v3, v4);
            AddQuadColor(cell.cellColor, neighbor.cellColor);
        }

        // Create triangle left
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        // direction <= HexDirection.E is to avoid overlapping triangles
        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            Vector3 v5 = v2 + HexMetrics.GetBridge(direction.Next());
            v5.y = nextNeighbor.Elevation * HexMetrics.ElevationStep;

            if (cell.Elevation <= neighbor.Elevation)
            {
                if (cell.Elevation <= nextNeighbor.Elevation)
                {
                    TriangulateCorner(v2, cell, v4, neighbor, v5, nextNeighbor);
                }
                else
                {
                    TriangulateCorner(v5, nextNeighbor, v2, cell, v4, neighbor);
                }
            }
            else if (neighbor.Elevation <= nextNeighbor.Elevation)
            {
                TriangulateCorner(v4, neighbor, v5, nextNeighbor, v2, cell);
            }
            else
            {
                TriangulateCorner(v5, nextNeighbor, v2, cell, v4, neighbor);
            }
        }
    }
コード例 #26
0
    private void TriangulateConnection(
        HexDirection direction, HexCell cell, Vector3 v1, Vector3 v2
        )
    {
        var neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }

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

        v3.y = v4.y = neighbor.Elevation * HexMetrics.elevationStep;

        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            TriangulateEdgeTerraces(v1, v2, cell, v3, v4, neighbor);
        }
        else
        {
            AddQuad(v1, v2, v3, v4);
            AddQuadColor(cell.color, neighbor.color);
        }

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

        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            var v5 = v2 + HexMetrics.GetBridge(direction.Next());
            v5.y = nextNeighbor.Elevation * HexMetrics.elevationStep;

            if (cell.Elevation <= neighbor.Elevation)
            {
                if (cell.Elevation <= nextNeighbor.Elevation)
                {
                    TriangulateCorner(v2, cell, v4, neighbor, v5, nextNeighbor);
                }
                else
                {
                    TriangulateCorner(v5, nextNeighbor, v2, cell, v4, neighbor);
                }
            }
            else if (neighbor.Elevation <= nextNeighbor.Elevation)
            {
                TriangulateCorner(v4, neighbor, v5, nextNeighbor, v2, cell);
            }
            else
            {
                TriangulateCorner(v5, nextNeighbor, v2, cell, v4, neighbor);
            }
        }
    }
コード例 #27
0
    // Create bridge to neighbor, simplify geometry of hexes (less vertices/lines)
    void TriangulateConnection(HexDirection direction, HexCell cell, Vector3 v1, Vector3 v2)
    {
        // Get direction vectors of neighbors for bridges
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null)
        {
            return;
        }
        Vector3 bridge = HexMetrics.GetBridge(direction);
        Vector3 v3     = v1 + bridge;
        Vector3 v4     = v2 + bridge;

        v3.y = v4.y = neighbor.Elevation * HexMetrics.elevationStep;
        if (cell.GetEdgeType(direction) == HexEdgeType.Slope)
        {
            TriangulateEdgeTerraces(v1, v2, cell, v3, v4, neighbor);
        }
        else
        {
            AddQuad(v1, v2, v3, v4);
            AddQuadColor(cell.color, neighbor.color);
        }

        // Create sloped bridges between cell and its neighbors
        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        if (direction <= HexDirection.E && nextNeighbor != null)
        {
            Vector3 v5 = v2 + HexMetrics.GetBridge(direction.Next());
            v5.y = nextNeighbor.Elevation * HexMetrics.elevationStep;

            if (cell.Elevation <= neighbor.Elevation)
            {
                if (cell.Elevation <= nextNeighbor.Elevation)
                {
                    TriangulateCorner(v2, cell, v4, neighbor, v5, nextNeighbor);
                }
                else
                {
                    TriangulateCorner(v5, nextNeighbor, v2, cell, v4, neighbor);
                }
            }
            else if (neighbor.Elevation <= nextNeighbor.Elevation)
            {
                TriangulateCorner(v4, neighbor, v5, nextNeighbor, v2, cell);
            }
            else
            {
                TriangulateCorner(v5, nextNeighbor, v2, cell, v4, neighbor);
            }
        }
    }
コード例 #28
0
    void TriangulateConnection(HexDirection direction, Vector3 c, Vector3 v1, Vector3 v2)
    {
        Vector3 bridge = HexMetrics.GetBridge(direction);
        Vector3 v3     = v1 + bridge;
        Vector3 v4     = v2 + bridge;

        v3.y = v4.y = getNoise(c, direction);

        AddQuad(v1, v2, v3, v4);
        if (direction <= HexDirection.E)
        {
            Vector3 v5 = v2 + HexMetrics.GetBridge(direction.Next());
            v5.y = getNoise(c, direction.Next());
            AddTriangle(v2, v4, v5);
        }
    }
コード例 #29
0
    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);
         * }*/
    }
コード例 #30
0
    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)
                );
        }
    }