public void ListSlots(WTModel parent) { for (int i = 0; i < TextureSlots.Length; i++) { int tId = TextureSlots[i]; string tName = "NULL"; if (tId >= 0) { if (parent.Textures.ContainsKey(tId)) { tName = parent.Textures[tId]; } else { Name = "INVALID"; } } Console.WriteLine($"{i}\t{tId}\t{tName}"); } }
public static WTModel ReadBinary(Stream stream) { var reader = new BinaryReader(stream); var returnModel = new WTModel(); //determine filetype bool isSceneFile = false; reader.BaseStream.Seek(24, SeekOrigin.Begin); float version = reader.ReadSingle(); if (version == 1f) { isSceneFile = true; } else { reader.BaseStream.Seek(0, SeekOrigin.Begin); version = reader.ReadSingle(); if (version != 1f) { throw new System.Exception($"Expected version 1.0, got version {version}. Either not a MDL/SCN file, or wrong version."); } } //read data int meshCount = reader.ReadInt32(); int lightCount = reader.ReadInt32(); int helperCount = reader.ReadInt32(); int splineCount = reader.ReadInt32(); int materialCount = reader.ReadInt32(); int textureCount = reader.ReadInt32(); //textures for (int i = 0; i < textureCount; i++) { string tex = reader.ReadNullTerminatedString(); int id = reader.ReadInt32(); returnModel.Textures.Add(id, tex); } //materials for (int i = 0; i < materialCount; i++) { var material = WTMaterial.ReadBinary(reader); returnModel.Materials.Add(material.ID, material); } //meshes for (int i = 0; i < meshCount; i++) { returnModel.Meshes.Add(WTMesh.ReadBinary(reader, isSceneFile)); } //lights for (int i = 0; i < lightCount; i++) { returnModel.Lights.Add(WTLight.ReadBinary(reader)); } //helpers for (int i = 0; i < helperCount; i++) { returnModel.Helpers.Add(WTHelper.ReadBinary(reader)); } //splines for (int i = 0; i < splineCount; i++) { returnModel.Splines.Add(WTSpline.ReadBinary(reader)); } reader.Dispose(); return(returnModel); }