Пример #1
0
        public override IEnumerable <TexturePackage> CreatePackages(IEnumerable <string> sourceRoots, IEnumerable <string> additionalPackages, IEnumerable <string> blacklist, IEnumerable <string> whitelist)
        {
            var blist = blacklist.Select(x => x.TrimEnd('/', '\\')).Where(x => !String.IsNullOrWhiteSpace(x)).ToList();
            var wlist = whitelist.Select(x => x.TrimEnd('/', '\\')).Where(x => !String.IsNullOrWhiteSpace(x)).ToList();

            var roots    = sourceRoots.ToList();
            var packages = new Dictionary <string, TexturePackage>();

            var types = new HashSet <string>
            {
                "unlitgeneric",
                "lightmappedgeneric",
                "lightmappedreflective",
                "water",
                "sprite",
                "decalmodulate",
                "modulate",
                "subrect",
                "worldvertextransition",
                "lightmapped_4wayblend",
                "unlittwotexture",
                "worldtwotextureblend",
                "skyfog"
            };

            var packageRoot = String.Join(";", roots);
            var add         = additionalPackages.ToList();

            var vmtRoot = new QuickRoot(roots, add, "materials", ".vmt");
            var vtfRoot = new QuickRoot(roots, add, "materials", ".vtf");

            const StringComparison ctype = StringComparison.InvariantCultureIgnoreCase;

            foreach (var vmt in vmtRoot.GetFiles())
            {
                var idx = vmt.LastIndexOf('/');
                var dir = idx >= 0 ? vmt.Substring(0, idx) : "";

                if ((blist.Any(x => dir.Equals(x, ctype) || dir.StartsWith(x + '/', ctype))) ||
                    (wlist.Any() && !wlist.Any(x => dir.Equals(x, ctype) || dir.StartsWith(x + '/', ctype))))
                {
                    continue;
                }

                if (!packages.ContainsKey(dir))
                {
                    packages.Add(dir, new TexturePackage(packageRoot, dir, this));
                }
                if (packages[dir].HasTexture(vmt))
                {
                    continue;
                }

                var gs = GenericStructure.Parse(new StreamReader(vmtRoot.OpenFile(vmt))).FirstOrDefault();
                if (gs == null || !types.Contains(gs.Name.ToLowerInvariant()))
                {
                    continue;
                }

                var baseTexture = gs.GetPropertyValue("$basetexture", true);
                if (baseTexture == null)
                {
                    continue;
                }
                baseTexture = baseTexture.ToLowerInvariant().Replace('\\', '/');

                if (!vtfRoot.HasFile(baseTexture))
                {
                    continue;
                }

                var size = Vtf.VtfProvider.GetSize(vtfRoot.OpenFile(baseTexture));
                packages[dir].AddTexture(new TextureItem(packages[dir], vmt, GetFlags(gs), baseTexture, size.Width, size.Height));
            }

            vmtRoot.Dispose();

            foreach (var tp in packages.Values)
            {
                _roots.Add(tp, vtfRoot);
            }

            return(packages.Values);
        }
Пример #2
0
        public override IEnumerable<TexturePackage> CreatePackages(IEnumerable<string> sourceRoots, IEnumerable<string> additionalPackages, IEnumerable<string> blacklist, IEnumerable<string> whitelist)
        {
            var blist = blacklist.Select(x => x.TrimEnd('/', '\\')).Where(x => !String.IsNullOrWhiteSpace(x)).ToList();
            var wlist = whitelist.Select(x => x.TrimEnd('/', '\\')).Where(x => !String.IsNullOrWhiteSpace(x)).ToList();

            var roots = sourceRoots.ToList();
            var packages = new Dictionary<string, TexturePackage>();

            var types = new HashSet<string>
            {
                "unlitgeneric",
                "lightmappedgeneric",
                "lightmappedreflective",
                "water",
                "sprite",
                "decalmodulate",
                "modulate",
                "subrect",
                "worldvertextransition",
                "lightmapped_4wayblend",
                "unlittwotexture",
                "worldtwotextureblend",
                "skyfog"
            };

            var packageRoot = String.Join(";", roots);
            var add = additionalPackages.ToList();

            var vmtRoot = new QuickRoot(roots, add, "materials", ".vmt");
            var vtfRoot = new QuickRoot(roots, add, "materials", ".vtf");

            const StringComparison ctype = StringComparison.InvariantCultureIgnoreCase;

            foreach (var vmt in vmtRoot.GetFiles())
            {
                var idx = vmt.LastIndexOf('/');
                var dir = idx >= 0 ? vmt.Substring(0, idx) : "";

                if ((blist.Any(x => dir.Equals(x, ctype) || dir.StartsWith(x + '/', ctype))) ||
                    (wlist.Any() && !wlist.Any(x => dir.Equals(x, ctype) || dir.StartsWith(x + '/', ctype))))
                {
                    continue;
                }

                if (!packages.ContainsKey(dir)) packages.Add(dir, new TexturePackage(packageRoot, dir, this));
                if (packages[dir].HasTexture(vmt)) continue;

                var gs = GenericStructure.Parse(new StreamReader(vmtRoot.OpenFile(vmt))).FirstOrDefault();
                if (gs == null || !types.Contains(gs.Name.ToLowerInvariant())) continue;

                var baseTexture = gs.GetPropertyValue("$basetexture", true);
                if (baseTexture == null) continue;
                baseTexture = baseTexture.ToLowerInvariant().Replace('\\', '/');

                if (!vtfRoot.HasFile(baseTexture)) continue;

                var size = Vtf.VtfProvider.GetSize(vtfRoot.OpenFile(baseTexture));
                packages[dir].AddTexture(new TextureItem(packages[dir], vmt, GetFlags(gs), baseTexture, size.Width, size.Height));
            }

            vmtRoot.Dispose();

            foreach (var tp in packages.Values)
            {
                _roots.Add(tp, vtfRoot);
            }

            return packages.Values;
        }