Exemplo n.º 1
0
 public BoneHierarchyResolver(WTSkinnedModel mdl)
 {
     this.model = mdl;
 }
Exemplo n.º 2
0
        public static WTSkinnedModel ReadBinary(Stream stream)
        {
            var reader = new BinaryReader(stream);

            //Header is 5 bytes long. V2.0 + a null byte
            int  headerMagic = reader.ReadInt32();
            byte nullByte    = reader.ReadByte();

            if (headerMagic != HEADER_MAGIC || nullByte != 0)
            {
                reader.Dispose();
                throw new Exception("Bad SMS header!");
            }
            reader.BaseStream.Seek(4, SeekOrigin.Current);

            //cosntruct model
            var returnModel = new WTSkinnedModel();

            int objectCount = reader.ReadInt32();
            int unkCount    = reader.ReadInt32();

            int tagCount      = 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);
            }

            //weird tag list
            for (int i = 0; i < tagCount; i++)
            {
                string item1 = reader.ReadNullTerminatedString();

                bool   hasPair2 = reader.ReadUInt16() != 0;
                string item2    = (hasPair2) ? reader.ReadNullTerminatedString() : null;

                returnModel.UnkStringList.Add(new Tuple <string, string>(item1, item2));
            }

            for (int i = 0; i < objectCount; i++)
            {
                var obj = WTSkinnedObject.ReadBinary(reader);
                returnModel.Objects.Add(obj);
            }

            //read bone count
            int boneCount = reader.ReadInt32();

            for (int i = 0; i < boneCount; i++)
            {
                returnModel.Bones.Add(SkinnedModelBone.ReadBinary(reader));
            }

            reader.Dispose();
            return(returnModel);
        }