using System; using System.Collections; using System.Collections.Generic; using System.IO; using SharpDX; namespace AssetStudio { public interface IImported { List FrameList { get; } List MeshList { get; } List MaterialList { get; } List TextureList { get; } List AnimationList { get; } List MorphList { get; } } public class ImportedFrame : IEnumerable { public string Name { get; set; } public float[] LocalRotation { get; set; } public float[] LocalPosition { get; set; } public float[] LocalScale { get; set; } public ImportedFrame Parent { get; set; } private List children; public ImportedFrame this[int i] => children[i]; public int Count => children.Count; public void InitChildren(int count) { children = new List(count); } public void AddChild(ImportedFrame obj) { children.Add(obj); obj.Parent = this; } public void InsertChild(int i, ImportedFrame obj) { children.Insert(i, obj); obj.Parent = this; } public void RemoveChild(ImportedFrame obj) { obj.Parent = null; children.Remove(obj); } public void RemoveChild(int i) { children[i].Parent = null; children.RemoveAt(i); } public int IndexOf(ImportedFrame obj) { return children.IndexOf(obj); } public void ClearChild() { children.Clear(); } public IEnumerator GetEnumerator() { return children.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public class ImportedMesh { public string Name { get; set; } public List SubmeshList { get; set; } public List BoneList { get; set; } } public class ImportedSubmesh { public List VertexList { get; set; } public List FaceList { get; set; } public string Material { get; set; } } public class ImportedVertex { public Vector3 Position { get; set; } public float[] Weights { get; set; } public byte[] BoneIndices { get; set; } public Vector3 Normal { get; set; } public float[] UV { get; set; } public Vector4 Tangent { get; set; } } public class ImportedVertexWithColour : ImportedVertex { public Color4 Colour { get; set; } } public class ImportedFace { public int[] VertexIndices { get; set; } } public class ImportedBone { public string Name { get; set; } public float[,] Matrix { get; set; } } public class ImportedMaterial { public string Name { get; set; } public Color4 Diffuse { get; set; } public Color4 Ambient { get; set; } public Color4 Specular { get; set; } public Color4 Emissive { get; set; } public float Power { get; set; } public string[] Textures { get; set; } public Vector2[] TexOffsets { get; set; } public Vector2[] TexScales { get; set; } } public class ImportedTexture { public string Name { get; set; } public byte[] Data { get; set; } public ImportedTexture(MemoryStream stream, string name) { Name = name; Data = stream.ToArray(); } } public class ImportedKeyframedAnimation { public string Name { get; set; } public List TrackList { get; set; } public ImportedAnimationKeyframedTrack FindTrack(string name) { var track = TrackList.Find(x => x.Name == name); if (track == null) { track = new ImportedAnimationKeyframedTrack { Name = name }; TrackList.Add(track); } return track; } } public class ImportedAnimationKeyframedTrack { public string Name { get; set; } public List> Scalings = new List>(); public List> Rotations = new List>(); public List> Translations = new List>(); public List> Curve = new List>(); } public class ImportedKeyframe { public float time { get; set; } public T value { get; set; } public ImportedKeyframe(float time, T value) { this.time = time; this.value = value; } } public class ImportedMorph { public string Name { get; set; } public string ClipName { get; set; } public List> Channels { get; set; } public List KeyframeList { get; set; } public List MorphedVertexIndices { get; set; } } public class ImportedMorphKeyframe { public string Name { get; set; } public List VertexList { get; set; } public List MorphedVertexIndices { get; set; } public float Weight { get; set; } } public static class ImportedHelpers { public static ImportedFrame FindFrame(string name, ImportedFrame root) { ImportedFrame frame = root; if ((frame != null) && (frame.Name == name)) { return frame; } for (int i = 0; i < root.Count; i++) { if ((frame = FindFrame(name, root[i])) != null) { return frame; } } return null; } public static ImportedMesh FindMesh(string frameName, List importedMeshList) { foreach (ImportedMesh mesh in importedMeshList) { if (mesh.Name == frameName) { return mesh; } } return null; } public static ImportedMesh FindMesh(ImportedFrame frame, List importedMeshList) { string framePath = frame.Name; ImportedFrame root = frame; while (root.Parent != null) { root = root.Parent; framePath = root.Name + "/" + framePath; } foreach (ImportedMesh mesh in importedMeshList) { if (mesh.Name == framePath) { return mesh; } } return null; } public static ImportedMaterial FindMaterial(string name, List importedMats) { foreach (ImportedMaterial mat in importedMats) { if (mat.Name == name) { return mat; } } return null; } public static ImportedTexture FindTexture(string name, List importedTextureList) { if (string.IsNullOrEmpty(name)) { return null; } foreach (ImportedTexture tex in importedTextureList) { if (tex.Name == name) { return tex; } } return null; } } }