Exemplo n.º 1
0
    private void TriangulateWaterShoreWithRiver(
        EdgeVertices edge1,
        EdgeVertices edge2,
        bool incomingRiver,
        Vector3 indices,
        float hexOuterRadius,
        int wrapSize,
        MapMeshChunkLayer waterShore
        )
    {
        waterShore.AddTrianglePerturbed(
            edge2.vertex1,
            edge1.vertex2,
            edge1.vertex1,
            hexOuterRadius,
            wrapSize
            );

        waterShore.AddTrianglePerturbed(
            edge2.vertex5,
            edge1.vertex5,
            edge1.vertex4,
            hexOuterRadius,
            wrapSize
            );

        waterShore.AddTriangleUV
        (
            new Vector2(0f, 1f),
            new Vector2(0f, 0f),
            new Vector2(0f, 0f)
        );

        waterShore.AddTriangleUV
        (
            new Vector2(0f, 1f),
            new Vector2(0f, 0f),
            new Vector2(0f, 0f)
        );

        waterShore.AddTriangleHexData(
            indices,
            _weights2,
            _weights1,
            _weights1
            );

        waterShore.AddTriangleHexData(
            indices,
            _weights2,
            _weights1,
            _weights1
            );
    }
    private void TriangulateRoadEdge(
        Vector3 center,
        Vector3 middleLeft,
        Vector3 middleRight,
        float index,
        float hexOuterRadius,
        int wrapSize,
        MapMeshChunkLayer roads
        )
    {
        roads.AddTrianglePerturbed(
            center,
            middleLeft,
            middleRight,
            hexOuterRadius,
            wrapSize
            );

        roads.AddTriangleUV(
            new Vector2(1f, 0f),
            new Vector2(0f, 0f),
            new Vector2(0f, 0f)
            );

        Vector3 indices;

        indices.x = indices.y = indices.z = index;
        roads.AddTriangleHexData(indices, _weights1);
    }
Exemplo n.º 3
0
    private TerrainTriangulationData TriangulateRiverBeginOrEndRiver(
        Hex source,
        TerrainTriangulationData triangulationData,
        HexRiverData riverData,
        float hexOuterRadius,
        int wrapSize,
        MapMeshChunkLayer rivers
        )
    {
        Vector3 riverSurfaceCenter = triangulationData.terrainCenter;
//            bool reversed = hex.HasIncomingRiver;
        bool reversed = riverData.HasIncomingRiver;

        Vector3 indices = new Vector3(
            source.Index,
            source.Index,
            source.Index
            );

        TriangulateRiverQuad(
            triangulationData.middleEdgeVertices.vertex2,
            triangulationData.middleEdgeVertices.vertex4,
            triangulationData.centerEdgeVertices.vertex2,
            triangulationData.centerEdgeVertices.vertex4,
            source.RiverSurfaceY,
            0.6f,
            reversed,
            indices,
            hexOuterRadius,
            wrapSize,
            rivers
            );

        riverSurfaceCenter.y =
            triangulationData.middleEdgeVertices.vertex2.y     =
                triangulationData.middleEdgeVertices.vertex4.y =
                    source.RiverSurfaceY;

        rivers.AddTrianglePerturbed(
            riverSurfaceCenter,
            triangulationData.middleEdgeVertices.vertex2,
            triangulationData.middleEdgeVertices.vertex4,
            hexOuterRadius,
            wrapSize
            );

        if (reversed)
        {
            rivers.AddTriangleUV(
                new Vector2(0.5f, 0.4f),
                new Vector2(1f, 0.2f),
                new Vector2(0f, 0.2f)
                );
        }
        else
        {
            rivers.AddTriangleUV(
                new Vector2(0.5f, 0.4f),
                new Vector2(0f, 0.6f),
                new Vector2(1f, 0.6f)
                );
        }

        rivers.AddTriangleHexData(indices, _weights1);

        return(triangulationData);
    }
Exemplo n.º 4
0
    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 TriangulateRoad(
        Vector3 center,
        Vector3 middleLeft,
        Vector3 middleRight,
        EdgeVertices edgeVertices,
        bool hasRoadThroughHexEdge,
        float index,
        float hexOuterRadius,
        int wrapSize,
        MapMeshChunkLayer roads
        )
    {
        Vector3 indices;

        indices.x = indices.y = indices.z = index;

        if (hasRoadThroughHexEdge)
        {
            Vector3 middleCenter = Vector3.Lerp(middleLeft, middleRight, 0.5f);

            TriangulateRoadSegment(
                middleLeft,
                middleCenter,
                middleRight,
                edgeVertices.vertex2,
                edgeVertices.vertex3,
                edgeVertices.vertex4,
                _weights1,
                _weights1,
                indices,
                hexOuterRadius,
                wrapSize,
                roads
                );

            roads.AddTrianglePerturbed(
                center,
                middleLeft,
                middleCenter,
                hexOuterRadius,
                wrapSize
                );

            roads.AddTrianglePerturbed(
                center,
                middleCenter,
                middleRight,
                hexOuterRadius,
                wrapSize
                );

            roads.AddTriangleUV(
                new Vector2(1f, 0f),
                new Vector2(0f, 0f),
                new Vector2(1f, 0f)
                );

            roads.AddTriangleUV(
                new Vector2(1f, 0f),
                new Vector2(1f, 0f),
                new Vector2(0f, 0f)
                );

            roads.AddTriangleHexData(indices, _weights1);
            roads.AddTriangleHexData(indices, _weights1);
        }
        else
        {
            TriangulateRoadEdge(
                center,
                middleLeft,
                middleRight,
                index,
                hexOuterRadius,
                wrapSize,
                roads
                );
        }
    }
Exemplo n.º 6
0
    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)
                );
        }
    }