Exemplo n.º 1
0
        public Vector3 GetAbsolutePosition(SkinnedModelBone bone)
        {
            Vector3 current  = bone.Origin;
            int     parentId = bone.ParentIndex;

            while (parentId >= 0)
            {
                current += model.Bones[parentId].Origin;
                parentId = model.Bones[parentId].ParentIndex;
            }
            return(current);
        }
Exemplo n.º 2
0
        public static SkinnedModelBone ReadBinary(BinaryReader reader)
        {
            var returnBone = new SkinnedModelBone();

            returnBone.Name        = reader.ReadNullTerminatedString();
            returnBone.ParentIndex = reader.ReadInt32();
            returnBone.Origin      = reader.ReadVector3();

            Matrix3x3 mtx = new Matrix3x3();

            for (int i = 0; i < 3; i++)
            {
                float x = reader.ReadInt16() / 32767f;
                float y = reader.ReadInt16() / 32767f;
                float z = reader.ReadInt16() / 32767f;
                mtx.SetRow(i, new Vector3(x, y, z));
            }
            returnBone.Matrix = mtx;

            return(returnBone);
        }
Exemplo n.º 3
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);
        }