Пример #1
0
        public static TEnum ReadByteAsEnum <TEnum>(this BinaryReader reader)
            where TEnum : struct
        {
            var value = reader.ReadByte();

            return(EnumUtility.CastValueAsEnum <byte, TEnum>(value));
        }
Пример #2
0
        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);
        }
Пример #4
0
        public TEnum ToEnum <TEnum>() where TEnum : struct
        {
            if (Type != ValueType.Integer)
            {
                throw new InvalidOperationException();
            }

            return(EnumUtility.CastValueAsEnum <int, TEnum>(_number));
        }
Пример #5
0
        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);
        }
Пример #6
0
 private static W3dVertexMappingType ConvertStageMapping(uint attributes, uint mask, int shift)
 {
     return(EnumUtility.CastValueAsEnum <uint, W3dVertexMappingType>((attributes & mask) >> shift));
 }