public static BoneMapEntry LoadFromStream(Stream stream) { if (stream == null) { return(null); } BinaryReader binaryReader = new BinaryReader(stream); BoneMapEntry boneMapEntry = new BoneMapEntry(); boneMapEntry.BoneIndex = binaryReader.ReadUInt16(); boneMapEntry.GlobalIndex = binaryReader.ReadUInt16(); return(boneMapEntry); }
public bool Deserialize(BinaryStream stream, AssetManager assetManager) { // Header string magic = stream.ReadString(4); Assert.AreEqual(MAGIC, magic, "Model File header does not match magic value!"); Version = stream.ReadUInt32(); if (!Enum.IsDefined(typeof(ModelType), (int)Version)) { Debug.LogWarning("Could not decode model " + Name + ". Unknown DME version " + Version); return(false); } ModelType = (ModelType)Version; ModelHeaderOffset = stream.ReadUInt32(); // DMA Dma.LoadFromStream(stream, TextureStrings, Materials); // Bounding Box Min = stream.ReadVector3(); Max = stream.ReadVector3(); // Meshes uint meshCount = stream.ReadUInt32(); for (int i = 0; i < meshCount; ++i) { Mesh mesh = Mesh.LoadFromStream(stream, Materials); if (mesh == null) { continue; } Material material = Materials[(int)mesh.MaterialIndex]; foreach (Material.Parameter parameter in material.Parameters) { LookupTextures(mesh, parameter, TextureStrings); if (mesh.BaseDiffuse != null && mesh.BumpMap != null && mesh.SpecMap != null) { break; } } Meshes.Add(mesh); } // Bone Maps uint boneMapCount = stream.ReadUInt32(); for (int i = 0; i < boneMapCount; ++i) { BoneMap boneMap = BoneMap.LoadFromStream(stream); if (boneMap != null) { BoneMaps.Add(boneMap); } } // Bone Map Entries uint boneMapEntryCount = stream.ReadUInt32(); for (int i = 0; i < boneMapEntryCount; ++i) { BoneMapEntry boneMapEntry = BoneMapEntry.LoadFromStream(stream); if (boneMapEntry != null) { BoneMapEntries.Add(boneMapEntry); } } return(true); }