Exemplo n.º 1
0
    void Start()
    {
        map = WADReader.LoadMap("E1M1");

        vertices = new List <Vector3>();
        List <CombineInstance> floorCIs = new List <CombineInstance>();

        foreach (SubSector ssector in map.subsectors)
        {
            List <Vector3> floorVerts = new List <Vector3>();
            //SubSector ssector = map.subsectors[0];
            for (int i = 0; i < ssector.num; i++)
            {
                Seg     seg     = map.segs[ssector.start + i];
                Vertex  vertS   = map.vertexes[seg.start];
                Vertex  vertE   = map.vertexes[seg.end];
                Linedef line    = map.linedefs[seg.linedef];
                Sidedef sideR   = map.sidedefs[line.right];
                Sector  sectorR = map.sectors[sideR.sector];
                if (line.left >= 0)
                {
                    Sidedef sideL   = map.sidedefs[line.left];
                    Sector  sectorL = map.sectors[sideL.sector];
                }
                Vector3 vStart = new Vector3(vertS.x, 0, vertS.y) * scale;
                Vector3 vEnd   = new Vector3(vertE.x, 0, vertE.y) * scale;
                /*if (!floorVerts.Contains(vStart))*/ floorVerts.Add(vStart);
                /*if (!floorVerts.Contains(vEnd))*/ floorVerts.Add(vEnd);
            }

            List <int> floorTris = new List <int>();
            int        p0        = 0;
            int        pHelper   = 1;
            for (int i = 2; i < floorVerts.Count; i++)
            {
                int pTemp = i;
                floorTris.AddRange(new int[] { p0, pHelper, pTemp });
                pHelper = pTemp;
            }

            CombineInstance ci   = new CombineInstance();
            Mesh            mesh = new Mesh();
            mesh.vertices  = floorVerts.ToArray();
            mesh.triangles = floorTris.ToArray();
            mesh.RecalculateNormals();
            ci.mesh      = mesh;
            ci.transform = transform.localToWorldMatrix;
            floorCIs.Add(ci);
        }

        Mesh combinedFloor = new Mesh();

        combinedFloor.CombineMeshes(floorCIs.ToArray());

        meshFilter.sharedMesh = combinedFloor;

        inited = true;
    }