Ejemplo n.º 1
0
        public static SourceMaterial LoadFromStream(Stream stream)
        {
            SourceMaterial mat = new SourceMaterial();
            StreamReader reader = new StreamReader(stream);
            string line;
            int progress = 0;
            while ((line = reader.ReadLine()) != null && !line.Trim().Equals(""))
            {
                //System.Console.WriteLine(line);
                line = line.Trim().ToLower();
                switch (progress)
                {
                    case 0:
                        // Read shadername
                        mat.Name = line;
                        progress++;

                        break;
                    case 1:
                        // Read arguments..
                        if (line.Contains("$basetexture\""))
                        {
                            mat.baseTextureName = ReadVarString(line);
                            mat.baseTexture = LoadVTF(Renderer.Instance.device, mat.baseTextureName);
                            if (mat.baseTexture != null && mat.baseTexture.GetLevelDescription(0).Format == Format.A8R8G8B8)
                                mat.Alpha = true;
                        }
                        else if (line.Contains("\"include\""))
                        {
                            string name = ReadVarString(line);
                            SourceMaterial material = TextureManager.Instance.LoadMaterial(name);
                            if (material != null)
                                mat = material;
                        }
                        else if(line.Contains("\"$detail\""))
                        {
                            string detailname = ReadVarString(line);
                            mat.detailTexture = LoadVTF(Renderer.Instance.device, detailname);
                            if (mat.detailTexture != null)
                                mat.Detail = true;

                        }
                        else if (line.Contains("\"$bumpmap\""))
                        {
                            string bumpname = ReadVarString(line);
                            mat.bumpmapTexture = LoadVTF(Renderer.Instance.device, bumpname);
                            if (mat.bumpmapTexture != null)
                                mat.Bumpmap = true;
                        }
                        //System.Console.WriteLine(line);
                        break;
                }
            }
            if (mat.baseTexture == null)
            {
                int test = 2;
            }
            return mat;
        }
Ejemplo n.º 2
0
 public RenderItem(RenderChildren parent, SourceMaterial material)
 {
     vb = null;
     SharedTexture1 = false;
     SharedTexture2 = false;
     this.parent = parent;
     this.material = material;
     if (this.material == null)
         this.material = new SourceMaterial();
     this.ID = Renderer.Instance.NextRenderItemID;
 }
Ejemplo n.º 3
0
        public SourceMaterial LoadMaterial(string name)
        {
            // Clean up name
            name = name.Replace('\\', '/').ToLower();
            if (name.Contains("" + '\0'))
                name = name.Substring(0, name.IndexOf('\0'));
            if (name.StartsWith("materials/"))
                name = name.Substring("materials/".Length);

            // Look in cache
            if (name.Contains("" + '.'))
            {
                if (materials.ContainsKey(name))
                    return materials[name];
            }
            else
            {
                if (materials.ContainsKey(name+".vmt"))
                    return materials[name + ".vmt"];
                else if (materials.ContainsKey(name + ".vtf"))
                    return materials[name + ".vtf"];
            }

            // Look in FileCache
            FCFile file;
            if (name.Contains("" + '.'))
                file = FileCache.Instance.GetFile(name);
            else {
                // No extension.. try vmt first, then vtf
                if ((file = FileCache.Instance.GetFile(name + ".vmt")) == null)
                    file = FileCache.Instance.GetFile(name + ".vtf");
            }

            if (file != null)
            {
                SourceMaterial material = null;

                if (file.FullName.EndsWith(".vmt"))
                    material = SourceMaterial.LoadFromFile(file.FullName);
                else if (file.FullName.EndsWith(".vtf"))
                {
                    material = new SourceMaterial();
                    material.baseTexture = SourceMaterial.LoadVTF(Renderer.Instance.device, file.FullName);
                }

                if (material != null)
                {
                    CacheMaterial(name, material);
                    return material;
                }
            }

            // Give up
            System.Console.WriteLine("Could not find Material: " + name);
            return null;
        }
Ejemplo n.º 4
0
 public void CacheMaterial(string name, SourceMaterial mat)
 {
     // Add if it doesnt excist
     if (!materials.ContainsKey(name))
         materials.Add(name, mat);
     else
         System.Console.WriteLine("Material already cached: " + name);
 }
Ejemplo n.º 5
0
 //public SourceMaterial material;
 public MDLMesh(MDLMesh_t mesh, RenderChildren parent, SourceMaterial material)
     : base(parent, material)
 {
     this.mesh = mesh;
 }