Ejemplo n.º 1
0
        //============================================================
        // <T>导出数据文件。</T>
        //
        // @param fileName 文件名称
        //============================================================
        public void ExportFile(string fileName)
        {
            FCompressFile file = new FCompressFile();

            Serialize(file);
            file.SaveFile(fileName);
        }
Ejemplo n.º 2
0
        //============================================================
        // <T>解压文件信息。</T>
        //
        // @param fileName 路径
        //============================================================
        public void UnserializeFile(string fileName)
        {
            FCompressFile file = new FCompressFile();

            file.Decompress(fileName);
            Unserialize(file);
        }
Ejemplo n.º 3
0
 //============================================================
 // <T>序列化资源信息。</T>
 //
 // @param output 流信息
 //============================================================
 public virtual void SerializeCompress(IOutput output, FXmlNode xconfig)
 {
     // 写入编号
     output.WriteString(_code);
     //............................................................
     output.WriteInt16((short)_resources.Count);
     foreach (FDrResource resource in _resources)
     {
         resource.Open();
         // 序列化资源
         FByteStream   data   = new FByteStream();
         FCompressFile stream = new FCompressFile();
         resource.Serialize(stream);
         stream.Compress(data);
         // 输出资源
         output.WriteInt32(data.Length);
         output.WriteBytes(data.Memory, 0, data.Length);
         //// 创建资源设置
         //if (null != xconfig) {
         //   FXmlNode xresources = xconfig.Sync("Resources");
         //   FXmlNode xresource = xresources.CreateNode("Resource");
         //   xresource.Set("code", resource.Code);
         //   xresource.Set("label", resource.Label);
         //   xresource.Set("type_name", resource.TypeName);
         //   xresource.Set("size", stream.Length);
         //   xresource.Set("size_compress", data.Length);
         //}
     }
 }
Ejemplo n.º 4
0
        //============================================================
        // <T>序列化信息文件。</T>
        //
        // @param fileName 路径
        //============================================================
        public void SerializeFile(string fileName)
        {
            FCompressFile file = new FCompressFile();

            Serialize(file);
            file.BlockCompress(fileName, RInt.SIZE_256K);
        }
Ejemplo n.º 5
0
        //============================================================
        // <T>导入打包文件。</T>
        //
        // @param fileName 文件名称
        //============================================================
        public void ImportFile(string fileName)
        {
            // 创建压缩文件
            FCompressFile file = new FCompressFile();

            file.Decompress(fileName);
            _bitmap = RestoreCompress(file);
        }
Ejemplo n.º 6
0
        //============================================================
        public void LoadFile(string fileName)
        {
            _logger.Debug(this, "LoadFile", "Load resource model file. (file_name={0})", fileName);
            FCompressFile file = new FCompressFile();

            file.BlockDecompress(fileName);
            Unserialize(file);
        }
Ejemplo n.º 7
0
        //============================================================
        // <T>根据指定模式导出数据到文件。</T>
        //
        // @param modeCd 导出模式
        // @param fileName 文件名称
        //============================================================
        public void ExportFile(ERsExportMode modeCd, string fileName)
        {
            FCompressFile file = new FCompressFile();

            Serialize(file);
            file.Compress(fileName);
            _logger.Debug(this, "Export", "Export model success. (file_name={0})", fileName);
        }
Ejemplo n.º 8
0
        //============================================================
        // <T>序列化内部数据到输出流中。</T>
        //
        // @param output 输出流
        //============================================================
        public byte[] CompressBytes()
        {
            Open();
            FByteStream   stream   = new FByteStream();
            FCompressFile compress = new FCompressFile();

            Serialize(compress);
            compress.Compress(stream);
            return(stream.ToArray());
        }
Ejemplo n.º 9
0
        //============================================================
        // <T>导出处理。</T>
        //============================================================
        public void Export()
        {
            Open();
            // 存储文件
            string        exportFileName = RContent3dManager.MaterialConsole.ExportDirectory + "\\mt_" + Code + ".swf";
            FCompressFile file           = new FCompressFile();

            Serialize(file);
            file.Compress(exportFileName);
            _logger.Debug(this, "Export", "Export material success. (file_name={0})", exportFileName);
            Dispose();
        }
Ejemplo n.º 10
0
        //============================================================
        // <T>序列化数据。</T>
        //============================================================
        public void ExportFile(string fileName)
        {
            // 打开
            Open();
            // 压缩文件
            FCompressFile file = new FCompressFile();

            Serialize(file);
            file.Compress(_exportFileName);
            _logger.Debug(this, "Export", "Export texture success. (file_name={0})", _exportFileName);
            // 释放资源
            Dispose();
        }
Ejemplo n.º 11
0
        //============================================================
        // <T>资源图片压缩。</T>
        //============================================================
        private void tsbImageCut_Click(object sender, EventArgs e)
        {
            _image = picBoxImage.BackgroundImage;
            int width  = _image.Width;
            int height = _image.Height;

            _bitMap = new Bitmap(_image);
            FCompressFile CompressFile = new FCompressFile();
            FRsBitmapJpg  dsBitmap     = new FRsBitmapJpg(_bitMap);

            dsBitmap.Serialize(CompressFile);
            SaveFilePath(CompressFile);
        }
Ejemplo n.º 12
0
        //============================================================
        // <T>序列化数据。</T>
        //============================================================
        public void Export()
        {
            // 加载高度图
            _heightData.LoadFile(_path + "/texture/" + _textureHeight);
            _colorData.LoadFile(_path + "/texture/" + _textureColor);
            for (int n = 1; n <= _layerCount; n++)
            {
                FBitmap layerBitmap = _layers[n - 1].Bitmap;
                layerBitmap.LoadFile(_path + "/texture/level-" + n + ".jpg");
            }
            //............................................................
            FCompressFile file = new FCompressFile();

            // 存储编号
            file.WriteUint32((uint)_id);
            // 存储层数
            file.WriteUint16((ushort)_layerCount);
            // 当前地图的宽度和高度
            file.WriteUint16((ushort)_size.Width);
            file.WriteUint16((ushort)_size.Height);
            // 当前范围的宽度和高度
            file.WriteUint16((ushort)_range.Width);
            file.WriteUint16((ushort)_range.Height);
            file.WriteFloat(_deep);
            // 存储材质列表
            file.WriteInt16((short)_layers.Count);
            foreach (FDrMapLayer layer in _layers)
            {
                string materialCode = RDrUtil.FormatPathToCode(layer.MaterialName);
                file.WriteInt16((short)layer.Index);
                file.WriteString(materialCode);
                FDrMaterialGroup material = RContent3dManager.MaterialConsole.FindGroup(layer.MaterialName);
                material.Serialize(file);
            }
            // 输出文件
            file.SaveFile(_exportFilePath + "\\config.swf");
            //............................................................
            // 导出地图块
            int cx = _size.Width / _range.Width;
            int cy = _size.Height / _range.Height;

            for (int y = 0; y < cy; y++)
            {
                for (int x = 0; x < cx; x++)
                {
                    ExportRange(x, y);
                }
            }
            // RangeIncise();
            _logger.Debug(this, "Export", "Export template success. (file_name={0})", _exportFileName);
        }
Ejemplo n.º 13
0
 //============================================================
 // <T>资源图片压缩路径。</T>
 //============================================================
 public void SaveFilePath(FCompressFile CompressFile)
 {
     saveFileDialogInfo.Filter                = "*.mrp|";
     saveFileDialogInfo.FilterIndex           = 1;
     this.saveFileDialogInfo.InitialDirectory = @"c:\";
     saveFileDialogInfo.RestoreDirectory      = true;
     saveFileDialogInfo.DefaultExt            = "mrp";
     if (saveFileDialogInfo.ShowDialog() == DialogResult.OK)
     {
         string fileName = this.saveFileDialogInfo.FileName;
         CompressFile.SaveFile(fileName);
         MessageBox.Show("压缩成功!");
     }
 }
Ejemplo n.º 14
0
 //============================================================
 // <T>序列化资源信息。</T>
 //
 // @param output 流信息
 //============================================================
 public virtual void Serialize(IOutput output)
 {
     // 写入编号
     output.WriteString(_code);
     //............................................................
     output.WriteInt16((short)_resources.Count);
     foreach (FRsResource resource in _resources)
     {
         resource.Open();
         // 序列化资源
         FCompressFile file = new FCompressFile();
         resource.Serialize(file);
         FByteStream stream = new FByteStream();
         file.Compress(stream);
         // 输出资源
         output.WriteInt32(stream.Length);
         output.WriteBytes(stream.Memory, 0, stream.Length);
     }
 }
Ejemplo n.º 15
0
        //============================================================
        // <T>导入设置信息。</T>
        //============================================================
        public void ImportConfig()
        {
            Dispose();
            // 加载设置文件
            string fileName = _directory + "\\import." + _techniqueName + ".xml";

            if (RFile.Exists(fileName))
            {
                LoadOrignConfig(new FXmlDocument(fileName).Root);
            }
            // 压缩文件
            FCompressFile file = new FCompressFile();

            Serialize(file);
            file.Compress(_exportFileName);
            _logger.Debug(this, "Export", "Export scene success. (file_name={0})", _exportFileName);
            // 存储信息
            Store();
            _logger.Debug(this, "Import", "Import scene success. (file_name={0})", fileName);
        }
Ejemplo n.º 16
0
 //============================================================
 // <T>序列化位图数据。</T>
 //
 // @params output     输出流
 // @params colorCount 调色板颜色数量
 // @params pixelCount 分块的像素个数
 //============================================================
 public bool Compress(IOutput output, int compressCd, int colorCount, int pixelCount)
 {
     // 保存数据
     using (FByteStream stream = new FByteStream()) {
         Serialize(stream, colorCount, pixelCount);
         // 压缩数据
         byte[] data = null;
         if (compressCd == ERsCompress.NoneValue)
         {
             data = stream.ToArray();
         }
         else if (compressCd == ERsCompress.DeflateValue)
         {
             //using(FRsCompressFile compress = new FRsCompressFile(ERsCompress.Deflate, stream, RResourceManager.CompressBlockSplit)) {
             using (FCompressFile compress = new FCompressFile(stream)) {
                 data = compress.Compress();
             }
             if (data.Length > stream.Length)
             {
                 compressCd = ERsCompress.NoneValue;
                 data       = stream.ToArray();
             }
         }
         else if (compressCd == ERsCompress.LzmaValue)
         {
             using (FLzmaFile compress = new FLzmaFile(stream)) {
                 data = compress.CompressNative();
             }
             if (data.Length > stream.Length)
             {
                 compressCd = ERsCompress.NoneValue;
                 data       = stream.ToArray();
             }
         }
         output.WriteInt32(compressCd);
         output.WriteInt32(data.Length);
         output.WriteBytes(data, 0, data.Length);
     }
     return(true);
 }
Ejemplo n.º 17
0
        //============================================================
        // <T>序列化数据。</T>
        //============================================================
        public void ExportRange(int cx, int cy)
        {
            FCompressFile file = new FCompressFile();

            // 存储编号
            file.WriteUint32((uint)_id);
            // 存储层数
            file.WriteUint16((ushort)_layerCount);
            // 当前地图的宽度和高度
            file.WriteUint16((ushort)_size.Width);
            file.WriteUint16((ushort)_size.Height);
            // 当前范围的宽度和高度
            file.WriteUint16((ushort)_range.Width);
            file.WriteUint16((ushort)_range.Height);
            file.WriteFloat(_deep);
            // 当前范围的位置坐标
            file.WriteUint16((ushort)cx);
            file.WriteUint16((ushort)cy);
            // 计算开始坐标
            int offsetX = _range.Width * cx;
            int offsetY = _range.Height * cy;
            // 输出数据
            int width  = _range.Width;
            int height = _range.Height;

            for (int y = 0; y <= height; y++)
            {
                for (int x = 0; x <= width; x++)
                {
                    //............................................................
                    // 计算坐标位置
                    int positionX = offsetX + x;
                    if (positionX >= _size.Width)
                    {
                        positionX = _size.Width - 1;
                    }
                    int positionY = _size.Height - (offsetY + y) - 1;
                    if (positionY < 0)
                    {
                        positionY = 0;
                    }
                    else if (positionY >= _size.Height)
                    {
                        positionY = _size.Height - 1;
                    }
                    int   positionHeight = 2 * (_size.Width * positionY + positionX);
                    float h = _heightData[positionHeight] + _heightData[positionHeight + 1] * 256;
                    // 计算点高度(1, 0)
                    SFloatVector3 tangent = new SFloatVector3(1, 0, 0);
                    if (positionX < _size.Width - 1)
                    {
                        int   tangentPosition = 2 * (_size.Width * positionY + (positionX) + 1);
                        float h1 = _heightData[tangentPosition] + _heightData[tangentPosition + 1] * 256;
                        float dx = (h1 - h) / 65535 * _deep;
                        tangent.Set(1, dx, 0);
                    }
                    tangent.Normalize();
                    // 计算点高度(0, 1)
                    SFloatVector3 binormal = new SFloatVector3(0, 0, 1);
                    if (positionY < _size.Height - 1)
                    {
                        int   binormalPosition = 2 * (_size.Width * (positionY + 1) + positionX);
                        float h2 = _heightData[binormalPosition] + _heightData[binormalPosition + 1] * 256;
                        float dy = (h2 - h) / 65535 * _deep;
                        binormal.Set(0, dy, 1);
                    }
                    binormal.Normalize();
                    // 计算法线
                    SFloatVector3 normal = new SFloatVector3();
                    binormal.Cross(tangent, normal);
                    normal.Normalize();
                    //............................................................
                    // 输出像素的高度
                    file.WriteUint8(_heightData[positionHeight]);
                    file.WriteUint8(_heightData[positionHeight + 1]);
                    // 输出像素的颜色
                    Color color = _colorData.Bitmap.GetPixel(positionX, positionY);
                    file.WriteUint8(color.R);
                    file.WriteUint8(color.G);
                    file.WriteUint8(color.B);
                    // 输出像素的法线
                    file.WriteUint8((byte)((normal.X + 1) * 0.5 * 255));
                    file.WriteUint8((byte)((normal.Y + 1) * 0.5 * 255));
                    file.WriteUint8((byte)((normal.Z + 1) * 0.5 * 255));
                    // 输出像素的层数据
                    for (int n = 0; n < _layerCount; n++)
                    {
                        FBitmap layerData  = _layers[n].Bitmap;
                        Color   layerColor = layerData.Bitmap.GetPixel(positionX, positionY);
                        file.WriteUint8(layerColor.R);
                    }
                }
            }
            // 输出文件
            string rangeFile = "tile_" + RInt.Pad(cx, 2) + "_" + RInt.Pad(cy, 2) + ".swf";

            file.SaveFile(_exportFilePath + "\\" + rangeFile);
        }
Ejemplo n.º 18
0
        //============================================================
        public void RangeIncise()
        {
            FCompressFile file   = new FCompressFile();
            int           height = _size.Height;
            int           width  = _size.Width;

            for (int y = 0; y <= height; y++)
            {
                for (int x = 0; x <= width; x++)
                {
                    //............................................................
                    // 计算坐标位置
                    int positionX = x;
                    if (positionX >= _size.Width)
                    {
                        positionX = _size.Width - 1;
                    }
                    int positionY = y;
                    if (positionY >= _size.Height)
                    {
                        positionY = _size.Height - 1;
                    }
                    int   positionHeight = 2 * (_size.Width * positionY + positionX);
                    float h = _heightData[positionHeight] + _heightData[positionHeight + 1] * 256;
                    // 计算点高度(1, 0)
                    SFloatVector3 tangent = new SFloatVector3(1, 0, 0);
                    if (positionX < _size.Width - 1)
                    {
                        int   tangentPosition = 2 * (_size.Width * positionY + (positionX) + 1);
                        float h1 = _heightData[tangentPosition] + _heightData[tangentPosition + 1] * 256;
                        float dx = (h1 - h) / 65535 * _deep;
                        tangent.Set(1, dx, 0);
                    }
                    tangent.Normalize();
                    // 计算点高度(0, 1)
                    SFloatVector3 binormal = new SFloatVector3(0, 0, 1);
                    if (positionY < _size.Height - 1)
                    {
                        int   binormalPosition = 2 * (_size.Width * (positionY + 1) + positionX);
                        float h2 = _heightData[binormalPosition] + _heightData[binormalPosition + 1] * 256;
                        float dy = (h2 - h) / 65535 * _deep;
                        binormal.Set(0, dy, 1);
                    }
                    binormal.Normalize();
                    // 计算法线
                    SFloatVector3 normal = new SFloatVector3();
                    binormal.Cross(tangent, normal);
                    normal.Normalize();
                    //............................................................
                    // 输出像素的高度
                    file.WriteUint8(_heightData[positionHeight]);
                    file.WriteUint8(_heightData[positionHeight + 1]);
                    // 输出像素的颜色
                    Color color = _colorData.Bitmap.GetPixel(positionX, positionY);
                    file.WriteUint8(color.R);
                    file.WriteUint8(color.G);
                    file.WriteUint8(color.B);
                    // 输出像素的法线
                    file.WriteUint8((byte)((normal.X + 1) * 0.5 * 255));
                    file.WriteUint8((byte)((normal.Y + 1) * 0.5 * 255));
                    file.WriteUint8((byte)((normal.Z + 1) * 0.5 * 255));
                    // 输出像素的层数据
                    for (int n = 0; n < _layerCount; n++)
                    {
                        FBitmap layerData  = _layers[n].Bitmap;
                        Color   layerColor = layerData.Bitmap.GetPixel(positionX, positionY);
                        file.WriteUint8(layerColor.R);
                    }
                    x += 8;
                }
                y += 8;
            }
            /*string rangeFile = "tile_" + RInt.Pad(x, 2) + "_" + RInt.Pad(cy, 2) + ".swf";         */
        }
Ejemplo n.º 19
0
        //============================================================
        // <T>压缩字节数据。</T>
        //
        // @return 字节数据
        //============================================================
        public byte[] CompressBytes()
        {
            byte[] data = null;
            // Deflate压缩
            string compressCd = _compressCd;

            switch (compressCd)
            {
            case ERsCompress.Deflate:
                using (FCompressFile file = new FCompressFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompress(_blockSize);
                    }
                    else
                    {
                        data = file.Compress();
                    }
                }
                break;

            case ERsCompress.Lzma:
                using (FLzmaFile file = new FLzmaFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompress(_blockSize);
                    }
                    else
                    {
                        data = file.Compress();
                    }
                }
                break;

            case ERsCompress.LzmaAlchemy:
                using (FLzmaFile file = new FLzmaFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompressNative(_blockSize);
                    }
                    else
                    {
                        data = file.CompressNative();
                    }
                }
                break;
            }
            // 检查大小,如果压缩后更大,则不压缩数据
            if (data.Length > _length)
            {
                data       = ToArray();
                compressCd = ERsCompress.None;
            }
            // 计算效验码
            _vertifyCode = RByte.ComputeHash32(data, 0, data.Length);
            // 写入文件
            byte[] result = null;
            using (FByteStream stream = new FByteStream()) {
                // 写入信息
                stream.WriteUint8((byte)ERsCompress.Parse(compressCd));
                stream.WriteInt32(_length);
                stream.WriteInt32(_vertifyCode);
                stream.WriteInt32(_blockSize);
                // 写入数据
                if ((ERsCompress.None != compressCd) && (_blockSize > 0))
                {
                    stream.WriteBytes(data, 0, data.Length);
                }
                else
                {
                    stream.WriteInt32(1);
                    stream.WriteInt32(data.Length);
                    stream.WriteBytes(data, 0, data.Length);
                }
                result = stream.ToArray();
            }
            return(result);
        }