Ejemplo n.º 1
0
    void TriangulateRoadCentre(SquareCell cell, Vector3 centre, Vector3 vs0, Vector3 vs1, Vector3 vs2, Vector3 vs3)
    {
        roads.AddTriangle(centre, vs0, GetMidVector(vs0, vs1));
        roads.AddTriangle(centre, GetMidVector(vs0, vs1), vs1);
        roads.AddTriangle(centre, vs1, GetMidVector(vs1, vs2));
        roads.AddTriangle(centre, GetMidVector(vs1, vs2), vs2);
        roads.AddTriangle(centre, vs2, GetMidVector(vs2, vs3));
        roads.AddTriangle(centre, GetMidVector(vs2, vs3), vs3);
        roads.AddTriangle(centre, vs3, GetMidVector(vs3, vs0));
        roads.AddTriangle(centre, GetMidVector(vs3, vs0), vs0);

        // W
        float midU = cell.HasRoadThroughEdge(GridDirection.W) ? 1f : 0f;

        roads.AddTriangleUV(new Vector2(1f, 1f), new Vector2(0f, 1f), new Vector2(midU, 1f));
        roads.AddTriangleUV(new Vector2(1f, 1f), new Vector2(midU, 1f), new Vector2(0f, 1f));
        // N
        midU = cell.HasRoadThroughEdge(GridDirection.N) ? 1f : 0f;
        roads.AddTriangleUV(new Vector2(1f, 1f), new Vector2(0f, 1f), new Vector2(midU, 1f));
        roads.AddTriangleUV(new Vector2(1f, 1f), new Vector2(midU, 1f), new Vector2(0f, 1f));
        // E
        midU = cell.HasRoadThroughEdge(GridDirection.E) ? 1f : 0f;
        roads.AddTriangleUV(new Vector2(1f, 1f), new Vector2(0f, 1f), new Vector2(midU, 1f));
        roads.AddTriangleUV(new Vector2(1f, 1f), new Vector2(midU, 1f), new Vector2(0f, 1f));
        // S
        midU = cell.HasRoadThroughEdge(GridDirection.S) ? 1f : 0f;
        roads.AddTriangleUV(new Vector2(1f, 1f), new Vector2(0f, 1f), new Vector2(midU, 1f));
        roads.AddTriangleUV(new Vector2(1f, 1f), new Vector2(midU, 1f), new Vector2(0f, 1f));
    }
Ejemplo n.º 2
0
    public void TrimLinksToRoadType()
    {
        List <Node> nodesToCull = new List <Node>();

        for (int i = 0; i < 8; i += 2)
        {
            if (!parentCell.HasRoadThroughEdge((GridDirection)i))
            {
                nodesToCull.AddRange(nodes.FindAll(n => n.compassDirection == (GridDirection)i));
            }
        }
        foreach (Node n in nodesToCull)
        {
            network.DeleteNode(n);
        }
    }
Ejemplo n.º 3
0
    void AddHalfCell(SquareCell cell, GridDirection direction, Vector3 centre, Vector3 v0, Vector3 v1, Vector3 v2, Vector3 va, Vector3 vb, Vector3 vc, Vector3 vd, Vector3 vx, Vector3 vy, Vector3 vz)
    {
        Vector3    riverbed         = centre + Vector3.up * (cell.CentreElevation + GridMetrics.streamBedElevationOffset) * GridMetrics.elevationStep;
        Vector3    midSolidEdgePrev = centre + GridMetrics.GetSolidEdge(direction.Previous()) + Vector3.up * (cell.CentreElevation + GridMetrics.streamBedElevationOffset) * GridMetrics.elevationStep;
        Vector3    midSolidEdgeNext = centre + GridMetrics.GetSolidEdge(direction.Next()) + Vector3.up * (cell.CentreElevation + GridMetrics.streamBedElevationOffset) * GridMetrics.elevationStep;
        SquareCell neighborPrev     = cell.GetNeighbor(direction.Previous()) ?? cell;
        SquareCell neighborNext     = cell.GetNeighbor(direction.Next()) ?? cell;
        Vector3    midEdgePrev      = centre + GridMetrics.GetEdge(direction.Previous()) + Vector3.up * ((cell.CentreElevation + neighborPrev.CentreElevation) / 2 + GridMetrics.streamBedElevationOffset) * GridMetrics.elevationStep;
        Vector3    midEdgeNext      = centre + GridMetrics.GetEdge(direction.Next()) + Vector3.up * ((cell.CentreElevation + neighborNext.CentreElevation) / 2 + GridMetrics.streamBedElevationOffset) * GridMetrics.elevationStep;

        if (cell.HasRiver)
        {
            if (cell.HasRiverThroughEdge(direction.Previous()))
            {
                terrain.AddTriangle(v0, midSolidEdgePrev, riverbed); // split tri into two tris
                terrain.AddTriangle(midSolidEdgePrev, v1, riverbed);
            }
            else
            {
                terrain.AddTriangle(v0, v1, riverbed);
            }                                          // edge with no river
            if (cell.HasRiverThroughEdge(direction.Next()))
            {
                terrain.AddTriangle(v1, midSolidEdgeNext, riverbed); // split tri into two tris
                terrain.AddTriangle(midSolidEdgeNext, v2, riverbed);
            }
            else
            {
                terrain.AddTriangle(v1, v2, riverbed);
            }                                          // edge with no river
        }
        else
        {
            terrain.AddTriangle(v0, v1, v2);
        }

        if (cell.HasRiverThroughEdge(direction.Next()))
        {
            terrain.AddQuad(v1, va, midEdgeNext, midSolidEdgeNext);
            terrain.AddQuad(midSolidEdgeNext, midEdgeNext, vb, v2);
        }
        else
        {
            terrain.AddQuad(v1, va, vb, v2);
        }                                    // top Edge
        if (cell.HasRiverThroughEdge(direction.Previous()))
        {
            terrain.AddQuad(v1, midSolidEdgePrev, midEdgePrev, vd);
            terrain.AddQuad(midSolidEdgePrev, v0, vc, midEdgePrev);
        }
        else
        {
            terrain.AddQuad(v1, v0, vc, vd);
        }                                     // left Edge
        if (cell.HasRiverThroughEdge(direction))
        {
        }
        else
        {
            terrain.AddQuad(v1, vd, vx, va);
        }                                    // direction edge
        if (cell.HasRiverThroughEdge(direction.Next2()))
        {
        }
        else
        {
            terrain.AddQuad(v2, vb, vy, vz);
        }                                   // clockwise edge
        AddColors(cell, direction);

        if (cell.HasRoadThroughEdge(direction.Next()))
        {
            midEdgeNext      = centre + GridMetrics.GetEdge(direction.Next()) + Vector3.up * ((int)cell.GridElevations[direction] + (int)cell.GridElevations[direction.Next2()]) / 2 * GridMetrics.elevationStep;
            midSolidEdgeNext = centre + GridMetrics.GetSolidEdge(direction.Next()) + Vector3.up * ((int)cell.GridElevations[direction] + (int)cell.GridElevations[direction.Next2()]) / 2 * GridMetrics.elevationStep;
            TriangulateRoadSegment(v1, midSolidEdgeNext, v2, va, midEdgeNext, vb);
        }
        if (cell.HasRoadThroughEdge(direction.Previous()))
        {
            midEdgePrev      = centre + GridMetrics.GetEdge(direction.Previous()) + Vector3.up * ((int)cell.GridElevations[direction] + (int)cell.GridElevations[direction.Previous2()]) / 2 * GridMetrics.elevationStep;
            midSolidEdgePrev = centre + GridMetrics.GetSolidEdge(direction.Previous()) + Vector3.up * ((int)cell.GridElevations[direction] + (int)cell.GridElevations[direction.Previous2()]) / 2 * GridMetrics.elevationStep;
            TriangulateRoadSegment(v0, midSolidEdgePrev, v1, vc, midEdgePrev, vd);
        }
    }