internal static FXShaderConstant Parse(BinaryReader reader, AssetImportCollection imports)
        {
            var result = new FXShaderConstant
            {
                Type = reader.ReadUInt32AsEnum <FXShaderConstantType>(),
                Name = reader.ReadUInt32PrefixedAsciiStringAtOffset()
            };

            var value = new W3dShaderMaterialPropertyValue();

            switch (result.Type)
            {
            case FXShaderConstantType.Float:
                var values = reader.ReadArrayAtOffset(() => reader.ReadSingle());
                result.FloatValueCount = (uint)values.Length;
                switch (values.Length)
                {
                case 1:
                    value.Float = values[0];
                    break;

                case 2:
                    value.Vector2 = new Vector2(values[0], values[1]);
                    break;

                case 3:
                    value.Vector3 = new Vector3(values[0], values[1], values[2]);
                    break;

                case 4:
                    value.Vector4 = new Vector4(values[0], values[1], values[2], values[3]);
                    break;

                default:
                    throw new InvalidDataException();
                }
                break;

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

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

            case FXShaderConstantType.Texture:
                result.TextureValue = imports.GetImportedData <TextureAsset>(reader);
                break;

            default:
                throw new InvalidDataException();
            }

            result.Value = value;

            return(result);
        }
Ejemplo n.º 2
0
        internal static FXShaderMaterial Parse(BinaryReader reader, AssetImportCollection imports)
        {
            return(new FXShaderMaterial
            {
                ShaderName = reader.ReadUInt32PrefixedAsciiStringAtOffset(),
                TechniqueName = reader.ReadUInt32PrefixedAsciiStringAtOffset(),

                Constants = reader.ReadArrayAtOffset(() => FXShaderConstant.Parse(reader, imports), true),

                TechniqueIndex = reader.ReadUInt32()
            });
        }