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); }
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")); }
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(); } }
public Mesh Load(FileExisting resource, Entity appendToEntity = null) { var loadJob = new LoadJob(resource, appendToEntity); var mesh = loadJob.Parse(); mesh.file = resource; return(mesh); }
public Texture2D(FileExisting file) { Type = TextureType.FromFile; UseMipMaps = true; this.file = file; file.OnFileChanged(() => { VersionInFile++; }); }
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); } } }
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(); } }); }
public FolderExisting GetFolder(FileExisting file) { var virtualDir = Path.GetDirectoryName(file.VirtualPath); return(new FolderExisting(virtualDir)); }
void Prepend(FileExisting name) { using (var fs = new System.IO.StreamReader(name.OpenReadWrite())) prependSource += fs.ReadToEnd(); }
public Shader(FileExisting file) { this.file = file; this.Uniforms = new UniformsData(); }
public override ResourceCubemap Create(FileExisting path) { return(null); }
public override bool CanCreate(FileExisting path) { return(path.ToString().EndsWith(".cubemap")); }
public T LoadResource <T>(FileExisting path) where T : Resource { return(default(T)); }
public LoadJob(FileExisting file, Entity appendToEntity) { this.file = file; this.appendToEntity = appendToEntity; }