using System; 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 : ObjChildren, IObjChild { public string Name { get; set; } public Matrix Matrix { get; set; } public dynamic Parent { get; set; } } 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 Matrix 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 abstract class ImportedAnimation { public string Name { get; set; } } public abstract class ImportedAnimationTrackContainer : ImportedAnimation where TrackType : ImportedAnimationTrack { public List TrackList { get; set; } public TrackType FindTrack(string name) { return TrackList.Find(track => track.Name == name); } } public class ImportedKeyframedAnimation : ImportedAnimationTrackContainer { } public class ImportedSampledAnimation : ImportedAnimationTrackContainer { public float SampleRate { get; set; } } public abstract class ImportedAnimationTrack { public string Name { get; set; } } public class ImportedKeyframe { public float time { get; set; } public T value { get; set; } public T inSlope { get; set; } public T outSlope { get; set; } public ImportedKeyframe(float time, T value, T inSlope, T outSlope) { this.time = time; this.value = value; this.inSlope = inSlope; this.outSlope = outSlope; } } public class ImportedAnimationKeyframedTrack : ImportedAnimationTrack { public List> Scalings = new List>(); public List> Rotations = new List>(); public List> Translations = new List>(); } public class ImportedAnimationSampledTrack : ImportedAnimationTrack { public Vector3?[] Scalings; public Vector3?[] Rotations; public Vector3?[] Translations; public float?[] Curve; } 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; } } }