Ejemplo n.º 1
0
        public JToken GetVertexLighting([Url] string mapName, int index)
        {
            if (CheckNotExpired(mapName))
            {
                return(null);
            }

            var bsp = GetBspFile(Request, mapName);

            var hdrPath      = $"sp_hdr_{index}.vhv";
            var ldrPath      = $"sp_{index}.vhv";
            var existingPath = bsp.PakFile.ContainsFile(hdrPath)
                ? hdrPath : bsp.PakFile.ContainsFile(ldrPath) ? ldrPath : null;

            var array = new JArray();

            if (existingPath != null)
            {
                ValveVertexLightingFile vhv;
                using (var stream = bsp.PakFile.OpenFile(existingPath))
                {
                    vhv = new ValveVertexLightingFile(stream);
                }

                var meshCount = vhv.GetMeshCount(0);
                for (var meshId = 0; meshId < meshCount; ++meshId)
                {
                    array.Add(SerializeArray(vhv.GetSamples(0, meshId), sample => $"{sample.R},{sample.G},{sample.B}"));
                }
            }

            return(new JObject
            {
                { "meshes", array }
            });
        }
Ejemplo n.º 2
0
        public VertexLightingPage GetVertexLightingPage([Url] string map, [Url] int index)
        {
            var bsp = Program.GetMap(map);

            var info = IndexController.GetPageLayout(bsp, bsp.StaticProps.PropCount,
                                                     VertexLightingPage.PropsPerPage, null).Skip(index).FirstOrDefault();

            var first = info?.First ?? bsp.StaticProps.PropCount;
            var count = info?.Count ?? 0;

            var page = new VertexLightingPage();

            for (var i = 0; i < count; ++i)
            {
                var propIndex = first + i;

                StaticPropFlags flags;
                bsp.StaticProps.GetPropInfo(propIndex, out flags, out bool _, out uint _);
                if ((flags & StaticPropFlags.NoPerVertexLighting) != 0)
                {
                    page.Props.Add(null);
                    continue;
                }

                var ldrPath      = $"sp_{propIndex}.vhv";
                var hdrPath      = $"sp_hdr_{propIndex}.vhv";
                var existingPath = bsp.PakFile.ContainsFile(hdrPath)
                    ? hdrPath : bsp.PakFile.ContainsFile(ldrPath) ? ldrPath : null;

                if (existingPath == null)
                {
                    page.Props.Add(null);
                    continue;
                }

                var vhvFile = ValveVertexLightingFile.FromProvider(existingPath, bsp.PakFile);

                if (vhvFile == null)
                {
                    page.Props.Add(null);
                    continue;
                }

                var meshList  = new List <CompressedList <uint> >();
                var meshCount = vhvFile.GetMeshCount(0);

                for (var j = 0; j < meshCount; ++j)
                {
                    var vertices = new CompressedList <uint>();
                    var samples  = vhvFile.GetSamples(0, j);

                    vertices.AddRange(samples.Select(x => ((uint)x.A << 24) | ((uint)x.B << 16) | ((uint)x.G << 8) | x.R));

                    meshList.Add(vertices);
                }

                page.Props.Add(meshList);
            }

            return(page);
        }