예제 #1
0
        public static W3dTimeCodedBitChannel Parse(BinaryReader reader)
        {
            var startPosition = reader.BaseStream.Position;

            var result = new W3dTimeCodedBitChannel
            {
                NumTimeCodes = reader.ReadUInt32(),
                Pivot        = reader.ReadUInt16(),
                ChannelType  = (W3dBitChannelType)reader.ReadByte(),
                DefaultValue = reader.ReadBooleanChecked()
            };

            var data = new W3dTimeCodedBitDatum[result.NumTimeCodes];

            for (var i = 0; i < result.NumTimeCodes; i++)
            {
                var timecode = reader.ReadUInt32();

                // TODO: Verify this guess.
                var value = false;
                if ((timecode >> 31) == 1)
                {
                    value = true;

                    timecode &= ~(1 << 31);
                }

                data[i] = new W3dTimeCodedBitDatum
                {
                    TimeCode = timecode,
                    Value    = value
                };
            }

            result.Data = data;

            return(result);
        }
        internal static W3dTimeCodedBitChannel Parse(BinaryReader reader, W3dParseContext context)
        {
            return(ParseChunk(reader, context, header =>
            {
                var result = new W3dTimeCodedBitChannel
                {
                    NumTimeCodes = reader.ReadUInt32(),
                    Pivot = reader.ReadUInt16(),
                    ChannelType = reader.ReadByteAsEnum <W3dBitChannelType>(),
                    DefaultValue = reader.ReadBooleanChecked()
                };

                var data = new W3dTimeCodedBitDatum[result.NumTimeCodes];

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

                result.Data = data;

                return result;
            }));
        }
        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;
            }));
        }
예제 #4
0
        public static W3dCompressedAnimation Parse(BinaryReader reader, uint chunkSize)
        {
            var timeCodedChannels     = new List <W3dTimeCodedAnimationChannel>();
            var adaptiveDeltaChannels = new List <W3dAdaptiveDeltaAnimationChannel>();
            var timeCodedBitChannels  = new List <W3dTimeCodedBitChannel>();
            var motionChannels        = new List <W3dMotionChannel>();

            var finalResult = ParseChunk <W3dCompressedAnimation>(reader, chunkSize, (result, header) =>
            {
                switch (header.ChunkType)
                {
                case W3dChunkType.W3D_CHUNK_COMPRESSED_ANIMATION_HEADER:
                    result.Header = W3dCompressedAnimationHeader.Parse(reader);
                    break;

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

                    case W3dCompressedAnimationFlavor.AdaptiveDelta:
                        adaptiveDeltaChannels.Add(W3dAdaptiveDeltaAnimationChannel.Parse(reader, header.ChunkSize));
                        break;

                    default:
                        throw new InvalidDataException();
                    }
                    break;

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

                    default:
                        throw new InvalidDataException();
                    }
                    break;

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

                    default:
                        throw new InvalidDataException();
                    }
                    break;

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

            finalResult.TimeCodedChannels     = timeCodedChannels;
            finalResult.AdaptiveDeltaChannels = adaptiveDeltaChannels;
            finalResult.TimeCodedBitChannels  = timeCodedBitChannels;
            finalResult.MotionChannels        = motionChannels;

            return(finalResult);
        }