Exemple #1
0
            public ANK1Section(EndianBinaryReader er, out bool OK)
            {
                bool OK1;

                this.Header = new DataBlockHeader(er, "ANK1", out OK1);
                if (!OK1)
                {
                    OK = false;
                }
                else
                {
                    this.LoopFlags         = er.ReadByte();
                    this.AngleMultiplier   = er.ReadByte();
                    this.AnimLength        = er.ReadUInt16();
                    this.NrJoints          = er.ReadUInt16();
                    this.NrScale           = er.ReadUInt16();
                    this.NrRot             = er.ReadUInt16();
                    this.NrTrans           = er.ReadUInt16();
                    this.JointOffset       = er.ReadUInt32();
                    this.ScaleOffset       = er.ReadUInt32();
                    this.RotOffset         = er.ReadUInt32();
                    this.TransOffset       = er.ReadUInt32();
                    er.BaseStream.Position = (long)(32U + this.ScaleOffset);
                    this.Scale             = er.ReadSingles((int)this.NrScale);
                    er.BaseStream.Position = (long)(32U + this.RotOffset);
                    this.Rotation          = er.ReadInt16s((int)this.NrRot);
                    er.BaseStream.Position = (long)(32U + this.TransOffset);
                    this.Translation       = er.ReadSingles((int)this.NrTrans);
                    float RotScale =
                        (float)(Math.Pow(2.0, (double)this.AngleMultiplier) *
                                Math.PI /
                                32768.0);
                    er.BaseStream.Position = (long)(32U + this.JointOffset);
                    this.Joints            = new AnimatedJoint[(int)this.NrJoints];
                    for (int index = 0; index < (int)this.NrJoints; ++index)
                    {
                        var animatedJoint = new AnimatedJoint(er);
                        animatedJoint.SetValues(this.Scale,
                                                this.Rotation,
                                                this.Translation,
                                                RotScale);
                        this.Joints[index] = animatedJoint;
                    }
                    OK = true;
                }
            }
Exemple #2
0
        private void LoadANK1FromStream(EndianBinaryReader reader, long tagStart)
        {
            LoopMode = (LoopType)reader.ReadByte();   // 0 = Play Once. 2 = Loop
            byte angleMultiplier = reader.ReadByte(); // Multiply Angle Value by pow(2, angleMultiplier)

            AnimLengthInFrames = reader.ReadInt16();
            short jointEntryCount          = reader.ReadInt16();
            short numScaleFloatEntries     = reader.ReadInt16();
            short numRotationShortEntries  = reader.ReadInt16();
            short numTranslateFloatEntries = reader.ReadInt16();
            int   jointDataOffset          = reader.ReadInt32();
            int   scaleDataOffset          = reader.ReadInt32();
            int   rotationDataOffset       = reader.ReadInt32();
            int   translateDataOffset      = reader.ReadInt32();

            // Read array of scale data
            float[] scaleData = new float[numScaleFloatEntries];
            reader.BaseStream.Position = tagStart + scaleDataOffset;
            for (int j = 0; j < numScaleFloatEntries; j++)
            {
                scaleData[j] = reader.ReadSingle();
            }

            // Read array of rotation data (but don't convert it)
            float[] rotationData = new float[numRotationShortEntries];
            reader.BaseStream.Position = tagStart + rotationDataOffset;
            for (int j = 0; j < numRotationShortEntries; j++)
            {
                rotationData[j] = reader.ReadInt16();
            }

            // Read array of translation/position data
            float[] translationData = new float[numTranslateFloatEntries];
            reader.BaseStream.Position = tagStart + translateDataOffset;
            for (int j = 0; j < numTranslateFloatEntries; j++)
            {
                translationData[j] = reader.ReadSingle();
            }

            // Read the data for each joint that this animation.
            m_animationData = new List <JointAnim>();
            float rotScale = (float)Math.Pow(2f, angleMultiplier) * (180 / 32768f);

            reader.BaseStream.Position = tagStart + jointDataOffset;
            for (int j = 0; j < jointEntryCount; j++)
            {
                AnimatedJoint animatedJoint = ReadAnimJoint(reader);
                JointAnim     joint         = new JointAnim();

                joint.ScalesX = ReadComp(scaleData, animatedJoint.X.Scale);
                joint.ScalesY = ReadComp(scaleData, animatedJoint.Y.Scale);
                joint.ScalesZ = ReadComp(scaleData, animatedJoint.Z.Scale);

                joint.RotationsX = ReadComp(rotationData, animatedJoint.X.Rotation);
                joint.RotationsY = ReadComp(rotationData, animatedJoint.Y.Rotation);
                joint.RotationsZ = ReadComp(rotationData, animatedJoint.Z.Rotation);

                // Convert all of the rotations from compressed shorts back into -180, 180
                ConvertRotation(joint.RotationsX, rotScale);
                ConvertRotation(joint.RotationsY, rotScale);
                ConvertRotation(joint.RotationsZ, rotScale);

                joint.TranslationsX = ReadComp(translationData, animatedJoint.X.Translation);
                joint.TranslationsY = ReadComp(translationData, animatedJoint.Y.Translation);
                joint.TranslationsZ = ReadComp(translationData, animatedJoint.Z.Translation);

                m_animationData.Add(joint);
            }
        }