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 InitializeFromStream(string name, string displayName, Stream stream)
        {
            using (BinaryReader binaryReader = new BinaryReader(stream))
            {
                //Header
                byte[] magic = binaryReader.ReadBytes(4);

                if (magic[0] != 'D' ||
                    magic[1] != 'M' ||
                    magic[2] != 'O' ||
                    magic[3] != 'D')
                {
                    return(false);
                }

                Version = binaryReader.ReadUInt32();

                if (!Enum.IsDefined(typeof(ModelType), (int)Version))
                {
                    Debug.LogWarning("Could not decode model " + name + ". Unknown DME version " + Version);
                    return(false);
                }

                ModelType = (ModelType)Version;

                Name        = name;
                DisplayName = displayName;

                ModelHeaderOffset = binaryReader.ReadUInt32();

                //DMA
                Dma.LoadFromStream(binaryReader.BaseStream, TextureStrings, Materials);

                //Bounding Box
                Min = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                Max = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());

                //Meshes
                uint meshCount = binaryReader.ReadUInt32();

                for (int i = 0; i < meshCount; ++i)
                {
                    Mesh mesh = Mesh.LoadFromStream(binaryReader.BaseStream, 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 = binaryReader.ReadUInt32();

                for (int i = 0; i < boneMapCount; ++i)
                {
                    BoneMap boneMap = BoneMap.LoadFromStream(binaryReader.BaseStream);

                    if (boneMap != null)
                    {
                        BoneMaps.Add(boneMap);
                    }
                }

                //Bone Map Entries
                uint boneMapEntryCount = binaryReader.ReadUInt32();

                for (int i = 0; i < boneMapEntryCount; ++i)
                {
                    BoneMapEntry boneMapEntry = BoneMapEntry.LoadFromStream(binaryReader.BaseStream);

                    if (boneMapEntry != null)
                    {
                        BoneMapEntries.Add(boneMapEntry);
                    }
                }

                return(true);
            }
        }