internal static W3dTimeCodedAnimationChannel Parse(BinaryReader reader, W3dParseContext context)
        {
            return(ParseChunk(reader, context, header =>
            {
                var result = new W3dTimeCodedAnimationChannel
                {
                    NumTimeCodes = reader.ReadUInt32(),
                    Pivot = reader.ReadUInt16(),
                    VectorLength = reader.ReadByte(),
                    ChannelType = reader.ReadByteAsEnum <W3dAnimationChannelType>()
                };

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

                var data = new W3dTimeCodedDatum[result.NumTimeCodes];
                for (var i = 0; i < result.NumTimeCodes; i++)
                {
                    data[i] = W3dTimeCodedDatum.Parse(reader, result.ChannelType);
                }

                result.Data = data;

                return result;
            }));
        }
Esempio n. 2
0
        internal static W3dCompressedAnimation Parse(BinaryReader reader, W3dParseContext context)
        {
            return(ParseChunk(reader, context, header =>
            {
                var result = new W3dCompressedAnimation();

                ParseChunks(reader, context.CurrentEndPosition, chunkType =>
                {
                    switch (chunkType)
                    {
                    case W3dChunkType.W3D_CHUNK_COMPRESSED_ANIMATION_HEADER:
                        result.Header = W3dCompressedAnimationHeader.Parse(reader, context);
                        break;

                    case W3dChunkType.W3D_CHUNK_COMPRESSED_ANIMATION_CHANNEL:
                        switch (result.Header.Flavor)
                        {
                        case W3dCompressedAnimationFlavor.TimeCoded:
                            result.TimeCodedChannels.Add(W3dTimeCodedAnimationChannel.Parse(reader, context));
                            break;

                        case W3dCompressedAnimationFlavor.AdaptiveDelta4:
                            result.AdaptiveDeltaChannels.Add(W3dAdaptiveDeltaAnimationChannel.Parse(reader, context, W3dAdaptiveDeltaBitCount.FourBits));
                            break;

                        default:
                            throw new InvalidDataException();
                        }
                        break;

                    case W3dChunkType.W3D_CHUNK_COMPRESSED_BIT_CHANNEL:
                        switch (result.Header.Flavor)
                        {
                        case W3dCompressedAnimationFlavor.TimeCoded:
                            result.TimeCodedBitChannels.Add(W3dTimeCodedBitChannel.Parse(reader, context));
                            break;

                        default:
                            throw new InvalidDataException();
                        }
                        break;

                    case W3dChunkType.W3D_CHUNK_COMPRESSED_ANIMATION_MOTION_CHANNEL:
                        switch (result.Header.Flavor)
                        {
                        case W3dCompressedAnimationFlavor.TimeCoded:
                            result.MotionChannels.Add(W3dMotionChannel.Parse(reader, context));
                            break;

                        default:
                            throw new InvalidDataException();
                        }
                        break;

                    default:
                        throw CreateUnknownChunkException(chunkType);
                    }
                });

                return result;
            }));
        }