//============================================================ // <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)0); using (FRsBitmapTexture merger = new FRsBitmapTexture(bitmap.Image.Native)) { merger.Serialize(output); } } }
//============================================================ // <T>序列化多层数据。</T> // // @param output 输出流 //============================================================ public void Serialize2(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 (FRsBitmapTexture merger = new FRsBitmapTexture()) { if (null != bitmapDiffuse) { merger.LoadFile(path + bitmapDiffuse.Source, EBitmapChannels.RGB); } if (null != bitmapAlpha) { merger.LoadFileChannel(path + bitmapAlpha.Source, EBitmapChannel.R, EBitmapChannels.A); } merger.Serialize(bytes); } } // 合并法线和高光级别纹理 FDrTextureBitmap bitmapNormal = FindByTypeCd(EDrTexture.Normal); FDrTextureBitmap bitmapSpecularLevel = FindByTypeCd(EDrTexture.SpecularLevel); if ((null != bitmapNormal) || (null != bitmapSpecularLevel)) { bitmapCount++; bytes.WriteInt8(EDrTexture.PackNormal); bytes.WriteInt16(0); using (FRsBitmapTexture merger = new FRsBitmapTexture()) { if (null != bitmapNormal) { merger.LoadFile(path + bitmapNormal.Source, EBitmapChannels.RGB); } if (null != bitmapSpecularLevel) { merger.LoadFileChannel(path + bitmapSpecularLevel.Source, EBitmapChannel.R, EBitmapChannels.A); } merger.Serialize(bytes); } } // 合并高光和高度纹理 FDrTextureBitmap bitmapSpecular = FindByTypeCd(EDrTexture.Specular); FDrTextureBitmap bitmapHeight = FindByTypeCd(EDrTexture.Height); if ((null != bitmapSpecular) || (null != bitmapHeight)) { bitmapCount++; bytes.WriteInt8(EDrTexture.PackSpecular); bytes.WriteInt16(0); using (FRsBitmapTexture merger = new FRsBitmapTexture()) { if (null != bitmapSpecular) { merger.LoadFile(path + bitmapSpecular.Source, EBitmapChannels.RGB); } if (null != bitmapHeight) { merger.LoadFileChannel(path + bitmapHeight.Source, EBitmapChannel.R, EBitmapChannels.A); } merger.Serialize(bytes); } } // 合并透射和透射级别纹理 FDrTextureBitmap bitmapTransmittanceColor = FindByTypeCd(EDrTexture.TransmittanceColor); FDrTextureBitmap bitmapTransmittanceLevel = FindByTypeCd(EDrTexture.TransmittanceLevel); if ((null != bitmapTransmittanceColor) || (null != bitmapTransmittanceLevel)) { bitmapCount++; bytes.WriteInt8(EDrTexture.PackTransmittance); bytes.WriteInt16(0); using (FRsBitmapTexture merger = new FRsBitmapTexture()) { if (null != bitmapTransmittanceColor) { merger.LoadFile(path + bitmapTransmittanceColor.Source, EBitmapChannels.RGB); } if (null != bitmapTransmittanceLevel) { merger.LoadFileChannel(path + bitmapTransmittanceLevel.Source, EBitmapChannel.R, EBitmapChannels.A); } merger.Serialize(bytes); } } // 合并其他纹理 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 (FRsBitmapTexture merger = new FRsBitmapTexture()) { if (null != bitmapLight) { merger.LoadFileChannel(path + bitmapLight.Source, EBitmapChannel.R, EBitmapChannels.R); } if (null != bitmapReflect) { merger.LoadFileChannel(path + bitmapReflect.Source, EBitmapChannel.R, EBitmapChannels.G); } if (null != bitmapRefract) { merger.LoadFileChannel(path + bitmapRefract.Source, EBitmapChannel.R, EBitmapChannels.B); } if (null != bitmapEmissive) { merger.LoadFileChannel(path + bitmapEmissive.Source, EBitmapChannel.R, EBitmapChannels.A); } merger.Serialize(bytes); } } // 输出环境纹理 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; using (Bitmap cubeBitmap = new Bitmap(bitmap.Height, bitmap.Width, PixelFormat.Format32bppArgb)) { cubeBitmap.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution); 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 (FRsBitmapTexture merger = new FRsBitmapTexture(cubeBitmap)) { merger.Serialize(bytes); } } } // 输出纹理列表 output.WriteInt16((sbyte)bitmapCount); output.WriteBytes(bytes.Memory, 0, bytes.Length); }