public void ImportTexture(ImageKeyFrame[] Keys, string TextureName) { if (ResourceNodes.ContainsKey(TextureName) || Type != BRESGroupType.Textures) { return; } GTXTextureImporter importer = new GTXTextureImporter(); List <GTXImporterSettings> settings = new List <GTXImporterSettings>(); foreach (var key in Keys) { settings.Add(FTEX.SetImporterSettings(key.Image, $"{TextureName}{key.Frame}")); } importer.LoadSettings(settings); if (importer.ShowDialog() == DialogResult.OK) { ImportTexture(settings); } settings.Clear(); GC.Collect(); Cursor.Current = Cursors.Default; }
public void ReplaceImage(Image image, string FileName) { GTXImporterSettings setting = SetImporterSettings(image, FileName); setting.MipSwizzle = Tex2Swizzle; setting.MipCountOriginal = (int)MipCount; GTXTextureImporter importer = new GTXTextureImporter(); importer.LoadSetting(setting); if (importer.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; if (setting.GenerateMipmaps && !setting.IsFinishedCompressing) { setting.DataBlockOutput.Clear(); setting.DataBlockOutput.Add(setting.GenerateMips()); } if (setting.DataBlockOutput != null) { var surface = GTXSwizzle.CreateGx2Texture(setting.DataBlockOutput[0], setting); surface.compSel = new byte[4]; surface.compSel[0] = (byte)setting.RedComp; surface.compSel[1] = (byte)setting.GreenComp; surface.compSel[2] = (byte)setting.BlueComp; surface.compSel[3] = (byte)setting.alphaRef; var tex = FromGx2Surface(surface, setting.TexName); UpdateTex(tex); texture.Name = Text; IsReplaced = true; Read(texture); LoadOpenGLTexture(); } else { MessageBox.Show("Something went wrong???"); } } if (IsEditorActive() && IsReplaced) { UpdateEditor(); } }
public void ReplaceImage(Image image, string FileName) { GTXImporterSettings setting = SetImporterSettings(image, FileName); GTXTextureImporter importer = new GTXTextureImporter(); if (Tex2Swizzle != 0) { setting.swizzle = Tex2Swizzle; } importer.LoadSetting(setting); if (importer.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; if (setting.GenerateMipmaps) { setting.DataBlockOutput.Clear(); setting.DataBlockOutput.Add(setting.GenerateMips()); } if (setting.DataBlockOutput != null) { var surface = setting.CreateGx2Texture(setting.DataBlockOutput[0]); var tex = FromGx2Surface(surface, setting); if (texture == null) { texture = new Texture(); } UpdateTex(tex); texture.Name = Text; IsEdited = true; Read(texture); LoadOpenGLTexture(); } else { MessageBox.Show("Something went wrong???"); } } if (IsEditorActive()) { UpdateEditor(); } }
public void ReplaceTexture(string FileName, TEX_FORMAT DefaultFormat = TEX_FORMAT.UNKNOWN, uint MipMapCount = 0, uint swizzlePattern = 0, TEX_FORMAT[] SupportedFormats = null, bool DisplayBc4AlphaSetting = false, bool IsSwizzleReadOnly = false, bool IsTileModeReadOnly = false, bool IsFormatReadOnly = false, bool flipTextureY = false) { string ext = System.IO.Path.GetExtension(FileName); ext = ext.ToLower(); if (ext == ".bftex") { texture.Import(FileName, ((BFRESGroupNode)Parent).GetResFileU()); texture.Name = Text; IsReplaced = true; Read(texture); if (IsEditorActive()) { UpdateEditor(); } return; } GTXImporterSettings setting = SetImporterSettings(FileName, DefaultFormat); setting.FlipY = flipTextureY; setting.MipSwizzle = Tex2Swizzle; setting.SwizzlePattern = swizzlePattern; GTXTextureImporter importer = new GTXTextureImporter(); importer.DisplayBC4Alpha = DisplayBc4AlphaSetting; importer.ReadOnlySwizzle = IsSwizzleReadOnly; importer.ReadOnlyTileMode = IsSwizzleReadOnly; importer.ReadOnlyFormat = IsFormatReadOnly; if (MipMapCount != 0) { setting.MipCount = MipMapCount; importer.OverrideMipCounter = true; } if (SupportedFormats != null) { importer.LoadSupportedFormats(SupportedFormats); } importer.LoadSetting(setting); if (ext == ".dds") { if (setting.DataBlockOutput != null) { var surface = GTXSwizzle.CreateGx2Texture(setting.DataBlockOutput[0], setting); var tex = FromGx2Surface(surface, setting.TexName); UpdateTex(tex); texture.Name = Text; IsReplaced = true; Read(texture); LoadOpenGLTexture(); LibraryGUI.UpdateViewport(); } } else { if (importer.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; UseBc4Alpha = setting.UseBc4Alpha; if (setting.GenerateMipmaps && !setting.IsFinishedCompressing) { setting.DataBlockOutput.Clear(); setting.DataBlockOutput.Add(setting.GenerateMips()); } if (setting.DataBlockOutput != null) { var surface = GTXSwizzle.CreateGx2Texture(setting.DataBlockOutput[0], setting); var tex = FromGx2Surface(surface, setting.TexName); UpdateTex(tex); texture.Name = Text; IsReplaced = true; Read(texture); LoadOpenGLTexture(); LibraryGUI.UpdateViewport(); } else { MessageBox.Show("Something went wrong???"); } } } if (IsEditorActive() && IsReplaced) { UpdateEditor(); } }
public void ImportTexture(string[] FileNames) { GTXTextureImporter importer = new GTXTextureImporter(); List <GTXImporterSettings> settings = new List <GTXImporterSettings>(); foreach (string name in FileNames) { string TextureName = Path.GetFileNameWithoutExtension(name); string ext = Path.GetExtension(name); ext = ext.ToLower(); if (ext == ".bftex") { FTEX ftex = new FTEX(); ftex.texture = new ResU.Texture(); ftex.texture.Import(name, GetResFileU()); ftex.IsEdited = true; ftex.Read(ftex.texture); AddNode(ftex); } else if (ext == ".dds" || ext == ".dds2") { FTEX ftex = new FTEX(); ftex.texture = new ResU.Texture(); GTXImporterSettings setting = FTEX.SetImporterSettings(name); if (setting.DataBlockOutput != null) { var surface = GTXSwizzle.CreateGx2Texture(setting.DataBlockOutput[0], setting); var tex = FTEX.FromGx2Surface(surface, setting.TexName); ftex.UpdateTex(tex); ftex.IsEdited = true; ftex.Read(ftex.texture); ftex.LoadOpenGLTexture(); AddNode(ftex); } } else { settings.Add(FTEX.SetImporterSettings(name)); } } if (settings.Count == 0) { importer.Dispose(); } else { importer.LoadSettings(settings); if (importer.ShowDialog() == DialogResult.OK) { ImportTexture(settings); settings.Clear(); GC.Collect(); Cursor.Current = Cursors.Default; } } }
public override void ReplaceAll() { FolderSelectDialog sfd = new FolderSelectDialog(); if (sfd.ShowDialog() == DialogResult.OK) { if (Type == BRESGroupType.Textures) { GTXTextureImporter importer = new GTXTextureImporter(); List <GTXImporterSettings> settings = new List <GTXImporterSettings>(); foreach (string file in System.IO.Directory.GetFiles(sfd.SelectedPath)) { string FileName = System.IO.Path.GetFileNameWithoutExtension(file); foreach (FTEX ftex in Nodes) { if (FileName == ftex.Text) { string ext = Path.GetExtension(file); ext = ext.ToLower(); if (ext == ".bftex") { ftex.texture = new ResU.Texture(); ftex.texture.Import(file, GetResFileU()); ftex.IsEdited = true; ftex.Read(ftex.texture); } else if (ext == ".dds" || ext == ".dds2") { GTXImporterSettings setting = FTEX.SetImporterSettings(file); if (setting.DataBlockOutput != null) { var surface = GTXSwizzle.CreateGx2Texture(setting.DataBlockOutput[0], setting); var tex = FTEX.FromGx2Surface(surface, setting.TexName); ftex.UpdateTex(tex); ftex.IsReplaced = true; ftex.Read(ftex.texture); ftex.LoadOpenGLTexture(); } } else { var setting = FTEX.SetImporterSettings(file); setting.MipCountOriginal = (int)ftex.MipCount; setting.Format = (GX2.GX2SurfaceFormat)FTEX.ConvertToGx2Format(ftex.Format); settings.Add(setting); } } } } if (settings.Count == 0) { importer.Dispose(); } else { importer.LoadSettings(settings); if (importer.ShowDialog() == DialogResult.OK) { foreach (var setting in settings) { foreach (FTEX ftex in Nodes) { if (setting.TexName == ftex.Text) { if (setting.GenerateMipmaps && !setting.IsFinishedCompressing) { setting.DataBlockOutput.Clear(); setting.DataBlockOutput.Add(setting.GenerateMips()); } if (setting.DataBlockOutput != null) { var surface = GTXSwizzle.CreateGx2Texture(setting.DataBlockOutput[0], setting); var tex = FTEX.FromGx2Surface(surface, setting.TexName); ftex.UpdateTex(tex); tex.Name = ftex.Text; ftex.IsEdited = true; ftex.Read(ftex.texture); ftex.LoadOpenGLTexture(); } else { MessageBox.Show("Something went wrong???"); } } } } settings.Clear(); GC.Collect(); Cursor.Current = Cursors.Default; } } } else { foreach (string file in System.IO.Directory.GetFiles(sfd.SelectedPath)) { string FileName = System.IO.Path.GetFileNameWithoutExtension(file); foreach (TreeNode node in Nodes) { if (node is STGenericWrapper) { if (FileName == node.Text) { ((STGenericWrapper)node).Replace(file); } } } } } } }
public override void Replace(string FileName) { string ext = System.IO.Path.GetExtension(FileName); ext = ext.ToLower(); if (ext == ".bftex") { texture.Import(FileName, ((BFRESGroupNode)Parent).GetResFileU()); texture.Name = Text; IsEdited = true; Read(texture); if (IsEditorActive()) { UpdateEditor(); } return; } GTXImporterSettings setting = SetImporterSettings(FileName); GTXTextureImporter importer = new GTXTextureImporter(); if (Tex2Swizzle != 0) { setting.swizzle = Tex2Swizzle; } importer.LoadSetting(setting); if (ext == ".dds") { if (setting.DataBlockOutput != null) { var surface = setting.CreateGx2Texture(setting.DataBlockOutput[0]); var tex = FromGx2Surface(surface, setting); UpdateTex(tex); texture.Name = Text; IsEdited = true; Read(texture); LoadOpenGLTexture(); } } else { if (importer.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; if (setting.GenerateMipmaps) { setting.DataBlockOutput.Clear(); setting.DataBlockOutput.Add(setting.GenerateMips()); } if (setting.DataBlockOutput != null) { var surface = setting.CreateGx2Texture(setting.DataBlockOutput[0]); var tex = FromGx2Surface(surface, setting); UpdateTex(tex); texture.Name = Text; IsEdited = true; Read(texture); LoadOpenGLTexture(); } else { MessageBox.Show("Something went wrong???"); } } } if (IsEditorActive()) { UpdateEditor(); } }