private void TriangulateEdgeStripTerrain( EdgeVertices edge1, Color weight1, float index1, EdgeVertices edge2, Color weight2, float index2, float hexOuterRadius, int wrapSize, MapMeshChunkLayer terrain ) { terrain.AddQuadPerturbed( edge1.vertex1, edge1.vertex2, edge2.vertex1, edge2.vertex2, hexOuterRadius, wrapSize ); terrain.AddQuadPerturbed( edge1.vertex2, edge1.vertex3, edge2.vertex2, edge2.vertex3, hexOuterRadius, wrapSize ); terrain.AddQuadPerturbed( edge1.vertex3, edge1.vertex4, edge2.vertex3, edge2.vertex4, hexOuterRadius, wrapSize ); terrain.AddQuadPerturbed( edge1.vertex4, edge1.vertex5, edge2.vertex4, edge2.vertex5, hexOuterRadius, wrapSize ); Vector3 indices; indices.x = indices.z = index1; indices.y = index2; terrain.AddQuadHexData(indices, weight1, weight2); terrain.AddQuadHexData(indices, weight1, weight2); terrain.AddQuadHexData(indices, weight1, weight2); terrain.AddQuadHexData(indices, weight1, weight2); }
private void TriangulateWaterfallInWater( Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, Vector3 vertex4, float y1, float y2, float waterY, Vector3 indices, float hexOuterRadius, int wrapSize, MapMeshChunkLayer rivers ) { vertex1.y = vertex2.y = y1; vertex3.y = vertex4.y = y2; vertex1 = HexagonPoint.Perturb( vertex1, hexOuterRadius, wrapSize ); vertex2 = HexagonPoint.Perturb( vertex2, hexOuterRadius, wrapSize ); vertex3 = HexagonPoint.Perturb( vertex3, hexOuterRadius, wrapSize ); vertex4 = HexagonPoint.Perturb( vertex4, hexOuterRadius, wrapSize ); float t = (waterY - y2) / (y1 - y2); vertex3 = Vector3.Lerp(vertex3, vertex1, t); vertex4 = Vector3.Lerp(vertex4, vertex2, t); rivers.AddQuadUnperturbed( vertex1, vertex2, vertex3, vertex4 ); rivers.AddQuadUV(0f, 1f, 0.8f, 1f); rivers.AddQuadHexData(indices, _weights1, _weights2); }
protected void TriangulateRoadSegment( Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, Vector3 vertex4, Vector3 vertex5, Vector3 vertex6, Color weight1, Color weight2, Vector3 indices, float hexOuterRadius, int wrapSize, MapMeshChunkLayer roads ) { roads.AddQuadPerturbed( vertex1, vertex2, vertex4, vertex5, hexOuterRadius, wrapSize ); roads.AddQuadPerturbed( vertex2, vertex3, vertex5, vertex6, hexOuterRadius, wrapSize ); roads.AddQuadUV(0f, 1f, 0f, 0f); roads.AddQuadUV(1f, 0f, 0f, 0f); roads.AddQuadHexData(indices, weight1, weight2); roads.AddQuadHexData(indices, weight1, weight2); }
private void TriangulateRiverQuad( Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, Vector3 vertex4, float y1, float y2, float v, bool reversed, Vector3 indices, float hexOuterRadius, int wrapSize, MapMeshChunkLayer rivers ) { vertex1.y = vertex2.y = y1; vertex3.y = vertex4.y = y2; rivers.AddQuadPerturbed( vertex1, vertex2, vertex3, vertex4, hexOuterRadius, wrapSize ); if (reversed) { rivers.AddQuadUV(1f, 0f, 0.8f - v, 0.6f - v); } else { rivers.AddQuadUV(0f, 1f, v, v + 0.2f); } rivers.AddQuadHexData(indices, _weights1, _weights2); }
private void TriangulateCornerTerraces( Vector3 begin, Hex beginHex, Vector3 left, Hex leftHex, Vector3 right, Hex rightHex, float hexOuterRadius, int wrapSize, MapMeshChunkLayer terrain ) { Vector3 vertex3 = HexagonPoint.TerraceLerp(begin, left, 1); Vector3 vertex4 = HexagonPoint.TerraceLerp(begin, right, 1); Color weight3 = HexagonPoint.TerraceLerp(_weights1, _weights2, 1); Color weight4 = HexagonPoint.TerraceLerp(_weights1, _weights3, 1); Vector3 indices; indices.x = beginHex.Index; indices.y = leftHex.Index; indices.z = rightHex.Index; terrain.AddTrianglePerturbed( begin, vertex3, vertex4, hexOuterRadius, wrapSize ); terrain.AddTriangleHexData( indices, _weights1, weight3, weight4 ); for (int i = 2; i < HexagonPoint.terraceSteps; i++) { Vector3 vertex1 = vertex3; Vector3 vertex2 = vertex4; Color weight1 = weight3; Color weight2 = weight4; vertex3 = HexagonPoint.TerraceLerp(begin, left, i); vertex4 = HexagonPoint.TerraceLerp(begin, right, i); weight3 = HexagonPoint.TerraceLerp(_weights1, _weights2, i); weight4 = HexagonPoint.TerraceLerp(_weights1, _weights3, i); terrain.AddQuadPerturbed( vertex1, vertex2, vertex3, vertex4, hexOuterRadius, wrapSize ); terrain.AddQuadHexData( indices, weight1, weight2, weight3, weight4 ); } terrain.AddQuadPerturbed( vertex3, vertex4, left, right, hexOuterRadius, wrapSize ); terrain.AddQuadHexData( indices, weight3, weight4, _weights2, _weights3 ); }
private TerrainTriangulationData TriangulateRiverTerrain( Hex source, TerrainTriangulationData triangulationData, float hexOuterRadius, int wrapSize, MapMeshChunkLayer terrain ) { TriangulateEdgeStripTerrain( triangulationData.middleEdgeVertices, _weights1, source.Index, triangulationData.centerEdgeVertices, _weights1, source.Index, hexOuterRadius, wrapSize, terrain ); terrain.AddTrianglePerturbed( triangulationData.riverCenterLeft, triangulationData.middleEdgeVertices.vertex1, triangulationData.middleEdgeVertices.vertex2, hexOuterRadius, wrapSize ); terrain.AddQuadPerturbed( triangulationData.riverCenterLeft, triangulationData.terrainCenter, triangulationData.middleEdgeVertices.vertex2, triangulationData.middleEdgeVertices.vertex3, hexOuterRadius, wrapSize ); terrain.AddQuadPerturbed( triangulationData.terrainCenter, triangulationData.riverCenterRight, triangulationData.middleEdgeVertices.vertex3, triangulationData.middleEdgeVertices.vertex4, hexOuterRadius, wrapSize ); terrain.AddTrianglePerturbed( triangulationData.riverCenterRight, triangulationData.middleEdgeVertices.vertex4, triangulationData.middleEdgeVertices.vertex5, hexOuterRadius, wrapSize ); Vector3 centerHexIndices; centerHexIndices.x = centerHexIndices.y = centerHexIndices.z = source.Index; terrain.AddTriangleHexData( centerHexIndices, _weights1 ); terrain.AddQuadHexData( centerHexIndices, _weights1 ); terrain.AddQuadHexData( centerHexIndices, _weights1 ); terrain.AddTriangleHexData( centerHexIndices, _weights1 ); return(triangulationData); }
private WaterTriangulationData TriangulateOpenWaterConnection( Hex source, Hex target, HexDirections direction, WaterTriangulationData waterTriData, TerrainTriangulationData terrainTriData, Dictionary <HexDirections, Hex> neighbors, float hexOuterRadius, int wrapSize, MapMeshChunkLayer water ) { if ( direction <= HexDirections.Southeast ) { Vector3 bridge = HexagonPoint.GetWaterBridge( direction, hexOuterRadius ); Vector3 edge1 = waterTriData.waterSurfaceCornerLeft + bridge; Vector3 edge2 = waterTriData.waterSurfaceCornerRight + bridge; water.AddQuadPerturbed( waterTriData.waterSurfaceCornerLeft, waterTriData.waterSurfaceCornerRight, edge1, edge2, hexOuterRadius, wrapSize ); Vector3 openWaterIndices; openWaterIndices.x = openWaterIndices.z = source.Index; openWaterIndices.y = target.Index; water.AddQuadHexData( openWaterIndices, _weights1, _weights2 ); if (direction <= HexDirections.East) { Hex nextNeighbor; if ( neighbors.TryGetValue( direction.NextClockwise(), out nextNeighbor ) && nextNeighbor.IsUnderwater ) { water.AddTrianglePerturbed( waterTriData.waterSurfaceCornerRight, edge2, waterTriData.waterSurfaceCornerRight + HexagonPoint.GetWaterBridge( direction.NextClockwise(), hexOuterRadius ), hexOuterRadius, wrapSize ); openWaterIndices.z = nextNeighbor.Index; water.AddTriangleHexData( openWaterIndices, _weights1, _weights2, _weights3 ); } } } return(waterTriData); }
private void TriangulateEstuary( EdgeVertices edge1, EdgeVertices edge2, bool incomingRiver, Vector3 waterSourceRelativeHexIndices, float hexOuterRadius, int wrapSize, MapMeshChunkLayer estuaries ) { estuaries.AddQuadPerturbed( edge2.vertex1, edge1.vertex2, edge2.vertex2, edge1.vertex3, hexOuterRadius, wrapSize ); estuaries.AddTrianglePerturbed( edge1.vertex3, edge2.vertex2, edge2.vertex4, hexOuterRadius, wrapSize ); estuaries.AddQuadPerturbed( edge1.vertex3, edge1.vertex4, edge2.vertex4, edge2.vertex5, hexOuterRadius, wrapSize ); estuaries.AddQuadUV( new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(0f, 0f) ); estuaries.AddQuadHexData( waterSourceRelativeHexIndices, _weights2, _weights1, _weights2, _weights1 ); estuaries.AddTriangleHexData(waterSourceRelativeHexIndices, _weights1, _weights2, _weights2); estuaries.AddQuadHexData(waterSourceRelativeHexIndices, _weights1, _weights2); estuaries.AddTriangleUV( new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(1f, 1f) ); estuaries.AddQuadUV( new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(0f, 1f) ); if (incomingRiver) { estuaries.AddQuadUV2( new Vector2(1.5f, 1f), new Vector2(0.7f, 1.15f), new Vector2(1f, 0.8f), new Vector2(0.5f, 1.1f) ); estuaries.AddTriangleUV2( new Vector2(0.5f, 1.1f), new Vector2(1f, 0.8f), new Vector2(0f, 0.8f) ); estuaries.AddQuadUV2( new Vector2(0.5f, 1.1f), new Vector2(0.3f, 1.15f), new Vector2(0f, 0.8f), new Vector2(-0.5f, 1f) ); } else { estuaries.AddQuadUV2( new Vector2(-0.5f, -0.2f), new Vector2(0.3f, -0.35f), new Vector2(0f, 0f), new Vector2(0.5f, -0.3f) ); estuaries.AddTriangleUV2( new Vector2(0.5f, -0.3f), new Vector2(0f, 0f), new Vector2(1f, 0f) ); estuaries.AddQuadUV2( new Vector2(0.5f, -0.3f), new Vector2(0.7f, -0.35f), new Vector2(1f, 0f), new Vector2(1.5f, -0.2f) ); } }
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) ); } }