Example #1
0
        /// <summary>
        /// Reads a bone from a IOBuffer.
        /// </summary>
        /// <param name="reader">An IOBuffer instance used to read from a stream holding a skeleton.</param>
        /// <returns>A Bone instance.</returns>
        private Bone ReadBone(BCFReadProxy reader, bool bcf)
        {
            var bone = new Bone();

            if (!bcf)
            {
                bone.Unknown = reader.ReadInt32();
            }
            bone.Name       = reader.ReadPascalString();
            bone.ParentName = reader.ReadPascalString();
            bone.HasProps   = bcf || reader.ReadByte() > 0;
            if (bcf && bone.Name == "")
            {
                return(null);
            }
            if (bone.HasProps)
            {
                var propertyCount = reader.ReadInt32();
                var property      = new PropertyListItem();

                for (var i = 0; i < propertyCount; i++)
                {
                    var pairCount = reader.ReadInt32();
                    for (var x = 0; x < pairCount; x++)
                    {
                        property.KeyPairs.Add(new KeyValuePair <string, string>(
                                                  reader.ReadPascalString(),
                                                  reader.ReadPascalString()
                                                  ));
                    }
                }
                bone.Properties.Add(property);
            }

            var xx = -reader.ReadFloat();

            bone.Translation = new Vector3(
                xx,
                reader.ReadFloat(),
                reader.ReadFloat()
                );
            bone.Rotation = new Quaternion(
                reader.ReadFloat(),
                -reader.ReadFloat(),
                -reader.ReadFloat(),
                -reader.ReadFloat()
                );
            bone.CanTranslate = reader.ReadInt32();
            bone.CanRotate    = reader.ReadInt32();
            bone.CanBlend     = reader.ReadInt32();
            bone.WiggleValue  = reader.ReadFloat();
            bone.WigglePower  = reader.ReadFloat();
            return(bone);
        }
Example #2
0
        /// <summary>
        /// Reads an animation from a stream.
        /// </summary>
        /// <param name="stream">The Stream instance to read from.</param>
        public void Read(BCFReadProxy io, bool bcf)
        {
            if (!bcf)
            {
                var version = io.ReadUInt32();
            }

            if (bcf)
            {
                Name       = io.ReadPascalString();
                XSkillName = io.ReadPascalString();
            }
            else
            {
                Name = io.ReadLongPascalString();
            }
            Duration = io.ReadFloat();
            Distance = io.ReadFloat();
            IsMoving = (bcf)?((byte)io.ReadInt32()):io.ReadByte();

            TranslationCount = io.ReadUInt32();
            if (!bcf)
            {
                Translations = new Vector3[TranslationCount];
                for (var i = 0; i < TranslationCount; i++)
                {
                    Translations[i] = new Vector3
                    {
                        X = -io.ReadFloat(),
                        Y = io.ReadFloat(),
                        Z = io.ReadFloat()
                    };
                }
            }

            RotationCount = io.ReadUInt32();
            if (!bcf)
            {
                Rotations = new Quaternion[RotationCount];
                for (var i = 0; i < RotationCount; i++)
                {
                    Rotations[i] = new Quaternion
                    {
                        X = io.ReadFloat(),
                        Y = -io.ReadFloat(),
                        Z = -io.ReadFloat(),
                        W = -io.ReadFloat()
                    };
                }
            }

            var motionCount = io.ReadUInt32();

            Motions = new AnimationMotion[motionCount];
            for (var i = 0; i < motionCount; i++)
            {
                var motion = new AnimationMotion();
                if (!bcf)
                {
                    var unknown = io.ReadUInt32();
                }
                motion.BoneName              = io.ReadPascalString();
                motion.FrameCount            = io.ReadUInt32();
                motion.Duration              = io.ReadFloat();
                motion.HasTranslation        = (((bcf) ? io.ReadInt32() : io.ReadByte()) == 1);
                motion.HasRotation           = (((bcf) ? io.ReadInt32() : io.ReadByte()) == 1);
                motion.FirstTranslationIndex = io.ReadUInt32();
                motion.FirstRotationIndex    = io.ReadUInt32();

                var hasPropsList = bcf || io.ReadByte() == 1;
                if (hasPropsList)
                {
                    var propListCount = io.ReadUInt32();
                    var props         = new PropertyList[propListCount];
                    for (var x = 0; x < propListCount; x++)
                    {
                        props[x] = ReadPropertyList(io, bcf);
                    }
                    motion.Properties = props;
                }

                var hasTimeProps = bcf || io.ReadByte() == 1;
                if (hasTimeProps)
                {
                    var timePropsListCount = io.ReadUInt32();
                    var timePropsList      = new TimePropertyList[timePropsListCount];

                    for (var x = 0; x < timePropsListCount; x++)
                    {
                        var list           = new TimePropertyList();
                        var timePropsCount = io.ReadUInt32();
                        list.Items = new TimePropertyListItem[timePropsCount];
                        for (var y = 0; y < timePropsCount; y++)
                        {
                            var id = io.ReadUInt32();
                            list.Items[y] = new TimePropertyListItem {
                                ID         = id,
                                Properties = ReadPropertyList(io, bcf)
                            };
                        }
                        timePropsList[x] = list;
                    }
                    motion.TimeProperties = timePropsList;
                }

                Motions[i] = motion;
            }
        }