Beispiel #1
0
        internal static W3dMotionChannel Parse(BinaryReader reader, W3dParseContext context)
        {
            return(ParseChunk(reader, context, header =>
            {
                var zero = reader.ReadByte();
                if (zero != 0)
                {
                    throw new InvalidDataException();
                }

                var result = new W3dMotionChannel
                {
                    DeltaType = reader.ReadByteAsEnum <W3dMotionChannelDeltaType>(),
                    VectorLength = reader.ReadByte(),
                    ChannelType = reader.ReadByteAsEnum <W3dAnimationChannelType>(),
                    NumTimeCodes = reader.ReadUInt16(),
                    Pivot = reader.ReadUInt16()
                };

                W3dAnimationChannel.ValidateChannelDataSize(result.ChannelType, result.VectorLength);

                switch (result.DeltaType)
                {
                case W3dMotionChannelDeltaType.TimeCoded:
                    result.Data = W3dMotionChannelTimeCodedData.Parse(reader, result.NumTimeCodes, result.ChannelType);
                    break;

                case W3dMotionChannelDeltaType.Delta4:
                    result.Data = W3dMotionChannelAdaptiveDeltaData.Parse(reader, result.NumTimeCodes, result.ChannelType, result.VectorLength, W3dAdaptiveDeltaBitCount.FourBits);
                    break;

                case W3dMotionChannelDeltaType.Delta8:
                    result.Data = W3dMotionChannelAdaptiveDeltaData.Parse(reader, result.NumTimeCodes, result.ChannelType, result.VectorLength, W3dAdaptiveDeltaBitCount.EightBits);
                    break;

                default:
                    throw new InvalidDataException();
                }

                return result;
            }));
        }
Beispiel #2
0
        public static W3dMotionChannel Parse(BinaryReader reader, uint chunkSize)
        {
            var startPosition = reader.BaseStream.Position;

            var zero = reader.ReadByte();

            if (zero != 0)
            {
                throw new InvalidDataException();
            }

            var result = new W3dMotionChannel
            {
                DeltaType    = reader.ReadByteAsEnum <W3dMotionChannelDeltaType>(),
                VectorLength = reader.ReadByte(),
                ChannelType  = (W3dAnimationChannelType)reader.ReadByte(),
                NumTimeCodes = reader.ReadUInt16(),
                Pivot        = reader.ReadUInt16()
            };

            W3dAnimationChannel.ValidateChannelDataSize(result.ChannelType, result.VectorLength);

            switch (result.DeltaType)
            {
            case W3dMotionChannelDeltaType.TimeCoded:
                result.Data = W3dMotionChannelTimeCodedData.Parse(reader, result.NumTimeCodes, result.ChannelType);
                break;

            case W3dMotionChannelDeltaType.Delta4:
                result.Data = W3dMotionChannelAdaptiveDeltaData.Parse(reader, result.NumTimeCodes, result.ChannelType, result.VectorLength, 4);
                break;

            case W3dMotionChannelDeltaType.Delta8:
                result.Data = W3dMotionChannelAdaptiveDeltaData.Parse(reader, result.NumTimeCodes, result.ChannelType, result.VectorLength, 8);
                break;

            default:
                throw new InvalidDataException();
            }

            return(result);
        }