Esempio n. 1
0
    public Mesh BuildCarLaneMesh()
    {
        if (Corners.Count != 4)
        {
            return(null);
        }

        List <Vector3> verts = new List <Vector3> {
            Corners[0].Position, Corners[1].Position, Corners[2].Position, Corners[3].Position
        };

        verts.SortAsPointsClockwiseAlongY();
        for (int i = 0; i < verts.Count; i++)
        {
            verts[i] -= Position;
        }
        List <int> tris = new List <int> {
            0, 1, 2, 0, 2, 3
        };
        Mesh m = ExtMesh.BuildMesh(verts, tris);

        m.Subdivide(2);
        return(m);
    }
Esempio n. 2
0
    public List <Mesh> BuildSidewalkMeshes()
    {
        if (Corners.Count != 4)
        {
            return(null);
        }
        List <Mesh> meshes = new List <Mesh>();

        for (int i = 0; i < Corners.Count; i++)
        {
            List <Vector3> verts = new List <Vector3>();
            List <int>     tris  = new List <int>();
            //a corner can only ever be connected to 1 or 2 Streets
            if (Corners[i].ConnectedTo.Count == 1)
            {
            }
            else if (Corners[i].ConnectedTo.Count == 2)
            {
                Vector3 offset0 = Corners[i].GetSidewalkOffset(0);
                Vector3 offset1 = Corners[i].GetSidewalkOffset(0);
                Vector3 yOffset = sidewalkHeight * Vector3.up;
                //top face
                verts.Add(Corners[i].Position - Position + yOffset);
                verts.Add(Corners[i].Position + offset0 - Position + yOffset);
                verts.Add(Corners[i].Position + offset1 - Position + yOffset);
                verts.Add(Corners[i].Position + offset0 + offset1 - Position + yOffset);

                tris.Add(0);
                tris.Add(3);
                tris.Add(1);

                tris.Add(0);
                tris.Add(2);
                tris.Add(3);

                //side faces
                verts.Add(Corners[i].Position + offset0 - Position + yOffset);
                verts.Add(Corners[i].Position + offset0 - Position - yOffset);
                verts.Add(Corners[i].Position + offset0 + offset1 - Position + yOffset);
                verts.Add(Corners[i].Position + offset0 + offset1 - Position - yOffset);

                tris.Add(5);
                tris.Add(4);
                tris.Add(6);

                tris.Add(5);
                tris.Add(7);
                tris.Add(4);

                verts.Add(Corners[i].Position + offset1 - Position + yOffset);
                verts.Add(Corners[i].Position + offset1 - Position - yOffset);
                verts.Add(Corners[i].Position + offset0 + offset1 - Position + yOffset);
                verts.Add(Corners[i].Position + offset0 + offset1 - Position - yOffset);

                tris.Add(9);
                tris.Add(8);
                tris.Add(10);

                tris.Add(9);
                tris.Add(11);
                tris.Add(8);
            }
            else
            {
                DB.Error("Corner of Intersection can't be built because of invalid n of connections");
            }
            meshes.Add(ExtMesh.BuildMesh(verts, tris));
        }
        return(meshes);
    }