Exemple #1
0
        public byte[] Debug_LookForDataAfterFixedStr(int size)
        {
            var dataCpy = new ByteChunk(ReadBytes(size));

            Index -= size;

            var str      = dataCpy.ReadFixedLength(size);
            var strClean = Util.SanatizeFixedString(str);

            dataCpy.Reset();
            dataCpy.Index = strClean.Length;
            var bytesAfterClean = dataCpy.ReadBytes(dataCpy.BytesLeft);
            var nonZeroBytes    = bytesAfterClean.Count(x => x != 0);

            if (nonZeroBytes != 0)
            {
                return(bytesAfterClean);
            }

            return(null);
        }
        public static AnimationFile Create(ByteChunk chunk)
        {
            if (chunk.BytesLeft == 0)
            {
                throw new Exception("Trying to load animation with no data, chunk size = 0");
            }
            var output = new AnimationFile();

            chunk.Reset();
            output.Header = GetAnimationHeader(chunk);

            var boneCount = chunk.ReadUInt32();

            output.Bones = new BoneInfo[boneCount];
            for (int i = 0; i < boneCount; i++)
            {
                var boneNameSize = chunk.ReadShort();
                output.Bones[i] = new BoneInfo()
                {
                    Name     = chunk.ReadFixedLength(boneNameSize),
                    ParentId = chunk.ReadInt32(),
                    Id       = i
                };
            }

            // Remapping tables, not sure how they really should be used, but this works.
            for (int i = 0; i < boneCount; i++)
            {
                int mappingValue = chunk.ReadInt32();
                output.TranslationMappings.Add(new AnimationBoneMapping(mappingValue));
            }

            for (int i = 0; i < boneCount; i++)
            {
                int mappingValue = chunk.ReadInt32();
                output.RotationMappings.Add(new AnimationBoneMapping(mappingValue));
            }

            // A single static frame - Can be inverse, a pose or empty. Not sure? Hand animations are stored here
            if (output.Header.AnimationType == 7)
            {
                var staticPosCount = chunk.ReadUInt32();
                var staticRotCount = chunk.ReadUInt32();
                if (staticPosCount != 0 || staticRotCount != 0)
                {
                    output.StaticFrame = ReadFrame(chunk, staticPosCount, staticRotCount);
                }
            }

            // Animation Data
            var animPosCount = chunk.ReadInt32();
            var animRotCount = chunk.ReadInt32();
            var frameCount   = chunk.ReadInt32();  // Always 3 when there is no data? Why?

            if (animPosCount != 0 || animRotCount != 0)
            {
                for (int i = 0; i < frameCount; i++)
                {
                    var frame = ReadFrame(chunk, (uint)animPosCount, (uint)animRotCount);
                    output.DynamicFrames.Add(frame);
                }
            }
            // ----------------------

            return(output);
        }