예제 #1
0
        public bool TryFindFile(string virtualPath, out FileExisting file)
        {
            var realPath = CombineDirectory(rootResourceDirectoryPath, virtualPath);

            if (GlobSearch.IsNeeded(virtualPath))
            {
                var fileInfo = GlobSearch.FindFile(realPath);
                if (fileInfo == null)
                {
                    file = null;
                    return(false);
                }
                else
                {
                    file = new FileExisting(this, fileInfo.FullName.RemoveFromBegin(rootResourceDirectoryInfo.FullName.Length), fileInfo.FullName);
                    return(true);
                }
            }
            else
            {
                if (System.IO.File.Exists(realPath))
                {
                    file = new FileExisting(this, virtualPath, realPath);
                    return(true);
                }
            }
            file = null;
            return(false);
        }
예제 #2
0
        string AddLineMarkers(string text, FileExisting file)
        {
            if (!includedFiles.Contains(file))
            {
                includedFiles.Add(file);
            }


            var fileId = includedFiles.IndexOf(file);


            var lines = text.Split('\n').ToList();

            int macrosInserted = 0;

            lines.Insert(1, "#line " + 2 + " " + fileId);
            macrosInserted++;

            for (int i = 0; i < lines.Count; i++)
            {
                var line = lines[i];
                if (ShouldMarkLine(line))
                {
                    lines.Insert(i + 1, "#line " + (i + 2 - macrosInserted) + " " + fileId);
                    macrosInserted++;
                }
            }

            return(lines.Join("\n"));
        }
예제 #3
0
            public MaterialLibrary(FileExisting file)
            {
                using (var s = file.OpenReadWrite())
                    using (StreamReader textReader = new StreamReader(s))
                    {
                        MaterialPBR lastMat = new MaterialPBR();
                        string      line;
                        while ((line = textReader.ReadLine()) != null)
                        {
                            line = line.Trim();
                            line = line.Replace("  ", " ");

                            string[] parameters = line.Split(splitCharacters);

                            /*
                             *      Ka 1.000 1.000 1.000
                             * Kd 1.000 1.000 1.000
                             * Ks 0.000 0.000 0.000
                             * d 1.0
                             * illum 2
                             * map_Ka lenna.tga           # the ambient texture map
                             * map_Kd lenna.tga           # the diffuse texture map (most of the time, it will
                             # be the same as the ambient texture map)
                             # map_Ks lenna.tga           # specular color texture map
                             # map_Ns lenna_spec.tga      # specular highlight component
                             # map_d lenna_alpha.tga      # the alpha texture map
                             # map_bump lenna_bump.tga    # some implementations use 'map_bump' instead of 'bump' below
                             * */

                            switch (parameters[0])
                            {
                            case "newmtl":
                                lastMat = new MaterialPBR();
                                materials[parameters[1]] = lastMat;
                                break;

                            case "Kd":                             // diffuse
                                if (parameters.Length > 2)
                                {
                                    Parse(ref parameters[1], ref lastMat.albedo.X);
                                    Parse(ref parameters[2], ref lastMat.albedo.Y);
                                    Parse(ref parameters[3], ref lastMat.albedo.Z);
                                }
                                else
                                {
                                    float r = 1;
                                    Parse(ref parameters[1], ref r);
                                    lastMat.albedo.X = lastMat.albedo.Y = lastMat.albedo.Z = r;
                                }
                                break;

                            case "map_Kd":
                                lastMat.albedoTexture = new Texture2D(FileSystem.FindFile(parameters[1], file.Folder));
                                break;
                            }
                        }

                        textReader.Close();
                    }
            }
예제 #4
0
        public Mesh Load(FileExisting resource, Entity appendToEntity = null)
        {
            var loadJob = new LoadJob(resource, appendToEntity);
            var mesh    = loadJob.Parse();

            mesh.file = resource;
            return(mesh);
        }
예제 #5
0
 public Texture2D(FileExisting file)
 {
     Type       = TextureType.FromFile;
     UseMipMaps = true;
     this.file  = file;
     file.OnFileChanged(() =>
     {
         VersionInFile++;
     });
 }
예제 #6
0
        public void LoadAndParse(FileExisting file)
        {
            string source = file.ReadAllText();

            source = AddLineMarkers(source, file);
            source = ReplaceIncludeDirectiveWithFileContents(source, file.Folder);

            // the contents above first shader part (program) [VertexShader] are shared amongs all parts (prepended to all parts)
            string prependContents = "";

            {
                ShaderType shaderType = ShaderType.VertexShader;
                int        startOfTag = GetClosestShaderTypeTagPosition(source, 0, ref shaderType);
                if (startOfTag > 0)
                {
                    prependContents += source.Substring(0, startOfTag - 1);
                    source           = source.Substring(startOfTag);
                }
            }


            foreach (ShaderType type in Enum.GetValues(typeof(ShaderType)))
            {
                ShaderType shaderType = ShaderType.VertexShader;
                int        startOfTag = GetClosestShaderTypeTagPosition(source, 0, ref shaderType);

                if (startOfTag != -1)
                {
                    var tagLength = shaderType.ToString().Length + 2;

                    ShaderType notUsed         = ShaderType.VertexShader;
                    int        endOfShaderPart = GetClosestShaderTypeTagPosition(source, startOfTag + tagLength, ref notUsed);
                    if (endOfShaderPart == -1)
                    {
                        endOfShaderPart = source.Length;
                    }

                    var    startOfShaderPart = startOfTag + tagLength;
                    string shaderPart        = source.Substring(
                        startOfShaderPart,
                        endOfShaderPart - startOfShaderPart
                        );

                    AttachShader(prependContents + shaderPart, shaderType, file.VirtualPath);

                    source = source.Substring(endOfShaderPart);
                }
            }
        }
예제 #7
0
        public CVarFactory(FileExisting file, ILog log)
        {
            this.Log  = log;
            this.file = file;
            TryReadConfig();

            //file.OnFileChanged(() =>
            //{
            //	// make sure our save does not trigger file changed event and reload
            //	if (fileLastSaved.IsOver(seconds: 10).InPastComparedTo(DateTime.Now))
            //	{
            //		TryReadConfig();
            //	}
            //});

            GetCVar("debug / save cvars to file", false).OnChanged(cvar =>
            {
                if (cvar.EatBoolIfTrue())
                {
                    GetCVar("debug / show debug form").Bool = false;
                    SaveData();
                }
            });
        }
예제 #8
0
        public FolderExisting GetFolder(FileExisting file)
        {
            var virtualDir = Path.GetDirectoryName(file.VirtualPath);

            return(new FolderExisting(virtualDir));
        }
예제 #9
0
 void Prepend(FileExisting name)
 {
     using (var fs = new System.IO.StreamReader(name.OpenReadWrite()))
         prependSource += fs.ReadToEnd();
 }
예제 #10
0
 public Shader(FileExisting file)
 {
     this.file     = file;
     this.Uniforms = new UniformsData();
 }
예제 #11
0
 public override ResourceCubemap Create(FileExisting path)
 {
     return(null);
 }
예제 #12
0
 public override bool CanCreate(FileExisting path)
 {
     return(path.ToString().EndsWith(".cubemap"));
 }
예제 #13
0
 public T LoadResource <T>(FileExisting path) where T : Resource
 {
     return(default(T));
 }
예제 #14
0
 public LoadJob(FileExisting file, Entity appendToEntity)
 {
     this.file           = file;
     this.appendToEntity = appendToEntity;
 }