public static ElData Parse(ElTokenizer tokenizer) { while (tokenizer.Current.Kind == ElTokenizer.NewLineTokenKind) tokenizer.MoveNext(); var rt = new ElData(); if (tokenizer.Current.Kind == ElTokenizer.IdentifierTokenKind) { rt.Name = tokenizer.Current.Text; tokenizer.MoveNext(); } if (tokenizer.Current.Kind == ElTokenizer.BeginChildrenTokenKind) { rt.Children = tokenizer.TakeWhile(_ => _.Kind != ElTokenizer.EndChildrenTokenKind) .Select(_ => Parse(tokenizer)) .ToList(); tokenizer.MoveNext(ElTokenizer.EndChildrenTokenKind); } else rt.Values = tokenizer.StartWith(tokenizer.Current) .TakeWhile(_ => _.Kind != ElTokenizer.NewLineTokenKind && _.Kind != ElTokenizer.EndChildrenTokenKind) .Select(_ => _.Text) .ToList(); return rt; }
public static ElData Parse(ElTokenizer tokenizer) { while (tokenizer.Current.Kind == ElTokenizer.NewLineTokenKind) { tokenizer.MoveNext(); } var rt = new ElData(); if (tokenizer.Current.Kind == ElTokenizer.IdentifierTokenKind) { rt.Name = tokenizer.Current.Text; tokenizer.MoveNext(); } if (tokenizer.Current.Kind == ElTokenizer.BeginChildrenTokenKind) { rt.Children = tokenizer.TakeWhile(_ => _.Kind != ElTokenizer.EndChildrenTokenKind) .Select(_ => Parse(tokenizer)) .ToList(); tokenizer.MoveNext(ElTokenizer.EndChildrenTokenKind); } else { rt.Values = tokenizer.StartWith(tokenizer.Current) .TakeWhile(_ => _.Kind != ElTokenizer.NewLineTokenKind && _.Kind != ElTokenizer.EndChildrenTokenKind) .Select(_ => _.Text) .ToList(); } return(rt); }
public static ElSetting Parse(ElData data) { var rt = new ElSetting { baseData = data, }; foreach (var i in data.Children) { switch (i.Name) { case "ElfreinaSoftVersion": rt.ElfreinaSoftVersion = float.Parse(i.Values.First()); break; case "ElfreinaBetaVersion": rt.ElfreinaBetaVersion = int.Parse(i.Values.First()); break; case "LoadType": rt.LoadType = i.Values.First().Trim('"'); break; case "IsRightHand": rt.IsRightHand = bool.Parse(i.Values.First()); break; } } return(rt); }
public static ElSetting Parse(ElData data) { var rt = new ElSetting { baseData = data, }; foreach (var i in data.Children) switch (i.Name) { case "ElfreinaSoftVersion": rt.ElfreinaSoftVersion = float.Parse(i.Values.First()); break; case "ElfreinaBetaVersion": rt.ElfreinaBetaVersion = int.Parse(i.Values.First()); break; case "LoadType": rt.LoadType = i.Values.First().Trim('"'); break; case "IsRightHand": rt.IsRightHand = bool.Parse(i.Values.First()); break; } return rt; }
public static ElBlendPart Parse(ElData data) { var rt = new ElBlendPart { baseData = data, }; foreach (var i in data.Children) switch (i.Name) { case "BoneName": rt.BoneName = i.Values.First().Trim('"'); break; case "TransformIndex": rt.TransformIndex = int.Parse(i.Values.First()); break; case "VertexBlend": foreach (var j in i.Children) { var sl = j.Values.First().Split(','); rt.VertexBlend.Add(int.Parse(sl[0]), float.Parse(sl[1])); } break; } return rt; }
public static ElBlendPart Parse(ElData data) { var rt = new ElBlendPart { baseData = data, }; foreach (var i in data.Children) { switch (i.Name) { case "BoneName": rt.BoneName = i.Values.First().Trim('"'); break; case "TransformIndex": rt.TransformIndex = int.Parse(i.Values.First()); break; case "VertexBlend": foreach (var j in i.Children) { var sl = j.Values.First().Split(','); rt.VertexBlend.Add(int.Parse(sl[0]), float.Parse(sl[1])); } break; } } return(rt); }
public static ElNode Parse(ElData data) { var rt = new ElNode { baseData = data, }; foreach (var i in data.Children) switch (i.Name) { case "NodeName": rt.NodeName = i.Values.First().Trim('"'); break; case "InitPostureMatrix": rt.InitPostureMatrix = i.Values.Select(float.Parse).ToArray(); break; case "Node": rt.Nodes.Add(Parse(i)); break; } return rt; }
public ElData Child(string name, bool createIfNotFound = true) { if (this.Children == null) { if (createIfNotFound) { this.Children = new List <ElData>(); } else { return(null); } } var value = this.Children.FirstOrDefault(_ => _.Name.Equals(name)); if (createIfNotFound && value == null) { this.Children.Add(value = new ElData { Name = name, }); } return(value); }
public static ElNode Parse(ElData data) { var rt = new ElNode { baseData = data, }; foreach (var i in data.Children) { switch (i.Name) { case "NodeName": rt.NodeName = i.Values.First().Trim('"'); break; case "InitPostureMatrix": rt.InitPostureMatrix = i.Values.Select(float.Parse).ToArray(); break; case "Node": rt.Nodes.Add(Parse(i)); break; } } return(rt); }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Child("NodeName").SetValues("\"" + this.NodeName + "\""); baseData.Child("InitPostureMatrix").SetValues(this.InitPostureMatrix.Select(_ => _.ToString("0.000000"))); baseData.Children.AddRange(this.Nodes.Select(_ => _.ToData())); return(baseData); }
public static ElAnimationData Parse(ElData data) { var rt = new ElAnimationData { baseData = data, }; foreach (var i in data.Children) { switch (i.Name) { case "AnimationName": rt.AnimationName = i.Values.First().Trim('"'); break; case "AnimationTime": rt.AnimationTime = int.Parse(i.Values.First()); break; case "FrameParSecond": rt.FramesPerSecond = int.Parse(i.Values.First()); break; case "TransitionTime": rt.TransitionTime = int.Parse(i.Values.First()); break; case "Priority": rt.Priority = int.Parse(i.Values.First()); break; case "Loop": rt.Loop = bool.Parse(i.Values.First()); break; case "BoneAnimation": rt.BoneAnimationTimeKeys = i.Child("TimeKeys").Children.Select(_ => float.Parse(_.Values.First())).ToList(); rt.BoneAnimation = i.Children.Where(_ => _.Name == "AnimationPart").Select(ElBoneAnimationPart.Parse).ToList(); break; case "UVAnimation": rt.UVAnimationTimeKeys = i.Child("TimeKeys").Children.Select(_ => float.Parse(_.Values.First())).ToList(); rt.UVAnimation = i.Children.Where(_ => _.Name == "AnimationPart").Select(ElUVAnimationPart.Parse).ToList(); break; } } return(rt); }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Child("NodeName").SetValues("\"" + this.NodeName + "\""); baseData.Child("InitPostureMatrix").SetValues(this.InitPostureMatrix.Select(_ => _.ToString("0.000000"))); baseData.Children.AddRange(this.Nodes.Select(_ => _.ToData())); return baseData; }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "BlendPart"; baseData.Child("BoneName").SetValues("\"" + this.BoneName + "\""); baseData.Child("TransformIndex").SetValues(this.TransformIndex.ToString()); baseData.Child("VertexBlend").Children = this.VertexBlend.Select(_ => new ElData().SetValues(_.Key.ToString() + "," + _.Value.ToString("0.000000"))).ToList(); return(baseData); }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "BlendPart"; baseData.Child("BoneName").SetValues("\"" + this.BoneName + "\""); baseData.Child("TransformIndex").SetValues(this.TransformIndex.ToString()); baseData.Child("VertexBlend").Children = this.VertexBlend.Select(_ => new ElData().SetValues(_.Key.ToString() + "," + _.Value.ToString("0.000000"))).ToList(); return baseData; }
public static ElMesh Parse(ElData data) { var rt = new ElMesh { baseData = data, }; foreach (var i in data.Children) switch (i.Name) { case "Name": rt.Name = i.Values.First().Trim('"'); break; case "Positions": rt.Positions = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "Normals": rt.Normals = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "Diffuse": rt.Diffuse = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "BlendList": rt.BlendList = i.Children.Select(ElBlendPart.Parse).ToList(); break; case "TextureUV": case "Texture1UV": case "Texture2UV": case "Texture3UV": case "Texture4UV": case "Texture5UV": case "Texture6UV": case "Texture7UV": case "Texture8UV": rt.TextureUV[int.Parse(string.Join("", i.Name.Where(char.IsDigit).DefaultIfEmpty('0')))] = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "VertexIndices": rt.VertexIndices = i.Children.Select(_ => _.Values.Select(f => f.Split(',').Last()).Select(int.Parse).ToArray()).ToList(); break; case "Attributes": rt.Attributes = i.Children.Select(_ => int.Parse(_.Values.First())).ToList(); break; } return rt; }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "AnimationPart"; baseData.Child("MeshContainerName").SetValues("\"" + this.MeshContainerName + "\""); baseData.Child("MaterialName").SetValues("\"" + this.MaterialName + "\""); baseData.Child("TimeKeys").Children = this.TimeKeys.Select(_ => new ElData().SetValues(_.ToString("0.000000"))).ToList(); baseData.Child("TransKeys").Children = this.TransKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("RotateKeys").Children = this.RotateKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("ScaleKeys").Children = this.ScaleKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); return(baseData); }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "Material"; baseData.Child("Name").SetValues("\"" + this.Name + "\""); baseData.Child("Diffuse").SetValues(this.Diffuse.Select(_ => _.ToString("0.000000"))); baseData.Child("Ambient").SetValues(this.Ambient.Select(_ => _.ToString("0.000000"))); baseData.Child("Emissive").SetValues(this.Emissive.Select(_ => _.ToString("0.000000"))); baseData.Child("Specular").SetValues(this.Emissive.Select(_ => _.ToString("0.000000"))); baseData.Child("SpecularSharpness").SetValues(this.SpecularSharpness.ToString("0.000000")); baseData.Child("TextureFilename").SetValues("\"" + this.TextureFilename + "\""); return(baseData); }
public static ElBoneAnimationPart Parse(ElData data) { var rt = new ElBoneAnimationPart { baseData = data, }; foreach (var i in data.Children) { switch (i.Name) { case "NodeName": rt.NodeName = i.Values.First().Trim('"'); break; case "TransitionTime": rt.TransitionTime = int.Parse(i.Values.First()); break; case "InterpolationType": rt.InterpolationType = Util.ParseEnum <ElInterpolationType>(i.Values.First().Trim('"')); break; case "TimeKeys": rt.TimeKeys = i.Children.Select(_ => float.Parse(_.Values.First())).ToList(); break; case "TransKeys": rt.TransKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "RotateKeys": rt.RotateKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "ScaleKeys": rt.ScaleKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; } } return(rt); }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "AnimationPart"; baseData.Child("NodeName").SetValues("\"" + this.NodeName + "\""); baseData.Child("TransitionTime").SetValues(this.TransitionTime.ToString()); baseData.Child("InterpolationType").SetValues("\"" + this.InterpolationType + "\""); baseData.Child("TimeKeys").Children = this.TimeKeys.Select(_ => new ElData().SetValues(_.ToString("0.000000"))).ToList(); baseData.Child("TransKeys").Children = this.TransKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("RotateKeys").Children = this.RotateKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("ScaleKeys").Children = this.ScaleKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); return(baseData); }
public static ElMaterial Parse(ElData data) { var rt = new ElMaterial { baseData = data, }; foreach (var i in data.Children) { switch (i.Name) { case "Name": rt.Name = i.Values.First().Trim('"'); break; case "Diffuse": rt.Diffuse = i.Values.Select(float.Parse).ToArray(); break; case "Ambient": rt.Ambient = i.Values.Select(float.Parse).ToArray(); break; case "Emissive": rt.Emissive = i.Values.Select(float.Parse).ToArray(); break; case "Specular": rt.Specular = i.Values.Select(float.Parse).ToArray(); break; case "SpecularSharpness": rt.SpecularSharpness = float.Parse(i.Values.First()); break; case "TextureFilename": rt.TextureFilename = i.Values.First().Trim('"'); break; } } return(rt); }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "MeshContainer"; baseData.Child("Name").SetValues("\"" + this.Name + "\""); baseData.Child("BoneCount").SetValues(this.BoneNames.Count.ToString()); baseData.Child("MeshCount").SetValues(this.Meshes.Count.ToString()); baseData.Child("VertexFormat").Children = this.VertexFormat.Select(_ => new ElData().SetValues("\"" + _ + "\"")).ToList(); baseData.Child("BoneNames").Children = this.BoneNames.Select(_ => new ElData().SetValues("\"" + _ + "\"")).ToList(); baseData.Child("OffsetMatrices").Children = this.OffsetMatrices.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("Materials").Children = this.Materials.Select(_ => _.ToData()).StartWith(new ElData("MaterialCount").SetValues(this.Materials.Count.ToString())).ToList(); baseData.Children.AddRange(this.Meshes.Select(_ => _.ToData())); return(baseData); }
public static ElMeshContainer Parse(ElData data) { var rt = new ElMeshContainer { baseData = data, }; foreach (var i in data.Children) { switch (i.Name) { case "Name": rt.Name = i.Values.First().Trim('"'); break; case "VertexFormat": rt.VertexFormat = i.Children.Select(_ => Util.ParseEnum <ElVertexFormat>(_.Values.First().Trim('"'))).ToList(); break; case "BoneNames": rt.BoneNames = i.Children.Select(_ => _.Values.First().Trim('"')).ToList(); break; case "OffsetMatrices": rt.OffsetMatrices = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "Materials": rt.Materials = i.Children.Where(_ => _.Name == "Material").Select(ElMaterial.Parse).ToList(); break; case "Mesh": rt.Meshes.Add(ElMesh.Parse(i)); break; } } return(rt); }
public static ElUVAnimationPart Parse(ElData data) { var rt = new ElUVAnimationPart { baseData = data, }; foreach (var i in data.Children) { switch (i.Name) { case "MeshContainerName": rt.MeshContainerName = i.Values.First().Trim('"'); break; case "MaterialName": rt.MaterialName = i.Values.First().Trim('"'); break; case "TimeKeys": rt.TimeKeys = i.Children.Select(_ => float.Parse(_.Values.First())).ToList(); break; case "TransKeys": rt.TransKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "RotateKeys": rt.RotateKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "ScaleKeys": rt.ScaleKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; } } return(rt); }
public static ElBoneAnimationPart Parse(ElData data) { var rt = new ElBoneAnimationPart { baseData = data, }; foreach (var i in data.Children) switch (i.Name) { case "NodeName": rt.NodeName = i.Values.First().Trim('"'); break; case "TransitionTime": rt.TransitionTime = int.Parse(i.Values.First()); break; case "InterpolationType": rt.InterpolationType = Util.ParseEnum<ElInterpolationType>(i.Values.First().Trim('"')); break; case "TimeKeys": rt.TimeKeys = i.Children.Select(_ => float.Parse(_.Values.First())).ToList(); break; case "TransKeys": rt.TransKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "RotateKeys": rt.RotateKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "ScaleKeys": rt.ScaleKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; } return rt; }
public static ElMaterial Parse(ElData data) { var rt = new ElMaterial { baseData = data, }; foreach (var i in data.Children) switch (i.Name) { case "Name": rt.Name = i.Values.First().Trim('"'); break; case "Diffuse": rt.Diffuse = i.Values.Select(float.Parse).ToArray(); break; case "Ambient": rt.Ambient = i.Values.Select(float.Parse).ToArray(); break; case "Emissive": rt.Emissive = i.Values.Select(float.Parse).ToArray(); break; case "Specular": rt.Specular = i.Values.Select(float.Parse).ToArray(); break; case "SpecularSharpness": rt.SpecularSharpness = float.Parse(i.Values.First()); break; case "TextureFilename": rt.TextureFilename = i.Values.First().Trim('"'); break; } return rt; }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "Setting"; baseData.Child("ElfreinaSoftVersion").SetValues(this.ElfreinaSoftVersion.ToString("0.00")); if (this.ElfreinaBetaVersion == 0) { baseData.RemoveChildren("ElfreinaBetaVersion"); } else { baseData.Child("ElfreinaBetaVersion").SetValues(this.ElfreinaBetaVersion.ToString()); } baseData.Child("LoadType").SetValues("\"" + this.LoadType + "\""); baseData.Child("IsRightHand").SetValues(this.IsRightHand.ToString()); return(baseData); }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Child("AnimationName").SetValues("\"" + this.AnimationName + "\""); baseData.Child("AnimationTime").SetValues(this.AnimationTime.ToString()); baseData.Child("FrameParSecond").SetValues(this.FramesPerSecond.ToString()); baseData.Child("TransitionTime").SetValues(this.TransitionTime.ToString()); baseData.Child("Priority").SetValues(this.Priority.ToString()); baseData.Child("Loop").SetValues(this.Loop.ToString()); if (this.BoneAnimation.Any()) { baseData.Child("BoneAnimation").Children = this.BoneAnimation.Select(_ => _.ToData()) .StartWith(new ElData("TimeKeys") { Children = this.BoneAnimationTimeKeys.Select(f => new ElData().SetValues(f.ToString("0.000000"))).ToList(), }).ToList(); } else { baseData.RemoveChildren("BoneAnimation"); } if (this.UVAnimation.Any()) { baseData.Child("UVAnimation").Children = this.UVAnimation.Select(_ => _.ToData()) .StartWith(new ElData("TimeKeys") { Children = this.UVAnimationTimeKeys.Select(f => new ElData().SetValues(f.ToString("0.000000"))).ToList(), }).ToList(); } else { baseData.RemoveChildren("UVAnimation"); } return(baseData); }
public static ElUVAnimationPart Parse(ElData data) { var rt = new ElUVAnimationPart { baseData = data, }; foreach (var i in data.Children) switch (i.Name) { case "MeshContainerName": rt.MeshContainerName = i.Values.First().Trim('"'); break; case "MaterialName": rt.MaterialName = i.Values.First().Trim('"'); break; case "TimeKeys": rt.TimeKeys = i.Children.Select(_ => float.Parse(_.Values.First())).ToList(); break; case "TransKeys": rt.TransKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "RotateKeys": rt.RotateKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "ScaleKeys": rt.ScaleKeys = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; } return rt; }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "Mesh"; baseData.Child("Name").SetValues("\"" + this.Name + "\""); baseData.Child("VertexCount").SetValues(this.Positions.Count.ToString()); baseData.Child("FaceCount").SetValues(this.VertexIndices.Count.ToString()); baseData.Child("Positions").Children = this.Positions.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("Normals").Children = this.Normals.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("BlendList").Children = this.BlendList.Select(_ => _.ToData()).ToList(); baseData.RemoveChildren("TextureUV"); for (int i = 1; i < 9; i++) { baseData.RemoveChildren("Texture" + i + "UV"); } if (this.TextureUV.Any()) { if (this.TextureUV.Count == 1) { baseData.Child("TextureUV").Children = this.TextureUV.First().Value.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); } else { foreach (var i in this.TextureUV) { baseData.Child("Texture" + i.Key + "UV").Children = i.Value.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); } } } baseData.Child("VertexIndices").Children = this.VertexIndices.Select(_ => new ElData().SetValues(new[] { _.Length + "," + _.First().ToString() }.Concat(_.Skip(1).Select(i => i.ToString())))).ToList(); baseData.Child("Attributes").Children = this.Attributes.Select(_ => new ElData().SetValues(_.ToString())).ToList(); return(baseData); }
public static ElMeshContainer Parse(ElData data) { var rt = new ElMeshContainer { baseData = data, }; foreach (var i in data.Children) switch (i.Name) { case "Name": rt.Name = i.Values.First().Trim('"'); break; case "VertexFormat": rt.VertexFormat = i.Children.Select(_ => Util.ParseEnum<ElVertexFormat>(_.Values.First().Trim('"'))).ToList(); break; case "BoneNames": rt.BoneNames = i.Children.Select(_ => _.Values.First().Trim('"')).ToList(); break; case "OffsetMatrices": rt.OffsetMatrices = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "Materials": rt.Materials = i.Children.Where(_ => _.Name == "Material").Select(ElMaterial.Parse).ToList(); break; case "Mesh": rt.Meshes.Add(ElMesh.Parse(i)); break; } return rt; }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "Setting"; baseData.Child("ElfreinaSoftVersion").SetValues(this.ElfreinaSoftVersion.ToString("0.00")); if (this.ElfreinaBetaVersion == 0) baseData.RemoveChildren("ElfreinaBetaVersion"); else baseData.Child("ElfreinaBetaVersion").SetValues(this.ElfreinaBetaVersion.ToString()); baseData.Child("LoadType").SetValues("\"" + this.LoadType + "\""); baseData.Child("IsRightHand").SetValues(this.IsRightHand.ToString()); return baseData; }
public string GetFormattedText() { var sb = new StringBuilder(); sb.AppendLine("Elfreina Extension Model File"); sb.Append("File Version "); sb.AppendLine(this.Version.ToString("0.00")); if (this.Setting != null) sb.AppendLine(this.Setting.GetFormattedText()); if (this.MeshDataList.Any()) sb.AppendLine(new ElData("MeshDataList") { Children = this.MeshDataList.Select(_ => _.ToData()) .StartWith(new ElData("MeshContainerCount").SetValues(this.MeshDataList.Count.ToString())) .ToList(), }.GetFormattedText()); if (this.HierarchyList.Any()) sb.AppendLine(new ElData("HierarchyList") { Children = this.MeshDataList.Select(_ => _.ToData()).ToList(), }.GetFormattedText()); if (this.RenderingMeshList.Any()) sb.AppendLine(new ElData("RenderingMeshList") { Children = this.RenderingMeshList.Select(_ => { var rt = new ElData("RenderingMesh"); rt.Child("RenderingMeshName").SetValues("\"" + _.Key + "\""); rt.Child("HierarchyNamesCount").SetValues(_.Value.Count.ToString()); rt.Child("HierarchyNames").Children = _.Value.Select(s => new ElData().SetValues("\"" + s + "\"")).ToList(); return rt; }) .StartWith(new ElData("RenderingMeshCount").SetValues(this.RenderingMeshList.Count.ToString())) .ToList(), }.GetFormattedText()); if (this.AnimationList.Any()) sb.AppendLine(new ElData("AnimationList") { Children = this.AnimationList.Select(_ => _.ToData()) .StartWith(new ElData("AnimationCount").SetValues(this.AnimationList.Count.ToString())) .ToList(), }.GetFormattedText()); foreach (var i in this.CustomData) sb.AppendLine(i.GetFormattedText()); return sb.ToString(); }
public static ElAnimationData Parse(ElData data) { var rt = new ElAnimationData { baseData = data, }; foreach (var i in data.Children) switch (i.Name) { case "AnimationName": rt.AnimationName = i.Values.First().Trim('"'); break; case "AnimationTime": rt.AnimationTime = int.Parse(i.Values.First()); break; case "FrameParSecond": rt.FramesPerSecond = int.Parse(i.Values.First()); break; case "TransitionTime": rt.TransitionTime = int.Parse(i.Values.First()); break; case "Priority": rt.Priority = int.Parse(i.Values.First()); break; case "Loop": rt.Loop = bool.Parse(i.Values.First()); break; case "BoneAnimation": rt.BoneAnimationTimeKeys = i.Child("TimeKeys").Children.Select(_ => float.Parse(_.Values.First())).ToList(); rt.BoneAnimation = i.Children.Where(_ => _.Name == "AnimationPart").Select(ElBoneAnimationPart.Parse).ToList(); break; case "UVAnimation": rt.UVAnimationTimeKeys = i.Child("TimeKeys").Children.Select(_ => float.Parse(_.Values.First())).ToList(); rt.UVAnimation = i.Children.Where(_ => _.Name == "AnimationPart").Select(ElUVAnimationPart.Parse).ToList(); break; } return rt; }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Child("AnimationName").SetValues("\"" + this.AnimationName + "\""); baseData.Child("AnimationTime").SetValues(this.AnimationTime.ToString()); baseData.Child("FrameParSecond").SetValues(this.FramesPerSecond.ToString()); baseData.Child("TransitionTime").SetValues(this.TransitionTime.ToString()); baseData.Child("Priority").SetValues(this.Priority.ToString()); baseData.Child("Loop").SetValues(this.Loop.ToString()); if (this.BoneAnimation.Any()) baseData.Child("BoneAnimation").Children = this.BoneAnimation.Select(_ => _.ToData()) .StartWith(new ElData("TimeKeys") { Children = this.BoneAnimationTimeKeys.Select(f => new ElData().SetValues(f.ToString("0.000000"))).ToList(), }).ToList(); else baseData.RemoveChildren("BoneAnimation"); if (this.UVAnimation.Any()) baseData.Child("UVAnimation").Children = this.UVAnimation.Select(_ => _.ToData()) .StartWith(new ElData("TimeKeys") { Children = this.UVAnimationTimeKeys.Select(f => new ElData().SetValues(f.ToString("0.000000"))).ToList(), }).ToList(); else baseData.RemoveChildren("UVAnimation"); return baseData; }
public static ElDocument Parse(string text) { var rt = new ElDocument(); var tokenizer = new ElTokenizer(text); var header = new[] { "Elfreina", "Extension", "Model", "File", "\n", "File", "Version" }; if (!tokenizer.Take(header.Length).Select(_ => _.Text).SequenceEqual(header)) { throw new InvalidOperationException("invalid format"); } rt.Version = float.Parse(tokenizer.MoveNext().EnsureKind(ElTokenizer.ValueTokenKind).Text); if (rt.Version >= 2) { throw new NotSupportedException("specified format version not supported"); } foreach (var i in tokenizer) { if (i.Kind == ElTokenizer.IdentifierTokenKind) { var data = ElData.Parse(tokenizer); switch (data.Name) { case "Setting": rt.Setting = ElSetting.Parse(data); break; case "MeshDataList": rt.MeshDataList = data.Children.Where(_ => _.Name == "MeshContainer").Select(ElMeshContainer.Parse).ToList(); break; case "HierarchyList": rt.HierarchyList = data.Children.Select(ElNode.Parse).ToList(); break; case "RenderingMeshList": foreach (var j in data.Children.Where(_ => _.Name == "RenderingMesh")) { rt.RenderingMeshList.Add(j.Child("RenderingMeshName").Values.First().Trim('"'), j.Child("HierarchyNames").Children.Select(_ => _.Values.First().Trim('"')).ToList()); } break; case "AnimationList": rt.AnimationList = data.Children.Where(_ => _.Name == "AnimationData").Select(ElAnimationData.Parse).ToList(); break; default: rt.CustomData.Add(data); break; } } } return(rt); }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "MeshContainer"; baseData.Child("Name").SetValues("\"" + this.Name + "\""); baseData.Child("BoneCount").SetValues(this.BoneNames.Count.ToString()); baseData.Child("MeshCount").SetValues(this.Meshes.Count.ToString()); baseData.Child("VertexFormat").Children = this.VertexFormat.Select(_ => new ElData().SetValues("\"" + _ + "\"")).ToList(); baseData.Child("BoneNames").Children = this.BoneNames.Select(_ => new ElData().SetValues("\"" + _ + "\"")).ToList(); baseData.Child("OffsetMatrices").Children = this.OffsetMatrices.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("Materials").Children = this.Materials.Select(_ => _.ToData()).StartWith(new ElData("MaterialCount").SetValues(this.Materials.Count.ToString())).ToList(); baseData.Children.AddRange(this.Meshes.Select(_ => _.ToData())); return baseData; }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "AnimationPart"; baseData.Child("NodeName").SetValues("\"" + this.NodeName + "\""); baseData.Child("TransitionTime").SetValues(this.TransitionTime.ToString()); baseData.Child("InterpolationType").SetValues("\"" + this.InterpolationType + "\""); baseData.Child("TimeKeys").Children = this.TimeKeys.Select(_ => new ElData().SetValues(_.ToString("0.000000"))).ToList(); baseData.Child("TransKeys").Children = this.TransKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("RotateKeys").Children = this.RotateKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("ScaleKeys").Children = this.ScaleKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); return baseData; }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "Material"; baseData.Child("Name").SetValues("\"" + this.Name + "\""); baseData.Child("Diffuse").SetValues(this.Diffuse.Select(_ => _.ToString("0.000000"))); baseData.Child("Ambient").SetValues(this.Ambient.Select(_ => _.ToString("0.000000"))); baseData.Child("Emissive").SetValues(this.Emissive.Select(_ => _.ToString("0.000000"))); baseData.Child("Specular").SetValues(this.Emissive.Select(_ => _.ToString("0.000000"))); baseData.Child("SpecularSharpness").SetValues(this.SpecularSharpness.ToString("0.000000")); baseData.Child("TextureFilename").SetValues("\"" + this.TextureFilename + "\""); return baseData; }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "Mesh"; baseData.Child("Name").SetValues("\"" + this.Name + "\""); baseData.Child("VertexCount").SetValues(this.Positions.Count.ToString()); baseData.Child("FaceCount").SetValues(this.VertexIndices.Count.ToString()); baseData.Child("Positions").Children = this.Positions.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("Normals").Children = this.Normals.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("BlendList").Children = this.BlendList.Select(_ => _.ToData()).ToList(); baseData.RemoveChildren("TextureUV"); for (int i = 1; i < 9; i++) baseData.RemoveChildren("Texture" + i + "UV"); if (this.TextureUV.Any()) if (this.TextureUV.Count == 1) baseData.Child("TextureUV").Children = this.TextureUV.First().Value.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); else foreach (var i in this.TextureUV) baseData.Child("Texture" + i.Key + "UV").Children = i.Value.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("VertexIndices").Children = this.VertexIndices.Select(_ => new ElData().SetValues(new[] { _.Length + "," + _.First().ToString() }.Concat(_.Skip(1).Select(i => i.ToString())))).ToList(); baseData.Child("Attributes").Children = this.Attributes.Select(_ => new ElData().SetValues(_.ToString())).ToList(); return baseData; }
public static ElMesh Parse(ElData data) { var rt = new ElMesh { baseData = data, }; foreach (var i in data.Children) { switch (i.Name) { case "Name": rt.Name = i.Values.First().Trim('"'); break; case "Positions": rt.Positions = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "Normals": rt.Normals = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "Diffuse": rt.Diffuse = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "BlendList": rt.BlendList = i.Children.Select(ElBlendPart.Parse).ToList(); break; case "TextureUV": case "Texture1UV": case "Texture2UV": case "Texture3UV": case "Texture4UV": case "Texture5UV": case "Texture6UV": case "Texture7UV": case "Texture8UV": rt.TextureUV[int.Parse(string.Join("", i.Name.Where(char.IsDigit).DefaultIfEmpty('0')))] = i.Children.Select(_ => _.Values.Select(float.Parse).ToArray()).ToList(); break; case "VertexIndices": rt.VertexIndices = i.Children.Select(_ => _.Values.Select(f => f.Split(',').Last()).Select(int.Parse).ToArray()).ToList(); break; case "Attributes": rt.Attributes = i.Children.Select(_ => int.Parse(_.Values.First())).ToList(); break; } } return(rt); }
public string GetFormattedText() { var sb = new StringBuilder(); sb.AppendLine("Elfreina Extension Model File"); sb.Append("File Version "); sb.AppendLine(this.Version.ToString("0.00")); if (this.Setting != null) { sb.AppendLine(this.Setting.GetFormattedText()); } if (this.MeshDataList.Any()) { sb.AppendLine(new ElData("MeshDataList") { Children = this.MeshDataList.Select(_ => _.ToData()) .StartWith(new ElData("MeshContainerCount").SetValues(this.MeshDataList.Count.ToString())) .ToList(), }.GetFormattedText()); } if (this.HierarchyList.Any()) { sb.AppendLine(new ElData("HierarchyList") { Children = this.MeshDataList.Select(_ => _.ToData()).ToList(), }.GetFormattedText()); } if (this.RenderingMeshList.Any()) { sb.AppendLine(new ElData("RenderingMeshList") { Children = this.RenderingMeshList.Select(_ => { var rt = new ElData("RenderingMesh"); rt.Child("RenderingMeshName").SetValues("\"" + _.Key + "\""); rt.Child("HierarchyNamesCount").SetValues(_.Value.Count.ToString()); rt.Child("HierarchyNames").Children = _.Value.Select(s => new ElData().SetValues("\"" + s + "\"")).ToList(); return(rt); }) .StartWith(new ElData("RenderingMeshCount").SetValues(this.RenderingMeshList.Count.ToString())) .ToList(), }.GetFormattedText()); } if (this.AnimationList.Any()) { sb.AppendLine(new ElData("AnimationList") { Children = this.AnimationList.Select(_ => _.ToData()) .StartWith(new ElData("AnimationCount").SetValues(this.AnimationList.Count.ToString())) .ToList(), }.GetFormattedText()); } foreach (var i in this.CustomData) { sb.AppendLine(i.GetFormattedText()); } return(sb.ToString()); }
public ElData Child(string name, bool createIfNotFound = true) { if (this.Children == null) if (createIfNotFound) this.Children = new List<ElData>(); else return null; var value = this.Children.FirstOrDefault(_ => _.Name.Equals(name)); if (createIfNotFound && value == null) this.Children.Add(value = new ElData { Name = name, }); return value; }
public ElData ToData() { baseData = baseData ?? new ElData(); baseData.Name = "AnimationPart"; baseData.Child("MeshContainerName").SetValues("\"" + this.MeshContainerName + "\""); baseData.Child("MaterialName").SetValues("\"" + this.MaterialName + "\""); baseData.Child("TimeKeys").Children = this.TimeKeys.Select(_ => new ElData().SetValues(_.ToString("0.000000"))).ToList(); baseData.Child("TransKeys").Children = this.TransKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("RotateKeys").Children = this.RotateKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); baseData.Child("ScaleKeys").Children = this.ScaleKeys.Select(_ => new ElData().SetValues(_.Select(f => f.ToString("0.000000")))).ToList(); return baseData; }