Exemplo n.º 1
0
 //============================================================
 // <T>序列化多层数据。</T>
 //
 // @param output 输出流
 //============================================================
 public override void SerializeIndex(IOutput output)
 {
     base.Serialize(output);
     // 输出位图列表
     output.WriteInt16((short)_bitmaps.Count);
     foreach (FDrTextureBitmap bitmap in _bitmaps)
     {
         output.WriteInt8((sbyte)bitmap.TypeCd);
         output.WriteInt16((short)0);
         // 存储信息
         bitmap.Serialize(output);
         // 存储图片
         using (FIndexBitmap resource = new FIndexBitmap(bitmap.Image.Native)) {
             //resource.OptionAlpha = true;
             resource.OptionAlpha = false;
             output.WriteInt8((sbyte)bitmap.TypeCd);
             output.WriteInt16((short)0);
             //resource.SerializeUnpackIndexed(output, compressColor, pixelCount);
             resource.SerializeIndexed(output, EDrTexture.SplitColorCount, EDrTexture.SplitPixelCount);
         }
     }
 }
Exemplo n.º 2
0
 //============================================================
 // <T>序列化多层数据。</T>
 //
 // @param output 输出流
 //============================================================
 public override void Serialize(IOutput output)
 {
     base.Serialize(output);
     // 输出位图列表
     output.WriteInt16((short)_bitmaps.Count);
     foreach (FDrTextureBitmap bitmap in _bitmaps)
     {
         //// 存储图片
         //output.WriteInt8((sbyte)bitmap.TypeCd);
         //output.WriteInt16((short)bitmap.Index);
         //using (FDsBitmap merger = new FDsBitmap(bitmap.Image.Native)) {
         //   merger.Serialize(output);
         //}
         // 存储信息
         bitmap.Serialize(output);
         using (FIndexBitmap resource = new FIndexBitmap(bitmap.Image.Native)) {
             resource.OptionAlpha = true;
             output.WriteInt8((sbyte)bitmap.TypeCd);
             output.WriteInt16((short)bitmap.Index);
             resource.SerializeIndexed(output, EDrTexture.SplitColorCount, EDrTexture.SplitPixelCount);
         }
     }
 }
Exemplo n.º 3
0
        //============================================================
        // <T>序列化多层数据。</T>
        //
        // @param output 输出流
        //============================================================
        public override void SerializeIndex(IOutput output)
        {
            base.Serialize(output);
            // 输出位图列表
            output.WriteInt16((short)_bitmaps.Count);
            foreach (FDrTextureBitmap bitmap in _bitmaps)
            {
                bitmap.Serialize(output);
            }
            // 压缩颜色
            int         bitmapCount = 0;
            string      path        = RContent3dManager.TextureConsole.ResourceDirectory;
            FByteStream bytes       = new FByteStream();
            // 合并漫反射和透明纹理
            FDrTextureBitmap bitmapDiffuse = FindByTypeCd(EDrTexture.Diffuse);
            FDrTextureBitmap bitmapAlpha   = FindByTypeCd(EDrTexture.Alpha);

            if ((null != bitmapDiffuse) || (null != bitmapAlpha))
            {
                bitmapCount++;
                bytes.WriteInt8(EDrTexture.PackDiffuse);
                bytes.WriteInt16(0);
                using (FPngMerger merger = new FPngMerger()) {
                    if (null != bitmapDiffuse)
                    {
                        merger.LoadColorFile(path + bitmapDiffuse.Source);
                    }
                    if (null != bitmapAlpha)
                    {
                        merger.LoadAlphaFile(path + bitmapAlpha.Source);
                    }
                    Bitmap bitmap = merger.Merge();
                    using (FIndexBitmap resource = new FIndexBitmap(bitmap)) {
                        resource.OptionAlpha = true;
                        resource.SerializeIndexed(bytes, EDrTexture.SplitColorCount, EDrTexture.SplitPixelCount);
                    }
                }
            }
            // 合并法线和高光级别纹理
            FDrTextureBitmap bitmapNormal        = FindByTypeCd(EDrTexture.Normal);
            FDrTextureBitmap bitmapSpecularLevel = FindByTypeCd(EDrTexture.SpecularLevel);

            if ((null != bitmapNormal) || (null != bitmapSpecularLevel))
            {
                bitmapCount++;
                bytes.WriteInt8(EDrTexture.PackNormal);
                bytes.WriteInt16(0);
                using (FPngMerger merger = new FPngMerger()) {
                    if (null != bitmapNormal)
                    {
                        merger.LoadColorFile(path + bitmapNormal.Source);
                    }
                    if (null != bitmapSpecularLevel)
                    {
                        merger.LoadAlphaFile(path + bitmapSpecularLevel.Source);
                    }
                    Bitmap bitmap = merger.Merge();
                    using (FIndexBitmap resource = new FIndexBitmap(bitmap)) {
                        resource.OptionAlpha = true;
                        resource.SerializeIndexed(bytes, EDrTexture.SplitColorCount, EDrTexture.SplitPixelCount);
                    }
                }
            }
            // 合并高光和高度纹理
            FDrTextureBitmap bitmapSpecular = FindByTypeCd(EDrTexture.Specular);
            FDrTextureBitmap bitmapHeight   = FindByTypeCd(EDrTexture.Height);

            if ((null != bitmapSpecular) || (null != bitmapHeight))
            {
                bitmapCount++;
                bytes.WriteInt8(EDrTexture.PackSpecular);
                bytes.WriteInt16(0);
                using (FPngMerger merger = new FPngMerger()) {
                    if (null != bitmapSpecular)
                    {
                        merger.LoadColorFile(path + bitmapSpecular.Source);
                    }
                    if (null != bitmapHeight)
                    {
                        merger.LoadAlphaFile(path + bitmapHeight.Source);
                    }
                    Bitmap bitmap = merger.Merge();
                    using (FIndexBitmap resource = new FIndexBitmap(bitmap)) {
                        resource.OptionAlpha = true;
                        resource.SerializeIndexed(bytes, EDrTexture.SplitColorCount, EDrTexture.SplitPixelCount);
                    }
                }
            }
            // 合并透射和透射级别纹理
            FDrTextureBitmap bitmapTransmittanceColor = FindByTypeCd(EDrTexture.TransmittanceColor);
            FDrTextureBitmap bitmapTransmittanceLevel = FindByTypeCd(EDrTexture.TransmittanceLevel);

            if ((null != bitmapTransmittanceColor) || (null != bitmapTransmittanceLevel))
            {
                bitmapCount++;
                bytes.WriteInt8(EDrTexture.PackTransmittance);
                bytes.WriteInt16(0);
                using (FPngMerger merger = new FPngMerger()) {
                    if (null != bitmapTransmittanceColor)
                    {
                        merger.LoadColorFile(path + bitmapTransmittanceColor.Source);
                    }
                    if (null != bitmapTransmittanceLevel)
                    {
                        merger.LoadAlphaFile(path + bitmapTransmittanceLevel.Source);
                    }
                    Bitmap bitmap = merger.Merge();
                    using (FIndexBitmap resource = new FIndexBitmap(bitmap)) {
                        resource.OptionAlpha = true;
                        resource.SerializeIndexed(bytes, EDrTexture.SplitColorCount, EDrTexture.SplitPixelCount);
                    }
                }
            }
            // 合并其他纹理
            FDrTextureBitmap bitmapLight    = FindByTypeCd(EDrTexture.Light);
            FDrTextureBitmap bitmapReflect  = FindByTypeCd(EDrTexture.Reflect);
            FDrTextureBitmap bitmapRefract  = FindByTypeCd(EDrTexture.Refract);
            FDrTextureBitmap bitmapEmissive = FindByTypeCd(EDrTexture.Emissive);

            if ((null != bitmapLight) || (null != bitmapReflect) || (null != bitmapRefract) || (null != bitmapEmissive))
            {
                bitmapCount++;
                bytes.WriteInt8(EDrTexture.PackLight);
                bytes.WriteInt16(0);
                using (FPngMerger merger = new FPngMerger()) {
                    if (null != bitmapLight)
                    {
                        merger.LoadRFile(path + bitmapLight.Source);
                    }
                    if (null != bitmapReflect)
                    {
                        merger.LoadGFile(path + bitmapReflect.Source);
                    }
                    if (null != bitmapRefract)
                    {
                        merger.LoadBFile(path + bitmapRefract.Source);
                    }
                    if (null != bitmapEmissive)
                    {
                        merger.LoadAlphaFile(path + bitmapEmissive.Source);
                    }
                    Bitmap bitmap = merger.MergeAll();
                    using (FIndexBitmap resource = new FIndexBitmap(bitmap)) {
                        resource.OptionAlpha = true;
                        resource.SerializeIndexed(bytes, EDrTexture.SplitColorCount, EDrTexture.SplitPixelCount);
                    }
                }
            }
            // 输出环境纹理
            FDrTextureBitmap bitmapEnvironment = FindByTypeCd(EDrTexture.Environment);

            if (null != bitmapEnvironment)
            {
                bitmapCount++;
                bytes.WriteInt8(EDrTexture.Environment);
                bytes.WriteInt16(0);
                Bitmap bitmap     = new Bitmap(path + bitmapEnvironment.Source);
                int    size       = bitmap.Height;
                int    block      = bitmap.Width / bitmap.Height;
                Bitmap cubeBitmap = new Bitmap(bitmap.Height, bitmap.Width, PixelFormat.Format32bppArgb);
                using (Graphics g = Graphics.FromImage(cubeBitmap)) {
                    for (int n = 0; n < 6; n++)
                    {
                        g.DrawImage(bitmap,
                                    new Rectangle(0, size * n, size, size),
                                    new Rectangle(size * n, 0, size, size),
                                    GraphicsUnit.Pixel);
                    }
                }
                using (FIndexBitmap resource = new FIndexBitmap(cubeBitmap)) {
                    resource.OptionAlpha = true;
                    resource.SerializeIndexed(bytes, EDrTexture.SplitColorCount, EDrTexture.SplitPixelCount);
                }
                cubeBitmap.Dispose();
            }
            // 输出纹理列表
            output.WriteInt16((sbyte)bitmapCount);
            output.WriteBytes(bytes.Memory, 0, bytes.Length);
        }