コード例 #1
0
        private void mnuExportDDS8_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (this.DataContext != null && this.DataContext.GetType() == typeof(RW4Section))
                {
                    RW4Section section = this.DataContext as RW4Section;
                    SporeMaster.RenderWare4.Texture textureSection = section.obj as SporeMaster.RenderWare4.Texture;

                    SaveFileDialog dlg = new SaveFileDialog();
                    dlg.Filter = "DirectDraw Surface .DDS|*.dds";
                    if (dlg.ShowDialog().GetValueOrDefault(false))
                    {
                        using (Stream stream = File.Create(dlg.FileName))
                        {
                            DXT8Image img = new DXT8Image();
                            img.Height      = textureSection.height;
                            img.Width       = textureSection.width;
                            img.TextureType = textureSection.textureType;
                            img.MipMaps     = (int)textureSection.mipmapInfo;

                            img.SetData(textureSection.texData.blob);

                            img.Write(stream);
                        }
                    }
                }
            }
            catch
            {
            }
        }
コード例 #2
0
        private void mnuImportDXT8_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt = "dds";
            dlg.Filter     = "DDS|*.dds";

            //get the section
            RW4Section section = this.DataContext as RW4Section;

            SporeMaster.RenderWare4.Texture textureSection = section.obj as SporeMaster.RenderWare4.Texture;

            //needs to be an 8.8.8.8 ARGB texture
            if (dlg.ShowDialog().GetValueOrDefault(false))
            {
                uint textureBlobNumber = textureSection.texData.section.Number;

                DXT8Image img = new DXT8Image();
                using (Stream strm = File.OpenRead(dlg.FileName))
                {
                    img.Read(strm);

                    var texture = new SporeMaster.RenderWare4.Texture()
                    {
                        width       = (ushort)img.Width,
                        height      = (ushort)img.Height,
                        mipmapInfo  = (uint)(0x120),
                        textureType = img.TextureType,
                        texData     = new TextureBlob()
                        {
                            blob = img.GetAsByteArray()
                        },
                        unk1 = 0x0121afec
                    };

                    texture.texData.section = new RW4Section()
                    {
                        Number = textureBlobNumber
                    };
                    texture.texData.section.obj = new TextureBlob()
                    {
                        blob = texture.texData.blob
                    };

                    section.obj = texture;

                    section.Changed();
                }
            }
        }