Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="mat"></param>
        public static void ReadShaderParams(XmlWriter writer, Material mat)
        {
            writer.WriteStartElement("ShaderParams");

            if (mat.ShaderParamData == null)
            {
                return;
            }

            BinaryDataReader reader = new BinaryDataReader(new System.IO.MemoryStream(mat.ShaderParamData));

            reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
            foreach (ShaderParam param in mat.ShaderParams.Values)
            {
                writer.WriteStartElement("ShaderParam");

                writer.WriteAttributeString("Type", param.Type.ToString());
                writer.WriteAttributeString("Name", param.Name);
                writer.WriteAttributeString("HasPadding", param.UsePadding.ToString());
                writer.WriteAttributeString("PaddingLength", param.PaddingLength.ToString());
                writer.WriteAttributeString("DependedIndex", param.DependedIndex.ToString());
                writer.WriteAttributeString("DependIndex", param.DependIndex.ToString());

                reader.Seek(param.DataOffset, System.IO.SeekOrigin.Begin);
                WriteValue(writer, reader, (int)param.DataSize, param.Type);


                writer.WriteEndElement();
            }
            reader.Close();
            writer.WriteEndElement();
        }
Exemplo n.º 2
0
        public override void Convert(ResourceLocation source, ResourceLocation dest)
        {
            ContentBinaryReader br = new ContentBinaryReader(source);

            BinaryDataReader data      = br.ReadBinaryData();
            float            xllcorner = data.GetDataSingle("xllcorner");
            float            yllcorner = data.GetDataSingle("yllcorner");

            int width  = data.GetDataInt32("width");
            int height = data.GetDataInt32("height");

            float[] demData = new float[height * width];


            int bits = data.GetDataInt32("bits", 32);

            ContentBinaryReader br2 = data.GetData("data");

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    demData[i * width + j] = br2.ReadSingle();
                }
            }

            br2.Close();

            data.Close();


            Half[] demData16 = Half.ConvertToHalf(demData);

            // =========================================================


            BinaryDataWriter result = new BinaryDataWriter();

            result.AddEntry("xllcorner", xllcorner);
            result.AddEntry("yllcorner", yllcorner);
            result.AddEntry("width", width);
            result.AddEntry("height", height);

            result.AddEntry("bits", 16);

            Stream dataStream = result.AddEntryStream("data");

            ContentBinaryWriter bw = new ContentBinaryWriter(dataStream);

            for (int i = 0; i < demData.Length; i++)
            {
                bw.Write(demData16[i].InternalValue);
            }

            bw.Close();

            bw = new ContentBinaryWriter(dest);
            bw.Write(result);
            bw.Close();
        }
Exemplo n.º 3
0
        public void Load(BinaryDataReader reader)
        {
            reader.Seek(0);
            string Magic = reader.ReadString(4);

            Console.WriteLine(Magic);
            if (Magic != "DDS ")
            {
                MessageBox.Show("The file does not appear to be a valid DDS file.");
            }

            header        = new Header();
            header.size   = reader.ReadUInt32();
            header.flags  = reader.ReadUInt32();
            header.height = reader.ReadUInt32();
            header.width  = reader.ReadUInt32();


            header.pitchOrLinearSize = reader.ReadUInt32();
            header.depth             = reader.ReadUInt32();
            header.mipmapCount       = reader.ReadUInt32();
            header.reserved1         = new uint[11];
            for (int i = 0; i < 11; ++i)
            {
                header.reserved1[i] = reader.ReadUInt32();
            }

            header.ddspf.size        = reader.ReadUInt32();
            header.ddspf.flags       = reader.ReadUInt32();
            header.ddspf.fourCC      = reader.ReadString(4);
            header.ddspf.RGBBitCount = reader.ReadUInt32();
            header.ddspf.RBitMask    = reader.ReadUInt32();
            header.ddspf.GBitMask    = reader.ReadUInt32();
            header.ddspf.BBitMask    = reader.ReadUInt32();
            header.ddspf.ABitMask    = reader.ReadUInt32();

            header.caps      = reader.ReadUInt32();
            header.caps2     = reader.ReadUInt32();
            header.caps3     = reader.ReadUInt32();
            header.caps4     = reader.ReadUInt32();
            header.reserved2 = reader.ReadUInt32();

            int DX10HeaderSize = 0;

            if (header.ddspf.fourCC == "DX10")
            {
                DX10HeaderSize = 20;
                ReadDX10Header(reader);
            }

            reader.TemporarySeek((int)(4 + header.size + DX10HeaderSize), SeekOrigin.Begin);
            bdata = reader.ReadBytes((int)(reader.BaseStream.Length - reader.Position));



            reader.Dispose();
            reader.Close();
        }
Exemplo n.º 4
0
        public void Load(BinaryDataReader reader)
        {
            reader.Seek(0);
            string Magic = reader.ReadString(4);

            Console.WriteLine(Magic);
            if (Magic != "DDS ")
            {
                MessageBox.Show("The file does not appear to be a valid DDS file.");
            }

            header                   = new Header();
            header.size              = reader.ReadUInt32();
            header.flags             = reader.ReadUInt32();
            header.height            = reader.ReadUInt32();
            header.width             = reader.ReadUInt32();
            header.pitchOrLinearSize = reader.ReadUInt32();
            header.depth             = reader.ReadUInt32();
            header.mipmapCount       = reader.ReadUInt32();
            header.reserved1         = new uint[11];
            for (int i = 0; i < 11; ++i)
            {
                header.reserved1[i] = reader.ReadUInt32();
            }

            header.ddspf.size        = reader.ReadUInt32();
            header.ddspf.flags       = reader.ReadUInt32();
            header.ddspf.fourCC      = reader.ReadUInt32();
            header.ddspf.RGBBitCount = reader.ReadUInt32();
            header.ddspf.RBitMask    = reader.ReadUInt32();
            header.ddspf.GBitMask    = reader.ReadUInt32();
            header.ddspf.BBitMask    = reader.ReadUInt32();
            header.ddspf.ABitMask    = reader.ReadUInt32();

            header.caps      = reader.ReadUInt32();
            header.caps2     = reader.ReadUInt32();
            header.caps3     = reader.ReadUInt32();
            header.caps4     = reader.ReadUInt32();
            header.reserved2 = reader.ReadUInt32();

            int DX10HeaderSize = 0;

            if (header.ddspf.fourCC == FOURCC_DX10)
            {
                IsDX10 = true;

                DX10HeaderSize = 20;
                ReadDX10Header(reader);
            }

            if (IsCompressed())
            {
                imageSize = ((header.width + 3) >> 2) * ((header.height + 3) >> 2) * getFormatSize(header.ddspf.fourCC);
            }
            else
            {
                imageSize = header.width * header.height * getFormatSize(header.ddspf.fourCC);
            }

            reader.TemporarySeek((int)(4 + header.size + DX10HeaderSize), SeekOrigin.Begin);
            bdata = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position));

            reader.Dispose();
            reader.Close();

            ArrayCount = 1;
            MipCount   = header.mipmapCount;
            Width      = header.width;
            Height     = header.height;
            Format     = GetFormat();
        }