public static W3dShaderMaterialProperty Parse(BinaryReader reader, uint chunkSize)
        {
            var result = new W3dShaderMaterialProperty
            {
                PropertyType = reader.ReadUInt32AsEnum <W3dShaderMaterialPropertyType>(),
                PropertyName = reader.ReadFixedLengthString((int)reader.ReadUInt32())
            };

            var value = new W3dShaderMaterialPropertyValue();

            switch (result.PropertyType)
            {
            case W3dShaderMaterialPropertyType.Texture:
                result.StringValue = reader.ReadFixedLengthString((int)reader.ReadUInt32());
                break;

            case W3dShaderMaterialPropertyType.Float:
                value.Float = reader.ReadSingle();
                break;

            case W3dShaderMaterialPropertyType.Vector2:
                value.Vector2 = reader.ReadVector2();
                break;

            case W3dShaderMaterialPropertyType.Vector3:
                value.Vector3 = reader.ReadVector3();
                break;

            case W3dShaderMaterialPropertyType.Color:
                value.Color = reader.ReadColorRgbaF();
                break;

            case W3dShaderMaterialPropertyType.Int:
                value.Int = reader.ReadInt32();
                break;

            case W3dShaderMaterialPropertyType.Bool:
                value.Bool = reader.ReadBooleanChecked();
                break;

            default:
                throw new InvalidDataException();
            }

            result.Value = value;

            return(result);
        }
Ejemplo n.º 2
0
        internal static W3dShaderMaterialProperty Parse(BinaryReader reader, W3dParseContext context)
        {
            return(ParseChunk(reader, context, header =>
            {
                var result = new W3dShaderMaterialProperty
                {
                    PropertyType = reader.ReadUInt32AsEnum <W3dShaderMaterialPropertyType>(),
                    PropertyName = reader.ReadFixedLengthString((int)reader.ReadUInt32())
                };

                var value = new W3dShaderMaterialPropertyValue();

                switch (result.PropertyType)
                {
                case W3dShaderMaterialPropertyType.Texture:
                    result.StringValue = reader.ReadFixedLengthString((int)reader.ReadUInt32());
                    break;

                case W3dShaderMaterialPropertyType.Float:
                case W3dShaderMaterialPropertyType.Vector2:
                case W3dShaderMaterialPropertyType.Vector3:
                case W3dShaderMaterialPropertyType.Vector4:
                case W3dShaderMaterialPropertyType.Int:
                case W3dShaderMaterialPropertyType.Bool:
                    value = W3dShaderMaterialPropertyValue.Parse(reader, result.PropertyType);
                    break;

                default:
                    throw new InvalidDataException();
                }

                result.Value = value;

                return result;
            }));
        }