Esempio n. 1
0
 public bool ThingInside(Thing thing)
 {
     if (SectorTriangulation.PointInPolygon(new Vector2(thing.x, thing.y), points))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 2
0
    public void BuildMap(WadFile wad, string mapname, bool benchmark = false)
    {
        this.benchmark = benchmark;
        this.wad       = wad;
        textureTable   = wad.textureTable;

        // Graphics setup. TODO: Move this to DoomGraphic, or somewhere else graphic related.
        paletteLookup  = new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture();
        colormapLookup = new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture();

        doomMaterial = new Material(Shader.Find("Doom/Texture"));
        doomMaterial.SetTexture("_Palette", paletteLookup);
        doomMaterial.SetTexture("_Colormap", colormapLookup);

        pngMaterial = new Material(Shader.Find("Doom/Unlit Truecolor Texture"));

        skyMaterial = new Material(Shader.Find("Doom/Sky"));
        skyMaterial.SetTexture("_Palette", paletteLookup);
        skyMaterial.SetTexture("_RenderMap", GetTexture(skyName));

        spriteMaterial = new Material(Shader.Find("Doom/Texture"));
        spriteMaterial.SetTexture("_Palette", paletteLookup);
        spriteMaterial.SetTexture("_Colormap", colormapLookup);

        map = MapData.Load(wad, mapname);
        if (map == null)
        {
            throw new Exception("Loading map failed.");
        }

        st           = new SectorTriangulation(map, benchmark);
        levelObject  = new GameObject(mapname);
        geoObject    = new GameObject("Geometry");
        thingsObject = new GameObject("Things");
        geoObject.transform.SetParent(levelObject.transform);
        thingsObject.transform.SetParent(levelObject.transform);

        // Build thing information
        unclaimedThings = new List <int>();
        for (int i = 0; i < map.things.Length; i++)
        {
            unclaimedThings.Add(i);
        }
        thingSectors = new Dictionary <int, Sector>();

        CoroutineRunner cr = levelObject.AddComponent <CoroutineRunner>();

        cr.dmb      = this;
        cr.map      = map;
        linesDone   = false;
        sectorsDone = false;

        cr.StartCoroutine(cr.BuildLines());
        cr.StartCoroutine(cr.BuildSectors());

        levelObject.transform.localScale = new Vector3(SCALE, SCALE * 1.2f, SCALE);
    }
Esempio n. 3
0
    // Test a map without building it
    public int TestMap(WadFile wad, string mapname)
    {
        map = new DoomMapData(wad, mapname);
        st  = new SectorTriangulation(map);
        int failedSectors = 0;

        for (int i = 0; i < map.sectors.Length; i++)
        {
            List <SectorPolygon> polygons = null;
            try {
                polygons = st.Triangulate(i);
            } catch  {
                //Debug.Log("Exception found in "+mapname+" sector "+i);
            }
            if (polygons == null)
            {
                failedSectors += 1;
            }
        }
        return(failedSectors);
    }
Esempio n. 4
0
    void BuildSector(int index)
    {
        SectorTriangulation  st       = new SectorTriangulation(map);
        List <SectorPolygon> polygons = st.Triangulate(index);

        if (polygons == null)
        {
            return;
        }

        for (int i = 0; i < polygons.Count; i++)
        {
            for (int t = 0; t < unclaimedThings.Count; t++)
            {
                if (polygons[i].ThingInside(map.things[unclaimedThings[t]]))
                {
                    thingSectors.Add(unclaimedThings[t], map.sectors[index]);
                    unclaimedThings.RemoveAt(t);
                }
            }
        }

        int floorHeight   = map.sectors[index].floorHeight;
        int ceilingHeight = map.sectors[index].ceilingHeight;

        float brightness = map.sectors[index].lightLevel / 256f;


        for (int i = 0; i < polygons.Count; i++)
        {
            Mesh      mesh     = new Mesh();
            Vector3[] vertices = polygons[i].PointsToVector3(floorHeight).ToArray();
            int[]     tris     = polygons[i].triangles.ToArray();
            Vector2[] uvs      = polygons[i].points.ToArray();

            for (int j = 0; j < uvs.Length; j++)
            {
                uvs[j] /= 64f;
            }

            mesh.vertices  = vertices;
            mesh.triangles = tris;
            mesh.uv        = uvs;

            GameObject   newObj = new GameObject();
            Material     mat    = doomMaterial;
            MeshRenderer mr     = newObj.AddComponent <MeshRenderer>();

            newObj.AddComponent <MeshCollider>().sharedMesh = mesh;
            if (map.sectors[index].floorTexture != "F_SKY1")
            {
                mr.material = doomMaterial;
                mr.material.SetTexture("_MainTex", GetFlat(map.sectors[index].floorTexture));
                mr.material.SetFloat("_Brightness", brightness);
            }
            else
            {
                mr.material = skyMaterial;
            }
            newObj.AddComponent <MeshFilter>().mesh = mesh;
            newObj.transform.parent = levelObject.transform;

            mesh = new Mesh();
            Array.Reverse(tris);
            for (int j = 0; j < vertices.Length; j++)
            {
                vertices[j].y = ceilingHeight;
            }
            mesh.vertices  = vertices;
            mesh.triangles = tris;
            mesh.uv        = uvs;

            newObj = new GameObject();
            newObj.AddComponent <MeshCollider>().sharedMesh = mesh;
            mr = newObj.AddComponent <MeshRenderer>();
            if (map.sectors[index].ceilingTexture != "F_SKY1")
            {
                mr.material = doomMaterial;
                mr.material.SetTexture("_MainTex", GetFlat(map.sectors[index].ceilingTexture));
                mr.material.SetFloat("_Brightness", brightness);
            }
            else
            {
                mr.material = skyMaterial;
            }
            newObj.AddComponent <MeshFilter>().mesh = mesh;
            newObj.transform.parent = levelObject.transform;
        }
    }