public void Init() { string[] allfiles = Directory.GetFiles(BaseDirectory, "*.*", SearchOption.AllDirectories); foreach (string tfile in allfiles) { string file = tfile.Replace('\\', '/'); if (file.Length == 0 || file[file.Length - 1] == '/') { continue; } if (file.EndsWith(".pak")) { Paks.Add(new PakFile(file.Replace(BaseDirectory, ""))); } else { Files.Add(new PakkedFile(file.Replace(BaseDirectory, ""))); } } int id = 0; foreach (PakFile pak in Paks) { List <ZipStorer.ZipFileEntry> zents = pak.Storer.ReadCentralDir(); SysConsole.Output(OutputType.INIT, id + ") Pak " + pak.Name + " has " + zents.Count + " files."); pak.FileListIndex = Files.Count; foreach (ZipStorer.ZipFileEntry zent in zents) { string name = zent.FilenameInZip.Replace('\\', '/').Replace("..", ".").Replace(":", "").ToLower(); if (name.Length == 0 || name[name.Length - 1] == '/') { continue; } SysConsole.Output(OutputType.INIT, "--> " + name); Files.Add(new PakkedFile(name, id, zent)); } id++; } }
void AddMesh(Mesh mesh, List <Vector3> vertices, List <int> indices) { for (int i = 0; i < mesh.Vertices.Count; i++) { Vector3D vert = mesh.Vertices[i]; vertices.Add(new Vector3(vert.X, vert.Y, vert.Z)); } foreach (Face face in mesh.Faces) { if (face.Indices.Count == 3) { for (int i = 2; i >= 0; i--) { indices.Add(face.Indices[i]); } } else { SysConsole.Output(OutputType.WARNING, "Mesh has face with " + face.Indices.Count + " faces!!"); } } }
SingleAnimation LoadAnimation(string name) { if (Program.Files.Exists("animations/" + name + ".anim")) { SingleAnimation created = new SingleAnimation(); created.Name = name; string[] data = Program.Files.ReadText("animations/" + name + ".anim").Split('\n'); int entr = 0; for (int i = 0; i < data.Length; i++) { if (data[i].StartsWith("//")) { continue; } string type = data[i]; if (data.Length <= i + 1 || data[i + 1] != "{") { break; } List <KeyValuePair <string, string> > entries = new List <KeyValuePair <string, string> >(); for (i += 2; i < data.Length; i++) { if (data[i].Trim().StartsWith("//")) { continue; } if (data[i] == "}") { break; } string[] dat = data[i].Split(':'); if (dat.Length <= 1) { SysConsole.Output(OutputType.WARNING, "Invalid key dat: " + dat[0]); } else { string key = dat[0].Trim(); string value = dat[1].Substring(0, dat[1].Length - 1).Trim(); entries.Add(new KeyValuePair <string, string>(key, value)); } } bool isgeneral = type == "general" && entr == 0; SingleAnimationNode node = null; if (!isgeneral) { node = new SingleAnimationNode(); node.Name = type.ToLower(); } foreach (KeyValuePair <string, string> entry in entries) { if (isgeneral) { if (entry.Key == "length") { created.Length = Utilities.StringToDouble(entry.Value); } else { SysConsole.Output(OutputType.WARNING, "Unknown GENERAL key: " + entry.Key); } } else { if (entry.Key == "positions") { string[] poses = entry.Value.Split(' '); for (int x = 0; x < poses.Length; x++) { if (poses[x].Length > 0) { string[] posdata = poses[x].Split('='); node.PosTimes.Add(Utilities.StringToDouble(posdata[0])); node.Positions.Add(new Location(Utilities.StringToFloat(posdata[1]), Utilities.StringToFloat(posdata[2]), Utilities.StringToFloat(posdata[3]))); } } } else if (entry.Key == "rotations") { string[] rots = entry.Value.Split(' '); for (int x = 0; x < rots.Length; x++) { if (rots[x].Length > 0) { string[] posdata = rots[x].Split('='); node.RotTimes.Add(Utilities.StringToDouble(posdata[0])); node.Rotations.Add(new Quaternion(Utilities.StringToFloat(posdata[1]), Utilities.StringToFloat(posdata[2]), Utilities.StringToFloat(posdata[3]), Utilities.StringToFloat(posdata[4]))); } } } else if (entry.Key == "parent") { node.ParentName = entry.Value.ToLower(); } else if (entry.Key == "offset") { string[] posdata = entry.Value.Split('='); node.Offset = new Location(Utilities.StringToFloat(posdata[0]), Utilities.StringToFloat(posdata[1]), Utilities.StringToFloat(posdata[2])); } else { SysConsole.Output(OutputType.WARNING, "Unknown NODE key: " + entry.Key); } } } if (!isgeneral) { created.Nodes.Add(node); created.node_map.Add(node.Name, node); } entr++; } foreach (SingleAnimationNode node in created.Nodes) { for (int i = 0; i < created.Nodes.Count; i++) { if (created.Nodes[i].Name == node.ParentName) { node.Parent = created.Nodes[i]; break; } } } created.Engine = this; return(created); } else { throw new Exception("Invalid animation file - file not found: animations/" + name + ".anim"); } }