Ejemplo n.º 1
0
        public static ValveMaterialFile FromProvider(string path, params IResourceProvider[] providers)
        {
            var provider = providers.FirstOrDefault(x => x.ContainsFile(path));

            if (provider == null)
            {
                return(null);
            }

            ValveMaterialFile vmt;

            using (var stream = provider.OpenFile(path))
            {
                if (stream == null)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"Could not open {path} for reading using provider {provider.ToString()}");
                    return(null);
                }

                vmt = new ValveMaterialFile(stream);
            }

            if (!vmt.Shaders.Any())
            {
                return(null);
            }

            var shader = vmt.Shaders.First();
            var props  = vmt[shader];

            if (!shader.Equals("patch", StringComparison.InvariantCultureIgnoreCase))
            {
                return(vmt);
            }

            var includePath = ((string)props["include"]).Replace('\\', '/');
            var includeVmt  = FromProvider(includePath, providers);

            if (includeVmt == null)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine($"Missing material '{includePath}' included by '{path}'!");
                Console.ResetColor();

                return(null);
            }

            var includeShader = includeVmt.Shaders.First();

            includeVmt[includeShader].MergeFrom(props["insert"], false);
            includeVmt[includeShader].MergeFrom(props["replace"], true);

            return(includeVmt);
        }
Ejemplo n.º 2
0
        public static ValveMaterialFile FromProvider(string path, params IResourceProvider[] providers)
        {
            var provider = providers.FirstOrDefault(x => x.ContainsFile(path));

            if (provider == null)
            {
                return(null);
            }

            ValveMaterialFile vmt;

            using (var stream = provider.OpenFile(path))
            {
                vmt = new ValveMaterialFile(stream);
            }

            if (!vmt.Shaders.Any())
            {
                return(null);
            }

            var shader = vmt.Shaders.First();
            var props  = vmt[shader];

            if (!shader.Equals("patch", StringComparison.InvariantCultureIgnoreCase))
            {
                return(vmt);
            }

            var includePath   = ((string)props["include"]).Replace('\\', '/');
            var includeVmt    = FromProvider(includePath, providers);
            var includeShader = includeVmt.Shaders.First();

            includeVmt[includeShader].MergeFrom(props["insert"], false);
            includeVmt[includeShader].MergeFrom(props["replace"], true);

            return(includeVmt);
        }