private WaterTriangulationData TriangulateOpenWaterCenter( Hex source, WaterTriangulationData triangulationData, HexDirections direction, float hexOuterRadius, int wrapSize, MapMeshChunkLayer water ) { triangulationData.waterSurfaceCornerLeft = triangulationData.waterSurfaceCenter + HexagonPoint.GetFirstWaterCorner( direction, hexOuterRadius ); triangulationData.waterSurfaceCornerRight = triangulationData.waterSurfaceCenter + HexagonPoint.GetSecondWaterCorner( direction, hexOuterRadius ); water.AddTrianglePerturbed( triangulationData.waterSurfaceCenter, triangulationData.waterSurfaceCornerLeft, triangulationData.waterSurfaceCornerRight, hexOuterRadius, wrapSize ); Vector3 openWaterCenterIndices; openWaterCenterIndices.x = openWaterCenterIndices.y = openWaterCenterIndices.z = source.Index; water.AddTriangleHexData( openWaterCenterIndices, _weights1 ); return(triangulationData); }
private WaterTriangulationData GetWaterData( Hex source, Hex neighbor, WaterTriangulationData waterTriData, HexDirections direction, float hexOuterRadius, int wrapSize ) { waterTriData.waterSurfaceCenter = source.Position; waterTriData.waterSurfaceCenter.y = source.WaterSurfaceY; waterTriData.sourceWaterEdge = new EdgeVertices( waterTriData.waterSurfaceCenter + HexagonPoint.GetFirstWaterCorner( direction, hexOuterRadius ), waterTriData.waterSurfaceCenter + HexagonPoint.GetSecondWaterCorner( direction, hexOuterRadius ) ); Vector3 neighborCenter = neighbor.Position; float hexInnerRadius = HexagonPoint.OuterToInnerRadius(hexOuterRadius); float hexInnerDiameter = hexInnerRadius * 2f; // TODO: This will not work once the column index is removed from // Hex class. // If the neighbor outside the wrap boundaries, adjust accordingly. if (neighbor.ColumnIndex < source.ColumnIndex - 1) { neighborCenter.x += wrapSize * hexInnerDiameter; } else if (neighbor.ColumnIndex > source.ColumnIndex + 1) { neighborCenter.x -= wrapSize * hexInnerDiameter; } neighborCenter.y = waterTriData.waterSurfaceCenter.y; waterTriData.neighborWaterEdge = new EdgeVertices( neighborCenter + HexagonPoint.GetSecondSolidCorner( direction.Opposite(), hexOuterRadius ), neighborCenter + HexagonPoint.GetFirstSolidCorner( direction.Opposite(), hexOuterRadius ) ); return(waterTriData); }
private void TriangulateWaterShore( Hex source, Hex target, Vector3 waterSourceRelativeHexIndices, HexDirections direction, Dictionary <HexDirections, Hex> neighbors, HexRiverData riverData, Vector3 center, float hexOuterRadius, int wrapSize, MapMeshChunkLayer waterShore, EdgeVertices edge1, EdgeVertices edge2, float hexInnerDiameter ) { // hex.HasRiverThroughEdge(direction) if (riverData.HasRiverInDirection(direction)) { TriangulateWaterShoreWithRiver( edge1, edge2, riverData.HasIncomingRiverInDirection(direction), waterSourceRelativeHexIndices, hexOuterRadius, wrapSize, waterShore ); } else { waterShore.AddQuadPerturbed( edge1.vertex1, edge1.vertex2, edge2.vertex1, edge2.vertex2, hexOuterRadius, wrapSize ); waterShore.AddQuadPerturbed( edge1.vertex2, edge1.vertex3, edge2.vertex2, edge2.vertex3, hexOuterRadius, wrapSize ); waterShore.AddQuadPerturbed( edge1.vertex3, edge1.vertex4, edge2.vertex3, edge2.vertex4, hexOuterRadius, wrapSize ); waterShore.AddQuadPerturbed( edge1.vertex4, edge1.vertex5, edge2.vertex4, edge2.vertex5, hexOuterRadius, wrapSize ); waterShore.AddQuadUV(0f, 0f, 0f, 1f); waterShore.AddQuadUV(0f, 0f, 0f, 1f); waterShore.AddQuadUV(0f, 0f, 0f, 1f); waterShore.AddQuadUV(0f, 0f, 0f, 1f); waterShore.AddQuadHexData( waterSourceRelativeHexIndices, _weights1, _weights2 ); waterShore.AddQuadHexData( waterSourceRelativeHexIndices, _weights1, _weights2 ); waterShore.AddQuadHexData( waterSourceRelativeHexIndices, _weights1, _weights2 ); waterShore.AddQuadHexData( waterSourceRelativeHexIndices, _weights1, _weights2 ); } Hex nextNeighbor; // hex.GetNeighbor(direction.NextClockwise()); if ( neighbors.TryGetValue( direction.NextClockwise(), out nextNeighbor ) ) { Vector3 center3 = nextNeighbor.Position; if (nextNeighbor.ColumnIndex < source.ColumnIndex - 1) { center3.x += wrapSize * hexInnerDiameter; } else if (nextNeighbor.ColumnIndex > source.ColumnIndex + 1) { center3.x -= wrapSize * hexInnerDiameter; } // Work backward from the shore to obtain the triangle if the neighbor is // underwater, otherwise obtain normal triangle. Vector3 vertex3 = center3 + ( nextNeighbor.IsUnderwater ? HexagonPoint.GetFirstWaterCorner( direction.PreviousClockwise(), hexOuterRadius ) : HexagonPoint.GetFirstSolidCorner( direction.PreviousClockwise(), hexOuterRadius ) ); vertex3.y = center.y; waterShore.AddTrianglePerturbed( edge1.vertex5, edge2.vertex5, vertex3, hexOuterRadius, wrapSize ); waterSourceRelativeHexIndices.z = nextNeighbor.Index; waterShore.AddTriangleHexData( waterSourceRelativeHexIndices, _weights1, _weights2, _weights3 ); waterShore.AddTriangleUV( new Vector2(0f, 0f), new Vector2(0f, 1f), new Vector2(0f, nextNeighbor.IsUnderwater ? 0f : 1f) ); } }