Пример #1
0
        internal BulkDataInfo FindCompressedDataHeader(Mipmap mipmap)
        {
            BulkDataInfo info = bulk[mipmap.MipIdx];

            if (info.Width == mipmap.Width && info.Height == mipmap.Height ||
                info.Width == 4 && mipmap.Width < 4 && info.Height == 4 && mipmap.Height < 4)
            {
                return(info);
            }
            throw new Exception("BulkDataInfo for specified mipmap was not found.");
        }
Пример #2
0
        internal void ReplaceTexture(Texture2D texture, DDSFile dds)
        {
            for (int mipId = 0; mipId < dds.MipmapCount; mipId++)
            {
                Mipmap mipmap = dds.GetMipmap(mipId);
                Texture2D.BulkDataInfo info = texture.FindCompressedDataHeader(mipmap);;
                if (info.Format == 16)
                {
                    mipmap.Compress();
                }

                if (mipmap.CompressedSize > info.CompressedSize)
                {
                    throw new Exception("New DDS is larger than the old one");
                }

                //fs.Seek(info.OffsetInUpk - 8, SeekOrigin.Begin);
                //writer.Write(Convert.ToInt32(mipmap.CompressedSize));
                fs.Seek(info.OffsetInUpk, SeekOrigin.Begin);
                writer.Write(mipmap.CompressedData);
                writer.Write(info.Footer);
            }
        }