public static (Scene, bool) LoadScene(string proPath, ISkyBoxAble skyBox) { bool readed = true; string basePath = Path.GetDirectoryName(proPath); string fname = Path.Combine(proPath); string[] lines = File.ReadAllLines(fname); HashSet <string> mtlFiles = new HashSet <string>(); Scene result = new Scene(skyBox); int linenum = 0; try { foreach (string line in lines) { linenum++; if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#")) { continue; } string[] cmds = line.Split(' '); if (cmds.Length != 3) { throw new Exception("错误的行指令数量: " + fname); } RenderObject robj; switch (cmds[0]) { case "mt": // mashtrigle { string mtfile = Path.Combine(basePath, cmds[1] + ".mritri"); robj = GetMashTrigle(mtfile); } break; case "l.p": // point light { PointLight p = new PointLight(); string[] values = cmds[1].Split(','); if (values.Length != 4) { throw new Exception("错误的描述信息"); } float x = 0.0f, y = 0.0f, z = 0.0f, r = 0.0f; float.TryParse(values[0], out x); float.TryParse(values[1], out y); float.TryParse(values[2], out z); float.TryParse(values[3], out r); p.Position = new Vector3f(x, y, z); p.R = r; robj = p; } break; default: throw new Exception("未知的实体类型" + cmds[0]); //break; } string mtlPath = Path.Combine(basePath, cmds[2] + ".mrimtl"); Material material = GetMaterial(mtlPath); robj.Material = material; result.Objects.Add(robj); } } catch (Exception ex) { Console.WriteLine($"error on line {linenum} : {ex.Message}"); readed = false; } return(result, readed); }
public Scene(ISkyBoxAble skyBox) { SkyBox = skyBox; }