public static TEnum ReadByteAsEnum <TEnum>(this BinaryReader reader) where TEnum : struct { var value = reader.ReadByte(); return(EnumUtility.CastValueAsEnum <byte, TEnum>(value)); }
public static TEnum ReadUInt16AsEnum <TEnum>(this BinaryReader reader) where TEnum : struct { var value = reader.ReadUInt16(); return(EnumUtility.CastValueAsEnum <ushort, TEnum>(value)); }
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); }
public TEnum ToEnum <TEnum>() where TEnum : struct { if (Type != ValueType.Integer) { throw new InvalidOperationException(); } return(EnumUtility.CastValueAsEnum <int, TEnum>(_number)); }
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); }
private static W3dVertexMappingType ConvertStageMapping(uint attributes, uint mask, int shift) { return(EnumUtility.CastValueAsEnum <uint, W3dVertexMappingType>((attributes & mask) >> shift)); }