internal static W3dAdaptiveDeltaAnimationChannel Parse(BinaryReader reader, W3dParseContext context, W3dAdaptiveDeltaBitCount bitCount) { return(ParseChunk(reader, context, header => { var result = new W3dAdaptiveDeltaAnimationChannel { NumTimeCodes = reader.ReadUInt32(), Pivot = reader.ReadUInt16(), VectorLength = reader.ReadByte(), ChannelType = reader.ReadByteAsEnum <W3dAnimationChannelType>(), Scale = reader.ReadSingle(), }; W3dAnimationChannel.ValidateChannelDataSize(result.ChannelType, result.VectorLength); result.Data = W3dAdaptiveDeltaData.Parse( reader, result.NumTimeCodes, result.ChannelType, result.VectorLength, bitCount); // Skip 3 unknown bytes at chunk end. reader.BaseStream.Seek(3, SeekOrigin.Current); return result; })); }
internal static W3dAnimationChannel Parse(BinaryReader reader, W3dParseContext context) { return(ParseChunk(reader, context, header => { var startPosition = reader.BaseStream.Position; var result = new W3dAnimationChannel { FirstFrame = reader.ReadUInt16(), LastFrame = reader.ReadUInt16(), VectorLength = reader.ReadUInt16(), ChannelType = reader.ReadUInt16AsEnum <W3dAnimationChannelType>(), Pivot = reader.ReadUInt16(), Unknown = reader.ReadUInt16() }; ValidateChannelDataSize(result.ChannelType, result.VectorLength); var numElements = result.LastFrame - result.FirstFrame + 1; var data = new W3dAnimationChannelDatum[numElements]; for (var i = 0; i < numElements; i++) { data[i] = W3dAnimationChannelDatum.Parse(reader, result.ChannelType); } result.Data = data; result.NumPadBytes = (uint)(context.CurrentEndPosition - reader.BaseStream.Position); reader.BaseStream.Seek((int)result.NumPadBytes, SeekOrigin.Current); return result; })); }
public static W3dAdaptiveDeltaAnimationChannel Parse(BinaryReader reader, int nBits) { var startPosition = reader.BaseStream.Position; var result = new W3dAdaptiveDeltaAnimationChannel { NumTimeCodes = reader.ReadUInt32(), Pivot = reader.ReadUInt16(), VectorLength = reader.ReadByte(), ChannelType = EnumUtility.CastValueAsEnum <byte, W3dAnimationChannelType>(reader.ReadByte()), Scale = reader.ReadSingle(), }; W3dAnimationChannel.ValidateChannelDataSize(result.ChannelType, result.VectorLength); result.Data = W3dAdaptiveDelta.ReadAdaptiveDelta(reader, result.NumTimeCodes, result.ChannelType, result.VectorLength, result.Scale, nBits); //Skip 3 unknown bytes at chunkend. Only set for quaternions. reader.BaseStream.Seek(3, SeekOrigin.Current); return(result); }
internal static W3dAnimation Parse(BinaryReader reader, W3dParseContext context) { return(ParseChunk(reader, context, header => { var result = new W3dAnimation(); ParseChunks(reader, context.CurrentEndPosition, chunkType => { switch (chunkType) { case W3dChunkType.W3D_CHUNK_ANIMATION_HEADER: result.Header = W3dAnimationHeader.Parse(reader, context); break; case W3dChunkType.W3D_CHUNK_ANIMATION_CHANNEL: result.Channels.Add(W3dAnimationChannel.Parse(reader, context)); break; case W3dChunkType.W3D_CHUNK_BIT_CHANNEL: result.Channels.Add(W3dBitChannel.Parse(reader, context)); break; default: throw CreateUnknownChunkException(chunkType); } }); return result; })); }
public static W3dAnimation Parse(BinaryReader reader, uint chunkSize) { var channels = new List <W3dAnimationChannel>(); var bitChannels = new List <W3dBitChannel>(); var finalResult = ParseChunk <W3dAnimation>(reader, chunkSize, (result, header) => { switch (header.ChunkType) { case W3dChunkType.W3D_CHUNK_ANIMATION_HEADER: result.Header = W3dAnimationHeader.Parse(reader); break; case W3dChunkType.W3D_CHUNK_ANIMATION_CHANNEL: channels.Add(W3dAnimationChannel.Parse(reader, header.ChunkSize)); break; case W3dChunkType.W3D_CHUNK_BIT_CHANNEL: bitChannels.Add(W3dBitChannel.Parse(reader, header.ChunkSize)); break; default: throw CreateUnknownChunkException(header); } }); finalResult.Channels = channels; finalResult.BitChannels = bitChannels; return(finalResult); }
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; })); }
public static W3dAnimationChannel Parse(BinaryReader reader, uint chunkSize) { var startPosition = reader.BaseStream.Position; var result = new W3dAnimationChannel { FirstFrame = reader.ReadUInt16(), LastFrame = reader.ReadUInt16(), VectorLength = reader.ReadUInt16(), ChannelType = reader.ReadUInt16AsEnum <W3dAnimationChannelType>(), Pivot = reader.ReadUInt16() }; reader.ReadUInt16(); // Pad ValidateChannelDataSize(result.ChannelType, result.VectorLength); var numElements = result.LastFrame - result.FirstFrame + 1; var data = new W3dAnimationChannelDatum[numElements]; for (var i = 0; i < numElements; i++) { data[i] = W3dAnimationChannelDatum.Parse(reader, result.ChannelType); } result.Data = data; // Pad var endPosition = startPosition + chunkSize; reader.ReadBytes((int)(endPosition - reader.BaseStream.Position)); return(result); }
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: // TODO reader.ReadBytes((int)(startPosition + chunkSize - reader.BaseStream.Position)); break; case W3dMotionChannelDeltaType.Delta8: // TODO reader.ReadBytes((int)(startPosition + chunkSize - reader.BaseStream.Position)); break; default: throw new InvalidDataException(); } return(result); }
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; })); }
public static W3dAdaptiveDeltaAnimationChannel Parse(BinaryReader reader, uint chunkSize) { var startPosition = reader.BaseStream.Position; var result = new W3dAdaptiveDeltaAnimationChannel { NumTimeCodes = reader.ReadUInt32(), Pivot = reader.ReadUInt16(), VectorLength = reader.ReadByte(), ChannelType = EnumUtility.CastValueAsEnum <byte, W3dAnimationChannelType>(reader.ReadByte()), Scale = reader.ReadSingle() }; W3dAnimationChannel.ValidateChannelDataSize(result.ChannelType, result.VectorLength); // TODO reader.ReadBytes((int)(startPosition + chunkSize - reader.BaseStream.Position)); return(result); }
public static W3dTimeCodedAnimationChannel Parse(BinaryReader reader) { var startPosition = reader.BaseStream.Position; var result = new W3dTimeCodedAnimationChannel { NumTimeCodes = reader.ReadUInt32(), Pivot = reader.ReadUInt16(), VectorLength = reader.ReadByte(), ChannelType = (W3dAnimationChannelType)reader.ReadByte() }; W3dAnimationChannel.ValidateChannelDataSize(result.ChannelType, result.VectorLength); var data = new W3dTimeCodedDatum[result.NumTimeCodes]; for (var i = 0; i < result.NumTimeCodes; i++) { var datum = new W3dTimeCodedDatum(); datum.TimeCode = reader.ReadUInt32(); // MSB is used to indicate a binary (non interpolated) movement if ((datum.TimeCode >> 31) == 1) { // TODO: non-interpolated movement. datum.TimeCode &= ~(1 << 31); } datum.Value = W3dAnimationChannelDatum.Parse(reader, result.ChannelType); data[i] = datum; } result.Data = data; return(result); }