/// <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 e1, Vector3 e2, Vector3 e3, Vector3 v2) { if (direction <= HexDirection.SE && cell.GetNeighbor(direction) != null) { //添加矩形连接桥 HexCell neighbor = cell.GetNeighbor(direction) ?? cell; Vector3 bright = HexMetrics.GetBirdge(direction); Vector3 v3 = v1 + bright; Vector3 v4 = v2 + bright; //将对面连接点添加高度修正 v3.y = v4.y = neighbor.Position.y; //增加多顶点,添加细节 //e4,e5,e6为对面顶点 Vector3 e4 = Vector3.Lerp(v3, v4, 0.25f); Vector3 e5 = Vector3.Lerp(v3, v4, 0.5f); Vector3 e6 = Vector3.Lerp(v3, v4, 0.75f); if (cell.HasRiverThroughEdge(direction)) { e5.y = neighbor.StreamBedY; } //限制只在倾斜时进行阶梯化 if (cell.GetEdgeType(direction) == HexEdgeType.Slope) { TriangulateEdgeTerraces(v1, e1, cell, v3, e4, neighbor); TriangulateEdgeTerraces(e1, e2, cell, e4, e5, neighbor); TriangulateEdgeTerraces(e2, e3, cell, e5, e6, neighbor); TriangulateEdgeTerraces(e3, v2, cell, e6, v4, neighbor); } else { //AddQuad(v1, v2, v3, v4); //AddQuadColor(cell.Color, neighbor.Color); AddQuad(v1, e1, v3, e4); AddQuadColor(cell.Color, neighbor.Color); AddQuad(e1, e2, e4, e5); AddQuadColor(cell.Color, neighbor.Color); AddQuad(e2, e3, e5, e6); AddQuadColor(cell.Color, neighbor.Color); AddQuad(e3, v2, e6, v4); AddQuadColor(cell.Color, neighbor.Color); } //处理三角形连接 HexCell nextNeighbor = cell.GetNeighbor(direction.Next()); if (nextNeighbor) { Vector3 v5 = v2 + HexMetrics.GetBirdge(direction.Next()); v5.y = nextNeighbor.Position.y; //TriangulateCorner(v2, cell, v4, neighbor, v5, nextNeighbor); //找出最小的一个cell,然后顺时针将三个cell传入 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); } } } } }