예제 #1
0
        private static Curves.LinearCurve CreateUncompressedLinearCurve(BinaryReaderEx reader, AnimatedComponent component, short count)
        {
            var result = new Curves.LinearCurve(component);

            System.Diagnostics.Trace.WriteLine("Found UncompressedLinearCurve but we don't parse them properly yet :(");

            reader.BaseStream.Position += 6 * count;
            return(result);
        }
예제 #2
0
        private static Curves.LinearCurve CreateCompressedLinearCurve(BinaryReaderEx reader, AnimatedComponent component, short count)
        {
            var result = new Curves.LinearCurve(component);

            bool  flag      = (count & 0x8000) != 0;
            int   numValues = count & 0x7FFF;
            float offset    = reader.ReadSingle(Endianness.BigEndian);
            float scale     = reader.ReadSingle(Endianness.BigEndian);
            var   lengths   = reader.ReadBytes(numValues);

            for (var i = 0; i < numValues; i++)
            {
                var length = lengths[i];
                if (length == 0)
                {
                    length = 1;
                }
                var indices = reader.ReadBytes(length);
                if (flag)
                {
                    for (var j = 0; j < length; j++)
                    {
                        ushort sval  = reader.ReadUInt16(Endianness.BigEndian);
                        bool   isNeg = (sval & 0x8000) != 0;
                        float  val   = (sval & 0x7FFF) / 32767.0f;
                        if (isNeg)
                        {
                            val = -val;
                        }
                        val = val * scale + offset;

                        Curves.LinearCurveValue curveVal = new Curves.LinearCurveValue()
                        {
                            Time  = (float)(indices[j] + 256 * i),
                            Value = val
                        };
                        result.Values.Add(curveVal);
                    }
                }
                else
                {
                    for (var j = 0; j < length; j++)
                    {
                        byte  sval  = reader.ReadByte();
                        bool  isNeg = (sval & 0x80) != 0;
                        float val   = (sval & 0x7F) / 127.0f;
                        if (isNeg)
                        {
                            val = -val;
                        }
                        val = val * scale + offset;
                        Curves.LinearCurveValue curveVal = new Curves.LinearCurveValue()
                        {
                            Time  = (float)(indices[j] + 256 * i),
                            Value = val
                        };
                        result.Values.Add(curveVal);
                    }
                }
            }

            // Align reader position to 4-byte boundary
            reader.BaseStream.Position = (reader.BaseStream.Position + 3) & 0x7FFFFFFFFFFFFFFC;

            return(result);
        }